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 193 of file LHCInfoPerLSPopConAnalyzer.cc.

Constructor & Destructor Documentation

◆ LHCInfoPerLSPopConSourceHandler()

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

Definition at line 195 of file LHCInfoPerLSPopConAnalyzer.cc.

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

196  : m_debug(pset.getUntrackedParameter<bool>("debug", false)),
197  m_startTime(),
198  m_endTime(),
199  m_samplingInterval((unsigned int)pset.getUntrackedParameter<unsigned int>("samplingInterval", 300)),
200  m_endFillMode(pset.getUntrackedParameter<bool>("endFill", true)),
201  m_name(pset.getUntrackedParameter<std::string>("name", "LHCInfoPerLSPopConSourceHandler")),
202  m_connectionString(pset.getUntrackedParameter<std::string>("connectionString", "")),
203  m_dipSchema(pset.getUntrackedParameter<std::string>("DIPSchema", "")),
204  m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
205  m_omsBaseUrl(pset.getUntrackedParameter<std::string>("omsBaseUrl", "")),
206  m_fillPayload(),
207  m_prevPayload(),
208  m_tmpBuffer() {
209  if (!pset.getUntrackedParameter<std::string>("startTime").empty()) {
210  m_startTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("startTime"));
211  }
212  boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
213  m_endTime = now;
214  if (!pset.getUntrackedParameter<std::string>("endTime").empty()) {
215  m_endTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("endTime"));
216  if (m_endTime > now)
217  m_endTime = now;
218  }
219  }
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 404 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().

404  {
405  bool add = false;
406  if (m_iovs.empty()) {
407  if (!m_lastPayloadEmpty)
408  add = true;
409  } else {
410  auto lastAdded = m_iovs.rbegin()->second;
411  if (lastAdded->fillNumber() != 0) {
412  add = true;
413  }
414  }
415  if (add) {
416  auto newPayload = std::make_shared<LHCInfoPerLS>();
417  m_iovs.insert(make_pair(iov, newPayload));
418  m_prevPayload = newPayload;
419  m_prevEndFillTime = 0;
421  edm::LogInfo(m_name) << "Added empty payload with IOV" << iov << " ( "
422  << boost::posix_time::to_iso_extended_string(cond::time::to_boost(iov)) << " )";
423  }
424  }
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 444 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().

