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 getCTPPSData (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 65 of file LHCInfoPopConSourceHandler.cc.

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

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

93 {}

Member Function Documentation

◆ addEmptyPayload()

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

Definition at line 479 of file LHCInfoPopConSourceHandler.cc.

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

Referenced by getNewObjects().

479  {
480  bool add = false;
481  if (m_iovs.empty()) {
482  if (!m_lastPayloadEmpty)
483  add = true;
484  } else {
485  auto lastAdded = m_iovs.rbegin()->second;
486  if (lastAdded->fillNumber() != 0) {
487  add = true;
488  }
489  }
490  if (add) {
491  auto newPayload = std::make_shared<LHCInfo>();
492  m_iovs.insert(std::make_pair(iov, newPayload));
493  m_prevPayload = newPayload;
494  }
495 }
std::shared_ptr< LHCInfo > m_prevPayload
void add(std::map< std::string, TH1 *> &h, TH1 *hist)

◆ getCTPPSData()

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

Definition at line 243 of file LHCInfoPopConSourceHandler.cc.

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

Referenced by getNewObjects().

245  {
246  //run the fifth query against the CTPPS schema
247  //Initializing the CMS_CTP_CTPPS_COND schema.
248  coral::ISchema& CTPPS = session.coralSession().schema("CMS_PPS_SPECT_COND");
249  //execute query for CTPPS Data
250  std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
251  //FROM clause
252  CTPPSDataQuery->addToTableList(std::string("PPS_LHC_MACHINE_PARAMS"));
253  //SELECT clause
254  CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME"));
255  CTPPSDataQuery->addToOutputList(std::string("LHC_STATE"));
256  CTPPSDataQuery->addToOutputList(std::string("LHC_COMMENT"));
257  CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION"));
258  CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_X_URAD"));
259  CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_X_M"));
260  //WHERE CLAUSE
261  coral::AttributeList CTPPSDataBindVariables;
262  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("beginFillTime"));
263  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("endFillTime"));
264  CTPPSDataBindVariables[std::string("beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
265  CTPPSDataBindVariables[std::string("endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
266  std::string conditionStr = std::string("DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
267  CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
268  //ORDER BY clause
269  CTPPSDataQuery->addToOrderList(std::string("DIP_UPDATE_TIME"));
270  //define query output
271  coral::AttributeList CTPPSDataOutput;
272  CTPPSDataOutput.extend<coral::TimeStamp>(std::string("DIP_UPDATE_TIME"));
273  CTPPSDataOutput.extend<std::string>(std::string("LHC_STATE"));
274  CTPPSDataOutput.extend<std::string>(std::string("LHC_COMMENT"));
275  CTPPSDataOutput.extend<int>(std::string("LUMI_SECTION"));
276  CTPPSDataOutput.extend<float>(std::string("XING_ANGLE_P5_X_URAD"));
277  CTPPSDataOutput.extend<float>(std::string("BETA_STAR_P5_X_M"));
278  CTPPSDataQuery->defineOutput(CTPPSDataOutput);
279  //execute the query
280  coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
281  cond::Time_t dipTime = 0;
282  std::string lhcState = "", lhcComment = "", ctppsStatus = "";
283  unsigned int lumiSection = 0;
284  float crossingAngle = 0., betastar = 0.;
285 
286  bool ret = false;
288  while (CTPPSDataCursor.next()) {
289  if (m_debug) {
290  std::ostringstream CTPPS;
291  CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
292  }
293  coral::Attribute const& dipTimeAttribute = CTPPSDataCursor.currentRow()[std::string("DIP_UPDATE_TIME")];
294  if (!dipTimeAttribute.isNull()) {
295  dipTime = cond::time::from_boost(dipTimeAttribute.data<coral::TimeStamp>().time());
296  if (filter.process(dipTime)) {
297  ret = true;
298  coral::Attribute const& lhcStateAttribute = CTPPSDataCursor.currentRow()[std::string("LHC_STATE")];
299  if (!lhcStateAttribute.isNull()) {
300  lhcState = lhcStateAttribute.data<std::string>();
301  }
302  coral::Attribute const& lhcCommentAttribute = CTPPSDataCursor.currentRow()[std::string("LHC_COMMENT")];
303  if (!lhcCommentAttribute.isNull()) {
304  lhcComment = lhcCommentAttribute.data<std::string>();
305  }
306  coral::Attribute const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[std::string("LUMI_SECTION")];
307  if (!lumiSectionAttribute.isNull()) {
308  lumiSection = lumiSectionAttribute.data<int>();
309  }
310  coral::Attribute const& crossingAngleXAttribute =
311  CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_X_URAD")];
312  if (!crossingAngleXAttribute.isNull()) {
313  crossingAngle = crossingAngleXAttribute.data<float>();
314  }
315  coral::Attribute const& betaStarXAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_X_M")];
316  if (!betaStarXAttribute.isNull()) {
317  betastar = betaStarXAttribute.data<float>();
318  }
319  for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) {
320  // set the current values to all of the payloads of the lumi section samples after the current since
321  LHCInfo& payload = *(it->second);
322  payload.setCrossingAngle(crossingAngle);
323  payload.setBetaStar(betastar);
324  payload.setLhcState(lhcState);
325  payload.setLhcComment(lhcComment);
326  payload.setCtppsStatus(ctppsStatus);
327  payload.setLumiSection(lumiSection);
328  }
329  }
330  }
331  }
332  return ret;
333 }
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 181 of file LHCInfoPopConSourceHandler.cc.

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

Referenced by getNewObjects().

183  {
184  // unsure how to handle this.
185  // the old implementation is not helping: apparently it is checking only the bunchconfiguration for the first diptime set of values...
186  auto query1 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam1");
187  query1->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime);
188  //This query is limited to 100 rows, but currently only one is used
189  //If all this data is needed and saved properly the limit has to be set: query1->limit(...)
190  if (query1->execute()) {
191  auto res = query1->result();
192  if (!res.empty()) {
193  std::bitset<LHCInfo::bunchSlots + 1> bunchConfiguration1(0ULL);
194  auto row = *res.begin();
195  auto vbunchConf1 = row.getArray<unsigned short>("value");
196  for (auto vb : vbunchConf1) {
197  if (vb != 0) {
198  unsigned short slot = (vb - 1) / 10 + 1;
199  bunchConfiguration1[slot] = true;
200  }
201  }
202  m_fillPayload->setBunchBitsetForBeam1(bunchConfiguration1);
203  }
204  }
205  auto query2 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam2");
206  query2->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime);
207  //This query is limited to 100 rows, but currently only one is used
208  if (query2->execute()) {
209  auto res = query2->result();
210  if (!res.empty()) {
211  std::bitset<LHCInfo::bunchSlots + 1> bunchConfiguration2(0ULL);
212  auto row = *res.begin();
213  auto vbunchConf2 = row.getArray<unsigned short>("value");
214  for (auto vb : vbunchConf2) {
215  if (vb != 0) {
216  unsigned short slot = (vb - 1) / 10 + 1;
217  bunchConfiguration2[slot] = true;
218  }
219  }
220  m_fillPayload->setBunchBitsetForBeam2(bunchConfiguration2);
221  }
222  }
223 
224  auto query3 = oms.query("diplogger/dip/CMS/LHC/LumiPerBunch");
225  query3->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime);
226  //This query is limited to 100 rows, but currently only one is used
227  if (query3->execute()) {
228  auto res = query3->result();
229  if (!res.empty()) {
230  std::vector<float> lumiPerBX;
231  auto row = *res.begin();
232  auto lumiBunchInst = row.getArray<float>("lumi_bunch_inst");
233  for (auto lb : lumiBunchInst) {
234  if (lb != 0.) {
235  lumiPerBX.push_back(lb);
236  }
237  }
238  m_fillPayload->setLumiPerBX(lumiPerBX);
239  }
240  }
241 }
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 373 of file LHCInfoPopConSourceHandler.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, theLHCInfoImpl::setElementData(), AlCaHLTBitMon_QueryRunRegistry::string, hcalRecHitTable_cff::time, cond::time::to_boost(), and update.

