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
 
std::string m_dipSchema
 
std::string m_ecalConnectionString
 
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
 
unsigned int m_samplingInterval
 
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 130 of file LHCInfoPerLSPopConAnalyzer.cc.

Constructor & Destructor Documentation

◆ LHCInfoPerLSPopConSourceHandler()

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

Definition at line 132 of file LHCInfoPerLSPopConAnalyzer.cc.

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

133  : m_debug(pset.getUntrackedParameter<bool>("debug", false)),
134  m_startTime(),
135  m_endTime(),
136  m_samplingInterval((unsigned int)pset.getUntrackedParameter<unsigned int>("samplingInterval", 300)),
137  m_endFillMode(pset.getUntrackedParameter<bool>("endFill", true)),
138  m_name(pset.getUntrackedParameter<std::string>("name", "LHCInfoPerLSPopConSourceHandler")),
139  m_connectionString(pset.getUntrackedParameter<std::string>("connectionString", "")),
140  m_dipSchema(pset.getUntrackedParameter<std::string>("DIPSchema", "")),
141  m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
142  m_omsBaseUrl(pset.getUntrackedParameter<std::string>("omsBaseUrl", "")),
143  m_fillPayload(),
144  m_prevPayload(),
145  m_tmpBuffer() {
146  if (!pset.getUntrackedParameter<std::string>("startTime").empty()) {
147  m_startTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("startTime"));
148  }
149  boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
150  m_endTime = now;
151  if (!pset.getUntrackedParameter<std::string>("endTime").empty()) {
152  m_endTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("endTime"));
153  if (m_endTime > now)
154  m_endTime = now;
155  }
156  }
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 341 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().

341  {
342  bool add = false;
343  if (m_iovs.empty()) {
344  if (!m_lastPayloadEmpty)
345  add = true;
346  } else {
347  auto lastAdded = m_iovs.rbegin()->second;
348  if (lastAdded->fillNumber() != 0) {
349  add = true;
350  }
351  }
352  if (add) {
353  auto newPayload = std::make_shared<LHCInfoPerLS>();
354  m_iovs.insert(make_pair(iov, newPayload));
355  m_prevPayload = newPayload;
356  m_prevEndFillTime = 0;
358  edm::LogInfo(m_name) << "Added empty payload with IOV" << iov << " ( "
359  << boost::posix_time::to_iso_extended_string(cond::time::to_boost(iov)) << " )";
360  }
361  }
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 381 of file LHCInfoPerLSPopConAnalyzer.cc.

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

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

381  {
382  auto lumiTime = row.get<boost::posix_time::ptime>("start_time");
383  LHCInfoPerLS* thisLumiSectionInfo = new LHCInfoPerLS(*m_fillPayload);
384  thisLumiSectionInfo->setLumiSection(std::stoul(row.get<std::string>("lumisection_number")));
385  thisLumiSectionInfo->setRunNumber(std::stoull(row.get<std::string>("run_number")));
386  m_lsIdMap[make_pair(thisLumiSectionInfo->runNumber(), thisLumiSectionInfo->lumiSection())] = make_pair(-1, -1);
387  m_tmpBuffer.emplace_back(make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
388  }
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 390 of file LHCInfoPerLSPopConAnalyzer.cc.

References addPayloadToBuffer(), and alignCSCRings::r.

Referenced by getLumiData().

390  {
391  for (auto r : queryResult) {
393  }
394  return queryResult.size();
395  }
void addPayloadToBuffer(cond::OMSServiceResultRef &row)

◆ bufferFirstStableBeamLS()

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

Definition at line 397 of file LHCInfoPerLSPopConAnalyzer.cc.

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

397  {
398  for (auto r : queryResult) {
399  if (r.get<std::string>("beams_stable") == "true") {
401  edm::LogInfo(m_name) << "Buffered first lumisection of stable beam: LS: "
402  << r.get<std::string>("lumisection_number")
403  << " run: " << r.get<std::string>("run_number");
404  return 1;
405  }
406  }
407  return 0;
408  }
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 441 of file LHCInfoPerLSPopConAnalyzer.cc.

References cond::persistency::Session::coralSession(), m_debug, m_lsIdMap, m_tmpBuffer, jetsAK4_Puppi_cff::payload, runTheMatrix::ret, convertSQLiteXML::runNumber, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getNewObjects().

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

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

Referenced by getNewObjects().

413  {
414  auto query = oms.query("lumisections");
415  query->addOutputVars({"start_time", "run_number", "beams_stable", "lumisection_number"});
416  query->filterEQ("fill_number", fillId);
417  query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime);
419  size_t nlumi = 0;
420  if (query->execute()) {
421  auto queryResult = query->result();
422  if (m_endFillMode) {
423  nlumi = bufferAllLS(queryResult);
424  } else if (!queryResult.empty()) {
425  auto newestPayload = queryResult.back();
426  if (newestPayload.get<std::string>("beams_stable") == "true") {
427  addPayloadToBuffer(newestPayload);
428  nlumi = 1;
429  edm::LogInfo(m_name) << "Buffered most recent lumisection:"
430  << " LS: " << newestPayload.get<std::string>("lumisection_number")
431  << " run: " << newestPayload.get<std::string>("run_number");
432  }
433  }
434  edm::LogInfo(m_name) << "Found " << queryResult.size() << " lumisections during the fill " << fillId;
435  } else {
436  edm::LogInfo(m_name) << "OMS query for lumisections of fill " << fillId << "failed, status:" << query->status();
437  }
438  return nlumi;
439  }
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 160 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(), getLumiData(), cond::TagInfo_t::lastInterval, 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(), cond::TagInfo_t::name, cond::Iov_t::payloadId, cond::OMSService::query(), mps_fire::result, 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().

