CMS 3D CMS Logo

List of all members | Public Member Functions | 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 ()
 

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 529 of file LHCInfoPopConSourceHandler.cc.

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

Referenced by getNewObjects().

529  {
530  bool add = false;
531  if (m_iovs.empty()) {
532  if (!m_lastPayloadEmpty)
533  add = true;
534  } else {
535  auto lastAdded = m_iovs.rbegin()->second;
536  if (lastAdded->fillNumber() != 0) {
537  add = true;
538  }
539  }
540  if (add) {
541  auto newPayload = std::make_shared<LHCInfo>();
542  m_iovs.insert(std::make_pair(iov, newPayload));
543  m_prevPayload = newPayload;
544  }
545 }
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 293 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().

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

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

Referenced by getNewObjects().

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

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

◆ getNewObjects()

void LHCInfoPopConSourceHandler::getNewObjects ( )
overridevirtual

Implements popcon::PopConSourceHandler< LHCInfo >.

Definition at line 599 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(), seconds(), cond::persistency::ConnectionPool::setAuthenticationPath(), cond::persistency::ConnectionPool::setMessageVerbosity(), cond::Iov_t::since, cond::TagInfo_t::size, findQualityFiles::size, cond::persistency::Transaction::start(), startTime, popcon::PopConSourceHandler< LHCInfo >::tagInfo(), cond::time::to_boost(), cond::persistency::Session::transaction(), and LHCInfoImpl::transferPayloads().

599  {
600  //reference to the last payload in the tag
601  Ref previousFill;
602 
603  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
604  if (tagInfo().size == 0) {
605  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
606  } else {
607  //check what is already inside the database
608  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size
609  << ", last object valid since " << tagInfo().lastInterval.since << " ( "
610  << boost::posix_time::to_iso_extended_string(
611  cond::time::to_boost(tagInfo().lastInterval.since))
612  << " ); from " << m_name << "::getNewObjects";
613  }
614 
615  cond::Time_t lastSince = tagInfo().lastInterval.since;
616  if (tagInfo().isEmpty()) {
617  // for a new or empty tag, an empty payload should be added on top with since=1
618  addEmptyPayload(1);
619  lastSince = 1;
620  } else {
621  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
622  << m_name << "::getNewObjects";
623  }
624 
625  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
626  cond::Time_t targetSince = 0;
627  cond::Time_t endIov = cond::time::from_boost(executionTime);
628  if (!m_startTime.is_not_a_date_time()) {
629  targetSince = cond::time::from_boost(m_startTime);
630  }
631  if (lastSince > targetSince)
632  targetSince = lastSince;
633 
634  edm::LogInfo(m_name) << "Starting sampling at "
635  << boost::posix_time::to_simple_string(cond::time::to_boost(targetSince));
636 
637  //retrieve the data from the relational database source
639  //configure the connection
640  if (m_debug) {
641  connection.setMessageVerbosity(coral::Debug);
642  } else {
643  connection.setMessageVerbosity(coral::Error);
644  }
645  connection.setAuthenticationPath(m_authpath);
646  connection.configure();
647  //create the sessions
648  cond::persistency::Session session = connection.createSession(m_connectionString, false);
650  // fetch last payload when available
651  if (!tagInfo().lastInterval.payloadId.empty()) {
653  session3.transaction().start(true);
655  session3.transaction().commit();
656  }
657 
658  bool iovAdded = false;
659  while (true) {
660  if (targetSince >= endIov) {
661  edm::LogInfo(m_name) << "Sampling ended at the time "
662  << boost::posix_time::to_simple_string(cond::time::to_boost(endIov));
663  break;
664  }
665  bool updateEcal = false;
666  boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince);
667  boost::posix_time::ptime startSampleTime;
668  boost::posix_time::ptime endSampleTime;
669 
670  cond::OMSService oms;
671  oms.connect(m_omsBaseUrl);
672  auto query = oms.query("fills");
673 
674  if (!m_endFill and m_prevPayload->fillNumber() and m_prevPayload->endTime() == 0ULL) {
675  // execute the query for the current fill
676  edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber();
677  query->filterEQ("fill_number", m_prevPayload->fillNumber());
678  bool foundFill = query->execute();
679  if (foundFill)
680  foundFill = LHCInfoImpl::makeFillPayload(m_fillPayload, query->result());
681  if (!foundFill) {
682  edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber();
683  break;
684  }
685  updateEcal = true;
686  startSampleTime = cond::time::to_boost(lastSince);
687  } else {
688  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
689  boost::posix_time::ptime startTime = targetTime + boost::posix_time::seconds(1);
690  query->filterNotNull("start_stable_beam").filterGT("start_time", startTime).filterNotNull("fill_number");
691  if (m_endFill)
692  query->filterNotNull("end_time");
693  bool foundFill = query->execute();
694  if (foundFill)
695  foundFill = LHCInfoImpl::makeFillPayload(m_fillPayload, query->result());
696  if (!foundFill) {
697  edm::LogInfo(m_name) << "No fill found - END of job.";
698  if (iovAdded)
699  addEmptyPayload(targetSince);
700  break;
701  }
702  startSampleTime = cond::time::to_boost(m_fillPayload->createTime());
703  }
704  cond::Time_t startFillTime = m_fillPayload->createTime();
705  cond::Time_t endFillTime = m_fillPayload->endTime();
706  unsigned short lhcFill = m_fillPayload->fillNumber();
707  if (endFillTime == 0ULL) {
708  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime);
709  endSampleTime = executionTime;
710  targetSince = endIov;
711  } else {
712  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime)
713  << " ending at " << cond::time::to_boost(endFillTime);
714  endSampleTime = cond::time::to_boost(endFillTime);
715  targetSince = endFillTime;
716  }
717 
718  getDipData(oms, startSampleTime, endSampleTime);
719  size_t nlumi = getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
720  edm::LogInfo(m_name) << "Found " << nlumi << " lumisections during the fill " << lhcFill;
721  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
722  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
723  edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop;
724  session.transaction().start(true);
725  getCTTPSData(session, startSampleTime, endSampleTime);
726  session.transaction().commit();
727  session2.transaction().start(true);
728  getEcalData(session2, startSampleTime, endSampleTime, updateEcal);
729  session2.transaction().commit();
730  //
732  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
733  m_tmpBuffer.clear();
734  iovAdded = true;
735  if (m_prevPayload->fillNumber() and m_fillPayload->endTime() != 0ULL)
736  addEmptyPayload(m_fillPayload->endTime());
737  }
738 }
size
Write out results.
edm::ErrorSummaryEntry Error
double seconds()
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:107
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)
string startTime
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:106
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 740 of file LHCInfoPopConSourceHandler.cc.

