CMS 3D CMS Logo

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