160  {
161  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
162  if (tagInfo().size == 0) {
163  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
164  } else {
165  //check what is already inside the database
166  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size
167  << ", last object valid since " << tagInfo().lastInterval.since << " ( "
168  << boost::posix_time::to_iso_extended_string(
169  cond::time::to_boost(tagInfo().lastInterval.since))
170  << " ); from " << m_name << "::getNewObjects";
171  }
172 
173  cond::Time_t lastSince = tagInfo().lastInterval.since;
174  if (tagInfo().isEmpty()) {
175  // for a new or empty tag, an empty payload should be added on top with since=1
176  addEmptyPayload(1);
177  lastSince = 1;
178  } else {
179  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
180  << m_name << "::getNewObjects";
181  }
182 
183  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
184  cond::Time_t targetSince = 0;
185  cond::Time_t executionTimeIov = cond::time::from_boost(executionTime);
186  if (!m_startTime.is_not_a_date_time()) {
187  targetSince = cond::time::from_boost(m_startTime);
188  }
189  if (lastSince > targetSince)
190  targetSince = lastSince;
191 
192  edm::LogInfo(m_name) << "Starting sampling at "
193  << boost::posix_time::to_simple_string(cond::time::to_boost(targetSince));
194 
195  //retrieve the data from the relational database source
197  //configure the connection
198  if (m_debug) {
199  connection.setMessageVerbosity(coral::Debug);
200  } else {
201  connection.setMessageVerbosity(coral::Error);
202  }
203  connection.setAuthenticationPath(m_authpath);
204  connection.configure();
205  //create the sessions
206  cond::persistency::Session session = connection.createSession(m_connectionString, false);
207  // fetch last payload when available
208  if (!tagInfo().lastInterval.payloadId.empty()) {
210  session3.transaction().start(true);
212  session3.transaction().commit();
213 
214  // find startFillTime and endFillTime of the most recent fill already saved in the tag
215  if (m_prevPayload->fillNumber() != 0) {
216  cond::OMSService oms;
217  oms.connect(m_omsBaseUrl);
218  auto query = oms.query("fills");
219  query->addOutputVar("end_time");
220  query->addOutputVar("start_time");
221  query->filterEQ("fill_number", m_prevPayload->fillNumber());
222  bool foundFill = query->execute();
223  if (foundFill) {
224  auto result = query->result();
225 
226  if (!result.empty()) {
227  std::string endTimeStr = (*result.begin()).get<std::string>("end_time");
229  (endTimeStr == "null")
230  ? 0
231  : cond::time::from_boost((*result.begin()).get<boost::posix_time::ptime>("end_time"));
232  auto startFillTime = (*result.begin()).get<boost::posix_time::ptime>("start_time");
234  } else {
235  foundFill = false;
236  }
237  }
238  if (!foundFill) {
239  edm::LogError(m_name) << "Could not find end time of fill #" << m_prevPayload->fillNumber();
240  }
241  } else {
242  m_prevEndFillTime = 0;
244  }
245  }
246 
247  while (true) {
248  if (targetSince >= executionTimeIov) {
249  edm::LogInfo(m_name) << "Sampling ended at the time "
250  << boost::posix_time::to_simple_string(cond::time::to_boost(executionTimeIov));
251  break;
252  }
253  boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince);
254  boost::posix_time::ptime startSampleTime;
255  boost::posix_time::ptime endSampleTime;
256 
257  cond::OMSService oms;
258  oms.connect(m_omsBaseUrl);
259  auto query = oms.query("fills");
260 
261  if (!m_endFillMode and m_prevPayload->fillNumber() and m_prevEndFillTime == 0ULL) {
262  // continue processing unfinished fill with some payloads already in the tag
263  edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber();
264  query->filterEQ("fill_number", m_prevPayload->fillNumber());
265  bool foundFill = query->execute();
266  if (foundFill)
267  foundFill = makeFillPayload(m_fillPayload, query->result());
268  if (!foundFill) {
269  edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber();
270  break;
271  }
272  startSampleTime = cond::time::to_boost(lastSince);
273  } else {
274  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
275  query->filterNotNull("start_stable_beam").filterNotNull("fill_number");
276  if (targetTime > cond::time::to_boost(m_prevStartFillTime)) {
277  query->filterGE("start_time", targetTime);
278  } else {
279  query->filterGT("start_time", targetTime);
280  }
281 
282  query->filterLT("start_time", m_endTime);
283  if (m_endFillMode)
284  query->filterNotNull("end_time");
285  bool foundFill = query->execute();
286  if (foundFill)
287  foundFill = makeFillPayload(m_fillPayload, query->result());
288  if (!foundFill) {
289  edm::LogInfo(m_name) << "No fill found - END of job.";
290  break;
291  }
292  startSampleTime = cond::time::to_boost(m_startFillTime);
293  }
294 
295  unsigned short lhcFill = m_fillPayload->fillNumber();
296  bool ongoingFill = m_endFillTime == 0ULL;
297  if (ongoingFill) {
298  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at "
300  endSampleTime = executionTime;
301  targetSince = executionTimeIov;
302  } else {
303  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(m_startFillTime)
304  << " ending at " << cond::time::to_boost(m_endFillTime);
305  endSampleTime = cond::time::to_boost(m_endFillTime);
306  targetSince = m_endFillTime;
307  }
308 
309  if (m_endFillMode || ongoingFill) {
310  getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
311 
312  if (!m_tmpBuffer.empty()) {
313  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
314  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
315  edm::LogInfo(m_name) << "First buffered lumi starts at " << flumiStart << " last lumi starts at "
316  << flumiStop;
317  session.transaction().start(true);
318  getCTPPSData(session, startSampleTime, endSampleTime);
319  session.transaction().commit();
320  }
321  }
322 
325  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
326  if (niovs) {
329  }
330  m_tmpBuffer.clear();
331  m_lsIdMap.clear();
332  if (m_prevPayload->fillNumber() and !ongoingFill)
334  }
335  }
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
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
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 363 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().

