CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
LHCInfoPerLSPopConSourceHandler Class Reference
Inheritance diagram for LHCInfoPerLSPopConSourceHandler:
popcon::PopConSourceHandler< LHCInfoPerLS >

Public Member Functions

void getNewObjects () override
 
std::string id () const override
 
 LHCInfoPerLSPopConSourceHandler (edm::ParameterSet const &pset)
 
 ~LHCInfoPerLSPopConSourceHandler () override=default
 
- Public Member Functions inherited from popcon::PopConSourceHandler< LHCInfoPerLS >
void initialize (const cond::persistency::Session &dbSession, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry)
 
Ref lastPayload () const
 
cond::LogDBEntry_t const & logDBEntry () const
 
std::pair< Container const *, std::string const > operator() (const cond::persistency::Session &session, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry) const
 
 PopConSourceHandler ()
 
Container const & returnData ()
 
cond::TagInfo_t const & tagInfo () const
 
std::string const & userTextLog () const
 
virtual ~PopConSourceHandler ()
 

Static Public Attributes

static constexpr unsigned int kLumisectionsQueryLimit = 4000
 

Private Member Functions

void addEmptyPayload (cond::Time_t iov)
 
void addPayloadToBuffer (cond::OMSServiceResultRef &row)
 
size_t bufferAllLS (const cond::OMSServiceResult &queryResult)
 
size_t bufferFirstStableBeamLS (const cond::OMSServiceResult &queryResult)
 
bool getCTPPSData (cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
 
size_t getLumiData (const cond::OMSService &oms, unsigned short fillId, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
 
bool makeFillPayload (std::unique_ptr< LHCInfoPerLS > &targetPayload, const cond::OMSServiceResult &queryResult)
 

Private Attributes

std::string m_authpath
 
std::string m_connectionString
 
bool m_debug
 
bool m_endFillMode = true
 
cond::Time_t m_endFillTime
 
cond::Time_t m_endStableBeamTime
 
boost::posix_time::ptime m_endTime
 
std::unique_ptr< LHCInfoPerLSm_fillPayload
 
bool m_lastPayloadEmpty = false
 
std::map< pair< cond::Time_t, unsigned int >, pair< cond::Time_t, unsigned int > > m_lsIdMap
 
std::string m_name
 
std::string m_omsBaseUrl
 
cond::Time_t m_prevEndFillTime
 
std::shared_ptr< LHCInfoPerLSm_prevPayload
 
cond::Time_t m_prevStartFillTime
 
cond::Time_t m_startFillTime
 
cond::Time_t m_startStableBeamTime
 
boost::posix_time::ptime m_startTime
 
std::vector< pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > > m_tmpBuffer
 

Additional Inherited Members

- Public Types inherited from popcon::PopConSourceHandler< LHCInfoPerLS >
typedef std::map< Time_t, std::shared_ptr< LHCInfoPerLS > > Container
 
typedef std::unique_ptr< LHCInfoPerLSRef
 
typedef PopConSourceHandler< LHCInfoPerLSself
 
typedef cond::Time_t Time_t
 
typedef LHCInfoPerLS value_type
 
- Protected Member Functions inherited from popcon::PopConSourceHandler< LHCInfoPerLS >
cond::persistency::SessiondbSession () const
 
- Protected Attributes inherited from popcon::PopConSourceHandler< LHCInfoPerLS >
Container m_iovs
 
std::vector< std::pair< LHCInfoPerLS *, Time_t > > m_to_transfer
 
std::string m_userTextLog
 

Detailed Description

Definition at line 123 of file LHCInfoPerLSPopConAnalyzer.cc.

Constructor & Destructor Documentation

◆ LHCInfoPerLSPopConSourceHandler()

LHCInfoPerLSPopConSourceHandler::LHCInfoPerLSPopConSourceHandler ( edm::ParameterSet const &  pset)
inline

Definition at line 125 of file LHCInfoPerLSPopConAnalyzer.cc.

References m_endTime, m_startTime, submitPVValidationJobs::now, muonDTDigis_cfi::pset, and AlCaHLTBitMon_QueryRunRegistry::string.

126  : m_debug(pset.getUntrackedParameter<bool>("debug", false)),
127  m_startTime(),
128  m_endTime(),
129  m_endFillMode(pset.getUntrackedParameter<bool>("endFill", true)),
130  m_name(pset.getUntrackedParameter<std::string>("name", "LHCInfoPerLSPopConSourceHandler")),
131  m_connectionString(pset.getUntrackedParameter<std::string>("connectionString", "")),
132  m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
133  m_omsBaseUrl(pset.getUntrackedParameter<std::string>("omsBaseUrl", "")),
134  m_fillPayload(),
135  m_prevPayload(),
136  m_tmpBuffer() {
137  if (!pset.getUntrackedParameter<std::string>("startTime").empty()) {
138  m_startTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("startTime"));
139  }
140  boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
141  m_endTime = now;
142  if (!pset.getUntrackedParameter<std::string>("endTime").empty()) {
143  m_endTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("endTime"));
144  if (m_endTime > now)
145  m_endTime = now;
146  }
147  }
std::shared_ptr< LHCInfoPerLS > m_prevPayload
std::unique_ptr< LHCInfoPerLS > m_fillPayload
std::vector< pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > > m_tmpBuffer

