CMS 3D CMS Logo

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

Public Member Functions

void getNewObjects () override
 
std::string id () const override
 
 LHCInfoPerFillPopConSourceHandler (edm::ParameterSet const &pset)
 
 ~LHCInfoPerFillPopConSourceHandler () override=default
 
- Public Member Functions inherited from popcon::PopConSourceHandler< LHCInfoPerFill >
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)
 
bool getCTTPSData (cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
 
void getDipData (const cond::OMSService &oms, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
 
bool getEcalData (cond::persistency::Session &session, const boost::posix_time::ptime &lowerTime, const boost::posix_time::ptime &upperTime, bool update)
 
size_t getLumiData (const cond::OMSService &oms, unsigned short fillId, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
 

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
 
boost::posix_time::ptime m_endTime
 
std::unique_ptr< LHCInfoPerFillm_fillPayload
 
bool m_lastPayloadEmpty = false
 
std::string m_name
 
std::string m_omsBaseUrl
 
std::shared_ptr< LHCInfoPerFillm_prevPayload
 
unsigned int m_samplingInterval
 
boost::posix_time::ptime m_startTime
 
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer
 

Additional Inherited Members

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

Detailed Description

Definition at line 206 of file LHCInfoPerFillPopConAnalyzer.cc.

Constructor & Destructor Documentation

◆ LHCInfoPerFillPopConSourceHandler()

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

Definition at line 208 of file LHCInfoPerFillPopConAnalyzer.cc.

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

209  : m_debug(pset.getUntrackedParameter<bool>("debug", false)),
210  m_startTime(),
211  m_endTime(),
212  m_samplingInterval((unsigned int)pset.getUntrackedParameter<unsigned int>("samplingInterval", 300)),
213  m_endFillMode(pset.getUntrackedParameter<bool>("endFill", true)),
214  m_name(pset.getUntrackedParameter<std::string>("name", "LHCInfoPerFillPopConSourceHandler")),
215  m_connectionString(pset.getUntrackedParameter<std::string>("connectionString", "")),
216  m_ecalConnectionString(pset.getUntrackedParameter<std::string>("ecalConnectionString", "")),
217  m_dipSchema(pset.getUntrackedParameter<std::string>("DIPSchema", "")),
218  m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
219  m_omsBaseUrl(pset.getUntrackedParameter<std::string>("omsBaseUrl", "")),
220  m_fillPayload(),
221  m_prevPayload(),
222  m_tmpBuffer() {
223  if (!pset.getUntrackedParameter<std::string>("startTime").empty()) {
224  m_startTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("startTime"));
225  }
226  boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
227  m_endTime = now;
228  if (!pset.getUntrackedParameter<std::string>("endTime").empty()) {
229  m_endTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("endTime"));
230  if (m_endTime > now)
231  m_endTime = now;
232  }
233  }
std::shared_ptr< LHCInfoPerFill > m_prevPayload
std::unique_ptr< LHCInfoPerFill > m_fillPayload
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer

◆ ~LHCInfoPerFillPopConSourceHandler()

LHCInfoPerFillPopConSourceHandler::~LHCInfoPerFillPopConSourceHandler ( )
overridedefault

Member Function Documentation

◆ addEmptyPayload()

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

Definition at line 379 of file LHCInfoPerFillPopConAnalyzer.cc.

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

Referenced by getNewObjects().

379  {
380  bool add = false;
381  if (m_iovs.empty()) {
382  if (!m_lastPayloadEmpty)
383  add = true;
384  } else {
385  auto lastAdded = m_iovs.rbegin()->second;
386  if (lastAdded->fillNumber() != 0) {
387  add = true;
388  }
389  }
390  if (add) {
391  auto newPayload = std::make_shared<LHCInfoPerFill>();
392  m_iovs.insert(std::make_pair(iov, newPayload));
393  m_prevPayload = newPayload;
394  edm::LogInfo(m_name) << "Added empty payload with IOV " << iov << " ( "
395  << boost::posix_time::to_iso_extended_string(cond::time::to_boost(iov)) << " )";
396  }
397  }
std::shared_ptr< LHCInfoPerFill > 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 LHCInfoPerFillPopConSourceHandler::addPayloadToBuffer ( cond::OMSServiceResultRef row)
inlineprivate

Definition at line 399 of file LHCInfoPerFillPopConAnalyzer.cc.

References cond::time::from_boost(), cond::OMSServiceResultRef::get(), cond::time::lumiTime(), m_fillPayload, m_tmpBuffer, and jetsAK4_Puppi_cff::payload.

Referenced by getLumiData().

399  {
400  auto lumiTime = row.get<boost::posix_time::ptime>("start_time");
401  auto delivLumi = row.get<float>("delivered_lumi");
402  auto recLumi = row.get<float>("recorded_lumi");
403  LHCInfoPerFill* thisLumiSectionInfo = m_fillPayload->cloneFill();
404  m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
405  LHCInfoPerFill& payload = *thisLumiSectionInfo;
406  payload.setDelivLumi(delivLumi);
407  payload.setRecLumi(recLumi);
408  }
T get(const std::string &attributeName)
Definition: OMSAccess.h:114
Time_t lumiTime(unsigned int run, unsigned int lumiId)
Definition: Time.cc:66
std::unique_ptr< LHCInfoPerFill > m_fillPayload
Time_t from_boost(boost::posix_time::ptime bt)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer

◆ getCTTPSData()

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

Definition at line 500 of file LHCInfoPerFillPopConAnalyzer.cc.

References cond::persistency::Session::coralSession(), ALCARECOTkAlBeamHalo_cff::filter, cond::time::from_boost(), m_debug, m_name, m_tmpBuffer, jetsAK4_Puppi_cff::payload, runTheMatrix::ret, convertSQLiteXML::runNumber, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getNewObjects().

502  {
503  //run the fifth query against the CTPPS schema
504  //Initializing the CMS_CTP_CTPPS_COND schema.
505  coral::ISchema& CTPPS = session.coralSession().schema("CMS_PPS_SPECT_COND");
506  //execute query for CTPPS Data
507  std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
508  //FROM clause
509  CTPPSDataQuery->addToTableList(std::string("PPS_LHC_MACHINE_PARAMS"));
510  //SELECT clause
511  CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME"));
512  CTPPSDataQuery->addToOutputList(std::string("LHC_STATE"));
513  CTPPSDataQuery->addToOutputList(std::string("LHC_COMMENT"));
514  if (m_debug) {
515  CTPPSDataQuery->addToOutputList(std::string("RUN_NUMBER"));
516  CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION"));
517  }
518  //WHERE CLAUSE
519  coral::AttributeList CTPPSDataBindVariables;
520  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("beginFillTime"));
521  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("endFillTime"));
522  CTPPSDataBindVariables[std::string("beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
523  CTPPSDataBindVariables[std::string("endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
524  std::string conditionStr = std::string("DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
525  CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
526  //ORDER BY clause
527  CTPPSDataQuery->addToOrderList(std::string("DIP_UPDATE_TIME"));
528  //define query output
529  coral::AttributeList CTPPSDataOutput;
530  CTPPSDataOutput.extend<coral::TimeStamp>(std::string("DIP_UPDATE_TIME"));
531  CTPPSDataOutput.extend<std::string>(std::string("LHC_STATE"));
532  CTPPSDataOutput.extend<std::string>(std::string("LHC_COMMENT"));
533  if (m_debug) {
534  CTPPSDataOutput.extend<int>(std::string("RUN_NUMBER"));
535  CTPPSDataOutput.extend<int>(std::string("LUMI_SECTION"));
536  }
537  CTPPSDataQuery->defineOutput(CTPPSDataOutput);
538  //execute the query
539  coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
540  cond::Time_t dipTime = 0;
541  std::string lhcState = "", lhcComment = "", ctppsStatus = "";
542 
543  //debug informations
544  unsigned int lumiSection = 0;
546  cond::Time_t savedDipTime = 0;
547  unsigned int savedLumiSection = 0;
548  cond::Time_t savedRunNumber = 0;
549 
550  bool ret = false;
552  while (CTPPSDataCursor.next()) {
553  if (m_debug) {
554  std::ostringstream CTPPS;
555  CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
556  }
557  coral::Attribute const& dipTimeAttribute = CTPPSDataCursor.currentRow()[std::string("DIP_UPDATE_TIME")];
558  if (!dipTimeAttribute.isNull()) {
559  dipTime = cond::time::from_boost(dipTimeAttribute.data<coral::TimeStamp>().time());
560  if (filter.process(dipTime)) {
561  ret = true;
562  coral::Attribute const& lhcStateAttribute = CTPPSDataCursor.currentRow()[std::string("LHC_STATE")];
563  if (!lhcStateAttribute.isNull()) {
564  lhcState = lhcStateAttribute.data<std::string>();
565  }
566  coral::Attribute const& lhcCommentAttribute = CTPPSDataCursor.currentRow()[std::string("LHC_COMMENT")];
567  if (!lhcCommentAttribute.isNull()) {
568  lhcComment = lhcCommentAttribute.data<std::string>();
569  }
570 
571  if (m_debug) {
572  coral::Attribute const& runNumberAttribute = CTPPSDataCursor.currentRow()[std::string("RUN_NUMBER")];
573  if (!runNumberAttribute.isNull()) {
574  runNumber = runNumberAttribute.data<int>();
575  }
576  coral::Attribute const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[std::string("LUMI_SECTION")];
577  if (!lumiSectionAttribute.isNull()) {
578  lumiSection = lumiSectionAttribute.data<int>();
579  }
580  }
581 
582  for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) {
583  // set the current values to all of the payloads of the lumi section samples after the current since
584  LHCInfoPerFill& payload = *(it->second);
585  payload.setLhcState(lhcState);
586  payload.setLhcComment(lhcComment);
587  payload.setCtppsStatus(ctppsStatus);
588 
589  if (m_debug) {
590  savedDipTime = dipTime;
591  savedLumiSection = lumiSection;
592  savedRunNumber = runNumber;
593  }
594  }
595  }
596  }
597  }
598  if (m_debug) {
599  edm::LogInfo(m_name) << "Last assigned: "
600  << "DipTime: " << savedDipTime << " "
601  << "LumiSection: " << savedLumiSection << " "
602  << "RunNumber: " << savedRunNumber;
603  }
604  return ret;
605  }
ret
prodAgent to be discontinued
unsigned long long Time_t
Definition: Time.h:14
Time_t from_boost(boost::posix_time::ptime bt)
Log< level::Info, false > LogInfo
coral::ISessionProxy & coralSession()
Definition: Session.cc:218
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer

◆ getDipData()

void LHCInfoPerFillPopConSourceHandler::getDipData ( const cond::OMSService oms,
const boost::posix_time::ptime &  beginFillTime,
const boost::posix_time::ptime &  endFillTime 
)
inlineprivate

Definition at line 438 of file LHCInfoPerFillPopConAnalyzer.cc.

References m_fillPayload, and cond::OMSService::query().

Referenced by getNewObjects().

440  {
441  // unsure how to handle this.
442  // the old implementation is not helping: apparently it is checking only the bunchconfiguration for the first diptime set of values...
443  auto query1 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam1");
444  query1->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime);
445  //This query is limited to 100 rows, but currently only one is used
446  //If all this data is needed and saved properly the limit has to be set: query1->limit(...)
447  if (query1->execute()) {
448  auto res = query1->result();
449  if (!res.empty()) {
450  std::bitset<LHCInfoPerFill::bunchSlots + 1> bunchConfiguration1(0ULL);
451  auto row = *res.begin();
452  auto vbunchConf1 = row.getArray<unsigned short>("value");
453  for (auto vb : vbunchConf1) {
454  if (vb != 0) {
455  unsigned short slot = (vb - 1) / 10 + 1;
456  bunchConfiguration1[slot] = true;
457  }
458  }
459  m_fillPayload->setBunchBitsetForBeam1(bunchConfiguration1);
460  }
461  }
462  auto query2 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam2");
463  query2->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime);
464  //This query is limited to 100 rows, but currently only one is used
465  if (query2->execute()) {
466  auto res = query2->result();
467  if (!res.empty()) {
468  std::bitset<LHCInfoPerFill::bunchSlots + 1> bunchConfiguration2(0ULL);
469  auto row = *res.begin();
470  auto vbunchConf2 = row.getArray<unsigned short>("value");
471  for (auto vb : vbunchConf2) {
472  if (vb != 0) {
473  unsigned short slot = (vb - 1) / 10 + 1;
474  bunchConfiguration2[slot] = true;
475  }
476  }
477  m_fillPayload->setBunchBitsetForBeam2(bunchConfiguration2);
478  }
479  }
480 
481  auto query3 = oms.query("diplogger/dip/CMS/LHC/LumiPerBunch");
482  query3->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime);
483  //This query is limited to 100 rows, but currently only one is used
484  if (query3->execute()) {
485  auto res = query3->result();
486  if (!res.empty()) {
487  std::vector<float> lumiPerBX;
488  auto row = *res.begin();
489  auto lumiBunchInst = row.getArray<float>("lumi_bunch_inst");
490  for (auto lb : lumiBunchInst) {
491  if (lb != 0.) {
492  lumiPerBX.push_back(lb);
493  }
494  }
495  m_fillPayload->setLumiPerBX(lumiPerBX);
496  }
497  }
498  }
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:129
Definition: Electron.h:6
std::unique_ptr< LHCInfoPerFill > m_fillPayload