Referenced by getNewObjects().

376  {
377  //run the sixth query against the CMS_DCS_ENV_PVSS_COND schema
378  //Initializing the CMS_DCS_ENV_PVSS_COND schema.
379  coral::ISchema& ECAL = session.nominalSchema();
380  //start the transaction against the fill logging schema
381  //execute query for ECAL Data
382  std::unique_ptr<coral::IQuery> ECALDataQuery(ECAL.newQuery());
383  //FROM clause
384  ECALDataQuery->addToTableList(std::string("BEAM_PHASE"));
385  //SELECT clause
386  ECALDataQuery->addToOutputList(std::string("CHANGE_DATE"));
387  ECALDataQuery->addToOutputList(std::string("DIP_value"));
388  ECALDataQuery->addToOutputList(std::string("element_nr"));
389  ECALDataQuery->addToOutputList(std::string("VALUE_NUMBER"));
390  //WHERE CLAUSE
391  coral::AttributeList ECALDataBindVariables;
392  ECALDataBindVariables.extend<coral::TimeStamp>(std::string("lowerTime"));
393  ECALDataBindVariables.extend<coral::TimeStamp>(std::string("upperTime"));
394  ECALDataBindVariables[std::string("lowerTime")].data<coral::TimeStamp>() = coral::TimeStamp(lowerTime);
395  ECALDataBindVariables[std::string("upperTime")].data<coral::TimeStamp>() = coral::TimeStamp(upperTime);
396  std::string conditionStr = std::string(
397  "(DIP_value LIKE '%beamPhaseMean%' OR DIP_value LIKE '%cavPhaseMean%') AND CHANGE_DATE >= :lowerTime AND "
398  "CHANGE_DATE < :upperTime");
399 
400  ECALDataQuery->setCondition(conditionStr, ECALDataBindVariables);
401  //ORDER BY clause
402  ECALDataQuery->addToOrderList(std::string("CHANGE_DATE"));
403  ECALDataQuery->addToOrderList(std::string("DIP_value"));
404  ECALDataQuery->addToOrderList(std::string("element_nr"));
405  //define query output
406  coral::AttributeList ECALDataOutput;
407  ECALDataOutput.extend<coral::TimeStamp>(std::string("CHANGE_DATE"));
408  ECALDataOutput.extend<std::string>(std::string("DIP_value"));
409  ECALDataOutput.extend<unsigned int>(std::string("element_nr"));
410  ECALDataOutput.extend<float>(std::string("VALUE_NUMBER"));
411  //ECALDataQuery->limitReturnedRows( 14256 ); //3564 entries per vector.
412  ECALDataQuery->defineOutput(ECALDataOutput);
413  //execute the query
414  coral::ICursor& ECALDataCursor = ECALDataQuery->execute();
415  cond::Time_t changeTime = 0;
416  cond::Time_t firstTime = 0;
417  std::string dipVal = "";
418  unsigned int elementNr = 0;
419  float value = 0.;
420  std::set<cond::Time_t> initializedVectors;
422  bool ret = false;
423  if (m_prevPayload.get()) {
424  for (auto& lumiSlot : m_tmpBuffer) {
425  lumiSlot.second->setBeam1VC(m_prevPayload->beam1VC());
426  lumiSlot.second->setBeam2VC(m_prevPayload->beam2VC());
427  lumiSlot.second->setBeam1RF(m_prevPayload->beam1RF());
428  lumiSlot.second->setBeam2RF(m_prevPayload->beam2RF());
429  }
430  }
431  std::map<cond::Time_t, cond::Time_t> iovMap;
432  cond::Time_t lowerLumi = m_tmpBuffer.front().first;
433  while (ECALDataCursor.next()) {
434  if (m_debug) {
435  std::ostringstream ECAL;
436  ECALDataCursor.currentRow().toOutputStream(ECAL);
437  }
438  coral::Attribute const& changeDateAttribute = ECALDataCursor.currentRow()[std::string("CHANGE_DATE")];
439  if (!changeDateAttribute.isNull()) {
440  ret = true;
441  boost::posix_time::ptime chTime = changeDateAttribute.data<coral::TimeStamp>().time();
442  // move the first IOV found to the start of the fill interval selected
443  if (changeTime == 0) {
444  firstTime = cond::time::from_boost(chTime);
445  }
446  changeTime = cond::time::from_boost(chTime);
447  cond::Time_t iovTime = changeTime;
448  if (!update and changeTime == firstTime)
449  iovTime = lowerLumi;
450  coral::Attribute const& dipValAttribute = ECALDataCursor.currentRow()[std::string("DIP_value")];
451  coral::Attribute const& valueNumberAttribute = ECALDataCursor.currentRow()[std::string("VALUE_NUMBER")];
452  coral::Attribute const& elementNrAttribute = ECALDataCursor.currentRow()[std::string("element_nr")];
453  if (!dipValAttribute.isNull() and !valueNumberAttribute.isNull()) {
454  dipVal = dipValAttribute.data<std::string>();
455  elementNr = elementNrAttribute.data<unsigned int>();
456  value = valueNumberAttribute.data<float>();
457  if (std::isnan(value))
458  value = 0.;
459  if (filter.process(iovTime)) {
460  iovMap.insert(std::make_pair(changeTime, filter.current()->first));
461  for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) {
462  LHCInfo& payload = *(it->second);
463  theLHCInfoImpl::setElementData(it->first, dipVal, elementNr, value, payload, initializedVectors);
464  }
465  }
466  //}
467  }
468  }
469  }
470  if (m_debug) {
471  for (auto& im : iovMap) {
472  edm::LogInfo(m_name) << "Found iov=" << im.first << " (" << cond::time::to_boost(im.first) << " ) moved to "
473  << im.second << " ( " << cond::time::to_boost(im.second) << " )";
474  }
475  }
476  return ret;
477 }
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 154 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().