◆ ~LHCInfoPerLSPopConSourceHandler()

LHCInfoPerLSPopConSourceHandler::~LHCInfoPerLSPopConSourceHandler ( )
overridedefault

Member Function Documentation

◆ addEmptyPayload()

void LHCInfoPerLSPopConSourceHandler::addEmptyPayload ( cond::Time_t  iov)
inlineprivate

Definition at line 339 of file LHCInfoPerLSPopConAnalyzer.cc.

References PVValHelper::add(), popcon::PopConSourceHandler< LHCInfoPerLS >::m_iovs, m_lastPayloadEmpty, m_name, m_prevEndFillTime, m_prevPayload, m_prevStartFillTime, and cond::time::to_boost().

Referenced by getNewObjects().

339  {
340  bool add = false;
341  if (m_iovs.empty()) {
342  if (!m_lastPayloadEmpty)
343  add = true;
344  } else {
345  auto lastAdded = m_iovs.rbegin()->second;
346  if (lastAdded->fillNumber() != 0) {
347  add = true;
348  }
349  }
350  if (add) {
351  auto newPayload = std::make_shared<LHCInfoPerLS>();
352  m_iovs.insert(make_pair(iov, newPayload));
353  m_prevPayload = newPayload;
354  m_prevEndFillTime = 0;
356  edm::LogInfo(m_name) << "Added empty payload with IOV" << iov << " ( "
357  << boost::posix_time::to_iso_extended_string(cond::time::to_boost(iov)) << " )";
358  }
359  }
std::shared_ptr< LHCInfoPerLS > m_prevPayload
Log< level::Info, false > LogInfo
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
boost::posix_time::ptime to_boost(Time_t iValue)

◆ addPayloadToBuffer()

void LHCInfoPerLSPopConSourceHandler::addPayloadToBuffer ( cond::OMSServiceResultRef row)
inlineprivate

Definition at line 379 of file LHCInfoPerLSPopConAnalyzer.cc.

References cond::time::from_boost(), cond::OMSServiceResultRef::get(), cond::time::lumiTime(), m_endFillMode, m_fillPayload, m_lsIdMap, m_tmpBuffer, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by bufferAllLS(), bufferFirstStableBeamLS(), and getLumiData().