◆ getEcalData()

bool LHCInfoPerFillPopConSourceHandler::getEcalData ( cond::persistency::Session session,
const boost::posix_time::ptime &  lowerTime,
const boost::posix_time::ptime &  upperTime,
bool  update 
)
inlineprivate

Definition at line 607 of file LHCInfoPerFillPopConAnalyzer.cc.

References ECAL, ALCARECOTkAlBeamHalo_cff::filter, cond::time::from_boost(), CommonMethods::isnan(), m_debug, m_name, m_prevPayload, m_tmpBuffer, cond::persistency::Session::nominalSchema(), jetsAK4_Puppi_cff::payload, runTheMatrix::ret, theLHCInfoPerFillImpl::setElementData(), AlCaHLTBitMon_QueryRunRegistry::string, hcalRecHitTable_cff::time, cond::time::to_boost(), and update.

Referenced by getNewObjects().

610  {
611  //run the sixth query against the CMS_DCS_ENV_PVSS_COND schema
612  //Initializing the CMS_DCS_ENV_PVSS_COND schema.
613  coral::ISchema& ECAL = session.nominalSchema();
614  //start the transaction against the fill logging schema
615  //execute query for ECAL Data
616  std::unique_ptr<coral::IQuery> ECALDataQuery(ECAL.newQuery());
617  //FROM clause
618  ECALDataQuery->addToTableList(std::string("BEAM_PHASE"));
619  //SELECT clause
620  ECALDataQuery->addToOutputList(std::string("CHANGE_DATE"));
621  ECALDataQuery->addToOutputList(std::string("DIP_value"));
622  ECALDataQuery->addToOutputList(std::string("element_nr"));
623  ECALDataQuery->addToOutputList(std::string("VALUE_NUMBER"));
624  //WHERE CLAUSE
625  coral::AttributeList ECALDataBindVariables;
626  ECALDataBindVariables.extend<coral::TimeStamp>(std::string("lowerTime"));
627  ECALDataBindVariables.extend<coral::TimeStamp>(std::string("upperTime"));
628  ECALDataBindVariables[std::string("lowerTime")].data<coral::TimeStamp>() = coral::TimeStamp(lowerTime);
629  ECALDataBindVariables[std::string("upperTime")].data<coral::TimeStamp>() = coral::TimeStamp(upperTime);
630  std::string conditionStr = std::string(
631  "(DIP_value LIKE '%beamPhaseMean%' OR DIP_value LIKE '%cavPhaseMean%') AND CHANGE_DATE >= :lowerTime AND "
632  "CHANGE_DATE < :upperTime");
633 
634  ECALDataQuery->setCondition(conditionStr, ECALDataBindVariables);
635  //ORDER BY clause
636  ECALDataQuery->addToOrderList(std::string("CHANGE_DATE"));
637  ECALDataQuery->addToOrderList(std::string("DIP_value"));
638  ECALDataQuery->addToOrderList(std::string("element_nr"));
639  //define query output
640  coral::AttributeList ECALDataOutput;
641  ECALDataOutput.extend<coral::TimeStamp>(std::string("CHANGE_DATE"));
642  ECALDataOutput.extend<std::string>(std::string("DIP_value"));
643  ECALDataOutput.extend<unsigned int>(std::string("element_nr"));
644  ECALDataOutput.extend<float>(std::string("VALUE_NUMBER"));
645  //ECALDataQuery->limitReturnedRows( 14256 ); //3564 entries per vector.
646  ECALDataQuery->defineOutput(ECALDataOutput);
647  //execute the query
648  coral::ICursor& ECALDataCursor = ECALDataQuery->execute();
649  cond::Time_t changeTime = 0;
650  cond::Time_t firstTime = 0;
651  std::string dipVal = "";
652  unsigned int elementNr = 0;
653  float value = 0.;
654  std::set<cond::Time_t> initializedVectors;
656  bool ret = false;
657  if (m_prevPayload.get()) {
658  for (auto& lumiSlot : m_tmpBuffer) {
659  lumiSlot.second->setBeam1VC(m_prevPayload->beam1VC());
660  lumiSlot.second->setBeam2VC(m_prevPayload->beam2VC());
661  lumiSlot.second->setBeam1RF(m_prevPayload->beam1RF());
662  lumiSlot.second->setBeam2RF(m_prevPayload->beam2RF());
663  }
664  }
665  std::map<cond::Time_t, cond::Time_t> iovMap;
666  if (m_tmpBuffer.empty()) {
667  return ret;
668  }
669  cond::Time_t lowerLumi = m_tmpBuffer.front().first;
670  while (ECALDataCursor.next()) {
671  if (m_debug) {
672  std::ostringstream ECAL;
673  ECALDataCursor.currentRow().toOutputStream(ECAL);
674  }
675  coral::Attribute const& changeDateAttribute = ECALDataCursor.currentRow()[std::string("CHANGE_DATE")];
676  if (!changeDateAttribute.isNull()) {
677  ret = true;
678  boost::posix_time::ptime chTime = changeDateAttribute.data<coral::TimeStamp>().time();
679  // move the first IOV found to the start of the fill interval selected
680  if (changeTime == 0) {
681  firstTime = cond::time::from_boost(chTime);
682  }
683  changeTime = cond::time::from_boost(chTime);
684  cond::Time_t iovTime = changeTime;
685  if (!update and changeTime == firstTime)
686  iovTime = lowerLumi;
687  coral::Attribute const& dipValAttribute = ECALDataCursor.currentRow()[std::string("DIP_value")];
688  coral::Attribute const& valueNumberAttribute = ECALDataCursor.currentRow()[std::string("VALUE_NUMBER")];
689  coral::Attribute const& elementNrAttribute = ECALDataCursor.currentRow()[std::string("element_nr")];
690  if (!dipValAttribute.isNull() and !valueNumberAttribute.isNull()) {
691  dipVal = dipValAttribute.data<std::string>();
692  elementNr = elementNrAttribute.data<unsigned int>();
693  value = valueNumberAttribute.data<float>();
694  if (std::isnan(value))
695  value = 0.;
696  if (filter.process(iovTime)) {
697  iovMap.insert(std::make_pair(changeTime, filter.current()->first));
698  for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) {
699  LHCInfoPerFill& payload = *(it->second);
700  theLHCInfoPerFillImpl::setElementData(it->first, dipVal, elementNr, value, payload, initializedVectors);
701  }
702  }
703  //}
704  }
705  }
706  }
707  if (m_debug) {
708  for (auto& im : iovMap) {
709  edm::LogInfo(m_name) << "Found iov=" << im.first << " (" << cond::time::to_boost(im.first) << " ) moved to "
710  << im.second << " ( " << cond::time::to_boost(im.second) << " )";
711  }
712  }
713  return ret;
714  }
def isnan(num)
ret
prodAgent to be discontinued
std::shared_ptr< LHCInfoPerFill > m_prevPayload
void setElementData(cond::Time_t since, const std::string &dipVal, unsigned int elementNr, float value, LHCInfoPerFill &payload, std::set< cond::Time_t > &initList)
unsigned long long Time_t
Definition: Time.h:14
coral::ISchema & nominalSchema()
Definition: Session.cc:224
Definition: value.py:1
Time_t from_boost(boost::posix_time::ptime bt)
Log< level::Info, false > LogInfo
#define update(a, b)
boost::posix_time::ptime to_boost(Time_t iValue)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer

