Skip to content

Commit

Permalink
fix assigning lumiid value to targetTime
Browse files Browse the repository at this point in the history
  • Loading branch information
francescobrivio committed Mar 1, 2024
1 parent 99900e3 commit 7aa6331
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 68 deletions.
60 changes: 24 additions & 36 deletions CondTools/RunInfo/plugins/LHCInfoPerFillPopConAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,10 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
: m_debug(pset.getUntrackedParameter<bool>("debug", false)),
m_startTime(),
m_endTime(),
m_samplingInterval((unsigned int)pset.getUntrackedParameter<unsigned int>("samplingInterval", 300)),
m_endFillMode(pset.getUntrackedParameter<bool>("endFill", true)),
m_name(pset.getUntrackedParameter<std::string>("name", "LHCInfoPerFillPopConSourceHandler")),
m_connectionString(pset.getUntrackedParameter<std::string>("connectionString", "")),
m_ecalConnectionString(pset.getUntrackedParameter<std::string>("ecalConnectionString", "")),
m_dipSchema(pset.getUntrackedParameter<std::string>("DIPSchema", "")),
m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
m_omsBaseUrl(pset.getUntrackedParameter<std::string>("omsBaseUrl", "")),
m_fillPayload(),
Expand All @@ -227,13 +225,10 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
m_endTime = now;
}
}
//L1: try with different m_dipSchema
//L2: try with different m_name

~LHCInfoPerFillPopConSourceHandler() override = default;
void getNewObjects() override {
//reference to the last payload in the tag
Ref previousFill;

void getNewObjects() override {
//if a new tag is created, transfer fake fill from 1 to the first fill for the first time
if (tagInfo().size == 0) {
edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
Expand Down Expand Up @@ -261,18 +256,6 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
<< m_name << "::getNewObjects";
}

boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
cond::Time_t targetSince = 0;
cond::Time_t executionTimeIov = cond::time::from_boost(executionTime);
if (!m_startTime.is_not_a_date_time()) {
targetSince = cond::time::from_boost(m_startTime);
}
if (lastSince > targetSince)
targetSince = lastSince;

edm::LogInfo(m_name) << "Starting sampling at "
<< boost::posix_time::to_simple_string(cond::time::to_boost(targetSince));

//retrieve the data from the relational database source
cond::persistency::ConnectionPool connection;
//configure the connection
Expand All @@ -294,27 +277,36 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
session3.transaction().commit();
}

boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
cond::Time_t executionTimeIov = cond::time::from_boost(executionTime);

cond::Time_t startTimestamp = m_startTime.is_not_a_date_time() ? 0 : cond::time::from_boost(m_startTime);
cond::Time_t nextFillSearchTimestamp =
std::max(startTimestamp, m_endFillMode ? lastSince : m_prevPayload->createTime());

edm::LogInfo(m_name) << "Starting sampling at "
<< boost::posix_time::to_simple_string(cond::time::to_boost(nextFillSearchTimestamp));

while (true) {
if (targetSince >= executionTimeIov) {
if (nextFillSearchTimestamp >= executionTimeIov) {
edm::LogInfo(m_name) << "Sampling ended at the time "
<< boost::posix_time::to_simple_string(cond::time::to_boost(executionTimeIov));
break;
}
bool updateEcal = false;
boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince);
boost::posix_time::ptime nextFillSearchTime = cond::time::to_boost(nextFillSearchTimestamp);
boost::posix_time::ptime startSampleTime;
boost::posix_time::ptime endSampleTime;

cond::OMSService oms;
oms.connect(m_omsBaseUrl);
auto query = oms.query("fills");

edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(nextFillSearchTime);
query->filterNotNull("start_stable_beam").filterNotNull("fill_number");
if (targetTime > cond::time::to_boost(m_prevPayload->createTime())) {
query->filterGE("start_time", targetTime);
if (nextFillSearchTime > cond::time::to_boost(m_prevPayload->createTime())) {
query->filterGE("start_time", nextFillSearchTime);
} else {
query->filterGT("start_time", targetTime);
query->filterGT("start_time", nextFillSearchTime);
}

query->filterLT("start_time", m_endTime);
Expand All @@ -337,12 +329,12 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at "
<< cond::time::to_boost(startFillTime);
endSampleTime = executionTime;
targetSince = executionTimeIov;
nextFillSearchTimestamp = executionTimeIov;
} else {
edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime)
<< " ending at " << cond::time::to_boost(endFillTime);
endSampleTime = cond::time::to_boost(endFillTime);
targetSince = endFillTime;
nextFillSearchTimestamp = endFillTime;
}
if (m_endFillMode || ongoingFill) {
getDipData(oms, startSampleTime, endSampleTime);
Expand All @@ -355,7 +347,7 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
getCTPPSData(session, startSampleTime, endSampleTime);
session.transaction().commit();
session2.transaction().start(true);
getEcalData(session2, startSampleTime, endSampleTime, updateEcal);
getEcalData(session2, startSampleTime, endSampleTime);
session2.transaction().commit();
}
}
Expand Down Expand Up @@ -636,8 +628,7 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC

