CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
LHCInfoPopConSourceHandler Class Reference

#include <LHCInfoPopConSourceHandler.h>

Inheritance diagram for LHCInfoPopConSourceHandler:
popcon::PopConSourceHandler< LHCInfo >

Public Member Functions

void getNewObjects () override
 
std::string id () const override
 
 LHCInfoPopConSourceHandler (const edm::ParameterSet &pset)
 
 ~LHCInfoPopConSourceHandler () override
 
- Public Member Functions inherited from popcon::PopConSourceHandler< LHCInfo >
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)
 
bool getCTTPSData (cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
 
void getDipData (const cond::OMSService &service, 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 &service, 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_endFill = true
 
boost::posix_time::ptime m_endTime
 
std::unique_ptr< LHCInfom_fillPayload
 
bool m_lastPayloadEmpty = false
 
std::string m_name
 
std::string m_omsBaseUrl
 
std::shared_ptr< LHCInfom_prevPayload
 
unsigned int m_samplingInterval
 
boost::posix_time::ptime m_startTime
 
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > m_tmpBuffer
 

Additional Inherited Members

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

Detailed Description

Definition at line 14 of file LHCInfoPopConSourceHandler.h.

Constructor & Destructor Documentation

◆ LHCInfoPopConSourceHandler()

LHCInfoPopConSourceHandler::LHCInfoPopConSourceHandler ( const edm::ParameterSet pset)

Definition at line 64 of file LHCInfoPopConSourceHandler.cc.

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

65  : m_debug(pset.getUntrackedParameter<bool>("debug", false)),
66  m_startTime(),
67  m_endTime(),
68  m_samplingInterval((unsigned int)pset.getUntrackedParameter<unsigned int>("samplingInterval", 300)),
69  m_endFill(pset.getUntrackedParameter<bool>("endFill", true)),
70  m_name(pset.getUntrackedParameter<std::string>("name", "LHCInfoPopConSourceHandler")),
71  m_connectionString(pset.getUntrackedParameter<std::string>("connectionString", "")),
72  m_ecalConnectionString(pset.getUntrackedParameter<std::string>("ecalConnectionString", "")),
73  m_dipSchema(pset.getUntrackedParameter<std::string>("DIPSchema", "")),
74  m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
75  m_omsBaseUrl(pset.getUntrackedParameter<std::string>("omsBaseUrl", "")),
76  m_fillPayload(),
77  m_prevPayload(),
78  m_tmpBuffer() {
79  if (pset.exists("startTime")) {
80  m_startTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("startTime"));
81  }
82  boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
83  m_endTime = now;
84  if (pset.exists("endTime")) {
85  m_endTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("endTime"));
86  if (m_endTime > now)
87  m_endTime = now;
88  }
89 }
boost::posix_time::ptime m_startTime
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > m_tmpBuffer
std::unique_ptr< LHCInfo > m_fillPayload
std::shared_ptr< LHCInfo > m_prevPayload
boost::posix_time::ptime m_endTime

◆ ~LHCInfoPopConSourceHandler()

LHCInfoPopConSourceHandler::~LHCInfoPopConSourceHandler ( )
override

Definition at line 92 of file LHCInfoPopConSourceHandler.cc.

92 {}

Member Function Documentation

◆ addEmptyPayload()

void LHCInfoPopConSourceHandler::addEmptyPayload ( cond::Time_t  iov)
private

Definition at line 535 of file LHCInfoPopConSourceHandler.cc.

References PVValHelper::add(), popcon::PopConSourceHandler< LHCInfo >::m_iovs, m_lastPayloadEmpty, and m_prevPayload.

Referenced by getNewObjects().