379  {
380  auto lumiTime = row.get<boost::posix_time::ptime>("start_time");
381  LHCInfoPerLS* thisLumiSectionInfo = new LHCInfoPerLS(*m_fillPayload);
382  thisLumiSectionInfo->setLumiSection(std::stoul(row.get<std::string>("lumisection_number")));
383  thisLumiSectionInfo->setRunNumber(std::stoul(row.get<std::string>("run_number")));
384  m_lsIdMap[make_pair(thisLumiSectionInfo->runNumber(), thisLumiSectionInfo->lumiSection())] = make_pair(-1, -1);
385  if (m_endFillMode) {
386  m_tmpBuffer.emplace_back(make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
387  } else {
388  m_tmpBuffer.emplace_back(
389  make_pair(cond::time::lumiTime(thisLumiSectionInfo->runNumber(), thisLumiSectionInfo->lumiSection()),
390  thisLumiSectionInfo));
391  }
392  }
T get(const std::string &attributeName)
Definition: OMSAccess.h:114
Time_t lumiTime(unsigned int run, unsigned int lumiId)
Definition: Time.cc:66
Time_t from_boost(boost::posix_time::ptime bt)
std::map< pair< cond::Time_t, unsigned int >, pair< cond::Time_t, unsigned int > > m_lsIdMap
std::unique_ptr< LHCInfoPerLS > m_fillPayload
std::vector< pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > > m_tmpBuffer

◆ bufferAllLS()

size_t LHCInfoPerLSPopConSourceHandler::bufferAllLS ( const cond::OMSServiceResult queryResult)
inlineprivate

Definition at line 394 of file LHCInfoPerLSPopConAnalyzer.cc.

References addPayloadToBuffer(), and alignCSCRings::r.

Referenced by getLumiData().

394  {
395  for (auto r : queryResult) {
397  }
398  return queryResult.size();
399  }
void addPayloadToBuffer(cond::OMSServiceResultRef &row)

◆ bufferFirstStableBeamLS()

size_t LHCInfoPerLSPopConSourceHandler::bufferFirstStableBeamLS ( const cond::OMSServiceResult queryResult)
inlineprivate

Definition at line 401 of file LHCInfoPerLSPopConAnalyzer.cc.

References addPayloadToBuffer(), m_name, alignCSCRings::r, and AlCaHLTBitMon_QueryRunRegistry::string.

401  {
402  for (auto r : queryResult) {
403  if (r.get<std::string>("beams_stable") == "true") {
405  edm::LogInfo(m_name) << "Buffered first lumisection of stable beam: LS: "
406  << r.get<std::string>("lumisection_number")
407  << " run: " << r.get<std::string>("run_number");
408  return 1;
409  }
410  }
411  return 0;
412  }
void addPayloadToBuffer(cond::OMSServiceResultRef &row)
Log< level::Info, false > LogInfo

◆ getCTPPSData()

bool LHCInfoPerLSPopConSourceHandler::getCTPPSData ( cond::persistency::Session session,
const boost::posix_time::ptime &  beginFillTime,
const boost::posix_time::ptime &  endFillTime 
)
inlineprivate

Definition at line 445 of file LHCInfoPerLSPopConAnalyzer.cc.

References m_debug, m_lsIdMap, m_tmpBuffer, jetsAK4_Puppi_cff::payload, runTheMatrix::ret, convertSQLiteXML::runNumber, run_AlCaRecoTriggerBitsUpdateWorkflow::session, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getNewObjects().

447  {
448  //run the fifth query against the CTPPS schema
449  //Initializing the CMS_CTP_CTPPS_COND schema.
450  coral::ISchema& CTPPS = session.coralSession().schema("CMS_PPS_SPECT_COND");
451  //execute query for CTPPS Data
452  std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
453  //FROM clause
454  CTPPSDataQuery->addToTableList(std::string("PPS_LHC_MACHINE_PARAMS"));
455  //SELECT clause
456  CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME"));
457  CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION"));
458  CTPPSDataQuery->addToOutputList(std::string("RUN_NUMBER"));
459  CTPPSDataQuery->addToOutputList(std::string("FILL_NUMBER"));
460  CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_X_URAD"));
461  CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_Y_URAD"));
462  CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_X_M"));
463  CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_Y_M"));
464  //WHERE CLAUSE
465  coral::AttributeList CTPPSDataBindVariables;
466  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("beginFillTime"));
467  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("endFillTime"));
468  CTPPSDataBindVariables[std::string("beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
469  CTPPSDataBindVariables[std::string("endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
470  std::string conditionStr = std::string("DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
471  CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
472  //ORDER BY clause
473  CTPPSDataQuery->addToOrderList(std::string("DIP_UPDATE_TIME"));
474  //define query output
475  coral::AttributeList CTPPSDataOutput;
476  CTPPSDataOutput.extend<coral::TimeStamp>(std::string("DIP_UPDATE_TIME"));
477  CTPPSDataOutput.extend<int>(std::string("LUMI_SECTION"));
478  CTPPSDataOutput.extend<int>(std::string("RUN_NUMBER"));
479  CTPPSDataOutput.extend<int>(std::string("FILL_NUMBER"));
480  CTPPSDataOutput.extend<float>(std::string("XING_ANGLE_P5_X_URAD"));
481  CTPPSDataOutput.extend<float>(std::string("XING_ANGLE_P5_Y_URAD"));
482  CTPPSDataOutput.extend<float>(std::string("BETA_STAR_P5_X_M"));
483  CTPPSDataOutput.extend<float>(std::string("BETA_STAR_P5_Y_M"));
484  CTPPSDataQuery->defineOutput(CTPPSDataOutput);
485  //execute the query
486  coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
487  unsigned int lumiSection = 0;
489  int fillNumber = 0;
490  float crossingAngleX = 0., betaStarX = 0.;
491  float crossingAngleY = 0., betaStarY = 0.;
492 
493  bool ret = false;
494  int wrongFillNumbers = 0;
495  std::stringstream wrongFills;
496  std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::iterator current = m_tmpBuffer.begin();
497  while (CTPPSDataCursor.next()) {
498  if (m_debug) {
499  std::ostringstream CTPPS;
500  CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
501  }
502  coral::Attribute const& dipTimeAttribute = CTPPSDataCursor.currentRow()[std::string("DIP_UPDATE_TIME")];
503  if (!dipTimeAttribute.isNull()) {
504  ret = true;
505  coral::Attribute const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[std::string("LUMI_SECTION")];
506  if (!lumiSectionAttribute.isNull()) {
507  lumiSection = lumiSectionAttribute.data<int>();
508  }
509  coral::Attribute const& runNumberAttribute = CTPPSDataCursor.currentRow()[std::string("RUN_NUMBER")];
510  if (!runNumberAttribute.isNull()) {
511  runNumber = runNumberAttribute.data<int>();
512  }
513  coral::Attribute const& fillNumberAttribute = CTPPSDataCursor.currentRow()[std::string("FILL_NUMBER")];
514  if (!fillNumberAttribute.isNull()) {
515  fillNumber = fillNumberAttribute.data<int>();
516  }
517  coral::Attribute const& crossingAngleXAttribute =
518  CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_X_URAD")];
519  if (!crossingAngleXAttribute.isNull()) {
520  crossingAngleX = crossingAngleXAttribute.data<float>();
521  }
522  coral::Attribute const& crossingAngleYAttribute =
523  CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_Y_URAD")];
524  if (!crossingAngleYAttribute.isNull()) {
525  crossingAngleY = crossingAngleYAttribute.data<float>();
526  }
527  coral::Attribute const& betaStarXAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_X_M")];
528  if (!betaStarXAttribute.isNull()) {
529  betaStarX = betaStarXAttribute.data<float>();
530  }
531  coral::Attribute const& betaStarYAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_Y_M")];
532  if (!betaStarYAttribute.isNull()) {
533  betaStarY = betaStarYAttribute.data<float>();
534  }
535  if (current != m_tmpBuffer.end() && current->second->fillNumber() != fillNumber) {
536  wrongFills << "( " << runNumber << "_" << lumiSection << " fill: OMS: " << current->second->fillNumber()
537  << " PPSdb: " << fillNumber << " ) ";
538  wrongFillNumbers++;
539  }
540  for (;
541  current != m_tmpBuffer.end() && make_pair(current->second->runNumber(), current->second->lumiSection()) <=
542  make_pair(runNumber, lumiSection);
543  current++) {
544  LHCInfoPerLS& payload = *(current->second);
545  payload.setCrossingAngleX(crossingAngleX);
546  payload.setCrossingAngleY(crossingAngleY);
547  payload.setBetaStarX(betaStarX);
548  payload.setBetaStarY(betaStarY);
549  payload.setLumiSection(lumiSection);
550  payload.setRunNumber(runNumber);
551  if (m_lsIdMap.find(make_pair(payload.runNumber(), payload.lumiSection())) != m_lsIdMap.end()) {
552  m_lsIdMap[make_pair(payload.runNumber(), payload.lumiSection())] = make_pair(runNumber, lumiSection);
553  }
554  }
555  }
556  }
557  if (wrongFillNumbers) {
558  edm::LogWarning("getCTPPSData") << "Number of records from PPS DB with fillNumber different from OMS: "
559  << wrongFillNumbers;
560  edm::LogWarning("getCTPPSData") << "Records from PPS DB with fillNumber different from OMS: " << wrongFills.str();
561  }
562  return ret;
563  }
ret
prodAgent to be discontinued
unsigned long long Time_t
Definition: Time.h:14
std::map< pair< cond::Time_t, unsigned int >, pair< cond::Time_t, unsigned int > > m_lsIdMap
Log< level::Warning, false > LogWarning
std::vector< pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > > m_tmpBuffer

◆ getLumiData()

size_t LHCInfoPerLSPopConSourceHandler::getLumiData ( const cond::OMSService oms,
unsigned short  fillId,
const boost::posix_time::ptime &  beginFillTime,
const boost::posix_time::ptime &  endFillTime 
)
inlineprivate

Definition at line 414 of file LHCInfoPerLSPopConAnalyzer.cc.

References addPayloadToBuffer(), bufferAllLS(), kLumisectionsQueryLimit, m_endFillMode, m_name, cond::OMSService::query(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getNewObjects().

417  {
418  auto query = oms.query("lumisections");
419  query->addOutputVars({"start_time", "run_number", "beams_stable", "lumisection_number"});
420  query->filterEQ("fill_number", fillId);
421  query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime);
423  size_t nlumi = 0;
424  if (query->execute()) {
425  auto queryResult = query->result();
426  if (m_endFillMode) {
427  nlumi = bufferAllLS(queryResult);
428  } else if (!queryResult.empty()) {
429  auto newestPayload = queryResult.back();
430  if (newestPayload.get<std::string>("beams_stable") == "true") {
431  addPayloadToBuffer(newestPayload);
432  nlumi = 1;
433  edm::LogInfo(m_name) << "Buffered most recent lumisection:"
434  << " LS: " << newestPayload.get<std::string>("lumisection_number")
435  << " run: " << newestPayload.get<std::string>("run_number");
436  }
437  }
438  edm::LogInfo(m_name) << "Found " << queryResult.size() << " lumisections during the fill " << fillId;
439  } else {
440  edm::LogInfo(m_name) << "OMS query for lumisections of fill " << fillId << "failed, status:" << query->status();
441  }
442  return nlumi;
443  }
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:129
Definition: query.py:1
size_t bufferAllLS(const cond::OMSServiceResult &queryResult)
void addPayloadToBuffer(cond::OMSServiceResultRef &row)
Log< level::Info, false > LogInfo
static constexpr unsigned int kLumisectionsQueryLimit

◆ getNewObjects()

void LHCInfoPerLSPopConSourceHandler::getNewObjects ( )
inlineoverridevirtual

Implements popcon::PopConSourceHandler< LHCInfoPerLS >.

Definition at line 151 of file LHCInfoPerLSPopConAnalyzer.cc.

References addEmptyPayload(), cond::persistency::Transaction::commit(), cond::persistency::ConnectionPool::configure(), cond::OMSService::connect(), cond::persistency::ConnectionPool::createSession(), popcon::PopConSourceHandler< LHCInfoPerLS >::dbSession(), Debug, cond::persistency::Session::fetchPayload(), cond::time::from_boost(), getCTPPSData(), cond::lhcInfoHelper::getFillLastLumiIOV(), getLumiData(), cond::TagInfo_t::lastInterval, cond::time::lumiTime(), m_authpath, m_connectionString, m_debug, m_endFillMode, m_endFillTime, m_endStableBeamTime, m_endTime, m_fillPayload, popcon::PopConSourceHandler< LHCInfoPerLS >::m_iovs, m_lsIdMap, m_name, m_omsBaseUrl, m_prevEndFillTime, m_prevPayload, m_prevStartFillTime, m_startFillTime, m_startStableBeamTime, m_startTime, m_tmpBuffer, makeFillPayload(), WZElectronSkims53X_cff::max, cond::TagInfo_t::name, cond::Iov_t::payloadId, cond::OMSService::query(), mps_fire::result, run_AlCaRecoTriggerBitsUpdateWorkflow::session, cond::persistency::ConnectionPool::setAuthenticationPath(), cond::persistency::ConnectionPool::setMessageVerbosity(), cond::Iov_t::since, cond::TagInfo_t::size, findQualityFiles::size, cond::persistency::Transaction::start(), AlCaHLTBitMon_QueryRunRegistry::string, popcon::PopConSourceHandler< LHCInfoPerLS >::tagInfo(), cond::time::to_boost(), cond::persistency::Session::transaction(), and theLHCInfoPerLSImpl::transferPayloads().

151  {
152  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
153  if (tagInfo().size == 0) {
154  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
155  } else {
156  //check what is already inside the database
157  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size
158  << ", last object valid since " << tagInfo().lastInterval.since << " ( "
159  << boost::posix_time::to_iso_extended_string(
160  cond::time::to_boost(tagInfo().lastInterval.since))
161  << " ); from " << m_name << "::getNewObjects";
162  }
163 
164  cond::Time_t lastSince = tagInfo().lastInterval.since;
165  if (tagInfo().isEmpty()) {
166  // for a new or empty tag, an empty payload should be added on top with since=1
167  if (m_endFillMode) {
168  addEmptyPayload(1);
169  lastSince = 1;
170  } else {
172  lastSince = cond::time::lumiTime(1, 1);
173  }
174  } else {
175  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
176  << m_name << "::getNewObjects";
177  }
178 
179  //retrieve the data from the relational database source
181  //configure the connection
182  if (m_debug) {
183  connection.setMessageVerbosity(coral::Debug);
184  } else {
185  connection.setMessageVerbosity(coral::Error);
186  }
187  connection.setAuthenticationPath(m_authpath);
188  connection.configure();
189  //create the sessions
191  // fetch last payload when available
192  if (!tagInfo().lastInterval.payloadId.empty()) {
194  session3.transaction().start(true);
196  session3.transaction().commit();
197 
198  // find startFillTime and endFillTime of the most recent fill already saved in the tag
199  if (m_prevPayload->fillNumber() != 0) {
200  cond::OMSService oms;
201  oms.connect(m_omsBaseUrl);
202  auto query = oms.query("fills");
203  query->addOutputVar("end_time");
204  query->addOutputVar("start_time");
205  query->filterEQ("fill_number", m_prevPayload->fillNumber());
206  bool foundFill = query->execute();
207  if (foundFill) {
208  auto result = query->result();
209 
210  if (!result.empty()) {
211  std::string endTimeStr = (*result.begin()).get<std::string>("end_time");
213  (endTimeStr == "null")
214  ? 0
215  : cond::time::from_boost((*result.begin()).get<boost::posix_time::ptime>("end_time"));
216  auto startFillTime = (*result.begin()).get<boost::posix_time::ptime>("start_time");
218  } else {
219  foundFill = false;
220  }
221  }
222  if (!foundFill) {
223  edm::LogError(m_name) << "Could not find end time of fill #" << m_prevPayload->fillNumber();
224  }
225  } else {
226  m_prevEndFillTime = 0;
228  }
229  }
230 
231  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
232  cond::Time_t executionTimeIov = cond::time::from_boost(executionTime);
233 
234  cond::Time_t startTimestamp = m_startTime.is_not_a_date_time() ? 0 : cond::time::from_boost(m_startTime);
235  cond::Time_t nextFillSearchTimestamp = std::max(startTimestamp, m_endFillMode ? lastSince : m_prevEndFillTime);
236 
237  edm::LogInfo(m_name) << "Starting sampling at "
238  << boost::posix_time::to_simple_string(cond::time::to_boost(nextFillSearchTimestamp));
239 
240  while (true) {
241  if (nextFillSearchTimestamp >= executionTimeIov) {
242  edm::LogInfo(m_name) << "Sampling ended at the time "
243  << boost::posix_time::to_simple_string(cond::time::to_boost(executionTimeIov));
244  break;
245  }
246  boost::posix_time::ptime nextFillSearchTime = cond::time::to_boost(nextFillSearchTimestamp);
247  boost::posix_time::ptime startSampleTime;
248  boost::posix_time::ptime endSampleTime;
249 
250  cond::OMSService oms;
251  oms.connect(m_omsBaseUrl);
252  auto query = oms.query("fills");
253 
254  if (!m_endFillMode and m_prevPayload->fillNumber() and m_prevEndFillTime == 0ULL) {
255  // continue processing unfinished fill with some payloads already in the tag
256  edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber();
257  query->filterEQ("fill_number", m_prevPayload->fillNumber());
258  bool foundFill = query->execute();
259  if (foundFill)
260  foundFill = makeFillPayload(m_fillPayload, query->result());
261  if (!foundFill) {
262  edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber();
263  break;
264  }
265  startSampleTime = cond::time::to_boost(lastSince);
266  } else {
267  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(nextFillSearchTime);
268  query->filterNotNull("start_stable_beam").filterNotNull("fill_number");
269  if (nextFillSearchTime > cond::time::to_boost(m_prevStartFillTime)) {
270  query->filterGE("start_time", nextFillSearchTime);
271  } else {
272  query->filterGT("start_time", nextFillSearchTime);
273  }
274 
275  query->filterLT("start_time", m_endTime);
276  if (m_endFillMode)
277  query->filterNotNull("end_time");
278  bool foundFill = query->execute();
279  if (foundFill)
280  foundFill = makeFillPayload(m_fillPayload, query->result());
281  if (!foundFill) {
282  edm::LogInfo(m_name) << "No fill found - END of job.";
283  break;
284  }
285  startSampleTime = cond::time::to_boost(m_startFillTime);
286  }
287 
288  unsigned short lhcFill = m_fillPayload->fillNumber();
289  bool ongoingFill = m_endFillTime == 0ULL;
290  if (ongoingFill) {
291  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at "
293  endSampleTime = executionTime;
294  nextFillSearchTimestamp = executionTimeIov;
295  } else {
296  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(m_startFillTime)
297  << " ending at " << cond::time::to_boost(m_endFillTime);
298  endSampleTime = cond::time::to_boost(m_endFillTime);
299  nextFillSearchTimestamp = m_endFillTime;
300  }
301 
302  if (m_endFillMode || ongoingFill) {
303  getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
304 
305  if (!m_tmpBuffer.empty()) {
306  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
307  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
308  edm::LogInfo(m_name) << "First buffered lumi starts at " << flumiStart << " last lumi starts at "
309  << flumiStop;
310  session.transaction().start(true);
311  getCTPPSData(session, startSampleTime, endSampleTime);
312  session.transaction().commit();
313  }
314  }
315 
318  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
319  if (niovs) {
322  }
323  m_tmpBuffer.clear();
324  m_lsIdMap.clear();
325  if (m_prevPayload->fillNumber() and !ongoingFill) {
326  if (m_endFillMode) {
328  } else {
330  }
331  }
332  }
333  }
size
Write out results.
edm::ErrorSummaryEntry Error
size_t transferPayloads(const std::vector< pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS >>> &buffer, std::map< cond::Time_t, std::shared_ptr< LHCInfoPerLS >> &iovsToTransfer, std::shared_ptr< LHCInfoPerLS > &prevPayload, const std::map< pair< cond::Time_t, unsigned int >, pair< cond::Time_t, unsigned int >> &lsIdMap, cond::Time_t startStableBeamTime, cond::Time_t endStableBeamTime)
bool makeFillPayload(std::unique_ptr< LHCInfoPerLS > &targetPayload, const cond::OMSServiceResult &queryResult)
Iov_t lastInterval
Definition: Types.h:73
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:129
std::shared_ptr< LHCInfoPerLS > m_prevPayload
void start(bool readOnly=true)
Definition: Session.cc:18
Time_t since
Definition: Types.h:53
size_t size
Definition: Types.h:74
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
Log< level::Error, false > LogError
Transaction & transaction()
Definition: Session.cc:52
std::string name
Definition: Types.h:72
Definition: query.py:1
cond::TagInfo_t const & tagInfo() const
unsigned long long Time_t
Definition: Time.h:14
Time_t lumiTime(unsigned int run, unsigned int lumiId)
Definition: Time.cc:66
Hash payloadId
Definition: Types.h:55
Session createSession(const std::string &connectionString, bool writeCapable=false)
void setMessageVerbosity(coral::MsgLevel level)
Time_t from_boost(boost::posix_time::ptime bt)
Log< level::Info, false > LogInfo
std::map< pair< cond::Time_t, unsigned int >, pair< cond::Time_t, unsigned int > > m_lsIdMap
cond::persistency::Session & dbSession() const
std::unique_ptr< LHCInfoPerLS > m_fillPayload
void connect(const std::string &baseUrl)
Definition: OMSAccess.cc:128
bool getCTPPSData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
void setAuthenticationPath(const std::string &p)
const bool Debug
std::vector< pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > > m_tmpBuffer
cond::Time_t getFillLastLumiIOV(const cond::OMSService &oms, unsigned short fillId)
Definition: LHCInfoHelper.cc:8
boost::posix_time::ptime to_boost(Time_t iValue)
size_t getLumiData(const cond::OMSService &oms, unsigned short fillId, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)

◆ id()

std::string LHCInfoPerLSPopConSourceHandler::id ( ) const
inlineoverridevirtual

◆ makeFillPayload()

bool LHCInfoPerLSPopConSourceHandler::makeFillPayload ( std::unique_ptr< LHCInfoPerLS > &  targetPayload,
const cond::OMSServiceResult queryResult 
)
inlineprivate

Definition at line 361 of file LHCInfoPerLSPopConAnalyzer.cc.

References cond::OMSServiceResult::begin(), cond::OMSServiceResult::empty(), cond::time::from_boost(), m_endFillTime, m_endStableBeamTime, m_startFillTime, m_startStableBeamTime, runTheMatrix::ret, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getNewObjects().

361  {
362  bool ret = false;
363  if (!queryResult.empty()) {
364  auto row = *queryResult.begin();
365  auto currentFill = row.get<unsigned short>("fill_number");
366  m_startFillTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("start_time"));
367  std::string endTimeStr = row.get<std::string>("end_time");
368  m_endFillTime =
369  (endTimeStr == "null") ? 0 : cond::time::from_boost(row.get<boost::posix_time::ptime>("end_time"));
370  m_startStableBeamTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("start_stable_beam"));
371  m_endStableBeamTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("end_stable_beam"));
372  targetPayload = std::make_unique<LHCInfoPerLS>();
373  targetPayload->setFillNumber(currentFill);
374  ret = true;
375  }
376  return ret;
377  }
ret
prodAgent to be discontinued
bool empty() const
Definition: OMSAccess.cc:69
Time_t from_boost(boost::posix_time::ptime bt)
OMSServiceResultIterator begin() const
Definition: OMSAccess.cc:32

Member Data Documentation

◆ kLumisectionsQueryLimit

constexpr unsigned int LHCInfoPerLSPopConSourceHandler::kLumisectionsQueryLimit = 4000
static

Definition at line 336 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getLumiData().

◆ m_authpath

std::string LHCInfoPerLSPopConSourceHandler::m_authpath
private

Definition at line 574 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_connectionString

std::string LHCInfoPerLSPopConSourceHandler::m_connectionString
private

Definition at line 573 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_debug

bool LHCInfoPerLSPopConSourceHandler::m_debug
private

Definition at line 566 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getCTPPSData(), and getNewObjects().

◆ m_endFillMode

bool LHCInfoPerLSPopConSourceHandler::m_endFillMode = true
private

Definition at line 570 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addPayloadToBuffer(), getLumiData(), and getNewObjects().

◆ m_endFillTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_endFillTime
private

Definition at line 579 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects(), and makeFillPayload().

◆ m_endStableBeamTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_endStableBeamTime
private

Definition at line 583 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects(), and makeFillPayload().

◆ m_endTime

boost::posix_time::ptime LHCInfoPerLSPopConSourceHandler::m_endTime
private

◆ m_fillPayload

std::unique_ptr<LHCInfoPerLS> LHCInfoPerLSPopConSourceHandler::m_fillPayload
private

Definition at line 576 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addPayloadToBuffer(), and getNewObjects().

◆ m_lastPayloadEmpty

bool LHCInfoPerLSPopConSourceHandler::m_lastPayloadEmpty = false
private

Definition at line 585 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addEmptyPayload().

◆ m_lsIdMap

std::map<pair<cond::Time_t, unsigned int>, pair<cond::Time_t, unsigned int> > LHCInfoPerLSPopConSourceHandler::m_lsIdMap
private

Definition at line 588 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addPayloadToBuffer(), getCTPPSData(), and getNewObjects().

◆ m_name

std::string LHCInfoPerLSPopConSourceHandler::m_name
private

◆ m_omsBaseUrl

std::string LHCInfoPerLSPopConSourceHandler::m_omsBaseUrl
private

Definition at line 575 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_prevEndFillTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_prevEndFillTime
private

Definition at line 580 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addEmptyPayload(), and getNewObjects().

◆ m_prevPayload

std::shared_ptr<LHCInfoPerLS> LHCInfoPerLSPopConSourceHandler::m_prevPayload
private

Definition at line 577 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addEmptyPayload(), and getNewObjects().

◆ m_prevStartFillTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_prevStartFillTime
private

Definition at line 581 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addEmptyPayload(), and getNewObjects().

◆ m_startFillTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_startFillTime
private

Definition at line 578 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects(), and makeFillPayload().

◆ m_startStableBeamTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_startStableBeamTime
private

Definition at line 582 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects(), and makeFillPayload().

◆ m_startTime

boost::posix_time::ptime LHCInfoPerLSPopConSourceHandler::m_startTime
private

◆ m_tmpBuffer

std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS> > > LHCInfoPerLSPopConSourceHandler::m_tmpBuffer
private

Definition at line 584 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addPayloadToBuffer(), getCTPPSData(), and getNewObjects().