CMS 3D CMS Logo

LHCInfoPerLSPopConAnalyzer.cc
Go to the documentation of this file.
9 #include "CoralBase/Attribute.h"
10 #include "CoralBase/AttributeList.h"
11 #include "CoralBase/AttributeSpecification.h"
12 #include "CoralBase/TimeStamp.h"
17 #include "RelationalAccess/ICursor.h"
18 #include "RelationalAccess/IQuery.h"
19 #include "RelationalAccess/ISchema.h"
20 #include "RelationalAccess/ISessionProxy.h"
21 
22 using std::make_pair;
23 using std::pair;
24 
26 
28 //define this as a plug-in
30 
32  bool comparePayloads(const LHCInfoPerLS& rhs, const LHCInfoPerLS& lhs) {
33  if (rhs.fillNumber() != lhs.fillNumber() || rhs.runNumber() != lhs.runNumber() ||
34  rhs.crossingAngleX() != lhs.crossingAngleX() || rhs.crossingAngleY() != lhs.crossingAngleY() ||
35  rhs.betaStarX() != lhs.betaStarX() || rhs.betaStarY() != lhs.betaStarY()) {
36  return false;
37  }
38  return true;
39  }
40 
41  size_t transferPayloads(const std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>& buffer,
42  std::map<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>& iovsToTransfer,
43  std::shared_ptr<LHCInfoPerLS>& prevPayload,
44  const std::map<pair<cond::Time_t, unsigned int>, pair<cond::Time_t, unsigned int>>& lsIdMap,
45  cond::Time_t startStableBeamTime,
46  cond::Time_t endStableBeamTime) {
47  int lsMissingInPPS = 0;
48  int xAngleBothZero = 0, xAngleBothNonZero = 0, xAngleNegative = 0;
49  int betaNegative = 0;
50  size_t niovs = 0;
51  std::stringstream condIovs;
52  std::stringstream missingLsList;
53  for (auto& iov : buffer) {
54  bool add = false;
55  auto payload = iov.second;
56  cond::Time_t since = iov.first;
57  if (iovsToTransfer.empty()) {
58  add = true;
59  } else {
60  LHCInfoPerLS& lastAdded = *iovsToTransfer.rbegin()->second;
61  if (!comparePayloads(lastAdded, *payload)) {
62  add = true;
63  }
64  }
65  auto id = make_pair(payload->runNumber(), payload->lumiSection());
66  bool stableBeam = since >= startStableBeamTime && since <= endStableBeamTime;
67  bool isMissing = lsIdMap.find(id) != lsIdMap.end() && id != lsIdMap.at(id);
68  if (stableBeam && isMissing) {
69  missingLsList << id.first << "_" << id.second << " ";
70  lsMissingInPPS += isMissing;
71  }
72  if (add && !isMissing) {
73  niovs++;
74  if (stableBeam) {
75  if (payload->crossingAngleX() == 0 && payload->crossingAngleY() == 0)
76  xAngleBothZero++;
77  if (payload->crossingAngleX() != 0 && payload->crossingAngleY() != 0)
78  xAngleBothNonZero++;
79  if (payload->crossingAngleX() < 0 || payload->crossingAngleY() < 0)
80  xAngleNegative++;
81  if (payload->betaStarX() < 0 || payload->betaStarY() < 0)
82  betaNegative++;
83  }
84 
85  condIovs << since << " ";
86  iovsToTransfer.insert(make_pair(since, payload));
87  prevPayload = iov.second;
88  }
89  }
90  unsigned short fillNumber = (!buffer.empty()) ? buffer.front().second->fillNumber() : 0;
91  if (lsMissingInPPS > 0) {
92  edm::LogWarning("transferPayloads")
93  << "Number of stable beam LS in OMS without corresponding record in PPS DB for fill " << fillNumber << ": "
94  << lsMissingInPPS;
95  edm::LogWarning("transferPayloads")
96  << "Stable beam LS in OMS without corresponding record in PPS DB (run_LS): " << missingLsList.str();
97  }
98  if (xAngleBothZero > 0) {
99  edm::LogWarning("transferPayloads")
100  << "Number of payloads written with crossingAngle == 0 for both X and Y for fill " << fillNumber << ": "
101  << xAngleBothZero;
102  }
103  if (xAngleBothNonZero > 0) {
104  edm::LogWarning("transferPayloads")
105  << "Number of payloads written with crossingAngle != 0 for both X and Y for fill " << fillNumber << ": "
106  << xAngleBothNonZero;
107  }
108  if (xAngleNegative > 0) {
109  edm::LogWarning("transferPayloads")
110  << "Number of payloads written with negative crossingAngle for fill " << fillNumber << ": " << xAngleNegative;
111  }
112  if (betaNegative > 0) {
113  edm::LogWarning("transferPayloads")
114  << "Number of payloads written with negative betaSta for fill " << fillNumber << ": " << betaNegative;
115  }
116 
117  edm::LogInfo("transferPayloads") << "TRANSFERED COND IOVS: " << condIovs.str();
118  return niovs;
119  }
120 
121 } // namespace theLHCInfoPerLSImpl
122 
124 public:
126  : m_debug(pset.getUntrackedParameter<bool>("debug", false)),
127  m_startTime(),
128  m_endTime(),
129  m_endFillMode(pset.getUntrackedParameter<bool>("endFill", true)),
130  m_name(pset.getUntrackedParameter<std::string>("name", "LHCInfoPerLSPopConSourceHandler")),
131  m_connectionString(pset.getUntrackedParameter<std::string>("connectionString", "")),
132  m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
133  m_omsBaseUrl(pset.getUntrackedParameter<std::string>("omsBaseUrl", "")),
134  m_fillPayload(),
135  m_prevPayload(),
136  m_tmpBuffer() {
137  if (!pset.getUntrackedParameter<std::string>("startTime").empty()) {
138  m_startTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("startTime"));
139  }
140  boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
141  m_endTime = now;
142  if (!pset.getUntrackedParameter<std::string>("endTime").empty()) {
143  m_endTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("endTime"));
144  if (m_endTime > now)
145  m_endTime = now;
146  }
147  }
148 
149  ~LHCInfoPerLSPopConSourceHandler() override = default;
150 
151  void getNewObjects() override {
152  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
153  if (tagInfo().size == 0) {
154  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
155  } else {
156  //check what is already inside the database
157  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size
158  << ", last object valid since " << tagInfo().lastInterval.since << " ( "
159  << boost::posix_time::to_iso_extended_string(
160  cond::time::to_boost(tagInfo().lastInterval.since))
161  << " ); from " << m_name << "::getNewObjects";
162  }
163 
164  cond::Time_t lastSince = tagInfo().lastInterval.since;
165  if (tagInfo().isEmpty()) {
166  // for a new or empty tag, an empty payload should be added on top with since=1
167  if (m_endFillMode) {
168  addEmptyPayload(1);
169  lastSince = 1;
170  } else {
172  lastSince = cond::time::lumiTime(1, 1);
173  }
174  } else {
175  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
176  << m_name << "::getNewObjects";
177  }
178 
179  //retrieve the data from the relational database source
181  //configure the connection
182  if (m_debug) {
183  connection.setMessageVerbosity(coral::Debug);
184  } else {
185  connection.setMessageVerbosity(coral::Error);
186  }
187  connection.setAuthenticationPath(m_authpath);
188  connection.configure();
189  //create the sessions
190  cond::persistency::Session session = connection.createSession(m_connectionString, false);
191  // fetch last payload when available
192  if (!tagInfo().lastInterval.payloadId.empty()) {
194  session3.transaction().start(true);
196  session3.transaction().commit();
197 
198  // find startFillTime and endFillTime of the most recent fill already saved in the tag
199  if (m_prevPayload->fillNumber() != 0) {
200  cond::OMSService oms;
201  oms.connect(m_omsBaseUrl);
202  auto query = oms.query("fills");
203  query->addOutputVar("end_time");
204  query->addOutputVar("start_time");
205  query->filterEQ("fill_number", m_prevPayload->fillNumber());
206  bool foundFill = query->execute();
207  if (foundFill) {
208  auto result = query->result();
209 
210  if (!result.empty()) {
211  std::string endTimeStr = (*result.begin()).get<std::string>("end_time");
213  (endTimeStr == "null")
214  ? 0
215  : cond::time::from_boost((*result.begin()).get<boost::posix_time::ptime>("end_time"));
216  auto startFillTime = (*result.begin()).get<boost::posix_time::ptime>("start_time");
218  } else {
219  foundFill = false;
220  }
221  }
222  if (!foundFill) {
223  edm::LogError(m_name) << "Could not find end time of fill #" << m_prevPayload->fillNumber();
224  }
225  } else {
226  m_prevEndFillTime = 0;
228  }
229  }
230 
231  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
232  cond::Time_t executionTimeIov = cond::time::from_boost(executionTime);
233 
234  cond::Time_t startTimestamp = m_startTime.is_not_a_date_time() ? 0 : cond::time::from_boost(m_startTime);
235  cond::Time_t nextFillSearchTimestamp = std::max(startTimestamp, m_endFillMode ? lastSince : m_prevEndFillTime);
236 
237  edm::LogInfo(m_name) << "Starting sampling at "
238  << boost::posix_time::to_simple_string(cond::time::to_boost(nextFillSearchTimestamp));
239 
240  while (true) {
241  if (nextFillSearchTimestamp >= executionTimeIov) {
242  edm::LogInfo(m_name) << "Sampling ended at the time "
243  << boost::posix_time::to_simple_string(cond::time::to_boost(executionTimeIov));
244  break;
245  }
246  boost::posix_time::ptime nextFillSearchTime = cond::time::to_boost(nextFillSearchTimestamp);
247  boost::posix_time::ptime startSampleTime;
248  boost::posix_time::ptime endSampleTime;
249 
250  cond::OMSService oms;
251  oms.connect(m_omsBaseUrl);
252  auto query = oms.query("fills");
253 
254  if (!m_endFillMode and m_prevPayload->fillNumber() and m_prevEndFillTime == 0ULL) {
255  // continue processing unfinished fill with some payloads already in the tag
256  edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber();
257  query->filterEQ("fill_number", m_prevPayload->fillNumber());
258  bool foundFill = query->execute();
259  if (foundFill)
260  foundFill = makeFillPayload(m_fillPayload, query->result());
261  if (!foundFill) {
262  edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber();
263  break;
264  }
265  startSampleTime = cond::time::to_boost(lastSince);
266  } else {
267  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(nextFillSearchTime);
268  query->filterNotNull("start_stable_beam").filterNotNull("fill_number");
269  if (nextFillSearchTime > cond::time::to_boost(m_prevStartFillTime)) {
270  query->filterGE("start_time", nextFillSearchTime);
271  } else {
272  query->filterGT("start_time", nextFillSearchTime);
273  }
274 
275  query->filterLT("start_time", m_endTime);
276  if (m_endFillMode)
277  query->filterNotNull("end_time");
278  bool foundFill = query->execute();
279  if (foundFill)
280  foundFill = makeFillPayload(m_fillPayload, query->result());
281  if (!foundFill) {
282  edm::LogInfo(m_name) << "No fill found - END of job.";
283  break;
284  }
285  startSampleTime = cond::time::to_boost(m_startFillTime);
286  }
287 
288  unsigned short lhcFill = m_fillPayload->fillNumber();
289  bool ongoingFill = m_endFillTime == 0ULL;
290  if (ongoingFill) {
291  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at "
293  endSampleTime = executionTime;
294  nextFillSearchTimestamp = executionTimeIov;
295  } else {
296  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(m_startFillTime)
297  << " ending at " << cond::time::to_boost(m_endFillTime);
298  endSampleTime = cond::time::to_boost(m_endFillTime);
299  nextFillSearchTimestamp = m_endFillTime;
300  }
301 
302  if (m_endFillMode || ongoingFill) {
303  getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
304 
305  if (!m_tmpBuffer.empty()) {
306  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
307  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
308  edm::LogInfo(m_name) << "First buffered lumi starts at " << flumiStart << " last lumi starts at "
309  << flumiStop;
310  session.transaction().start(true);
311  getCTPPSData(session, startSampleTime, endSampleTime);
312  session.transaction().commit();
313  }
314  }
315 
318  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
319  if (niovs) {
322  }
323  m_tmpBuffer.clear();
324  m_lsIdMap.clear();
325  if (m_prevPayload->fillNumber() and !ongoingFill) {
326  if (m_endFillMode) {
328  } else {
330  }
331  }
332  }
333  }
334  std::string id() const override { return m_name; }
335 
336  static constexpr unsigned int kLumisectionsQueryLimit = 4000;
337 
338 private:
340  bool add = false;
341  if (m_iovs.empty()) {
342  if (!m_lastPayloadEmpty)
343  add = true;
344  } else {
345  auto lastAdded = m_iovs.rbegin()->second;
346  if (lastAdded->fillNumber() != 0) {
347  add = true;
348  }
349  }
350  if (add) {
351  auto newPayload = std::make_shared<LHCInfoPerLS>();
352  m_iovs.insert(make_pair(iov, newPayload));
353  m_prevPayload = newPayload;
354  m_prevEndFillTime = 0;
356  edm::LogInfo(m_name) << "Added empty payload with IOV" << iov << " ( "
357  << boost::posix_time::to_iso_extended_string(cond::time::to_boost(iov)) << " )";
358  }
359  }
360 
361  bool makeFillPayload(std::unique_ptr<LHCInfoPerLS>& targetPayload, const cond::OMSServiceResult& queryResult) {
362  bool ret = false;
363  if (!queryResult.empty()) {
364  auto row = *queryResult.begin();
365  auto currentFill = row.get<unsigned short>("fill_number");
366  m_startFillTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("start_time"));
367  std::string endTimeStr = row.get<std::string>("end_time");
368  m_endFillTime =
369  (endTimeStr == "null") ? 0 : cond::time::from_boost(row.get<boost::posix_time::ptime>("end_time"));
370  m_startStableBeamTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("start_stable_beam"));
371  m_endStableBeamTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("end_stable_beam"));
372  targetPayload = std::make_unique<LHCInfoPerLS>();
373  targetPayload->setFillNumber(currentFill);
374  ret = true;
375  }
376  return ret;
377  }
378 
380  auto lumiTime = row.get<boost::posix_time::ptime>("start_time");
381  LHCInfoPerLS* thisLumiSectionInfo = new LHCInfoPerLS(*m_fillPayload);
382  thisLumiSectionInfo->setLumiSection(std::stoul(row.get<std::string>("lumisection_number")));
383  thisLumiSectionInfo->setRunNumber(std::stoul(row.get<std::string>("run_number")));
384  m_lsIdMap[make_pair(thisLumiSectionInfo->runNumber(), thisLumiSectionInfo->lumiSection())] = make_pair(-1, -1);
385  if (m_endFillMode) {
386  m_tmpBuffer.emplace_back(make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
387  } else {
388  m_tmpBuffer.emplace_back(
389  make_pair(cond::time::lumiTime(thisLumiSectionInfo->runNumber(), thisLumiSectionInfo->lumiSection()),
390  thisLumiSectionInfo));
391  }
392  }
393 
394  size_t bufferAllLS(const cond::OMSServiceResult& queryResult) {
395  for (auto r : queryResult) {
397  }
398  return queryResult.size();
399  }
400 
401  size_t bufferFirstStableBeamLS(const cond::OMSServiceResult& queryResult) {
402  for (auto r : queryResult) {
403  if (r.get<std::string>("beams_stable") == "true") {
405  edm::LogInfo(m_name) << "Buffered first lumisection of stable beam: LS: "
406  << r.get<std::string>("lumisection_number")
407  << " run: " << r.get<std::string>("run_number");
408  return 1;
409  }
410  }
411  return 0;
412  }
413 
414  size_t getLumiData(const cond::OMSService& oms,
415  unsigned short fillId,
416  const boost::posix_time::ptime& beginFillTime,
417  const boost::posix_time::ptime& endFillTime) {
418  auto query = oms.query("lumisections");
419  query->addOutputVars({"start_time", "run_number", "beams_stable", "lumisection_number"});
420  query->filterEQ("fill_number", fillId);
421  query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime);
423  size_t nlumi = 0;
424  if (query->execute()) {
425  auto queryResult = query->result();
426  if (m_endFillMode) {
427  nlumi = bufferAllLS(queryResult);
428  } else if (!queryResult.empty()) {
429  auto newestPayload = queryResult.back();
430  if (newestPayload.get<std::string>("beams_stable") == "true") {
431  addPayloadToBuffer(newestPayload);
432  nlumi = 1;
433  edm::LogInfo(m_name) << "Buffered most recent lumisection:"
434  << " LS: " << newestPayload.get<std::string>("lumisection_number")
435  << " run: " << newestPayload.get<std::string>("run_number");
436  }
437  }
438  edm::LogInfo(m_name) << "Found " << queryResult.size() << " lumisections during the fill " << fillId;
439  } else {
440  edm::LogInfo(m_name) << "OMS query for lumisections of fill " << fillId << "failed, status:" << query->status();
441  }
442  return nlumi;
443  }
444 
446  const boost::posix_time::ptime& beginFillTime,
447  const boost::posix_time::ptime& endFillTime) {
448  //run the fifth query against the CTPPS schema
449  //Initializing the CMS_CTP_CTPPS_COND schema.
450  coral::ISchema& CTPPS = session.coralSession().schema("CMS_PPS_SPECT_COND");
451  //execute query for CTPPS Data
452  std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
453  //FROM clause
454  CTPPSDataQuery->addToTableList(std::string("PPS_LHC_MACHINE_PARAMS"));
455  //SELECT clause
456  CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME"));
457  CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION"));
458  CTPPSDataQuery->addToOutputList(std::string("RUN_NUMBER"));
459  CTPPSDataQuery->addToOutputList(std::string("FILL_NUMBER"));
460  CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_X_URAD"));
461  CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_Y_URAD"));
462  CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_X_M"));
463  CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_Y_M"));
464  //WHERE CLAUSE
465  coral::AttributeList CTPPSDataBindVariables;
466  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("beginFillTime"));
467  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("endFillTime"));
468  CTPPSDataBindVariables[std::string("beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
469  CTPPSDataBindVariables[std::string("endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
470  std::string conditionStr = std::string("DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
471  CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
472  //ORDER BY clause
473  CTPPSDataQuery->addToOrderList(std::string("DIP_UPDATE_TIME"));
474  //define query output
475  coral::AttributeList CTPPSDataOutput;
476  CTPPSDataOutput.extend<coral::TimeStamp>(std::string("DIP_UPDATE_TIME"));
477  CTPPSDataOutput.extend<int>(std::string("LUMI_SECTION"));
478  CTPPSDataOutput.extend<int>(std::string("RUN_NUMBER"));
479  CTPPSDataOutput.extend<int>(std::string("FILL_NUMBER"));
480  CTPPSDataOutput.extend<float>(std::string("XING_ANGLE_P5_X_URAD"));
481  CTPPSDataOutput.extend<float>(std::string("XING_ANGLE_P5_Y_URAD"));
482  CTPPSDataOutput.extend<float>(std::string("BETA_STAR_P5_X_M"));
483  CTPPSDataOutput.extend<float>(std::string("BETA_STAR_P5_Y_M"));
484  CTPPSDataQuery->defineOutput(CTPPSDataOutput);
485  //execute the query
486  coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
487  unsigned int lumiSection = 0;
489  int fillNumber = 0;
490  float crossingAngleX = 0., betaStarX = 0.;
491  float crossingAngleY = 0., betaStarY = 0.;
492 
493  bool ret = false;
494  int wrongFillNumbers = 0;
495  std::stringstream wrongFills;
496  std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::iterator current = m_tmpBuffer.begin();
497  while (CTPPSDataCursor.next()) {
498  if (m_debug) {
499  std::ostringstream CTPPS;
500  CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
501  }
502  coral::Attribute const& dipTimeAttribute = CTPPSDataCursor.currentRow()[std::string("DIP_UPDATE_TIME")];
503  if (!dipTimeAttribute.isNull()) {
504  ret = true;
505  coral::Attribute const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[std::string("LUMI_SECTION")];
506  if (!lumiSectionAttribute.isNull()) {
507  lumiSection = lumiSectionAttribute.data<int>();
508  }
509  coral::Attribute const& runNumberAttribute = CTPPSDataCursor.currentRow()[std::string("RUN_NUMBER")];
510  if (!runNumberAttribute.isNull()) {
511  runNumber = runNumberAttribute.data<int>();
512  }
513  coral::Attribute const& fillNumberAttribute = CTPPSDataCursor.currentRow()[std::string("FILL_NUMBER")];
514  if (!fillNumberAttribute.isNull()) {
515  fillNumber = fillNumberAttribute.data<int>();
516  }
517  coral::Attribute const& crossingAngleXAttribute =
518  CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_X_URAD")];
519  if (!crossingAngleXAttribute.isNull()) {
520  crossingAngleX = crossingAngleXAttribute.data<float>();
521  }
522  coral::Attribute const& crossingAngleYAttribute =
523  CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_Y_URAD")];
524  if (!crossingAngleYAttribute.isNull()) {
525  crossingAngleY = crossingAngleYAttribute.data<float>();
526  }
527  coral::Attribute const& betaStarXAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_X_M")];
528  if (!betaStarXAttribute.isNull()) {
529  betaStarX = betaStarXAttribute.data<float>();
530  }
531  coral::Attribute const& betaStarYAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_Y_M")];
532  if (!betaStarYAttribute.isNull()) {
533  betaStarY = betaStarYAttribute.data<float>();
534  }
535  if (current != m_tmpBuffer.end() && current->second->fillNumber() != fillNumber) {
536  wrongFills << "( " << runNumber << "_" << lumiSection << " fill: OMS: " << current->second->fillNumber()
537  << " PPSdb: " << fillNumber << " ) ";
538  wrongFillNumbers++;
539  }
540  for (;
541  current != m_tmpBuffer.end() && make_pair(current->second->runNumber(), current->second->lumiSection()) <=
542  make_pair(runNumber, lumiSection);
543  current++) {
544  LHCInfoPerLS& payload = *(current->second);
545  payload.setCrossingAngleX(crossingAngleX);
546  payload.setCrossingAngleY(crossingAngleY);
547  payload.setBetaStarX(betaStarX);
548  payload.setBetaStarY(betaStarY);
549  payload.setLumiSection(lumiSection);
550  payload.setRunNumber(runNumber);
551  if (m_lsIdMap.find(make_pair(payload.runNumber(), payload.lumiSection())) != m_lsIdMap.end()) {
552  m_lsIdMap[make_pair(payload.runNumber(), payload.lumiSection())] = make_pair(runNumber, lumiSection);
553  }
554  }
555  }
556  }
557  if (wrongFillNumbers) {
558  edm::LogWarning("getCTPPSData") << "Number of records from PPS DB with fillNumber different from OMS: "
559  << wrongFillNumbers;
560  edm::LogWarning("getCTPPSData") << "Records from PPS DB with fillNumber different from OMS: " << wrongFills.str();
561  }
562  return ret;
563  }
564 
565 private:
566  bool m_debug;
567  // starting date for sampling
568  boost::posix_time::ptime m_startTime;
569  boost::posix_time::ptime m_endTime;
570  bool m_endFillMode = true;
572  //for reading from relational database source
576  std::unique_ptr<LHCInfoPerLS> m_fillPayload;
577  std::shared_ptr<LHCInfoPerLS> m_prevPayload;
584  std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>> m_tmpBuffer;
585  bool m_lastPayloadEmpty = false;
586  //mapping of lumisections IDs (pairs of runnumber an LS number) found in OMS to the IDs they've been assignd from PPS DB
587  //value pair(-1, -1) means lumisection corresponding to the key exists in OMS but no lumisection was matched from PPS
588  std::map<pair<cond::Time_t, unsigned int>, pair<cond::Time_t, unsigned int>> m_lsIdMap;
589 };
size
Write out results.
edm::ErrorSummaryEntry Error
size_t transferPayloads(const std::vector< pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS >>> &buffer, std::map< cond::Time_t, std::shared_ptr< LHCInfoPerLS >> &iovsToTransfer, std::shared_ptr< LHCInfoPerLS > &prevPayload, const std::map< pair< cond::Time_t, unsigned int >, pair< cond::Time_t, unsigned int >> &lsIdMap, cond::Time_t startStableBeamTime, cond::Time_t endStableBeamTime)
bool makeFillPayload(std::unique_ptr< LHCInfoPerLS > &targetPayload, const cond::OMSServiceResult &queryResult)
cond::Time_t runNumber() const
Definition: LHCInfoPerLS.cc:23
Iov_t lastInterval
Definition: Types.h:73
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:129
T get(const std::string &attributeName)
Definition: OMSAccess.h:114
std::shared_ptr< LHCInfoPerLS > m_prevPayload
ret
prodAgent to be discontinued
void start(bool readOnly=true)
Definition: Session.cc:18
bool empty() const
Definition: OMSAccess.cc:69
~LHCInfoPerLSPopConSourceHandler() override=default
Time_t since
Definition: Types.h:53
size_t bufferFirstStableBeamLS(const cond::OMSServiceResult &queryResult)
LHCInfoPerLSPopConSourceHandler(edm::ParameterSet const &pset)
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
Transaction & transaction()
Definition: Session.cc:52
float const betaStarY() const
Definition: LHCInfoPerLS.cc:21
std::string name
Definition: Types.h:72
Definition: query.py:1
cond::TagInfo_t const & tagInfo() const
popcon::PopConAnalyzer< LHCInfoPerLSPopConSourceHandler > LHCInfoPerLSPopConAnalyzer
float const crossingAngleX() const
Definition: LHCInfoPerLS.cc:15
unsigned long long Time_t
Definition: Time.h:14
Time_t lumiTime(unsigned int run, unsigned int lumiId)
Definition: Time.cc:66
size_t bufferAllLS(const cond::OMSServiceResult &queryResult)
Hash payloadId
Definition: Types.h:55
Session createSession(const std::string &connectionString, bool writeCapable=false)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addPayloadToBuffer(cond::OMSServiceResultRef &row)
void setMessageVerbosity(coral::MsgLevel level)
Time_t from_boost(boost::posix_time::ptime bt)
float const crossingAngleY() const
Definition: LHCInfoPerLS.cc:17
Log< level::Info, false > LogInfo
std::map< pair< cond::Time_t, unsigned int >, pair< cond::Time_t, unsigned int > > m_lsIdMap
cond::persistency::Session & dbSession() const
coral::ISessionProxy & coralSession()
Definition: Session.cc:218
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
std::unique_ptr< LHCInfoPerLS > m_fillPayload
static constexpr unsigned int kLumisectionsQueryLimit
void connect(const std::string &baseUrl)
Definition: OMSAccess.cc:128
OMSServiceResultIterator begin() const
Definition: OMSAccess.cc:32
Log< level::Warning, false > LogWarning
bool getCTPPSData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
unsigned short const fillNumber() const
Definition: LHCInfoPerLS.cc:11
float const betaStarX() const
Definition: LHCInfoPerLS.cc:19
void setAuthenticationPath(const std::string &p)
const bool Debug
std::vector< pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > > m_tmpBuffer
cond::Time_t getFillLastLumiIOV(const cond::OMSService &oms, unsigned short fillId)
Definition: LHCInfoHelper.cc:8
boost::posix_time::ptime to_boost(Time_t iValue)
bool comparePayloads(const LHCInfoPerLS &rhs, const LHCInfoPerLS &lhs)
size_t getLumiData(const cond::OMSService &oms, unsigned short fillId, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)