535  {
536  bool add = false;
537  if (m_iovs.empty()) {
538  if (!m_lastPayloadEmpty)
539  add = true;
540  } else {
541  auto lastAdded = m_iovs.rbegin()->second;
542  if (lastAdded->fillNumber() != 0) {
543  add = true;
544  }
545  }
546  if (add) {
547  auto newPayload = std::make_shared<LHCInfo>();
548  m_iovs.insert(std::make_pair(iov, newPayload));
549  m_prevPayload = newPayload;
550  }
551 }
std::shared_ptr< LHCInfo > m_prevPayload
void add(std::map< std::string, TH1 *> &h, TH1 *hist)

◆ getCTTPSData()

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

Definition at line 299 of file LHCInfoPopConSourceHandler.cc.

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

Referenced by getNewObjects().

301  {
302  //run the fifth query against the CTPPS schema
303  //Initializing the CMS_CTP_CTPPS_COND schema.
304  coral::ISchema& CTPPS = session.coralSession().schema("CMS_PPS_SPECT_COND");
305  //execute query for CTPPS Data
306  std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
307  //FROM clause
308  CTPPSDataQuery->addToTableList(std::string("PPS_LHC_MACHINE_PARAMS"));
309  //SELECT clause
310  CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME"));
311  CTPPSDataQuery->addToOutputList(std::string("LHC_STATE"));
312  CTPPSDataQuery->addToOutputList(std::string("LHC_COMMENT"));
313  CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION"));
314  CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_X_URAD"));
315  CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_X_M"));
316  //WHERE CLAUSE
317  coral::AttributeList CTPPSDataBindVariables;
318  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("beginFillTime"));
319  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("endFillTime"));
320  CTPPSDataBindVariables[std::string("beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
321  CTPPSDataBindVariables[std::string("endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
322  std::string conditionStr = std::string("DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
323  CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
324  //ORDER BY clause
325  CTPPSDataQuery->addToOrderList(std::string("DIP_UPDATE_TIME"));
326  //define query output
327  coral::AttributeList CTPPSDataOutput;
328  CTPPSDataOutput.extend<coral::TimeStamp>(std::string("DIP_UPDATE_TIME"));
329  CTPPSDataOutput.extend<std::string>(std::string("LHC_STATE"));
330  CTPPSDataOutput.extend<std::string>(std::string("LHC_COMMENT"));
331  CTPPSDataOutput.extend<int>(std::string("LUMI_SECTION"));
332  CTPPSDataOutput.extend<float>(std::string("XING_ANGLE_P5_X_URAD"));
333  CTPPSDataOutput.extend<float>(std::string("BETA_STAR_P5_X_M"));
334  CTPPSDataQuery->defineOutput(CTPPSDataOutput);
335  //execute the query
336  coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
337  cond::Time_t dipTime = 0;
338  std::string lhcState = "", lhcComment = "", ctppsStatus = "";
339  unsigned int lumiSection = 0;
340  float crossingAngle = 0., betastar = 0.;
341 
342  bool ret = false;
344  while (CTPPSDataCursor.next()) {
345  if (m_debug) {
346  std::ostringstream CTPPS;
347  CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
348  }
349  coral::Attribute const& dipTimeAttribute = CTPPSDataCursor.currentRow()[std::string("DIP_UPDATE_TIME")];
350  if (!dipTimeAttribute.isNull()) {
351  dipTime = cond::time::from_boost(dipTimeAttribute.data<coral::TimeStamp>().time());
352  if (filter.process(dipTime)) {
353  ret = true;
354  coral::Attribute const& lhcStateAttribute = CTPPSDataCursor.currentRow()[std::string("LHC_STATE")];
355  if (!lhcStateAttribute.isNull()) {
356  lhcState = lhcStateAttribute.data<std::string>();
357  }
358  coral::Attribute const& lhcCommentAttribute = CTPPSDataCursor.currentRow()[std::string("LHC_COMMENT")];
359  if (!lhcCommentAttribute.isNull()) {
360  lhcComment = lhcCommentAttribute.data<std::string>();
361  }
362  coral::Attribute const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[std::string("LUMI_SECTION")];
363  if (!lumiSectionAttribute.isNull()) {
364  lumiSection = lumiSectionAttribute.data<int>();
365  }
366  coral::Attribute const& crossingAngleXAttribute =
367  CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_X_URAD")];
368  if (!crossingAngleXAttribute.isNull()) {
369  crossingAngle = crossingAngleXAttribute.data<float>();
370  }
371  coral::Attribute const& betaStarXAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_X_M")];
372  if (!betaStarXAttribute.isNull()) {
373  betastar = betaStarXAttribute.data<float>();
374  }
375  for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) {
376  // set the current values to all of the payloads of the lumi section samples after the current since
377  LHCInfo& payload = *(it->second);
378  payload.setCrossingAngle(crossingAngle);
379  payload.setBetaStar(betastar);
380  payload.setLhcState(lhcState);
381  payload.setLhcComment(lhcComment);
382  payload.setCtppsStatus(ctppsStatus);
383  payload.setLumiSection(lumiSection);
384  }
385  }
386  }
387  }
388  return ret;
389 }
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > m_tmpBuffer
ret
prodAgent to be discontinued
unsigned long long Time_t
Definition: Time.h:14
Time_t from_boost(boost::posix_time::ptime bt)
coral::ISessionProxy & coralSession()
Definition: Session.cc:218

◆ getDipData()

void LHCInfoPopConSourceHandler::getDipData ( const cond::OMSService service,
const boost::posix_time::ptime &  beginFillTime,
const boost::posix_time::ptime &  endFillTime 
)
private

Definition at line 237 of file LHCInfoPopConSourceHandler.cc.

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

Referenced by getNewObjects().

239  {
240  // unsure how to handle this.
241  // the old implementation is not helping: apparently it is checking only the bunchconfiguration for the first diptime set of values...
242  auto query1 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam1");
243  query1->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime);
244  //This query is limited to 100 rows, but currently only one is used
245  //If all this data is needed and saved properly the limit has to be set: query1->limit(...)
246  if (query1->execute()) {
247  auto res = query1->result();
248  if (!res.empty()) {
249  std::bitset<LHCInfo::bunchSlots + 1> bunchConfiguration1(0ULL);
250  auto row = *res.begin();
251  auto vbunchConf1 = row.getArray<unsigned short>("value");
252  for (auto vb : vbunchConf1) {
253  if (vb != 0) {
254  unsigned short slot = (vb - 1) / 10 + 1;
255  bunchConfiguration1[slot] = true;
256  }
257  }
258  m_fillPayload->setBunchBitsetForBeam1(bunchConfiguration1);
259  }
260  }
261  auto query2 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam2");
262  query2->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime);
263  //This query is limited to 100 rows, but currently only one is used
264  if (query2->execute()) {
265  auto res = query2->result();
266  if (!res.empty()) {
267  std::bitset<LHCInfo::bunchSlots + 1> bunchConfiguration2(0ULL);
268  auto row = *res.begin();
269  auto vbunchConf2 = row.getArray<unsigned short>("value");
270  for (auto vb : vbunchConf2) {
271  if (vb != 0) {
272  unsigned short slot = (vb - 1) / 10 + 1;
273  bunchConfiguration2[slot] = true;
274  }
275  }
276  m_fillPayload->setBunchBitsetForBeam2(bunchConfiguration2);
277  }
278  }
279 
280  auto query3 = oms.query("diplogger/dip/CMS/LHC/LumiPerBunch");
281  query3->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime);
282  //This query is limited to 100 rows, but currently only one is used
283  if (query3->execute()) {
284  auto res = query3->result();
285  if (!res.empty()) {
286  std::vector<float> lumiPerBX;
287  auto row = *res.begin();
288  auto lumiBunchInst = row.getArray<float>("lumi_bunch_inst");
289  for (auto lb : lumiBunchInst) {
290  if (lb != 0.) {
291  lumiPerBX.push_back(lb);
292  }
293  }
294  m_fillPayload->setLumiPerBX(lumiPerBX);
295  }
296  }
297 }
std::unique_ptr< LHCInfo > m_fillPayload
Definition: Electron.h:6

