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 getCTPPSData (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 208 of file LHCInfoPerFillPopConAnalyzer.cc.

Constructor & Destructor Documentation

◆ LHCInfoPerFillPopConSourceHandler()

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

Definition at line 210 of file LHCInfoPerFillPopConAnalyzer.cc.

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

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

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

401  {
402  auto lumiTime = row.get<boost::posix_time::ptime>("start_time");
403  auto delivLumi = row.get<float>("delivered_lumi");
404  auto recLumi = row.get<float>("recorded_lumi");
405  LHCInfoPerFill* thisLumiSectionInfo = m_fillPayload->cloneFill();
406  m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
407  LHCInfoPerFill& payload = *thisLumiSectionInfo;
408  payload.setDelivLumi(delivLumi);
409  payload.setRecLumi(recLumi);
410  }
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

◆ getCTPPSData()

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

Definition at line 502 of file LHCInfoPerFillPopConAnalyzer.cc.

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

Referenced by getNewObjects().

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

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

Referenced by getNewObjects().

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

References ECAL, ALCARECOTkAlBeamHalo_cff::filter, cond::time::from_boost(), CommonMethods::isnan(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, 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().

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

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

Referenced by getNewObjects().

415  {
416  auto query = oms.query("lumisections");
417  query->addOutputVars({"start_time", "delivered_lumi", "recorded_lumi", "beams_stable"});
418  query->filterEQ("fill_number", fillId);
419  query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime);
420  query->filterEQ("beams_stable", "true");
422  if (query->execute()) {
423  auto queryResult = query->result();
424  edm::LogInfo(m_name) << "Found " << queryResult.size() << " lumisections with STABLE BEAM during the fill "
425  << fillId;
426 
427  if (!queryResult.empty()) {
428  if (m_endFillMode) {
429  auto firstRow = queryResult.front();
430  addPayloadToBuffer(firstRow);
431  }
432 
433  auto lastRow = queryResult.back();
434  addPayloadToBuffer(lastRow);
435  }
436  }
437  return 0;
438  }
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 239 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(), getCTPPSData(), 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().

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

◆ id()

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

Member Data Documentation

◆ kLumisectionsQueryLimit

constexpr unsigned int LHCInfoPerFillPopConSourceHandler::kLumisectionsQueryLimit = 4000
static

Definition at line 378 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getLumiData().

◆ m_authpath

std::string LHCInfoPerFillPopConSourceHandler::m_authpath
private

Definition at line 729 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_connectionString

std::string LHCInfoPerFillPopConSourceHandler::m_connectionString
private

Definition at line 728 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_debug

bool LHCInfoPerFillPopConSourceHandler::m_debug
private

Definition at line 719 of file LHCInfoPerFillPopConAnalyzer.cc.

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

◆ m_dipSchema

std::string LHCInfoPerFillPopConSourceHandler::m_dipSchema
private

Definition at line 729 of file LHCInfoPerFillPopConAnalyzer.cc.

◆ m_ecalConnectionString

std::string LHCInfoPerFillPopConSourceHandler::m_ecalConnectionString
private

Definition at line 728 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_endFillMode

bool LHCInfoPerFillPopConSourceHandler::m_endFillMode = true
private

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

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

◆ m_lastPayloadEmpty

bool LHCInfoPerFillPopConSourceHandler::m_lastPayloadEmpty = false
private

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

Referenced by getNewObjects().

◆ m_prevPayload

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

Definition at line 732 of file LHCInfoPerFillPopConAnalyzer.cc.

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

◆ m_samplingInterval

unsigned int LHCInfoPerFillPopConSourceHandler::m_samplingInterval
private

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