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 503 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().

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

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

Referenced by getNewObjects().

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

Referenced by getNewObjects().

613  {
614  //run the sixth query against the CMS_DCS_ENV_PVSS_COND schema
615  //Initializing the CMS_DCS_ENV_PVSS_COND schema.
616  coral::ISchema& ECAL = session.nominalSchema();
617  //start the transaction against the fill logging schema
618  //execute query for ECAL Data
619  std::unique_ptr<coral::IQuery> ECALDataQuery(ECAL.newQuery());
620  //FROM clause
621  ECALDataQuery->addToTableList(std::string("BEAM_PHASE"));
622  //SELECT clause
623  ECALDataQuery->addToOutputList(std::string("CHANGE_DATE"));
624  ECALDataQuery->addToOutputList(std::string("DIP_value"));
625  ECALDataQuery->addToOutputList(std::string("element_nr"));
626  ECALDataQuery->addToOutputList(std::string("VALUE_NUMBER"));
627  //WHERE CLAUSE
628  coral::AttributeList ECALDataBindVariables;
629  ECALDataBindVariables.extend<coral::TimeStamp>(std::string("lowerTime"));
630  ECALDataBindVariables.extend<coral::TimeStamp>(std::string("upperTime"));
631  ECALDataBindVariables[std::string("lowerTime")].data<coral::TimeStamp>() = coral::TimeStamp(lowerTime);
632  ECALDataBindVariables[std::string("upperTime")].data<coral::TimeStamp>() = coral::TimeStamp(upperTime);
633  std::string conditionStr = std::string(
634  "(DIP_value LIKE '%beamPhaseMean%' OR DIP_value LIKE '%cavPhaseMean%') AND CHANGE_DATE >= :lowerTime AND "
635  "CHANGE_DATE < :upperTime");
636 
637  ECALDataQuery->setCondition(conditionStr, ECALDataBindVariables);
638  //ORDER BY clause
639  ECALDataQuery->addToOrderList(std::string("CHANGE_DATE"));
640  ECALDataQuery->addToOrderList(std::string("DIP_value"));
641  ECALDataQuery->addToOrderList(std::string("element_nr"));
642  //define query output
643  coral::AttributeList ECALDataOutput;
644  ECALDataOutput.extend<coral::TimeStamp>(std::string("CHANGE_DATE"));
645  ECALDataOutput.extend<std::string>(std::string("DIP_value"));
646  ECALDataOutput.extend<unsigned int>(std::string("element_nr"));
647  ECALDataOutput.extend<float>(std::string("VALUE_NUMBER"));
648  //ECALDataQuery->limitReturnedRows( 14256 ); //3564 entries per vector.
649  ECALDataQuery->defineOutput(ECALDataOutput);
650  //execute the query
651  coral::ICursor& ECALDataCursor = ECALDataQuery->execute();
652  cond::Time_t changeTime = 0;
653  cond::Time_t firstTime = 0;
654  std::string dipVal = "";
655  unsigned int elementNr = 0;
656  float value = 0.;
657  std::set<cond::Time_t> initializedVectors;
659  bool ret = false;
660  if (m_prevPayload.get()) {
661  for (auto& lumiSlot : m_tmpBuffer) {
662  lumiSlot.second->setBeam1VC(m_prevPayload->beam1VC());
663  lumiSlot.second->setBeam2VC(m_prevPayload->beam2VC());
664  lumiSlot.second->setBeam1RF(m_prevPayload->beam1RF());
665  lumiSlot.second->setBeam2RF(m_prevPayload->beam2RF());
666  }
667  }
668  std::map<cond::Time_t, cond::Time_t> iovMap;
669  if (m_tmpBuffer.empty()) {
670  return ret;
671  }
672  cond::Time_t lowerLumi = m_tmpBuffer.front().first;
673  while (ECALDataCursor.next()) {
674  if (m_debug) {
675  std::ostringstream ECAL;
676  ECALDataCursor.currentRow().toOutputStream(ECAL);
677  }
678  coral::Attribute const& changeDateAttribute = ECALDataCursor.currentRow()[std::string("CHANGE_DATE")];
679  if (!changeDateAttribute.isNull()) {
680  ret = true;
681  boost::posix_time::ptime chTime = changeDateAttribute.data<coral::TimeStamp>().time();
682  // move the first IOV found to the start of the fill interval selected
683  if (changeTime == 0) {
684  firstTime = cond::time::from_boost(chTime);
685  }
686  changeTime = cond::time::from_boost(chTime);
687  cond::Time_t iovTime = changeTime;
688  if (!update and changeTime == firstTime)
689  iovTime = lowerLumi;
690  coral::Attribute const& dipValAttribute = ECALDataCursor.currentRow()[std::string("DIP_value")];
691  coral::Attribute const& valueNumberAttribute = ECALDataCursor.currentRow()[std::string("VALUE_NUMBER")];
692  coral::Attribute const& elementNrAttribute = ECALDataCursor.currentRow()[std::string("element_nr")];
693  if (!dipValAttribute.isNull() and !valueNumberAttribute.isNull()) {
694  dipVal = dipValAttribute.data<std::string>();
695  elementNr = elementNrAttribute.data<unsigned int>();
696  value = valueNumberAttribute.data<float>();
697  if (std::isnan(value))
698  value = 0.;
699  if (filter.process(iovTime)) {
700  iovMap.insert(std::make_pair(changeTime, filter.current()->first));
701  for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) {
702  LHCInfoPerFill& payload = *(it->second);
703  theLHCInfoPerFillImpl::setElementData(it->first, dipVal, elementNr, value, payload, initializedVectors);
704  }
705  }
706  //}
707  }
708  }
709  }
710  if (m_debug) {
711  for (auto& im : iovMap) {
712  edm::LogInfo(m_name) << "Found iov=" << im.first << " (" << cond::time::to_boost(im.first) << " ) moved to "
713  << im.second << " ( " << cond::time::to_boost(im.second) << " )";
714  }
715  }
716  return ret;
717  }
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  int nLumi = 0;
422  auto queryResult = query->result();
423  edm::LogInfo(m_name) << "Found " << queryResult.size() << " lumisections with STABLE BEAM during the fill "
424  << fillId;
425 
426  if (!queryResult.empty()) {
427  if (m_endFillMode) {
428  auto firstRow = queryResult.front();
429  addPayloadToBuffer(firstRow);
430  nLumi++;
431  }
432 
433  auto lastRow = queryResult.back();
434  addPayloadToBuffer(lastRow);
435  nLumi++;
436  }
437  }
438  return 0;
439  }
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 730 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_connectionString

std::string LHCInfoPerFillPopConSourceHandler::m_connectionString
private

Definition at line 729 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_debug

bool LHCInfoPerFillPopConSourceHandler::m_debug
private

Definition at line 720 of file LHCInfoPerFillPopConAnalyzer.cc.

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

◆ m_dipSchema

std::string LHCInfoPerFillPopConSourceHandler::m_dipSchema
private

Definition at line 730 of file LHCInfoPerFillPopConAnalyzer.cc.

◆ m_ecalConnectionString

std::string LHCInfoPerFillPopConSourceHandler::m_ecalConnectionString
private

Definition at line 729 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_endFillMode

bool LHCInfoPerFillPopConSourceHandler::m_endFillMode = true
private

Definition at line 726 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 732 of file LHCInfoPerFillPopConAnalyzer.cc.

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

◆ m_lastPayloadEmpty

bool LHCInfoPerFillPopConSourceHandler::m_lastPayloadEmpty = false
private

Definition at line 735 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 731 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_prevPayload

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

Definition at line 733 of file LHCInfoPerFillPopConAnalyzer.cc.

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

◆ m_samplingInterval

unsigned int LHCInfoPerFillPopConSourceHandler::m_samplingInterval
private

Definition at line 725 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