◆ getEcalData()

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

Definition at line 429 of file LHCInfoPopConSourceHandler.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, LHCInfoImpl::setElementData(), AlCaHLTBitMon_QueryRunRegistry::string, protons_cff::time, cond::time::to_boost(), and update.

Referenced by getNewObjects().

432  {
433  //run the sixth query against the CMS_DCS_ENV_PVSS_COND schema
434  //Initializing the CMS_DCS_ENV_PVSS_COND schema.
435  coral::ISchema& ECAL = session.nominalSchema();
436  //start the transaction against the fill logging schema
437  //execute query for ECAL Data
438  std::unique_ptr<coral::IQuery> ECALDataQuery(ECAL.newQuery());
439  //FROM clause
440  ECALDataQuery->addToTableList(std::string("BEAM_PHASE"));
441  //SELECT clause
442  ECALDataQuery->addToOutputList(std::string("CHANGE_DATE"));
443  ECALDataQuery->addToOutputList(std::string("DIP_value"));
444  ECALDataQuery->addToOutputList(std::string("element_nr"));
445  ECALDataQuery->addToOutputList(std::string("VALUE_NUMBER"));
446  //WHERE CLAUSE
447  coral::AttributeList ECALDataBindVariables;
448  ECALDataBindVariables.extend<coral::TimeStamp>(std::string("lowerTime"));
449  ECALDataBindVariables.extend<coral::TimeStamp>(std::string("upperTime"));
450  ECALDataBindVariables[std::string("lowerTime")].data<coral::TimeStamp>() = coral::TimeStamp(lowerTime);
451  ECALDataBindVariables[std::string("upperTime")].data<coral::TimeStamp>() = coral::TimeStamp(upperTime);
452  std::string conditionStr = std::string(
453  "(DIP_value LIKE '%beamPhaseMean%' OR DIP_value LIKE '%cavPhaseMean%') AND CHANGE_DATE >= :lowerTime AND "
454  "CHANGE_DATE < :upperTime");
455 
456  ECALDataQuery->setCondition(conditionStr, ECALDataBindVariables);
457  //ORDER BY clause
458  ECALDataQuery->addToOrderList(std::string("CHANGE_DATE"));
459  ECALDataQuery->addToOrderList(std::string("DIP_value"));
460  ECALDataQuery->addToOrderList(std::string("element_nr"));
461  //define query output
462  coral::AttributeList ECALDataOutput;
463  ECALDataOutput.extend<coral::TimeStamp>(std::string("CHANGE_DATE"));
464  ECALDataOutput.extend<std::string>(std::string("DIP_value"));
465  ECALDataOutput.extend<unsigned int>(std::string("element_nr"));
466  ECALDataOutput.extend<float>(std::string("VALUE_NUMBER"));
467  //ECALDataQuery->limitReturnedRows( 14256 ); //3564 entries per vector.
468  ECALDataQuery->defineOutput(ECALDataOutput);
469  //execute the query
470  coral::ICursor& ECALDataCursor = ECALDataQuery->execute();
471  cond::Time_t changeTime = 0;
472  cond::Time_t firstTime = 0;
473  std::string dipVal = "";
474  unsigned int elementNr = 0;
475  float value = 0.;
476  std::set<cond::Time_t> initializedVectors;
478  bool ret = false;
479  if (m_prevPayload.get()) {
480  for (auto& lumiSlot : m_tmpBuffer) {
481  lumiSlot.second->setBeam1VC(m_prevPayload->beam1VC());
482  lumiSlot.second->setBeam2VC(m_prevPayload->beam2VC());
483  lumiSlot.second->setBeam1RF(m_prevPayload->beam1RF());
484  lumiSlot.second->setBeam2RF(m_prevPayload->beam2RF());
485  }
486  }
487  std::map<cond::Time_t, cond::Time_t> iovMap;
488  cond::Time_t lowerLumi = m_tmpBuffer.front().first;
489  while (ECALDataCursor.next()) {
490  if (m_debug) {
491  std::ostringstream ECAL;
492  ECALDataCursor.currentRow().toOutputStream(ECAL);
493  }
494  coral::Attribute const& changeDateAttribute = ECALDataCursor.currentRow()[std::string("CHANGE_DATE")];
495  if (!changeDateAttribute.isNull()) {
496  ret = true;
497  boost::posix_time::ptime chTime = changeDateAttribute.data<coral::TimeStamp>().time();
498  // move the first IOV found to the start of the fill interval selected
499  if (changeTime == 0) {
500  firstTime = cond::time::from_boost(chTime);
501  }
502  changeTime = cond::time::from_boost(chTime);
503  cond::Time_t iovTime = changeTime;
504  if (!update and changeTime == firstTime)
505  iovTime = lowerLumi;
506  coral::Attribute const& dipValAttribute = ECALDataCursor.currentRow()[std::string("DIP_value")];
507  coral::Attribute const& valueNumberAttribute = ECALDataCursor.currentRow()[std::string("VALUE_NUMBER")];
508  coral::Attribute const& elementNrAttribute = ECALDataCursor.currentRow()[std::string("element_nr")];
509  if (!dipValAttribute.isNull() and !valueNumberAttribute.isNull()) {
510  dipVal = dipValAttribute.data<std::string>();
511  elementNr = elementNrAttribute.data<unsigned int>();
512  value = valueNumberAttribute.data<float>();
513  if (std::isnan(value))
514  value = 0.;
515  if (filter.process(iovTime)) {
516  iovMap.insert(std::make_pair(changeTime, filter.current()->first));
517  for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) {
518  LHCInfo& payload = *(it->second);
519  LHCInfoImpl::setElementData(it->first, dipVal, elementNr, value, payload, initializedVectors);
520  }
521  }
522  //}
523  }
524  }
525  }
526  if (m_debug) {
527  for (auto& im : iovMap) {
528  edm::LogInfo(m_name) << "Found iov=" << im.first << " (" << cond::time::to_boost(im.first) << " ) moved to "
529  << im.second << " ( " << cond::time::to_boost(im.second) << " )";
530  }
531  }
532  return ret;
533 }
def isnan(num)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > m_tmpBuffer
ret
prodAgent to be discontinued
std::shared_ptr< LHCInfo > m_prevPayload
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
void setElementData(cond::Time_t since, const std::string &dipVal, unsigned int elementNr, float value, LHCInfo &payload, std::set< cond::Time_t > &initList)
#define update(a, b)
boost::posix_time::ptime to_boost(Time_t iValue)

