CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
LHCInfoPerLSPopConSourceHandler.cc
Go to the documentation of this file.
7 #include "CoralBase/Attribute.h"
8 #include "CoralBase/AttributeList.h"
9 #include "CoralBase/AttributeSpecification.h"
10 #include "CoralBase/TimeStamp.h"
13 #include "RelationalAccess/ICursor.h"
14 #include "RelationalAccess/IQuery.h"
15 #include "RelationalAccess/ISchema.h"
16 #include "RelationalAccess/ISessionProxy.h"
17 #include <boost/date_time/posix_time/posix_time.hpp>
18 #include <sstream>
19 
20 using std::make_pair;
21 using std::pair;
22 
24  bool comparePayloads(const LHCInfoPerLS& rhs, const LHCInfoPerLS& lhs) {
25  if (rhs.fillNumber() != lhs.fillNumber() || rhs.runNumber() != lhs.runNumber() ||
26  rhs.crossingAngleX() != lhs.crossingAngleX() || rhs.crossingAngleY() != lhs.crossingAngleY() ||
27  rhs.betaStarX() != lhs.betaStarX() || rhs.betaStarY() != lhs.betaStarY()) {
28  return false;
29  }
30  return true;
31  }
32 
33  size_t transferPayloads(const std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>& buffer,
34  std::map<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>& iovsToTransfer,
35  std::shared_ptr<LHCInfoPerLS>& prevPayload,
36  const std::map<pair<cond::Time_t, unsigned int>, pair<cond::Time_t, unsigned int>>& lsIdMap,
37  cond::Time_t startStableBeamTime,
38  cond::Time_t endStableBeamTime) {
39  int lsMissingInPPS = 0;
40  int xAngleBothZero = 0, xAngleBothNonZero = 0, xAngleNegative = 0;
41  int betaNegative = 0;
42  size_t niovs = 0;
43  std::stringstream condIovs;
44  std::stringstream missingLsList;
45  for (auto& iov : buffer) {
46  bool add = false;
47  auto payload = iov.second;
48  cond::Time_t since = iov.first;
49  if (iovsToTransfer.empty()) {
50  add = true;
51  } else {
52  LHCInfoPerLS& lastAdded = *iovsToTransfer.rbegin()->second;
53  if (!comparePayloads(lastAdded, *payload)) {
54  add = true;
55  }
56  }
57  auto id = make_pair(payload->runNumber(), payload->lumiSection());
58  bool stableBeam = since >= startStableBeamTime && since <= endStableBeamTime;
59  bool isMissing = lsIdMap.find(id) != lsIdMap.end() && id != lsIdMap.at(id);
60  if (stableBeam && isMissing) {
61  missingLsList << id.first << "_" << id.second << " ";
62  lsMissingInPPS += isMissing;
63  }
64  if (add && !isMissing) {
65  niovs++;
66  if (stableBeam) {
67  if (payload->crossingAngleX() == 0 && payload->crossingAngleY() == 0)
68  xAngleBothZero++;
69  if (payload->crossingAngleX() != 0 && payload->crossingAngleY() != 0)
70  xAngleBothNonZero++;
71  if (payload->crossingAngleX() < 0 || payload->crossingAngleY() < 0)
72  xAngleNegative++;
73  if (payload->betaStarX() < 0 || payload->betaStarY() < 0)
74  betaNegative++;
75  }
76 
77  condIovs << since << " ";
78  iovsToTransfer.insert(make_pair(since, payload));
79  prevPayload = iov.second;
80  }
81  }
82  unsigned short fillNumber = (!buffer.empty()) ? buffer.front().second->fillNumber() : 0;
83  if (lsMissingInPPS > 0) {
84  edm::LogWarning("transferPayloads")
85  << "Number of stable beam LS in OMS without corresponding record in PPS DB for fill " << fillNumber << ": "
86  << lsMissingInPPS;
87  edm::LogWarning("transferPayloads")
88  << "Stable beam LS in OMS without corresponding record in PPS DB (run_LS): " << missingLsList.str();
89  }
90  if (xAngleBothZero > 0) {
91  edm::LogWarning("transferPayloads")
92  << "Number of payloads written with crossingAngle == 0 for both X and Y for fill " << fillNumber << ": "
93  << xAngleBothZero;
94  }
95  if (xAngleBothNonZero > 0) {
96  edm::LogWarning("transferPayloads")
97  << "Number of payloads written with crossingAngle != 0 for both X and Y for fill " << fillNumber << ": "
98  << xAngleBothNonZero;
99  }
100  if (xAngleNegative > 0) {
101  edm::LogWarning("transferPayloads")
102  << "Number of payloads written with negative crossingAngle for fill " << fillNumber << ": " << xAngleNegative;
103  }
104  if (betaNegative > 0) {
105  edm::LogWarning("transferPayloads")
106  << "Number of payloads written with negative betaSta for fill " << fillNumber << ": " << betaNegative;
107  }
108 
109  edm::LogInfo("transferPayloads") << "TRANSFERED COND IOVS: " << condIovs.str();
110  return niovs;
111  }
112 
113 } // namespace theLHCInfoPerLSImpl
114 
116  : m_debug(pset.getUntrackedParameter<bool>("debug", false)),
117  m_startTime(),
118  m_endTime(),
119  m_endFillMode(pset.getUntrackedParameter<bool>("endFill", true)),
120  m_name(pset.getUntrackedParameter<std::string>("name", "LHCInfoPerLSPopConSourceHandler")),
121  m_connectionString(pset.getUntrackedParameter<std::string>("connectionString", "")),
122  m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
123  m_omsBaseUrl(pset.getUntrackedParameter<std::string>("omsBaseUrl", "")),
124  m_debugLogic(pset.getUntrackedParameter<bool>("debugLogic", false)),
125  m_defaultCrossingAngleX(pset.getUntrackedParameter<double>("defaultCrossingAngleX", 0)),
126  m_defaultCrossingAngleY(pset.getUntrackedParameter<double>("defaultCrossingAngleY", 0)),
127  m_defaultBetaStarX(pset.getUntrackedParameter<double>("defaultBetaStarX", 0)),
128  m_defaultBetaStarY(pset.getUntrackedParameter<double>("defaultBetaStarY", 0)),
129  m_minBetaStar(pset.getUntrackedParameter<double>("minBetaStar", 0.1)),
130  m_maxBetaStar(pset.getUntrackedParameter<double>("maxBetaStar", 100.)),
131  m_minCrossingAngle(pset.getUntrackedParameter<double>("minCrossingAngle", 10.)),
132  m_maxCrossingAngle(pset.getUntrackedParameter<double>("maxCrossingAngle", 500.)),
133  m_fillPayload(),
134  m_prevPayload(),
135  m_tmpBuffer() {
136  if (!pset.getUntrackedParameter<std::string>("startTime").empty()) {
137  m_startTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("startTime"));
138  }
139  boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
140  m_endTime = now;
141  if (!pset.getUntrackedParameter<std::string>("endTime").empty()) {
142  m_endTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("endTime"));
143  if (m_endTime > now)
144  m_endTime = now;
145  }
146  if (m_debugLogic && m_endFillMode) {
147  throw cms::Exception("invalid argument") << "debugLogic == true not supported for endFillMode == true";
148  }
149 }
150 
152 
154  populateIovs();
155  if (!m_endFillMode) { // duringFill mode
157  }
158 }
159 
161  // note: at the moment used only in duringFill mode so the m_iovs is quaranteed to have size() <= 1
162  // but iterating through the whole map is implemented just in case the way it's used changes
163  auto it = m_iovs.begin();
164  while (it != m_iovs.end()) {
165  std::stringstream payloadData;
166  payloadData << "LS = " << it->second->lumiSection() << ", run = " << it->second->runNumber() << ", "
167  << "xAngleX = " << it->second->crossingAngleX() << " urad, "
168  << "xAngleY = " << it->second->crossingAngleY() << " urad, "
169  << "beta*X = " << it->second->betaStarX() << " m, "
170  << "beta*Y = " << it->second->betaStarY() << " m";
171  if (!isPayloadValid(*(it->second))) {
172  edm::LogWarning(m_name) << "Skipping upload of payload with invalid values: " << payloadData.str();
173  m_iovs.erase(it++); // note: post-increment necessary to avoid using invalidated iterators
174  } else {
175  edm::LogInfo(m_name) << "Payload to be uploaded: " << payloadData.str();
176  ++it;
177  }
178  }
179 }
180 
182  if ((payload.crossingAngleX() == 0. && payload.crossingAngleY() == 0.) ||
183  (payload.crossingAngleX() != 0. && payload.crossingAngleY() != 0.))
184  return false;
185  auto non0CrossingAngle = payload.crossingAngleX() != 0. ? payload.crossingAngleX() : payload.crossingAngleY();
186  if ((non0CrossingAngle < m_minCrossingAngle || m_maxCrossingAngle < non0CrossingAngle) ||
187  (payload.betaStarX() < m_minBetaStar || m_maxBetaStar < payload.betaStarX()) ||
188  (payload.betaStarX() < m_minBetaStar || m_maxBetaStar < payload.betaStarX()))
189  return false;
190  return true;
191 }
192 
194  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
195  if (tagInfo().size == 0) {
196  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
197  } else {
198  //check what is already inside the database
199  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size
200  << ", last object valid since " << tagInfo().lastInterval.since << " ( "
201  << boost::posix_time::to_iso_extended_string(
202  cond::time::to_boost(tagInfo().lastInterval.since))
203  << " ); from " << m_name << "::getNewObjects";
204  }
205 
206  cond::Time_t lastSince = tagInfo().lastInterval.since;
207  if (tagInfo().isEmpty()) {
208  // for a new or empty tag in endFill mode, an empty payload should be added on top with since=1
209  if (m_endFillMode) {
210  addEmptyPayload(1);
211  lastSince = 1;
212  } else { //duringFill mode
213  edm::LogInfo(m_name) << "Empty or new tag: uploading a default payload and ending the job";
214  cond::OMSService oms;
215  oms.connect(m_omsBaseUrl);
216  addDefaultPayload(1, 1, 1, 1);
217  return;
218  }
219  } else {
220  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
221  << m_name << "::getNewObjects";
222  }
223 
224  //retrieve the data from the relational database source
226  //configure the connection
227  if (m_debug) {
228  connection.setMessageVerbosity(coral::Debug);
229  } else {
230  connection.setMessageVerbosity(coral::Error);
231  }
232  connection.setAuthenticationPath(m_authpath);
233  connection.configure();
234  //create the sessions
235  cond::persistency::Session session = connection.createSession(m_connectionString, false);
236  // fetch last payload when available
237  if (!tagInfo().lastInterval.payloadId.empty()) {
239  session3.transaction().start(true);
241  session3.transaction().commit();
242 
243  // find startFillTime and endFillTime of the most recent fill already saved in the tag
244  if (m_prevPayload->fillNumber() != 0) {
245  cond::OMSService oms;
246  oms.connect(m_omsBaseUrl);
247  auto query = oms.query("fills");
248  query->addOutputVar("end_time");
249  query->addOutputVar("start_time");
250  query->filterEQ("fill_number", m_prevPayload->fillNumber());
251  bool foundFill = query->execute();
252  if (foundFill) {
253  auto result = query->result();
254 
255  if (!result.empty()) {
256  std::string endTimeStr = (*result.begin()).get<std::string>("end_time");
257  m_prevEndFillTime = (endTimeStr == "null")
258  ? 0
259  : cond::time::from_boost((*result.begin()).get<boost::posix_time::ptime>("end_time"));
260  auto startFillTime = (*result.begin()).get<boost::posix_time::ptime>("start_time");
262  } else {
263  foundFill = false;
264  }
265  }
266  if (!foundFill) {
267  edm::LogError(m_name) << "Could not find end time of fill #" << m_prevPayload->fillNumber();
268  }
269  } else {
270  m_prevEndFillTime = 0;
272  }
273  }
274 
275  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
276  cond::Time_t executionTimeIov = cond::time::from_boost(executionTime);
277 
278  cond::Time_t startTimestamp = m_startTime.is_not_a_date_time() ? 0 : cond::time::from_boost(m_startTime);
279  cond::Time_t nextFillSearchTimestamp = std::max(startTimestamp, m_endFillMode ? lastSince : m_prevEndFillTime);
280 
281  edm::LogInfo(m_name) << "Starting sampling at "
282  << boost::posix_time::to_simple_string(cond::time::to_boost(nextFillSearchTimestamp));
283 
284  while (true) {
285  if (nextFillSearchTimestamp >= executionTimeIov) {
286  edm::LogInfo(m_name) << "Sampling ended at the time "
287  << boost::posix_time::to_simple_string(cond::time::to_boost(executionTimeIov));
288  break;
289  }
290  boost::posix_time::ptime nextFillSearchTime = cond::time::to_boost(nextFillSearchTimestamp);
291  boost::posix_time::ptime startSampleTime;
292  boost::posix_time::ptime endSampleTime;
293 
294  cond::OMSService oms;
295  oms.connect(m_omsBaseUrl);
296  auto query = oms.query("fills");
297 
298  if (m_debugLogic)
299  m_prevEndFillTime = 0ULL;
300 
301  if (!m_endFillMode and m_prevPayload->fillNumber() and m_prevEndFillTime == 0ULL) {
302  // continue processing unfinished fill with some payloads already in the tag
303  edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber();
304  query->filterEQ("fill_number", m_prevPayload->fillNumber());
305  bool foundFill = query->execute();
306  if (foundFill)
307  foundFill = makeFillPayload(m_fillPayload, query->result());
308  if (!foundFill) {
309  edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber();
310  break;
311  }
312  } else {
313  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(nextFillSearchTime);
314  query->filterNotNull("start_stable_beam").filterNotNull("fill_number");
315  if (nextFillSearchTime > cond::time::to_boost(m_prevStartFillTime)) {
316  query->filterGE("start_time", nextFillSearchTime);
317  } else {
318  query->filterGT("start_time", nextFillSearchTime);
319  }
320 
321  query->filterLT("start_time", m_endTime);
322  if (m_endFillMode)
323  query->filterNotNull("end_time");
324  else
325  query->filterEQ("end_time", cond::OMSServiceQuery::SNULL);
326 
327  bool querySuccess = query->execute();
328  if (!querySuccess) {
329  edm::LogError(m_name) << "OMS fill query failed (http status not 200 nor 201). Request URL:\n" << query->url();
330  }
331  bool foundFill = querySuccess ? makeFillPayload(m_fillPayload, query->result()) : false;
332 
333  if (!foundFill) {
334  if (m_endFillMode) {
335  edm::LogInfo(m_name) << "No fill found - END of job.";
336  } else { //duringFill mode
337  edm::LogInfo(m_name) << "No ongoing fill found.";
338  addDefaultPayload(1, m_prevPayload->fillNumber(), oms); //IOV doesn't matter here in duringFill mode
339  }
340  break;
341  }
342  }
343  startSampleTime = cond::time::to_boost(m_startFillTime);
344 
345  unsigned short lhcFill = m_fillPayload->fillNumber();
346  bool ongoingFill = m_endFillTime == 0ULL;
347  if (ongoingFill) {
348  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at "
350  endSampleTime = executionTime;
351  nextFillSearchTimestamp = executionTimeIov;
352  } else {
353  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(m_startFillTime)
354  << " ending at " << cond::time::to_boost(m_endFillTime);
355  endSampleTime = cond::time::to_boost(m_endFillTime);
356  nextFillSearchTimestamp = m_endFillTime;
357  }
358 
359  if (m_endFillMode || ongoingFill) {
360  getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
361 
362  if (!m_tmpBuffer.empty()) {
363  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
364  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
365  edm::LogInfo(m_name) << "First buffered lumi starts at " << flumiStart << " last lumi starts at " << flumiStop;
366  session.transaction().start(true);
367  getCTPPSData(session, startSampleTime, endSampleTime);
368  session.transaction().commit();
369  }
370  }
371 
372  if (!m_endFillMode) {
373  if (m_tmpBuffer.size() > 1) {
374  throw cms::Exception("LHCInfoPerFillPopConSourceHandler")
375  << "More than 1 payload buffered for writing in duringFill mode.\
376  In this mode only up to 1 payload can be written";
377  } else if (m_tmpBuffer.size() == 1) {
379  m_tmpBuffer.clear();
381  << "The buffered payload has the same data as the previous payload in the tag. It will not be written.";
382  }
383  } else if (m_tmpBuffer.empty()) {
384  // note: the IOV doesn't matter when using OnlinePopCon:
385  addDefaultPayload(1, lhcFill, oms);
386  }
387  }
388 
391  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
392  m_tmpBuffer.clear();
393  m_lsIdMap.clear();
394 
395  if (!m_endFillMode) {
396  return;
397  }
398 
399  // endFill mode only:
400  if (niovs) {
403  }
404  if (m_prevPayload->fillNumber() and !ongoingFill) {
405  if (m_endFillMode) {
407  }
408  }
409  }
410 }
411 
413 
415  bool add = false;
416  if (m_iovs.empty()) {
417  if (!m_lastPayloadEmpty)
418  add = true;
419  } else {
420  auto lastAdded = m_iovs.rbegin()->second;
421  if (lastAdded->fillNumber() != 0) {
422  add = true;
423  }
424  }
425  if (add) {
426  auto newPayload = std::make_shared<LHCInfoPerLS>();
427  m_iovs.insert(make_pair(iov, newPayload));
428  m_prevPayload = newPayload;
429  m_prevEndFillTime = 0;
431  edm::LogInfo(m_name) << "Added empty payload with IOV" << iov << " ( "
432  << boost::posix_time::to_iso_extended_string(cond::time::to_boost(iov)) << " )";
433  }
434 }
435 
437  unsigned short fill,
438  const cond::OMSService& oms) {
439  auto defaultPayload = std::make_shared<LHCInfoPerLS>();
440  defaultPayload->setFillNumber(fill);
443 }
444 
446  unsigned short fill,
447  int run,
448  unsigned short lumi) {
449  auto defaultPayload = std::make_shared<LHCInfoPerLS>();
450  defaultPayload->setFillNumber(fill);
451  defaultPayload->setRunNumber(run);
452  defaultPayload->setLumiSection(lumi);
453  defaultPayload->setCrossingAngleX(m_defaultCrossingAngleX);
454  defaultPayload->setCrossingAngleY(m_defaultCrossingAngleY);
455  defaultPayload->setBetaStarX(m_defaultBetaStarX);
456  defaultPayload->setBetaStarY(m_defaultBetaStarY);
457 
460  << "The default payload has the same data as the previous payload in the tag. It will not be written.";
461  } else {
462  m_iovs.insert(make_pair(iov, defaultPayload));
463  edm::LogInfo(m_name) << "Uploading the default payload.";
464  }
465 }
466 
467 bool LHCInfoPerLSPopConSourceHandler::makeFillPayload(std::unique_ptr<LHCInfoPerLS>& targetPayload,
468  const cond::OMSServiceResult& queryResult) {
469  bool ret = false;
470  if (!queryResult.empty()) {
471  auto row = *queryResult.begin();
472  auto currentFill = row.get<unsigned short>("fill_number");
473  m_startFillTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("start_time"));
474  std::string endTimeStr = row.get<std::string>("end_time");
475  if (m_debugLogic) {
476  m_endFillTime = 0;
477  } else {
478  m_endFillTime =
479  (endTimeStr == "null") ? 0 : cond::time::from_boost(row.get<boost::posix_time::ptime>("end_time"));
480  }
481  m_startStableBeamTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("start_stable_beam"));
482  m_endStableBeamTime = cond::time::from_boost(row.get<boost::posix_time::ptime>("end_stable_beam"));
483  targetPayload = std::make_unique<LHCInfoPerLS>();
484  targetPayload->setFillNumber(currentFill);
485  ret = true;
486  }
487  return ret;
488 }
489 
491  auto lumiTime = row.get<boost::posix_time::ptime>("start_time");
492  LHCInfoPerLS* thisLumiSectionInfo = new LHCInfoPerLS(*m_fillPayload);
493  thisLumiSectionInfo->setLumiSection(std::stoul(row.get<std::string>("lumisection_number")));
494  thisLumiSectionInfo->setRunNumber(std::stoul(row.get<std::string>("run_number")));
495  m_lsIdMap[make_pair(thisLumiSectionInfo->runNumber(), thisLumiSectionInfo->lumiSection())] = make_pair(-1, -1);
496  if (m_endFillMode) {
497  m_tmpBuffer.emplace_back(make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo));
498  } else {
499  m_tmpBuffer.emplace_back(
500  make_pair(cond::time::lumiTime(thisLumiSectionInfo->runNumber(), thisLumiSectionInfo->lumiSection()),
501  thisLumiSectionInfo));
502  }
503 }
504 
506  for (auto r : queryResult) {
508  }
509  return queryResult.size();
510 }
511 
513  unsigned short fillId,
514  const boost::posix_time::ptime& beginFillTime,
515  const boost::posix_time::ptime& endFillTime) {
516  auto query = oms.query("lumisections");
517  query->addOutputVars({"start_time", "run_number", "beams_stable", "lumisection_number"});
518  query->filterEQ("fill_number", fillId);
519  query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime);
521  size_t nlumi = 0;
522  if (query->execute()) {
523  auto queryResult = query->result();
524  if (m_endFillMode) {
525  nlumi = bufferAllLS(queryResult);
526  } else if (!queryResult.empty()) {
527  auto newestPayload = queryResult.back();
528  if (newestPayload.get<std::string>("beams_stable") == "true" || m_debugLogic) {
529  addPayloadToBuffer(newestPayload);
530  nlumi = 1;
531  edm::LogInfo(m_name) << "Buffered most recent lumisection:"
532  << " LS: " << newestPayload.get<std::string>("lumisection_number")
533  << " run: " << newestPayload.get<std::string>("run_number");
534  }
535  }
536  edm::LogInfo(m_name) << "Found " << queryResult.size() << " lumisections during the fill " << fillId;
537  } else {
538  edm::LogInfo(m_name) << "OMS query for lumisections of fill " << fillId << "failed, status:" << query->status();
539  }
540  return nlumi;
541 }
543  const boost::posix_time::ptime& beginFillTime,
544  const boost::posix_time::ptime& endFillTime) {
545  //run the fifth query against the CTPPS schema
546  //Initializing the CMS_CTP_CTPPS_COND schema.
547  coral::ISchema& CTPPS = session.coralSession().schema("CMS_PPS_SPECT_COND");
548  //execute query for CTPPS Data
549  std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
550  //FROM clause
551  CTPPSDataQuery->addToTableList(std::string("PPS_LHC_MACHINE_PARAMS"));
552  //SELECT clause
553  CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME"));
554  CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION"));
555  CTPPSDataQuery->addToOutputList(std::string("RUN_NUMBER"));
556  CTPPSDataQuery->addToOutputList(std::string("FILL_NUMBER"));
557  CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_X_URAD"));
558  CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_Y_URAD"));
559  CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_X_M"));
560  CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_Y_M"));
561  //WHERE CLAUSE
562  coral::AttributeList CTPPSDataBindVariables;
563  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("beginFillTime"));
564  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("endFillTime"));
565  CTPPSDataBindVariables[std::string("beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
566  CTPPSDataBindVariables[std::string("endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
567  std::string conditionStr = std::string("DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
568  CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
569  //ORDER BY clause
570  CTPPSDataQuery->addToOrderList(std::string("DIP_UPDATE_TIME"));
571  //define query output
572  coral::AttributeList CTPPSDataOutput;
573  CTPPSDataOutput.extend<coral::TimeStamp>(std::string("DIP_UPDATE_TIME"));
574  CTPPSDataOutput.extend<int>(std::string("LUMI_SECTION"));
575  CTPPSDataOutput.extend<int>(std::string("RUN_NUMBER"));
576  CTPPSDataOutput.extend<int>(std::string("FILL_NUMBER"));
577  CTPPSDataOutput.extend<float>(std::string("XING_ANGLE_P5_X_URAD"));
578  CTPPSDataOutput.extend<float>(std::string("XING_ANGLE_P5_Y_URAD"));
579  CTPPSDataOutput.extend<float>(std::string("BETA_STAR_P5_X_M"));
580  CTPPSDataOutput.extend<float>(std::string("BETA_STAR_P5_Y_M"));
581  CTPPSDataQuery->defineOutput(CTPPSDataOutput);
582  //execute the query
583  coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
584  unsigned int lumiSection = 0;
586  int fillNumber = 0;
587  float crossingAngleX = 0., betaStarX = 0.;
588  float crossingAngleY = 0., betaStarY = 0.;
589 
590  bool ret = false;
591  int wrongFillNumbers = 0;
592  std::stringstream wrongFills;
593  std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::iterator current = m_tmpBuffer.begin();
594  while (CTPPSDataCursor.next()) {
595  if (m_debug) {
596  std::ostringstream CTPPS;
597  CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
598  }
599  coral::Attribute const& dipTimeAttribute = CTPPSDataCursor.currentRow()[std::string("DIP_UPDATE_TIME")];
600  if (!dipTimeAttribute.isNull()) {
601  ret = true;
602  coral::Attribute const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[std::string("LUMI_SECTION")];
603  if (!lumiSectionAttribute.isNull()) {
604  lumiSection = lumiSectionAttribute.data<int>();
605  }
606  coral::Attribute const& runNumberAttribute = CTPPSDataCursor.currentRow()[std::string("RUN_NUMBER")];
607  if (!runNumberAttribute.isNull()) {
608  runNumber = runNumberAttribute.data<int>();
609  }
610  coral::Attribute const& fillNumberAttribute = CTPPSDataCursor.currentRow()[std::string("FILL_NUMBER")];
611  if (!fillNumberAttribute.isNull()) {
612  fillNumber = fillNumberAttribute.data<int>();
613  }
614  coral::Attribute const& crossingAngleXAttribute =
615  CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_X_URAD")];
616  if (!crossingAngleXAttribute.isNull()) {
617  crossingAngleX = crossingAngleXAttribute.data<float>();
618  }
619  coral::Attribute const& crossingAngleYAttribute =
620  CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_Y_URAD")];
621  if (!crossingAngleYAttribute.isNull()) {
622  crossingAngleY = crossingAngleYAttribute.data<float>();
623  }
624  coral::Attribute const& betaStarXAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_X_M")];
625  if (!betaStarXAttribute.isNull()) {
626  betaStarX = betaStarXAttribute.data<float>();
627  }
628  coral::Attribute const& betaStarYAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_Y_M")];
629  if (!betaStarYAttribute.isNull()) {
630  betaStarY = betaStarYAttribute.data<float>();
631  }
632  if (current != m_tmpBuffer.end() && current->second->fillNumber() != fillNumber) {
633  wrongFills << "( " << runNumber << "_" << lumiSection << " fill: OMS: " << current->second->fillNumber()
634  << " PPSdb: " << fillNumber << " ) ";
635  wrongFillNumbers++;
636  }
637  for (; current != m_tmpBuffer.end() && make_pair(current->second->runNumber(), current->second->lumiSection()) <=
638  make_pair(runNumber, lumiSection);
639  current++) {
640  LHCInfoPerLS& payload = *(current->second);
641  payload.setCrossingAngleX(crossingAngleX);
642  payload.setCrossingAngleY(crossingAngleY);
643  payload.setBetaStarX(betaStarX);
644  payload.setBetaStarY(betaStarY);
645  payload.setLumiSection(lumiSection);
646  payload.setRunNumber(runNumber);
647  if (m_lsIdMap.find(make_pair(payload.runNumber(), payload.lumiSection())) != m_lsIdMap.end()) {
648  m_lsIdMap[make_pair(payload.runNumber(), payload.lumiSection())] = make_pair(runNumber, lumiSection);
649  }
650  }
651  }
652  }
653  if (wrongFillNumbers) {
654  edm::LogWarning("getCTPPSData") << "Number of records from PPS DB with fillNumber different from OMS: "
655  << wrongFillNumbers;
656  edm::LogWarning("getCTPPSData") << "Records from PPS DB with fillNumber different from OMS: " << wrongFills.str();
657  }
658  return ret;
659 }
size
Write out results.
void addDefaultPayload(cond::Time_t iov, unsigned short fill, const cond::OMSService &oms)
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
Time_t since
Definition: Types.h:53
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
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > > m_tmpBuffer
Log< level::Error, false > LogError
Transaction & transaction()
Definition: Session.cc:52
float const betaStarY() const
Definition: LHCInfoPerLS.cc:21
std::pair< int, unsigned short > getFillLastRunAndLS(const cond::OMSService &oms, unsigned short fillId)
Definition: LHCInfoHelper.cc:9
bool isPayloadValid(const LHCInfoPerLS &payload) const
std::string name
Definition: Types.h:72
Definition: query.py:1
cond::TagInfo_t const & tagInfo() const
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)
void addPayloadToBuffer(cond::OMSServiceResultRef &row)
void setMessageVerbosity(coral::MsgLevel level)
Time_t from_boost(boost::posix_time::ptime bt)
std::map< std::pair< cond::Time_t, unsigned int >, std::pair< cond::Time_t, unsigned int > > m_lsIdMap
static constexpr unsigned int kLumisectionsQueryLimit
Definition: LHCInfoHelper.h:12
float const crossingAngleY() const
Definition: LHCInfoPerLS.cc:17
Log< level::Info, false > LogInfo
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
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
static constexpr const char *const SNULL
Definition: OMSAccess.h:183
void setAuthenticationPath(const std::string &p)
const bool Debug
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)