157  {
158  auto query = oms.query("lumisections");
159  query->addOutputVars({"start_time", "delivered_lumi", "recorded_lumi"});
160  query->filterEQ("fill_number", fillId);
161  query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime);
163  size_t nlumi = 0;
164  if (query->execute()) {
165  auto res = query->result();
166  for (auto r : res) {
167  nlumi++;
168  auto lumiTime = r.get<boost::posix_time::ptime>("start_time");
169  auto delivLumi = r.get<float>("delivered_lumi");
170  auto recLumi = r.get<float>("recorded_lumi");
171  LHCInfo* thisLumiSectionInfo = m_fillPayload->cloneFill();
172  m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
173  LHCInfo& payload = *thisLumiSectionInfo;
174  payload.setDelivLumi(delivLumi);
175  payload.setRecLumi(recLumi);
176  }
177  }
178  return nlumi;
179 }
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 536 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(), getCTPPSData(), getDipData(), getEcalData(), getLumiData(), cond::TagInfo_t::lastInterval, m_authpath, m_connectionString, m_debug, m_ecalConnectionString, m_endFill, m_endTime, m_fillPayload, popcon::PopConSourceHandler< LHCInfo >::m_iovs, m_name, m_omsBaseUrl, m_prevPayload, m_startTime, m_tmpBuffer, theLHCInfoImpl::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 theLHCInfoImpl::transferPayloads().