◆ getLumiData()

size_t LHCInfoPopConSourceHandler::getLumiData ( const cond::OMSService service,
unsigned short  fillId,
const boost::posix_time::ptime &  beginFillTime,
const boost::posix_time::ptime &  endFillTime 
)
private

Definition at line 153 of file LHCInfoPopConSourceHandler.cc.

References cond::time::from_boost(), kLumisectionsQueryLimit, cond::time::lumiTime(), m_fillPayload, m_tmpBuffer, jetsAK4_Puppi_cff::payload, cond::OMSService::query(), and alignCSCRings::r.

Referenced by getNewObjects().

156  {
157  auto query = oms.query("lumisections");
158  query->addOutputVars({"start_time", "delivered_lumi", "recorded_lumi"});
159  query->filterEQ("fill_number", fillId);
160  query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime);
162  size_t nlumi = 0;
163  if (query->execute()) {
164  auto res = query->result();
165  for (auto r : res) {
166  nlumi++;
167  auto lumiTime = r.get<boost::posix_time::ptime>("start_time");
168  auto delivLumi = r.get<float>("delivered_lumi");
169  auto recLumi = r.get<float>("recorded_lumi");
170  LHCInfo* thisLumiSectionInfo = m_fillPayload->cloneFill();
171  m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
172  LHCInfo& payload = *thisLumiSectionInfo;
173  payload.setDelivLumi(delivLumi);
174  payload.setRecLumi(recLumi);
175  }
176  }
177  return nlumi;
178 }
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > m_tmpBuffer
std::unique_ptr< LHCInfo > m_fillPayload
Definition: Electron.h:6
Definition: query.py:1
Time_t lumiTime(unsigned int run, unsigned int lumiId)
Definition: Time.cc:66
Time_t from_boost(boost::posix_time::ptime bt)
static constexpr unsigned int kLumisectionsQueryLimit