363  {
364  bool ret = false;
365  if (!queryResult.empty()) {
366  auto row = *queryResult.begin();
367  auto currentFill = row.get<unsigned short>("fill_number");
368  m_startFillTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("start_time"));
369  std::string endTimeStr = row.get<std::string>("end_time");
370  m_endFillTime =
371  (endTimeStr == "null") ? 0 : cond::time::from_boost(row.get<boost::posix_time::ptime>("end_time"));
372  m_startStableBeamTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("start_stable_beam"));
373  m_endStableBeamTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("end_stable_beam"));
374  targetPayload = std::make_unique<LHCInfoPerLS>();
375  targetPayload->setFillNumber(currentFill);
376  ret = true;
377  }
378  return ret;
379  }
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 338 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getLumiData().

◆ m_authpath

std::string LHCInfoPerLSPopConSourceHandler::m_authpath
private

Definition at line 572 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_connectionString

std::string LHCInfoPerLSPopConSourceHandler::m_connectionString
private

Definition at line 571 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_debug

bool LHCInfoPerLSPopConSourceHandler::m_debug
private

Definition at line 562 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getCTPPSData(), and getNewObjects().

◆ m_dipSchema

std::string LHCInfoPerLSPopConSourceHandler::m_dipSchema
private

Definition at line 572 of file LHCInfoPerLSPopConAnalyzer.cc.

◆ m_ecalConnectionString

std::string LHCInfoPerLSPopConSourceHandler::m_ecalConnectionString
private

Definition at line 571 of file LHCInfoPerLSPopConAnalyzer.cc.

◆ m_endFillMode

bool LHCInfoPerLSPopConSourceHandler::m_endFillMode = true
private

Definition at line 568 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getLumiData(), and getNewObjects().

◆ m_endFillTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_endFillTime
private

Definition at line 577 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects(), and makeFillPayload().

◆ m_endStableBeamTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_endStableBeamTime
private

Definition at line 581 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 574 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addPayloadToBuffer(), and getNewObjects().

◆ m_lastPayloadEmpty

bool LHCInfoPerLSPopConSourceHandler::m_lastPayloadEmpty = false
private

Definition at line 583 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 586 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 573 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_prevEndFillTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_prevEndFillTime
private

Definition at line 578 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addEmptyPayload(), and getNewObjects().

◆ m_prevPayload

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

Definition at line 575 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addEmptyPayload(), and getNewObjects().

◆ m_prevStartFillTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_prevStartFillTime
private

Definition at line 579 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addEmptyPayload(), and getNewObjects().

◆ m_samplingInterval

unsigned int LHCInfoPerLSPopConSourceHandler::m_samplingInterval
private

Definition at line 567 of file LHCInfoPerLSPopConAnalyzer.cc.

◆ m_startFillTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_startFillTime
private

Definition at line 576 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects(), and makeFillPayload().

◆ m_startStableBeamTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_startStableBeamTime
private

Definition at line 580 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 582 of file LHCInfoPerLSPopConAnalyzer.cc.

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