Skip to content

Commit

Permalink
fix LHCInfoPer* PopCons to produce lumi type IOVs when running in dur…
Browse files Browse the repository at this point in the history
…ingFill mode
  • Loading branch information
francescobrivio committed Feb 14, 2024
1 parent c4e1915 commit b33550a
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 33 deletions.
21 changes: 21 additions & 0 deletions CondTools/RunInfo/interface/LHCInfoHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef CondTools_RunInfo_LHCInfoHelper_h
#define CondTools_RunInfo_LHCInfoHelper_h

#include "CondCore/CondDB/interface/Time.h"
#include "CondTools/RunInfo/interface/OMSAccess.h"

namespace cond {

namespace lhcInfoHelper {

// Large number of LS for the OMS query, covering around 25 hours
static constexpr unsigned int kLumisectionsQueryLimit = 4000;

// Returns lumi-type IOV from last LS of last Run of the specified Fill
cond::Time_t getFillLastLumiIOV(const cond::OMSService& oms, unsigned short fillId);

} // namespace lhcInfoHelper

} // namespace cond

#endif
42 changes: 25 additions & 17 deletions CondTools/RunInfo/plugins/LHCInfoPerFillPopConAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "CondFormats/Common/interface/TimeConversions.h"
#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h"
#include "CondTools/RunInfo/interface/LumiSectionFilter.h"
#include "CondTools/RunInfo/interface/LHCInfoHelper.h"
#include "CondTools/RunInfo/interface/OMSAccess.h"
#include "CoralBase/Attribute.h"
#include "CoralBase/AttributeList.h"
Expand All @@ -17,13 +18,6 @@
#include "RelationalAccess/IQuery.h"
#include "RelationalAccess/ISchema.h"
#include "RelationalAccess/ISessionProxy.h"
#include <cmath>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

class LHCInfoPerFillPopConSourceHandler;

Expand Down Expand Up @@ -255,8 +249,13 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
cond::Time_t lastSince = tagInfo().lastInterval.since;
if (tagInfo().isEmpty()) {
// for a new or empty tag, an empty payload should be added on top with since=1
addEmptyPayload(1);
lastSince = 1;
if (m_endFillMode) {
addEmptyPayload(1);
lastSince = 1;
} else {
addEmptyPayload(cond::time::lumiTime(1, 1));
lastSince = cond::time::lumiTime(1, 1);
}
} else {
edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
<< m_name << "::getNewObjects";
Expand Down Expand Up @@ -295,7 +294,6 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
session3.transaction().commit();
}

// bool iovAdded = false;
while (true) {
if (targetSince >= executionTimeIov) {
edm::LogInfo(m_name) << "Sampling ended at the time "
Expand Down Expand Up @@ -327,8 +325,6 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
foundFill = theLHCInfoPerFillImpl::makeFillPayload(m_fillPayload, query->result());
if (!foundFill) {
edm::LogInfo(m_name) << "No fill found - END of job.";
// if (iovAdded)
// addEmptyPayload(targetSince);
break;
}

Expand Down Expand Up @@ -367,9 +363,13 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
size_t niovs = theLHCInfoPerFillImpl::transferPayloads(m_tmpBuffer, m_iovs, m_prevPayload);
edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
m_tmpBuffer.clear();
// iovAdded = true;
if (m_prevPayload->fillNumber() and !ongoingFill)
addEmptyPayload(endFillTime);
if (m_prevPayload->fillNumber() and !ongoingFill) {
if (m_endFillMode) {
addEmptyPayload(endFillTime);
} else {
addEmptyPayload(cond::lhcInfoHelper::getFillLastLumiIOV(oms, lhcFill));
}
}
}
}