444  {
445  auto lumiTime = row.get<boost::posix_time::ptime>("start_time");
446  LHCInfoPerLS* thisLumiSectionInfo = new LHCInfoPerLS(*m_fillPayload);
447  thisLumiSectionInfo->setLumiSection(std::stoul(row.get<std::string>("lumisection_number")));
448  thisLumiSectionInfo->setRunNumber(std::stoull(row.get<std::string>("run_number")));
449  m_lsIdMap[make_pair(thisLumiSectionInfo->runNumber(), thisLumiSectionInfo->lumiSection())] = make_pair(-1, -1);
450  m_tmpBuffer.emplace_back(make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
451  }
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 453 of file LHCInfoPerLSPopConAnalyzer.cc.

References addPayloadToBuffer(), and alignCSCRings::r.

Referenced by getLumiData().

453  {
454  for (auto r : queryResult) {
456  }
457  return queryResult.size();
458  }
void addPayloadToBuffer(cond::OMSServiceResultRef &row)

◆ bufferFirstStableBeamLS()

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

Definition at line 460 of file LHCInfoPerLSPopConAnalyzer.cc.

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

460  {
461  for (auto r : queryResult) {
462  if (r.get<std::string>("beams_stable") == "true") {
464  edm::LogInfo(m_name) << "Buffered first lumisection of stable beam: LS: "
465  << r.get<std::string>("lumisection_number")
466  << " run: " << r.get<std::string>("run_number");
467  return 1;
468  }
469  }
470  return 0;
471  }
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 504 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().

506  {
507  //run the fifth query against the CTPPS schema
508  //Initializing the CMS_CTP_CTPPS_COND schema.
509  coral::ISchema& CTPPS = session.coralSession().schema("CMS_PPS_SPECT_COND");
510  //execute query for CTPPS Data
511  std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
512  //FROM clause
513  CTPPSDataQuery->addToTableList(std::string("PPS_LHC_MACHINE_PARAMS"));
514  //SELECT clause
515  CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME"));
516  CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION"));
517  CTPPSDataQuery->addToOutputList(std::string("RUN_NUMBER"));
518  CTPPSDataQuery->addToOutputList(std::string("FILL_NUMBER"));
519  CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_X_URAD"));
520  CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_Y_URAD"));
521  CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_X_M"));
522  CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_Y_M"));
523  //WHERE CLAUSE
524  coral::AttributeList CTPPSDataBindVariables;
525  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("beginFillTime"));
526  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("endFillTime"));
527  CTPPSDataBindVariables[std::string("beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
528  CTPPSDataBindVariables[std::string("endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
529  std::string conditionStr = std::string("DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
530  CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
531  //ORDER BY clause
532  CTPPSDataQuery->addToOrderList(std::string("DIP_UPDATE_TIME"));
533  //define query output
534  coral::AttributeList CTPPSDataOutput;
535  CTPPSDataOutput.extend<coral::TimeStamp>(std::string("DIP_UPDATE_TIME"));
536  CTPPSDataOutput.extend<int>(std::string("LUMI_SECTION"));
537  CTPPSDataOutput.extend<int>(std::string("RUN_NUMBER"));
538  CTPPSDataOutput.extend<int>(std::string("FILL_NUMBER"));
539  CTPPSDataOutput.extend<float>(std::string("XING_ANGLE_P5_X_URAD"));
540  CTPPSDataOutput.extend<float>(std::string("XING_ANGLE_P5_Y_URAD"));
541  CTPPSDataOutput.extend<float>(std::string("BETA_STAR_P5_X_M"));
542  CTPPSDataOutput.extend<float>(std::string("BETA_STAR_P5_Y_M"));
543  CTPPSDataQuery->defineOutput(CTPPSDataOutput);
544  //execute the query
545  coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
546  unsigned int lumiSection = 0;
548  int fillNumber = 0;
549  float crossingAngleX = 0., betaStarX = 0.;
550  float crossingAngleY = 0., betaStarY = 0.;
551 
552  bool ret = false;
553  int wrongFillNumbers = 0;
554  std::stringstream wrongFills;
555  std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::iterator current = m_tmpBuffer.begin();
556  while (CTPPSDataCursor.next()) {
557  if (m_debug) {
558  std::ostringstream CTPPS;
559  CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
560  }
561  coral::Attribute const& dipTimeAttribute = CTPPSDataCursor.currentRow()[std::string("DIP_UPDATE_TIME")];
562  if (!dipTimeAttribute.isNull()) {
563  ret = true;
564  coral::Attribute const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[std::string("LUMI_SECTION")];
565  if (!lumiSectionAttribute.isNull()) {
566  lumiSection = lumiSectionAttribute.data<int>();
567  }
568  coral::Attribute const& runNumberAttribute = CTPPSDataCursor.currentRow()[std::string("RUN_NUMBER")];
569  if (!runNumberAttribute.isNull()) {
570  runNumber = runNumberAttribute.data<int>();
571  }
572  coral::Attribute const& fillNumberAttribute = CTPPSDataCursor.currentRow()[std::string("FILL_NUMBER")];
573  if (!fillNumberAttribute.isNull()) {
574  fillNumber = fillNumberAttribute.data<int>();
575  }
576  coral::Attribute const& crossingAngleXAttribute =
577  CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_X_URAD")];
578  if (!crossingAngleXAttribute.isNull()) {
579  crossingAngleX = crossingAngleXAttribute.data<float>();
580  }
581  coral::Attribute const& crossingAngleYAttribute =
582  CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_Y_URAD")];
583  if (!crossingAngleYAttribute.isNull()) {
584  crossingAngleY = crossingAngleYAttribute.data<float>();
585  }
586  coral::Attribute const& betaStarXAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_X_M")];
587  if (!betaStarXAttribute.isNull()) {
588  betaStarX = betaStarXAttribute.data<float>();
589  }
590  coral::Attribute const& betaStarYAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_Y_M")];
591  if (!betaStarYAttribute.isNull()) {
592  betaStarY = betaStarYAttribute.data<float>();
593  }
594  if (current != m_tmpBuffer.end() && current->second->fillNumber() != fillNumber) {
595  wrongFills << "( " << runNumber << "_" << lumiSection << " fill: OMS: " << current->second->fillNumber()
596  << " PPSdb: " << fillNumber << " ) ";
597  wrongFillNumbers++;
598  }
599  for (;
600  current != m_tmpBuffer.end() && make_pair(current->second->runNumber(), current->second->lumiSection()) <=
601  make_pair(runNumber, lumiSection);
602  current++) {
603  LHCInfoPerLS& payload = *(current->second);
604  payload.setCrossingAngleX(crossingAngleX);
605  payload.setCrossingAngleY(crossingAngleY);
606  payload.setBetaStarX(betaStarX);
607  payload.setBetaStarY(betaStarY);
608  payload.setLumiSection(lumiSection);
609  payload.setRunNumber(runNumber);
610  if (m_lsIdMap.find(make_pair(payload.runNumber(), payload.lumiSection())) != m_lsIdMap.end()) {
611  m_lsIdMap[make_pair(payload.runNumber(), payload.lumiSection())] = make_pair(runNumber, lumiSection);
612  }
613  }
614  }
615  }
616  if (wrongFillNumbers) {
617  edm::LogWarning("getCTPPSData") << "Number of records from PPS DB with fillNumber different from OMS: "
618  << wrongFillNumbers;
619  edm::LogWarning("getCTPPSData") << "Records from PPS DB with fillNumber different from OMS: " << wrongFills.str();
620  }
621  return ret;
622  }
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 473 of file LHCInfoPerLSPopConAnalyzer.cc.

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

Referenced by getNewObjects().

476  {
477  auto query = oms.query("lumisections");
478  query->addOutputVars({"start_time", "run_number", "beams_stable", "lumisection_number"});
479  query->filterEQ("fill_number", fillId);
480  query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime);
482  size_t nlumi = 0;
483  if (query->execute()) {
484  auto queryResult = query->result();
485  if (m_endFillMode) {
486  nlumi = bufferAllLS(queryResult);
487  } else if (!queryResult.empty()) {
488  auto newestPayload = queryResult.back();
489  if (newestPayload.get<std::string>("beams_stable") == "true") {
490  addPayloadToBuffer(newestPayload);
491  nlumi = 1;
492  edm::LogInfo(m_name) << "Buffered most recent lumisection:"
493  << " LS: " << newestPayload.get<std::string>("lumisection_number")
494  << " run: " << newestPayload.get<std::string>("run_number");
495  }
496  }
497  edm::LogInfo(m_name) << "Found " << queryResult.size() << " lumisections during the fill " << fillId;
498  } else {
499  edm::LogInfo(m_name) << "OMS query for lumisections of fill " << fillId << "failed, status:" << query->status();
500  }
501  return nlumi;
502  }
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 223 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().

223  {
224  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
225  if (tagInfo().size == 0) {
226  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
227  } else {
228  //check what is already inside the database
229  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size
230  << ", last object valid since " << tagInfo().lastInterval.since << " ( "
231  << boost::posix_time::to_iso_extended_string(
232  cond::time::to_boost(tagInfo().lastInterval.since))
233  << " ); from " << m_name << "::getNewObjects";
234  }
235 
236  cond::Time_t lastSince = tagInfo().lastInterval.since;
237  if (tagInfo().isEmpty()) {
238  // for a new or empty tag, an empty payload should be added on top with since=1
239  addEmptyPayload(1);
240  lastSince = 1;
241  } else {
242  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
243  << m_name << "::getNewObjects";
244  }
245 
246  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
247  cond::Time_t targetSince = 0;
248  cond::Time_t executionTimeIov = cond::time::from_boost(executionTime);
249  if (!m_startTime.is_not_a_date_time()) {
250  targetSince = cond::time::from_boost(m_startTime);
251  }
252  if (lastSince > targetSince)
253  targetSince = lastSince;
254 
255  edm::LogInfo(m_name) << "Starting sampling at "
256  << boost::posix_time::to_simple_string(cond::time::to_boost(targetSince));
257 
258  //retrieve the data from the relational database source
260  //configure the connection
261  if (m_debug) {
262  connection.setMessageVerbosity(coral::Debug);
263  } else {
264  connection.setMessageVerbosity(coral::Error);
265  }
266  connection.setAuthenticationPath(m_authpath);
267  connection.configure();
268  //create the sessions
269  cond::persistency::Session session = connection.createSession(m_connectionString, false);
270  // fetch last payload when available
271  if (!tagInfo().lastInterval.payloadId.empty()) {
273  session3.transaction().start(true);
275  session3.transaction().commit();
276 
277  // find startFillTime and endFillTime of the most recent fill already saved in the tag
278  if (m_prevPayload->fillNumber() != 0) {
279  cond::OMSService oms;
280  oms.connect(m_omsBaseUrl);
281  auto query = oms.query("fills");
282  query->addOutputVar("end_time");
283  query->addOutputVar("start_time");
284  query->filterEQ("fill_number", m_prevPayload->fillNumber());
285  bool foundFill = query->execute();
286  if (foundFill) {
287  auto result = query->result();
288 
289  if (!result.empty()) {
290  std::string endTimeStr = (*result.begin()).get<std::string>("end_time");
292  (endTimeStr == "null")
293  ? 0
294  : cond::time::from_boost((*result.begin()).get<boost::posix_time::ptime>("end_time"));
295  auto startFillTime = (*result.begin()).get<boost::posix_time::ptime>("start_time");
297  } else {
298  foundFill = false;
299  }
300  }
301  if (!foundFill) {
302  edm::LogError(m_name) << "Could not find end time of fill #" << m_prevPayload->fillNumber();
303  }
304  } else {
305  m_prevEndFillTime = 0;
307  }
308  }
309 
310  while (true) {
311  if (targetSince >= executionTimeIov) {
312  edm::LogInfo(m_name) << "Sampling ended at the time "
313  << boost::posix_time::to_simple_string(cond::time::to_boost(executionTimeIov));
314  break;
315  }
316  boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince);
317  boost::posix_time::ptime startSampleTime;
318  boost::posix_time::ptime endSampleTime;
319 
320  cond::OMSService oms;
321  oms.connect(m_omsBaseUrl);
322  auto query = oms.query("fills");
323 
324  if (!m_endFillMode and m_prevPayload->fillNumber() and m_prevEndFillTime == 0ULL) {
325  // continue processing unfinished fill with some payloads already in the tag
326  edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber();
327  query->filterEQ("fill_number", m_prevPayload->fillNumber());
328  bool foundFill = query->execute();
329  if (foundFill)
330  foundFill = makeFillPayload(m_fillPayload, query->result());
331  if (!foundFill) {
332  edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber();
333  break;
334  }
335  startSampleTime = cond::time::to_boost(lastSince);
336  } else {
337  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
338  query->filterNotNull("start_stable_beam").filterNotNull("fill_number");
339  if (targetTime > cond::time::to_boost(m_prevStartFillTime)) {
340  query->filterGE("start_time", targetTime);
341  } else {
342  query->filterGT("start_time", targetTime);
343  }
344 
345  query->filterLT("start_time", m_endTime);
346  if (m_endFillMode)
347  query->filterNotNull("end_time");
348  bool foundFill = query->execute();
349  if (foundFill)
350  foundFill = makeFillPayload(m_fillPayload, query->result());
351  if (!foundFill) {
352  edm::LogInfo(m_name) << "No fill found - END of job.";
353  break;
354  }
355  startSampleTime = cond::time::to_boost(m_startFillTime);
356  }
357 
358  unsigned short lhcFill = m_fillPayload->fillNumber();
359  bool ongoingFill = m_endFillTime == 0ULL;
360  if (ongoingFill) {
361  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at "
363  endSampleTime = executionTime;
364  targetSince = executionTimeIov;
365  } else {
366  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(m_startFillTime)
367  << " ending at " << cond::time::to_boost(m_endFillTime);
368  endSampleTime = cond::time::to_boost(m_endFillTime);
369  targetSince = m_endFillTime;
370  }
371 
372  if (m_endFillMode || ongoingFill) {
373  getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
374 
375  if (!m_tmpBuffer.empty()) {
376  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
377  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
378  edm::LogInfo(m_name) << "First buffered lumi starts at " << flumiStart << " last lumi starts at "
379  << flumiStop;
380  session.transaction().start(true);
381  getCTPPSData(session, startSampleTime, endSampleTime);
382  session.transaction().commit();
383  }
384  }
385 
388  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
389  if (niovs) {
392  }
393  m_tmpBuffer.clear();
394  m_lsIdMap.clear();
395  if (m_prevPayload->fillNumber() and !ongoingFill)
397  }
398  }
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 426 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().

426  {
427  bool ret = false;
428  if (!queryResult.empty()) {
429  auto row = *queryResult.begin();
430  auto currentFill = row.get<unsigned short>("fill_number");
431  m_startFillTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("start_time"));
432  std::string endTimeStr = row.get<std::string>("end_time");
433  m_endFillTime =
434  (endTimeStr == "null") ? 0 : cond::time::from_boost(row.get<boost::posix_time::ptime>("end_time"));
435  m_startStableBeamTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("start_stable_beam"));
436  m_endStableBeamTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("end_stable_beam"));
437  targetPayload = std::make_unique<LHCInfoPerLS>();
438  targetPayload->setFillNumber(currentFill);
439  ret = true;
440  }
441  return ret;
442  }
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 401 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getLumiData().