◆ getLumiData()

size_t LHCInfoPerFillPopConSourceHandler::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 LHCInfoPerFillPopConAnalyzer.cc.

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

Referenced by getNewObjects().

413  {
414  auto query = oms.query("lumisections");
415  query->addOutputVars({"start_time", "delivered_lumi", "recorded_lumi", "beams_stable"});
416  query->filterEQ("fill_number", fillId);
417  query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime);
418  query->filterEQ("beams_stable", "true");
420  if (query->execute()) {
421  auto queryResult = query->result();
422  edm::LogInfo(m_name) << "Found " << queryResult.size() << " lumisections with STABLE BEAM during the fill "
423  << fillId;
424 
425  if (!queryResult.empty()) {
426  if (m_endFillMode) {
427  auto firstRow = queryResult.front();
428  addPayloadToBuffer(firstRow);
429  }
430 
431  auto lastRow = queryResult.back();
432  addPayloadToBuffer(lastRow);
433  }
434  }
435  return 0;
436  }
static constexpr unsigned int kLumisectionsQueryLimit
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:129
Definition: query.py:1
void addPayloadToBuffer(cond::OMSServiceResultRef &row)
Log< level::Info, false > LogInfo

◆ getNewObjects()

void LHCInfoPerFillPopConSourceHandler::getNewObjects ( )
inlineoverridevirtual