References m_name.

740 { return m_name; }

Member Data Documentation

◆ m_authpath

std::string LHCInfoPopConSourceHandler::m_authpath
private

Definition at line 50 of file LHCInfoPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_connectionString

std::string LHCInfoPopConSourceHandler::m_connectionString
private

Definition at line 49 of file LHCInfoPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_debug

bool LHCInfoPopConSourceHandler::m_debug
private

Definition at line 40 of file LHCInfoPopConSourceHandler.h.

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

◆ m_dipSchema

std::string LHCInfoPopConSourceHandler::m_dipSchema
private

Definition at line 50 of file LHCInfoPopConSourceHandler.h.

◆ m_ecalConnectionString

std::string LHCInfoPopConSourceHandler::m_ecalConnectionString
private

Definition at line 49 of file LHCInfoPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_endFill

bool LHCInfoPopConSourceHandler::m_endFill = true
private

Definition at line 46 of file LHCInfoPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_endTime

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

Definition at line 43 of file LHCInfoPopConSourceHandler.h.

Referenced by LHCInfoPopConSourceHandler().

◆ m_fillPayload

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

Definition at line 52 of file LHCInfoPopConSourceHandler.h.

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

◆ m_lastPayloadEmpty

bool LHCInfoPopConSourceHandler::m_lastPayloadEmpty = false
private

Definition at line 55 of file LHCInfoPopConSourceHandler.h.

Referenced by addEmptyPayload().

◆ m_name

std::string LHCInfoPopConSourceHandler::m_name
private

Definition at line 47 of file LHCInfoPopConSourceHandler.h.

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

◆ m_omsBaseUrl

std::string LHCInfoPopConSourceHandler::m_omsBaseUrl
private

Definition at line 51 of file LHCInfoPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_prevPayload

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

Definition at line 53 of file LHCInfoPopConSourceHandler.h.

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

◆ m_samplingInterval

unsigned int LHCInfoPopConSourceHandler::m_samplingInterval
private

Definition at line 45 of file LHCInfoPopConSourceHandler.h.

◆ m_startTime

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

Definition at line 42 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 54 of file LHCInfoPopConSourceHandler.h.

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