◆ getNewObjects()

void LHCInfoPopConSourceHandler::getNewObjects ( )
overridevirtual

Implements popcon::PopConSourceHandler< LHCInfo >.

Definition at line 605 of file LHCInfoPopConSourceHandler.cc.

References addEmptyPayload(), cond::persistency::Transaction::commit(), cond::persistency::ConnectionPool::configure(), cond::OMSService::connect(), cond::persistency::ConnectionPool::createSession(), popcon::PopConSourceHandler< LHCInfo >::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_endFill, m_fillPayload, popcon::PopConSourceHandler< LHCInfo >::m_iovs, m_name, m_omsBaseUrl, m_prevPayload, m_startTime, m_tmpBuffer, LHCInfoImpl::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< LHCInfo >::tagInfo(), cond::time::to_boost(), cond::persistency::Session::transaction(), and LHCInfoImpl::transferPayloads().

605  {
606  //reference to the last payload in the tag
607  Ref previousFill;
608 
609  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
610  if (tagInfo().size == 0) {
611  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
612  } else {
613  //check what is already inside the database
614  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size
615  << ", last object valid since " << tagInfo().lastInterval.since << " ( "
616  << boost::posix_time::to_iso_extended_string(
617  cond::time::to_boost(tagInfo().lastInterval.since))
618  << " ); from " << m_name << "::getNewObjects";
619  }
620 
621  cond::Time_t lastSince = tagInfo().lastInterval.since;
622  if (tagInfo().isEmpty()) {
623  // for a new or empty tag, an empty payload should be added on top with since=1
624  addEmptyPayload(1);
625  lastSince = 1;
626  } else {
627  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
628  << m_name << "::getNewObjects";
629  }
630 
631  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
632  cond::Time_t targetSince = 0;
633  cond::Time_t endIov = cond::time::from_boost(executionTime);
634  if (!m_startTime.is_not_a_date_time()) {
635  targetSince = cond::time::from_boost(m_startTime);
636  }
637  if (lastSince > targetSince)
638  targetSince = lastSince;
639 
640  edm::LogInfo(m_name) << "Starting sampling at "
641  << boost::posix_time::to_simple_string(cond::time::to_boost(targetSince));
642 
643  //retrieve the data from the relational database source
645  //configure the connection
646  if (m_debug) {
647  connection.setMessageVerbosity(coral::Debug);
648  } else {
649  connection.setMessageVerbosity(coral::Error);
650  }
651  connection.setAuthenticationPath(m_authpath);
652  connection.configure();
653  //create the sessions
654  cond::persistency::Session session = connection.createSession(m_connectionString, false);
656  // fetch last payload when available
657  if (!tagInfo().lastInterval.payloadId.empty()) {
659  session3.transaction().start(true);
661  session3.transaction().commit();
662  }
663 
664  bool iovAdded = false;
665  while (true) {
666  if (targetSince >= endIov) {
667  edm::LogInfo(m_name) << "Sampling ended at the time "
668  << boost::posix_time::to_simple_string(cond::time::to_boost(endIov));
669  break;
670  }
671  bool updateEcal = false;
672  boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince);
673  boost::posix_time::ptime startSampleTime;
674  boost::posix_time::ptime endSampleTime;
675 
676  cond::OMSService oms;
677  oms.connect(m_omsBaseUrl);
678  auto query = oms.query("fills");
679 
680  if (!m_endFill and m_prevPayload->fillNumber() and m_prevPayload->endTime() == 0ULL) {
681  // execute the query for the current fill
682  edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber();
683  query->filterEQ("fill_number", m_prevPayload->fillNumber());
684  bool foundFill = query->execute();
685  if (foundFill)
686  foundFill = LHCInfoImpl::makeFillPayload(m_fillPayload, query->result());
687  if (!foundFill) {
688  edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber();
689  break;
690  }
691  updateEcal = true;
692  startSampleTime = cond::time::to_boost(lastSince);
693  } else {
694  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
695  query->filterNotNull("start_stable_beam").filterNotNull("fill_number");
696  if (targetTime > cond::time::to_boost(m_prevPayload->createTime())) {
697  query->filterGE("start_time", targetTime);
698  } else {
699  query->filterGT("start_time", targetTime);
700  }
701 
702  if (m_endFill)
703  query->filterNotNull("end_time");
704  bool foundFill = query->execute();
705  if (foundFill)
706  foundFill = LHCInfoImpl::makeFillPayload(m_fillPayload, query->result());
707  if (!foundFill) {
708  edm::LogInfo(m_name) << "No fill found - END of job.";
709  if (iovAdded)
710  addEmptyPayload(targetSince);
711  break;
712  }
713  startSampleTime = cond::time::to_boost(m_fillPayload->createTime());
714  }
715  cond::Time_t startFillTime = m_fillPayload->createTime();
716  cond::Time_t endFillTime = m_fillPayload->endTime();
717  unsigned short lhcFill = m_fillPayload->fillNumber();
718  if (endFillTime == 0ULL) {
719  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime);
720  endSampleTime = executionTime;
721  targetSince = endIov;
722  } else {
723  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime)
724  << " ending at " << cond::time::to_boost(endFillTime);
725  endSampleTime = cond::time::to_boost(endFillTime);
726  targetSince = endFillTime;
727  }
728 
729  getDipData(oms, startSampleTime, endSampleTime);
730  size_t nlumi = getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
731  edm::LogInfo(m_name) << "Found " << nlumi << " lumisections during the fill " << lhcFill;
732  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
733  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
734  edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop;
735  session.transaction().start(true);
736  getCTTPSData(session, startSampleTime, endSampleTime);
737  session.transaction().commit();
738  session2.transaction().start(true);
739  getEcalData(session2, startSampleTime, endSampleTime, updateEcal);
740  session2.transaction().commit();
741  //
743  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
744  m_tmpBuffer.clear();
745  iovAdded = true;
746  if (m_prevPayload->fillNumber() and m_fillPayload->endTime() != 0ULL)
747  addEmptyPayload(m_fillPayload->endTime());
748  }
749 }
size
Write out results.
edm::ErrorSummaryEntry Error
boost::posix_time::ptime m_startTime
bool getCTTPSData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
bool makeFillPayload(std::unique_ptr< LHCInfo > &targetPayload, const cond::OMSServiceResult &queryResult)
Iov_t lastInterval
Definition: Types.h:73
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > m_tmpBuffer
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:119
std::unique_ptr< LHCInfo > m_fillPayload
void start(bool readOnly=true)
Definition: Session.cc:18
Time_t since
Definition: Types.h:53
bool getEcalData(cond::persistency::Session &session, const boost::posix_time::ptime &lowerTime, const boost::posix_time::ptime &upperTime, bool update)
size_t size
Definition: Types.h:74
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
Log< level::Error, false > LogError
std::shared_ptr< LHCInfo > m_prevPayload
Transaction & transaction()
Definition: Session.cc:52
std::string name
Definition: Types.h:72
Definition: query.py:1
cond::TagInfo_t const & tagInfo() const
void getDipData(const cond::OMSService &service, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
unsigned long long Time_t
Definition: Time.h:14
Hash payloadId
Definition: Types.h:55
Session createSession(const std::string &connectionString, bool writeCapable=false)
size_t transferPayloads(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo >>> &buffer, std::map< cond::Time_t, std::shared_ptr< LHCInfo >> &iovsToTransfer, std::shared_ptr< LHCInfo > &prevPayload)
void setMessageVerbosity(coral::MsgLevel level)
Time_t from_boost(boost::posix_time::ptime bt)
Log< level::Info, false > LogInfo
size_t getLumiData(const cond::OMSService &service, unsigned short fillId, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
cond::persistency::Session & dbSession() const
void connect(const std::string &baseUrl)
Definition: OMSAccess.cc:118
void setAuthenticationPath(const std::string &p)
const bool Debug
boost::posix_time::ptime to_boost(Time_t iValue)

◆ id()

std::string LHCInfoPopConSourceHandler::id ( ) const
overridevirtual

Implements popcon::PopConSourceHandler< LHCInfo >.

Definition at line 751 of file LHCInfoPopConSourceHandler.cc.

References m_name.

751 { return m_name; }

Member Data Documentation

◆ kLumisectionsQueryLimit

constexpr unsigned int LHCInfoPopConSourceHandler::kLumisectionsQueryLimit = 4000
static

Definition at line 21 of file LHCInfoPopConSourceHandler.h.

Referenced by getLumiData().

◆ m_authpath

std::string LHCInfoPopConSourceHandler::m_authpath
private

Definition at line 52 of file LHCInfoPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_connectionString

std::string LHCInfoPopConSourceHandler::m_connectionString
private

Definition at line 51 of file LHCInfoPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_debug

bool LHCInfoPopConSourceHandler::m_debug
private

Definition at line 42 of file LHCInfoPopConSourceHandler.h.

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

◆ m_dipSchema

std::string LHCInfoPopConSourceHandler::m_dipSchema
private

Definition at line 52 of file LHCInfoPopConSourceHandler.h.

◆ m_ecalConnectionString

std::string LHCInfoPopConSourceHandler::m_ecalConnectionString
private

Definition at line 51 of file LHCInfoPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_endFill

bool LHCInfoPopConSourceHandler::m_endFill = true
private

Definition at line 48 of file LHCInfoPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_endTime

boost::posix_time::ptime LHCInfoPopConSourceHandler::m_endTime
private

Definition at line 45 of file LHCInfoPopConSourceHandler.h.

Referenced by LHCInfoPopConSourceHandler().

◆ m_fillPayload

std::unique_ptr<LHCInfo> LHCInfoPopConSourceHandler::m_fillPayload
private

Definition at line 54 of file LHCInfoPopConSourceHandler.h.

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

◆ m_lastPayloadEmpty

bool LHCInfoPopConSourceHandler::m_lastPayloadEmpty = false
private

Definition at line 57 of file LHCInfoPopConSourceHandler.h.

Referenced by addEmptyPayload().

◆ m_name

std::string LHCInfoPopConSourceHandler::m_name
private

Definition at line 49 of file LHCInfoPopConSourceHandler.h.

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

◆ m_omsBaseUrl

std::string LHCInfoPopConSourceHandler::m_omsBaseUrl
private

Definition at line 53 of file LHCInfoPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_prevPayload

std::shared_ptr<LHCInfo> LHCInfoPopConSourceHandler::m_prevPayload
private

Definition at line 55 of file LHCInfoPopConSourceHandler.h.

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

◆ m_samplingInterval

unsigned int LHCInfoPopConSourceHandler::m_samplingInterval
private

Definition at line 47 of file LHCInfoPopConSourceHandler.h.

◆ m_startTime

boost::posix_time::ptime LHCInfoPopConSourceHandler::m_startTime
private

Definition at line 44 of file LHCInfoPopConSourceHandler.h.

Referenced by getNewObjects(), and LHCInfoPopConSourceHandler().

◆ m_tmpBuffer

std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo> > > LHCInfoPopConSourceHandler::m_tmpBuffer
private

Definition at line 56 of file LHCInfoPopConSourceHandler.h.

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