Implements popcon::PopConSourceHandler< LHCInfoPerFill >.

Definition at line 237 of file LHCInfoPerFillPopConAnalyzer.cc.

References addEmptyPayload(), cond::persistency::Transaction::commit(), cond::persistency::ConnectionPool::configure(), cond::OMSService::connect(), cond::persistency::ConnectionPool::createSession(), popcon::PopConSourceHandler< LHCInfoPerFill >::dbSession(), Debug, cond::persistency::Session::fetchPayload(), cond::time::from_boost(), getCTTPSData(), getDipData(), getEcalData(), getLumiData(), cond::TagInfo_t::lastInterval, m_authpath, m_connectionString, m_debug, m_ecalConnectionString, m_endFillMode, m_endTime, m_fillPayload, popcon::PopConSourceHandler< LHCInfoPerFill >::m_iovs, m_name, m_omsBaseUrl, m_prevPayload, m_startTime, m_tmpBuffer, theLHCInfoPerFillImpl::makeFillPayload(), cond::TagInfo_t::name, cond::Iov_t::payloadId, cond::OMSService::query(), cond::persistency::ConnectionPool::setAuthenticationPath(), cond::persistency::ConnectionPool::setMessageVerbosity(), cond::Iov_t::since, cond::TagInfo_t::size, findQualityFiles::size, cond::persistency::Transaction::start(), popcon::PopConSourceHandler< LHCInfoPerFill >::tagInfo(), cond::time::to_boost(), cond::persistency::Session::transaction(), and theLHCInfoPerFillImpl::transferPayloads().

