CMS 3D CMS Logo

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