Expand Down Expand Up @@ -403,7 +403,14 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
auto delivLumi = row.get<float>("delivered_lumi");
auto recLumi = row.get<float>("recorded_lumi");
LHCInfoPerFill* thisLumiSectionInfo = m_fillPayload->cloneFill();
m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
if (m_endFillMode) {
m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
} else {
m_tmpBuffer.emplace_back(
std::make_pair(cond::time::lumiTime(std::stoull(row.get<std::string>("run_number")),
std::stoul(row.get<std::string>("lumisection_number"))),
thisLumiSectionInfo));
}
LHCInfoPerFill& payload = *thisLumiSectionInfo;
payload.setDelivLumi(delivLumi);
payload.setRecLumi(recLumi);
Expand All @@ -414,7 +421,8 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
const boost::posix_time::ptime& beginFillTime,
const boost::posix_time::ptime& endFillTime) {
auto query = oms.query("lumisections");
query->addOutputVars({"start_time", "delivered_lumi", "recorded_lumi", "beams_stable"});
query->addOutputVars(
{"start_time", "delivered_lumi", "recorded_lumi", "beams_stable", "run_number", "lumisection_number"});
query->filterEQ("fill_number", fillId);
query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime);
query->filterEQ("beams_stable", "true");
Expand Down
36 changes: 22 additions & 14 deletions CondTools/RunInfo/plugins/LHCInfoPerLSPopConAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "CondCore/PopCon/interface/PopConSourceHandler.h"
#include "CondFormats/Common/interface/TimeConversions.h"
#include "CondFormats/RunInfo/interface/LHCInfoPerLS.h"
#include "CondTools/RunInfo/interface/LHCInfoHelper.h"
#include "CondTools/RunInfo/interface/OMSAccess.h"
#include "CoralBase/Attribute.h"
#include "CoralBase/AttributeList.h"
Expand All @@ -17,15 +18,6 @@
#include "RelationalAccess/IQuery.h"
#include "RelationalAccess/ISchema.h"
#include "RelationalAccess/ISessionProxy.h"
#include <cmath>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using std::make_pair;
using std::pair;
Expand Down Expand Up @@ -173,8 +165,13 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
cond::Time_t lastSince = tagInfo().lastInterval.since;
if (tagInfo().isEmpty()) {
// for a new or empty tag, an empty payload should be added on top with since=1
addEmptyPayload(1);
lastSince = 1;
if (m_endFillMode) {
addEmptyPayload(1);
lastSince = 1;
} else {
addEmptyPayload(cond::time::lumiTime(1, 1));
lastSince = cond::time::lumiTime(1, 1);
}
} else {
edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
<< m_name << "::getNewObjects";
Expand Down Expand Up @@ -329,8 +326,13 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
}
m_tmpBuffer.clear();
m_lsIdMap.clear();
if (m_prevPayload->fillNumber() and !ongoingFill)
addEmptyPayload(m_endFillTime);
if (m_prevPayload->fillNumber() and !ongoingFill) {
if (m_endFillMode) {
addEmptyPayload(m_endFillTime);
} else {
addEmptyPayload(cond::lhcInfoHelper::getFillLastLumiIOV(oms, lhcFill));
}
}
}
}
std::string id() const override { return m_name; }
Expand Down Expand Up @@ -384,7 +386,13 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
thisLumiSectionInfo->setLumiSection(std::stoul(row.get<std::string>("lumisection_number")));
thisLumiSectionInfo->setRunNumber(std::stoull(row.get<std::string>("run_number")));
m_lsIdMap[make_pair(thisLumiSectionInfo->runNumber(), thisLumiSectionInfo->lumiSection())] = make_pair(-1, -1);
m_tmpBuffer.emplace_back(make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
if (m_endFillMode) {
m_tmpBuffer.emplace_back(make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
} else {
m_tmpBuffer.emplace_back(
make_pair(cond::time::lumiTime(thisLumiSectionInfo->runNumber(), thisLumiSectionInfo->lumiSection()),
thisLumiSectionInfo));
}
}

size_t bufferAllLS(const cond::OMSServiceResult& queryResult) {
Expand Down
8 changes: 7 additions & 1 deletion CondTools/RunInfo/python/LHCInfoPerFillPopConAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@
interval = cms.uint64(1)
)

# Write different time-types tags depending on the O2O mode
if options.mode == 'endFill':
timetype = 'timestamp'
else:
timetype = 'lumiid'

process.PoolDBOutputService = cms.Service("PoolDBOutputService",
CondDBConnection,
timetype = cms.untracked.string('timestamp'),
timetype = cms.untracked.string(timetype),
toPut = cms.VPSet(cms.PSet(record = cms.string('LHCInfoPerFillRcd'),
tag = cms.string( options.tag )
)
Expand Down
8 changes: 7 additions & 1 deletion CondTools/RunInfo/python/LHCInfoPerLSPopConAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@
interval = cms.uint64(1)
)

# Write different time-types tags depending on the O2O mode
if options.mode == 'endFill':
timetype = 'timestamp'
else:
timetype = 'lumiid'

process.PoolDBOutputService = cms.Service("PoolDBOutputService",
CondDBConnection,
timetype = cms.untracked.string('timestamp'),
timetype = cms.untracked.string(timetype),
toPut = cms.VPSet(cms.PSet(record = cms.string('LHCInfoPerLSRcd'),
tag = cms.string( options.tag )
)
Expand Down
30 changes: 30 additions & 0 deletions CondTools/RunInfo/src/LHCInfoHelper.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "CondTools/RunInfo/interface/LHCInfoHelper.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

//*****************************************************************
// Returns lumi-type IOV (packed using cond::time::lumiTime) from
// last LS of last Run of the specified Fill
//*****************************************************************
cond::Time_t cond::lhcInfoHelper::getFillLastLumiIOV(const cond::OMSService& oms, unsigned short fillId) {
// Define query
auto query = oms.query("lumisections");
query->addOutputVars({"lumisection_number", "run_number"});
query->filterEQ("fill_number", fillId);
query->limit(cond::lhcInfoHelper::kLumisectionsQueryLimit);

// Execute query
if (!query->execute()) {
throw cms::Exception("OMSQueryFailure")
<< "OMS query of fill " << fillId << " failed, status:" << query->status() << "\n";
}

// Get query result
auto queryResult = query->result();
if (queryResult.empty())
throw cms::Exception("OMSQueryFailure") << "OMS query of fill " << fillId << " returned empty result!\n";

// Return the final IOV
auto lastRun = queryResult.back().get<int>("run_number");
auto lastLumi = queryResult.back().get<unsigned short>("lumisection_number");
return cond::time::lumiTime(lastRun, lastLumi);
}

0 comments on commit b33550a

Please sign in to comment.