237  {
238  //reference to the last payload in the tag
239  Ref previousFill;
240 
241  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
242  if (tagInfo().size == 0) {
243  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
244  } else {
245  //check what is already inside the database
246  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size
247  << ", last object valid since " << tagInfo().lastInterval.since << " ( "
248  << boost::posix_time::to_iso_extended_string(
249  cond::time::to_boost(tagInfo().lastInterval.since))
250  << " ); from " << m_name << "::getNewObjects";
251  }
252 
253  cond::Time_t lastSince = tagInfo().lastInterval.since;
254  if (tagInfo().isEmpty()) {
255  // for a new or empty tag, an empty payload should be added on top with since=1
256  addEmptyPayload(1);
257  lastSince = 1;
258  } else {
259  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
260  << m_name << "::getNewObjects";
261  }
262 
263  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
264  cond::Time_t targetSince = 0;
265  cond::Time_t executionTimeIov = cond::time::from_boost(executionTime);
266  if (!m_startTime.is_not_a_date_time()) {
267  targetSince = cond::time::from_boost(m_startTime);
268  }
269  if (lastSince > targetSince)
270  targetSince = lastSince;
271 
272  edm::LogInfo(m_name) << "Starting sampling at "
273  << boost::posix_time::to_simple_string(cond::time::to_boost(targetSince));
274 
275  //retrieve the data from the relational database source
277  //configure the connection
278  if (m_debug) {
279  connection.setMessageVerbosity(coral::Debug);
280  } else {
281  connection.setMessageVerbosity(coral::Error);
282  }
283  connection.setAuthenticationPath(m_authpath);
284  connection.configure();
285  //create the sessions
286  cond::persistency::Session session = connection.createSession(m_connectionString, false);
288  // fetch last payload when available
289  if (!tagInfo().lastInterval.payloadId.empty()) {
291  session3.transaction().start(true);
293  session3.transaction().commit();
294  }
295 
296  // bool iovAdded = false;
297  while (true) {
298  if (targetSince >= executionTimeIov) {
299  edm::LogInfo(m_name) << "Sampling ended at the time "
300  << boost::posix_time::to_simple_string(cond::time::to_boost(executionTimeIov));
301  break;
302  }
303  bool updateEcal = false;
304  boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince);
305  boost::posix_time::ptime startSampleTime;
306  boost::posix_time::ptime endSampleTime;
307 
308  cond::OMSService oms;
309  oms.connect(m_omsBaseUrl);
310  auto query = oms.query("fills");
311 
312  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
313  query->filterNotNull("start_stable_beam").filterNotNull("fill_number");
314  if (targetTime > cond::time::to_boost(m_prevPayload->createTime())) {
315  query->filterGE("start_time", targetTime);
316  } else {
317  query->filterGT("start_time", targetTime);
318  }
319 
320  query->filterLT("start_time", m_endTime);
321  if (m_endFillMode)
322  query->filterNotNull("end_time");
323  bool foundFill = query->execute();
324  if (foundFill)
326  if (!foundFill) {
327  edm::LogInfo(m_name) << "No fill found - END of job.";
328  // if (iovAdded)
329  // addEmptyPayload(targetSince);
330  break;
331  }
332 
333  startSampleTime = cond::time::to_boost(m_fillPayload->createTime());
334  cond::Time_t startFillTime = m_fillPayload->createTime();
335  cond::Time_t endFillTime = m_fillPayload->endTime();
336  unsigned short lhcFill = m_fillPayload->fillNumber();
337  bool ongoingFill = endFillTime == 0ULL;
338  if (ongoingFill) {
339  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at "
340  << cond::time::to_boost(startFillTime);
341  endSampleTime = executionTime;
342  targetSince = executionTimeIov;
343  } else {
344  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime)
345  << " ending at " << cond::time::to_boost(endFillTime);
346  endSampleTime = cond::time::to_boost(endFillTime);
347  targetSince = endFillTime;
348  }
349  if (m_endFillMode || ongoingFill) {
350  getDipData(oms, startSampleTime, endSampleTime);
351  getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
352  if (!m_tmpBuffer.empty()) {
353  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
354  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
355  edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop;
356  session.transaction().start(true);
357  getCTTPSData(session, startSampleTime, endSampleTime);
358  session.transaction().commit();
359  session2.transaction().start(true);
360  getEcalData(session2, startSampleTime, endSampleTime, updateEcal);
361  session2.transaction().commit();
362  }
363  }
364 
366  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
367  m_tmpBuffer.clear();
368  // iovAdded = true;
369  if (m_prevPayload->fillNumber() and !ongoingFill)
370  addEmptyPayload(endFillTime);
371  }
372  }
size
Write out results.
edm::ErrorSummaryEntry Error
Iov_t lastInterval
Definition: Types.h:73
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:129
void start(bool readOnly=true)
Definition: Session.cc:18
std::shared_ptr< LHCInfoPerFill > m_prevPayload
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
Transaction & transaction()
Definition: Session.cc:52
void getDipData(const cond::OMSService &oms, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
std::string name
Definition: Types.h:72
Definition: query.py:1
unsigned long long Time_t
Definition: Time.h:14
bool makeFillPayload(std::unique_ptr< LHCInfoPerFill > &targetPayload, const cond::OMSServiceResult &queryResult)
std::unique_ptr< LHCInfoPerFill > m_fillPayload
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)
bool getEcalData(cond::persistency::Session &session, const boost::posix_time::ptime &lowerTime, const boost::posix_time::ptime &upperTime, bool update)
Log< level::Info, false > LogInfo
cond::persistency::Session & dbSession() const
void connect(const std::string &baseUrl)
Definition: OMSAccess.cc:128
size_t getLumiData(const cond::OMSService &oms, unsigned short fillId, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
void setAuthenticationPath(const std::string &p)
const bool Debug
boost::posix_time::ptime to_boost(Time_t iValue)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer
size_t transferPayloads(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill >>> &buffer, std::map< cond::Time_t, std::shared_ptr< LHCInfoPerFill >> &iovsToTransfer, std::shared_ptr< LHCInfoPerFill > &prevPayload)
bool getCTTPSData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)