◆ m_authpath

std::string LHCInfoPerLSPopConSourceHandler::m_authpath
private

Definition at line 635 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_connectionString

std::string LHCInfoPerLSPopConSourceHandler::m_connectionString
private

Definition at line 634 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_debug

bool LHCInfoPerLSPopConSourceHandler::m_debug
private

Definition at line 625 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getCTPPSData(), and getNewObjects().

◆ m_dipSchema

std::string LHCInfoPerLSPopConSourceHandler::m_dipSchema
private

Definition at line 635 of file LHCInfoPerLSPopConAnalyzer.cc.

◆ m_ecalConnectionString

std::string LHCInfoPerLSPopConSourceHandler::m_ecalConnectionString
private

Definition at line 634 of file LHCInfoPerLSPopConAnalyzer.cc.

◆ m_endFillMode

bool LHCInfoPerLSPopConSourceHandler::m_endFillMode = true
private

Definition at line 631 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getLumiData(), and getNewObjects().

◆ m_endFillTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_endFillTime
private

Definition at line 640 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects(), and makeFillPayload().

◆ m_endStableBeamTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_endStableBeamTime
private

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

Referenced by addPayloadToBuffer(), and getNewObjects().

◆ m_lastPayloadEmpty

bool LHCInfoPerLSPopConSourceHandler::m_lastPayloadEmpty = false
private

Definition at line 646 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 649 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 636 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_prevEndFillTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_prevEndFillTime
private

Definition at line 641 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addEmptyPayload(), and getNewObjects().

◆ m_prevPayload

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

Definition at line 638 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addEmptyPayload(), and getNewObjects().

◆ m_prevStartFillTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_prevStartFillTime
private

Definition at line 642 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by addEmptyPayload(), and getNewObjects().

◆ m_samplingInterval

unsigned int LHCInfoPerLSPopConSourceHandler::m_samplingInterval
private

Definition at line 630 of file LHCInfoPerLSPopConAnalyzer.cc.

◆ m_startFillTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_startFillTime
private

Definition at line 639 of file LHCInfoPerLSPopConAnalyzer.cc.

Referenced by getNewObjects(), and makeFillPayload().

◆ m_startStableBeamTime

cond::Time_t LHCInfoPerLSPopConSourceHandler::m_startStableBeamTime
private

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

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