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

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

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

94 {}

Member Function Documentation

◆ addEmptyPayload()

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

Definition at line 480 of file LHCInfoPopConSourceHandler.cc.

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

Referenced by getNewObjects().

480  {
481  bool add = false;
482  if (m_iovs.empty()) {
483  if (!m_lastPayloadEmpty)
484  add = true;
485  } else {
486  auto lastAdded = m_iovs.rbegin()->second;
487  if (lastAdded->fillNumber() != 0) {
488  add = true;
489  }
490  }
491  if (add) {
492  auto newPayload = std::make_shared<LHCInfo>();
493  m_iovs.insert(std::make_pair(iov, newPayload));
494  m_prevPayload = newPayload;
495  }
496 }
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 244 of file LHCInfoPopConSourceHandler.cc.

References simBeamSpotHLLHCPI::crossingAngle, ALCARECOTkAlBeamHalo_cff::filter, cond::time::from_boost(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, m_debug, m_tmpBuffer, jetsAK4_Puppi_cff::payload, runTheMatrix::ret, run_AlCaRecoTriggerBitsUpdateWorkflow::session, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getNewObjects().

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

◆ getDipData()

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

Definition at line 182 of file LHCInfoPopConSourceHandler.cc.

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

Referenced by getNewObjects().

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

References ECAL, ALCARECOTkAlBeamHalo_cff::filter, cond::time::from_boost(), edm::isNotFinite(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, m_debug, m_name, m_prevPayload, m_tmpBuffer, jetsAK4_Puppi_cff::payload, runTheMatrix::ret, run_AlCaRecoTriggerBitsUpdateWorkflow::session, theLHCInfoImpl::setElementData(), AlCaHLTBitMon_QueryRunRegistry::string, hcalRecHitTable_cff::time, cond::time::to_boost(), and update.

Referenced by getNewObjects().

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

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

Referenced by getNewObjects().

158  {
159  auto query = oms.query("lumisections");
160  query->addOutputVars({"start_time", "delivered_lumi", "recorded_lumi"});
161  query->filterEQ("fill_number", fillId);
162  query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime);
164  size_t nlumi = 0;
165  if (query->execute()) {
166  auto res = query->result();
167  for (auto r : res) {
168  nlumi++;
169  auto lumiTime = r.get<boost::posix_time::ptime>("start_time");
170  auto delivLumi = r.get<float>("delivered_lumi");
171  auto recLumi = r.get<float>("recorded_lumi");
172  LHCInfo* thisLumiSectionInfo = m_fillPayload->cloneFill();
173  m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
174  LHCInfo& payload = *thisLumiSectionInfo;
175  payload.setDelivLumi(delivLumi);
176  payload.setRecLumi(recLumi);
177  }
178  }
179  return nlumi;
180 }
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
Definition: LHCInfoHelper.h:12

◆ getNewObjects()

void LHCInfoPopConSourceHandler::getNewObjects ( )
overridevirtual

Implements popcon::PopConSourceHandler< LHCInfo >.

Definition at line 537 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(), run_AlCaRecoTriggerBitsUpdateWorkflow::session, 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().

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

References m_name.

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