◆ id()

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

Member Data Documentation

◆ kLumisectionsQueryLimit

constexpr unsigned int LHCInfoPerFillPopConSourceHandler::kLumisectionsQueryLimit = 4000
static

Definition at line 376 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getLumiData().

◆ m_authpath

std::string LHCInfoPerFillPopConSourceHandler::m_authpath
private

Definition at line 727 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_connectionString

std::string LHCInfoPerFillPopConSourceHandler::m_connectionString
private

Definition at line 726 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_debug

bool LHCInfoPerFillPopConSourceHandler::m_debug
private

Definition at line 717 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getCTTPSData(), getEcalData(), and getNewObjects().

◆ m_dipSchema

std::string LHCInfoPerFillPopConSourceHandler::m_dipSchema
private

Definition at line 727 of file LHCInfoPerFillPopConAnalyzer.cc.

◆ m_ecalConnectionString

std::string LHCInfoPerFillPopConSourceHandler::m_ecalConnectionString
private

Definition at line 726 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_endFillMode

bool LHCInfoPerFillPopConSourceHandler::m_endFillMode = true
private

Definition at line 723 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getLumiData(), and getNewObjects().

◆ m_endTime

boost::posix_time::ptime LHCInfoPerFillPopConSourceHandler::m_endTime
private