bool getEcalData(cond::persistency::Session& session,
const boost::posix_time::ptime& lowerTime,
const boost::posix_time::ptime& upperTime,
bool update) {
const boost::posix_time::ptime& upperTime) {
//run the sixth query against the CMS_DCS_ENV_PVSS_COND schema
//Initializing the CMS_DCS_ENV_PVSS_COND schema.
coral::ISchema& ECAL = session.nominalSchema();
Expand Down Expand Up @@ -712,7 +703,7 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
}
changeTime = cond::time::from_boost(chTime);
cond::Time_t iovTime = changeTime;
if (!update and changeTime == firstTime)
if (changeTime == firstTime)
iovTime = lowerLumi;
coral::Attribute const& dipValAttribute = ECALDataCursor.currentRow()[std::string("DIP_value")];
coral::Attribute const& valueNumberAttribute = ECALDataCursor.currentRow()[std::string("VALUE_NUMBER")];
Expand All @@ -730,7 +721,6 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
theLHCInfoPerFillImpl::setElementData(it->first, dipVal, elementNr, value, payload, initializedVectors);
}
}
//}
}
}
}
Expand All @@ -748,13 +738,11 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
// starting date for sampling
boost::posix_time::ptime m_startTime;
boost::posix_time::ptime m_endTime;
// sampling interval in seconds
unsigned int m_samplingInterval;
bool m_endFillMode = true;
std::string m_name;
//for reading from relational database source
std::string m_connectionString, m_ecalConnectionString;
std::string m_dipSchema, m_authpath;
std::string m_authpath;
std::string m_omsBaseUrl;
std::unique_ptr<LHCInfoPerFill> m_fillPayload;
std::shared_ptr<LHCInfoPerFill> m_prevPayload;
Expand Down
50 changes: 22 additions & 28 deletions CondTools/RunInfo/plugins/LHCInfoPerLSPopConAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,16 @@ namespace theLHCInfoPerLSImpl {
}

} // namespace theLHCInfoPerLSImpl

class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCInfoPerLS> {
public:
LHCInfoPerLSPopConSourceHandler(edm::ParameterSet const& pset)
: m_debug(pset.getUntrackedParameter<bool>("debug", false)),
m_startTime(),
m_endTime(),
m_samplingInterval((unsigned int)pset.getUntrackedParameter<unsigned int>("samplingInterval", 300)),
m_endFillMode(pset.getUntrackedParameter<bool>("endFill", true)),
m_name(pset.getUntrackedParameter<std::string>("name", "LHCInfoPerLSPopConSourceHandler")),
m_connectionString(pset.getUntrackedParameter<std::string>("connectionString", "")),
m_dipSchema(pset.getUntrackedParameter<std::string>("DIPSchema", "")),
m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
m_omsBaseUrl(pset.getUntrackedParameter<std::string>("omsBaseUrl", "")),
m_fillPayload(),
Expand All @@ -146,9 +145,9 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
m_endTime = now;
}
}
//L1: try with different m_dipSchema
//L2: try with different m_name

~LHCInfoPerLSPopConSourceHandler() override = default;

void getNewObjects() override {
//if a new tag is created, transfer fake fill from 1 to the first fill for the first time
if (tagInfo().size == 0) {
Expand Down Expand Up @@ -177,18 +176,6 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
<< m_name << "::getNewObjects";
}

boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
cond::Time_t targetSince = 0;
cond::Time_t executionTimeIov = cond::time::from_boost(executionTime);
if (!m_startTime.is_not_a_date_time()) {
targetSince = cond::time::from_boost(m_startTime);
}
if (lastSince > targetSince)
targetSince = lastSince;

edm::LogInfo(m_name) << "Starting sampling at "
<< boost::posix_time::to_simple_string(cond::time::to_boost(targetSince));

//retrieve the data from the relational database source
cond::persistency::ConnectionPool connection;
//configure the connection
Expand Down Expand Up @@ -241,13 +228,22 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
}
}

boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
cond::Time_t executionTimeIov = cond::time::from_boost(executionTime);