536  {
537  //reference to the last payload in the tag
538  Ref previousFill;
539 
540  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
541  if (tagInfo().size == 0) {
542  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
543  } else {
544  //check what is already inside the database
545  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size
546  << ", last object valid since " << tagInfo().lastInterval.since << " ( "
547  << boost::posix_time::to_iso_extended_string(
548  cond::time::to_boost(tagInfo().lastInterval.since))
549  << " ); from " << m_name << "::getNewObjects";
550  }
551 
552  cond::Time_t lastSince = tagInfo().lastInterval.since;
553  if (tagInfo().isEmpty()) {
554  // for a new or empty tag, an empty payload should be added on top with since=1
555  addEmptyPayload(1);
556  lastSince = 1;
557  } else {
558  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
559  << m_name << "::getNewObjects";
560  }
561 
562  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
563  cond::Time_t targetSince = 0;
564  cond::Time_t endIov = cond::time::from_boost(executionTime);
565  if (!m_startTime.is_not_a_date_time()) {
566  targetSince = cond::time::from_boost(m_startTime);
567  }
568  if (lastSince > targetSince)
569  targetSince = lastSince;
570 
571  edm::LogInfo(m_name) << "Starting sampling at "
572  << boost::posix_time::to_simple_string(cond::time::to_boost(targetSince));
573 
574  //retrieve the data from the relational database source
576  //configure the connection
577  if (m_debug) {
578  connection.setMessageVerbosity(coral::Debug);
579  } else {
580  connection.setMessageVerbosity(coral::Error);
581  }
582  connection.setAuthenticationPath(m_authpath);
583  connection.configure();
584  //create the sessions
585  cond::persistency::Session session = connection.createSession(m_connectionString, false);
587  // fetch last payload when available
588  if (!tagInfo().lastInterval.payloadId.empty()) {
590  session3.transaction().start(true);
592  session3.transaction().commit();
593  }
594 
595  bool iovAdded = false;
596  while (true) {
597  if (targetSince >= endIov) {
598  edm::LogInfo(m_name) << "Sampling ended at the time "
599  << boost::posix_time::to_simple_string(cond::time::to_boost(endIov));
600  break;
601  }
602  bool updateEcal = false;
603  boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince);
604  boost::posix_time::ptime startSampleTime;
605  boost::posix_time::ptime endSampleTime;
606 
607  cond::OMSService oms;
608  oms.connect(m_omsBaseUrl);
609  auto query = oms.query("fills");
610 
611  if (!m_endFill and m_prevPayload->fillNumber() and m_prevPayload->endTime() == 0ULL) {
612  // execute the query for the current fill
613  edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber();
614  query->filterEQ("fill_number", m_prevPayload->fillNumber());
615  bool foundFill = query->execute();
616  if (foundFill)
617  foundFill = theLHCInfoImpl::makeFillPayload(m_fillPayload, query->result());
618  if (!foundFill) {
619  edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber();
620  break;
621  }
622  updateEcal = true;
623  startSampleTime = cond::time::to_boost(lastSince);
624  } else {
625  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
626  query->filterNotNull("start_stable_beam").filterNotNull("fill_number");
627  if (targetTime > cond::time::to_boost(m_prevPayload->createTime())) {
628  query->filterGE("start_time", targetTime);
629  } else {
630  query->filterGT("start_time", targetTime);
631  }
632 
633  query->filterLT("start_time", m_endTime);
634  if (m_endFill)
635  query->filterNotNull("end_time");
636  bool foundFill = query->execute();
637  if (foundFill)
638  foundFill = theLHCInfoImpl::makeFillPayload(m_fillPayload, query->result());
639  if (!foundFill) {
640  edm::LogInfo(m_name) << "No fill found - END of job.";
641  if (iovAdded)
642  addEmptyPayload(targetSince);
643  break;
644  }
645  startSampleTime = cond::time::to_boost(m_fillPayload->createTime());
646  }
647  cond::Time_t startFillTime = m_fillPayload->createTime();
648  cond::Time_t endFillTime = m_fillPayload->endTime();
649  unsigned short lhcFill = m_fillPayload->fillNumber();
650  if (endFillTime == 0ULL) {
651  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime);
652  endSampleTime = executionTime;
653  targetSince = endIov;
654  } else {
655  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime)
656  << " ending at " << cond::time::to_boost(endFillTime);
657  endSampleTime = cond::time::to_boost(endFillTime);
658  targetSince = endFillTime;
659  }
660 
661  getDipData(oms, startSampleTime, endSampleTime);
662  size_t nlumi = getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
663  edm::LogInfo(m_name) << "Found " << nlumi << " lumisections during the fill " << lhcFill;
664  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
665  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
666  edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop;
667  session.transaction().start(true);
668  getCTPPSData(session, startSampleTime, endSampleTime);
669  session.transaction().commit();
670  session2.transaction().start(true);
671  getEcalData(session2, startSampleTime, endSampleTime, updateEcal);
672  session2.transaction().commit();
673  //
675  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
676  m_tmpBuffer.clear();
677  iovAdded = true;
678  if (m_prevPayload->fillNumber() and m_fillPayload->endTime() != 0ULL)
679  addEmptyPayload(m_fillPayload->endTime());
680  }
681 }
size
Write out results.
edm::ErrorSummaryEntry Error
boost::posix_time::ptime m_startTime
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:129
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
bool getCTPPSData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
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
boost::posix_time::ptime m_endTime
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)
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)
bool makeFillPayload(std::unique_ptr< LHCInfo > &targetPayload, const cond::OMSServiceResult &queryResult)
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)
cond::persistency::Session & dbSession() const
void connect(const std::string &baseUrl)
Definition: OMSAccess.cc:128
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 683 of file LHCInfoPopConSourceHandler.cc.

References m_name.

683 { 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 getCTPPSData(), 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 getNewObjects(), and 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 getCTPPSData(), getEcalData(), getLumiData(), and getNewObjects().