◆ m_fillPayload

std::unique_ptr<LHCInfoPerFill> LHCInfoPerFillPopConSourceHandler::m_fillPayload
private

Definition at line 729 of file LHCInfoPerFillPopConAnalyzer.cc.

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

◆ m_lastPayloadEmpty

bool LHCInfoPerFillPopConSourceHandler::m_lastPayloadEmpty = false
private

Definition at line 732 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by addEmptyPayload().

◆ m_name

std::string LHCInfoPerFillPopConSourceHandler::m_name
private

◆ m_omsBaseUrl

std::string LHCInfoPerFillPopConSourceHandler::m_omsBaseUrl
private

Definition at line 728 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_prevPayload

std::shared_ptr<LHCInfoPerFill> LHCInfoPerFillPopConSourceHandler::m_prevPayload
private

Definition at line 730 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by addEmptyPayload(), getEcalData(), and getNewObjects().

◆ m_samplingInterval

unsigned int LHCInfoPerFillPopConSourceHandler::m_samplingInterval
private

Definition at line 722 of file LHCInfoPerFillPopConAnalyzer.cc.

◆ m_startTime

boost::posix_time::ptime LHCInfoPerFillPopConSourceHandler::m_startTime
private

◆ m_tmpBuffer

std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerFill> > > LHCInfoPerFillPopConSourceHandler::m_tmpBuffer
private