cond::Time_t startTimestamp = m_startTime.is_not_a_date_time() ? 0 : cond::time::from_boost(m_startTime);
cond::Time_t nextFillSearchTimestamp = std::max(startTimestamp, m_endFillMode ? lastSince : m_prevEndFillTime);

edm::LogInfo(m_name) << "Starting sampling at "
<< boost::posix_time::to_simple_string(cond::time::to_boost(nextFillSearchTimestamp));

while (true) {
if (targetSince >= executionTimeIov) {
if (nextFillSearchTimestamp >= executionTimeIov) {
edm::LogInfo(m_name) << "Sampling ended at the time "
<< boost::posix_time::to_simple_string(cond::time::to_boost(executionTimeIov));
break;
}
boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince);
boost::posix_time::ptime nextFillSearchTime = cond::time::to_boost(nextFillSearchTimestamp);
boost::posix_time::ptime startSampleTime;
boost::posix_time::ptime endSampleTime;

Expand All @@ -268,12 +264,12 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
}
startSampleTime = cond::time::to_boost(lastSince);
} else {
edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(nextFillSearchTime);
query->filterNotNull("start_stable_beam").filterNotNull("fill_number");
if (targetTime > cond::time::to_boost(m_prevStartFillTime)) {
query->filterGE("start_time", targetTime);
if (nextFillSearchTime > cond::time::to_boost(m_prevStartFillTime)) {
query->filterGE("start_time", nextFillSearchTime);
} else {
query->filterGT("start_time", targetTime);
query->filterGT("start_time", nextFillSearchTime);
}

query->filterLT("start_time", m_endTime);
Expand All @@ -295,12 +291,12 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at "
<< cond::time::to_boost(m_startFillTime);
endSampleTime = executionTime;
targetSince = executionTimeIov;
nextFillSearchTimestamp = executionTimeIov;
} else {
edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(m_startFillTime)
<< " ending at " << cond::time::to_boost(m_endFillTime);
endSampleTime = cond::time::to_boost(m_endFillTime);
targetSince = m_endFillTime;
nextFillSearchTimestamp = m_endFillTime;
}

if (m_endFillMode || ongoingFill) {
Expand Down Expand Up @@ -571,13 +567,11 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
// starting date for sampling
boost::posix_time::ptime m_startTime;
boost::posix_time::ptime m_endTime;
// sampling interval in seconds
unsigned int m_samplingInterval;
bool m_endFillMode = true;
std::string m_name;
//for reading from relational database source
std::string m_connectionString, m_ecalConnectionString;
std::string m_dipSchema, m_authpath;
std::string m_connectionString;
std::string m_authpath;
std::string m_omsBaseUrl;
std::unique_ptr<LHCInfoPerLS> m_fillPayload;
std::shared_ptr<LHCInfoPerLS> m_prevPayload;
Expand Down
2 changes: 0 additions & 2 deletions CondTools/RunInfo/python/LHCInfoPerFillPopConAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@
Source = cms.PSet(fill = cms.untracked.uint32(6417),
startTime = cms.untracked.string(options.startTime),
endTime = cms.untracked.string(options.endTime),
samplingInterval = cms.untracked.uint32( 600 ),
endFill = cms.untracked.bool(True if options.mode == "endFill" else False),
name = cms.untracked.string("LHCInfoPerFillPopConSourceHandler"),
connectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_RUNTIME_LOGGER"),
ecalConnectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_DCS_ENV_PVSS_COND"),
DIPSchema = cms.untracked.string("CMS_BEAM_COND"),
omsBaseUrl = cms.untracked.string("http://vocms0184.cern.ch/agg/api/v1"),
authenticationPath = cms.untracked.string(""),
debug=cms.untracked.bool(False)
Expand Down
2 changes: 0 additions & 2 deletions CondTools/RunInfo/python/LHCInfoPerLSPopConAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@
Source = cms.PSet(fill = cms.untracked.uint32(6417),
startTime = cms.untracked.string(options.startTime),
endTime = cms.untracked.string(options.endTime),
samplingInterval = cms.untracked.uint32( 600 ),
endFill = cms.untracked.bool(True if options.mode == "endFill" else False),
name = cms.untracked.string("LHCInfoPerLSPopConSourceHandler"),
connectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_RUNTIME_LOGGER"),
DIPSchema = cms.untracked.string("CMS_BEAM_COND"),
omsBaseUrl = cms.untracked.string("http://vocms0184.cern.ch/agg/api/v1"),
authenticationPath = cms.untracked.string(""),
debug=cms.untracked.bool(False)
Expand Down

0 comments on commit 7aa6331

Please sign in to comment.