CMS 3D CMS Logo

LHCInfoPopConSourceHandler.cc
Go to the documentation of this file.
6 #include "RelationalAccess/ISessionProxy.h"
7 #include "RelationalAccess/ISchema.h"
8 #include "RelationalAccess/IQuery.h"
9 #include "RelationalAccess/ICursor.h"
10 #include "CoralBase/AttributeList.h"
11 #include "CoralBase/Attribute.h"
12 #include "CoralBase/AttributeSpecification.h"
13 #include "CoralBase/TimeStamp.h"
14 #include <iostream>
15 #include <memory>
16 #include <sstream>
17 #include <utility>
18 #include <vector>
19 #include <cmath>
20 
22  : m_debug(pset.getUntrackedParameter<bool>("debug", false)),
23  m_startTime(),
24  m_endTime(),
25  m_samplingInterval((unsigned int)pset.getUntrackedParameter<unsigned int>("samplingInterval", 300)),
26  m_endFill(pset.getUntrackedParameter<bool>("endFill", true)),
27  m_name(pset.getUntrackedParameter<std::string>("name", "LHCInfoPopConSourceHandler")),
28  m_connectionString(pset.getUntrackedParameter<std::string>("connectionString", "")),
29  m_ecalConnectionString(pset.getUntrackedParameter<std::string>("ecalConnectionString", "")),
30  m_dipSchema(pset.getUntrackedParameter<std::string>("DIPSchema", "")),
31  m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
32  m_fillPayload(),
33  m_prevPayload(),
34  m_tmpBuffer(),
35  m_payloadBuffer() {
36  if (pset.exists("startTime")) {
37  m_startTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("startTime"));
38  }
39  boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
40  m_endTime = now;
41  if (pset.exists("endTime")) {
42  m_endTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("endTime"));
43  if (m_endTime > now)
44  m_endTime = now;
45  }
46 }
47 //L1: try with different m_dipSchema
48 //L2: try with different m_name
50 
51 namespace LHCInfoImpl {
52 
53  struct IOVComp {
54  bool operator()(const cond::Time_t& x, const std::pair<cond::Time_t, std::shared_ptr<LHCInfo>>& y) {
55  return (x < y.first);
56  }
57  };
58 
59  // function to search in the vector the target time
60  std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo>>>::const_iterator search(
61  const cond::Time_t& val, const std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo>>>& container) {
62  if (container.empty())
63  return container.end();
64  auto p = std::upper_bound(container.begin(), container.end(), val, IOVComp());
65  return (p != container.begin()) ? p - 1 : container.end();
66  }
67 
69  const std::string& conditionString,
70  const coral::AttributeList& fillDataBindVariables,
71  std::unique_ptr<LHCInfo>& targetPayload,
72  bool debug) {
73  coral::ISchema& runTimeLoggerSchema = session.nominalSchema();
74  //prepare the query for table 1:
75  std::unique_ptr<coral::IQuery> fillDataQuery(runTimeLoggerSchema.newQuery());
76  //FROM clause
77  fillDataQuery->addToTableList(std::string("RUNTIME_SUMMARY"));
78  //SELECT clause
79  fillDataQuery->addToOutputList(std::string("LHCFILL"));
80  fillDataQuery->addToOutputList(std::string("NBUNCHESBEAM1"));
81  fillDataQuery->addToOutputList(std::string("NBUNCHESBEAM2"));
82  fillDataQuery->addToOutputList(std::string("NCOLLIDINGBUNCHES"));
83  fillDataQuery->addToOutputList(std::string("NTARGETBUNCHES"));
84  fillDataQuery->addToOutputList(std::string("RUNTIME_TYPE_ID"));
85  fillDataQuery->addToOutputList(std::string("PARTY1"));
86  fillDataQuery->addToOutputList(std::string("PARTY2"));
87  fillDataQuery->addToOutputList(std::string("INTENSITYBEAM1"));
88  fillDataQuery->addToOutputList(std::string("INTENSITYBEAM2"));
89  fillDataQuery->addToOutputList(std::string("ENERGY"));
90  fillDataQuery->addToOutputList(std::string("CREATETIME"));
91  fillDataQuery->addToOutputList(std::string("BEGINTIME"));
92  fillDataQuery->addToOutputList(std::string("ENDTIME"));
93  fillDataQuery->addToOutputList(std::string("INJECTIONSCHEME"));
94  //WHERE clause
95  fillDataQuery->setCondition(conditionString, fillDataBindVariables);
96  //ORDER BY clause
97  std::string orderStr("BEGINTIME");
98  //define query output
99  coral::AttributeList fillDataOutput;
100  fillDataOutput.extend<unsigned short>(std::string("LHCFILL"));
101  fillDataOutput.extend<unsigned short>(std::string("NBUNCHESBEAM1"));
102  fillDataOutput.extend<unsigned short>(std::string("NBUNCHESBEAM2"));
103  fillDataOutput.extend<unsigned short>(std::string("NCOLLIDINGBUNCHES"));
104  fillDataOutput.extend<unsigned short>(std::string("NTARGETBUNCHES"));
105  fillDataOutput.extend<int>(std::string("RUNTIME_TYPE_ID"));
106  fillDataOutput.extend<int>(std::string("PARTY1"));
107  fillDataOutput.extend<int>(std::string("PARTY2"));
108  fillDataOutput.extend<float>(std::string("INTENSITYBEAM1"));
109  fillDataOutput.extend<float>(std::string("INTENSITYBEAM2"));
110  fillDataOutput.extend<float>(std::string("ENERGY"));
111  fillDataOutput.extend<coral::TimeStamp>(std::string("CREATETIME"));
112  fillDataOutput.extend<coral::TimeStamp>(std::string("BEGINTIME"));
113  fillDataOutput.extend<coral::TimeStamp>(std::string("ENDTIME"));
114  fillDataOutput.extend<std::string>(std::string("INJECTIONSCHEME"));
115  fillDataQuery->defineOutput(fillDataOutput);
116  fillDataQuery->limitReturnedRows(1);
117  //execute the query
118  coral::ICursor& fillDataCursor = fillDataQuery->execute();
119  //
120  unsigned short currentFill = 0;
121  unsigned short bunches1 = 0, bunches2 = 0, collidingBunches = 0, targetBunches = 0;
123  LHCInfo::ParticleTypeId particleType1 = LHCInfo::NONE, particleType2 = LHCInfo::NONE;
124  float intensityBeam1 = 0., intensityBeam2 = 0., energy = 0.;
125  coral::TimeStamp stableBeamStartTimeStamp, beamDumpTimeStamp;
126  cond::Time_t creationTime = 0ULL, stableBeamStartTime = 0ULL, beamDumpTime = 0ULL;
127  std::string injectionScheme("None");
128  std::ostringstream ss;
129  bool ret = false;
130  if (fillDataCursor.next()) {
131  ret = true;
132  if (debug) {
133  std::ostringstream qs;
134  fillDataCursor.currentRow().toOutputStream(qs);
135  }
136  coral::Attribute const& fillAttribute = fillDataCursor.currentRow()[std::string("LHCFILL")];
137  if (!fillAttribute.isNull()) {
138  currentFill = fillAttribute.data<unsigned short>();
139  }
140  coral::Attribute const& bunches1Attribute = fillDataCursor.currentRow()[std::string("NBUNCHESBEAM1")];
141  if (!bunches1Attribute.isNull()) {
142  bunches1 = bunches1Attribute.data<unsigned short>();
143  }
144  coral::Attribute const& bunches2Attribute = fillDataCursor.currentRow()[std::string("NBUNCHESBEAM2")];
145  if (!bunches2Attribute.isNull()) {
146  bunches2 = bunches2Attribute.data<unsigned short>();
147  }
148  coral::Attribute const& collidingBunchesAttribute = fillDataCursor.currentRow()[std::string("NCOLLIDINGBUNCHES")];
149  if (!collidingBunchesAttribute.isNull()) {
150  collidingBunches = collidingBunchesAttribute.data<unsigned short>();
151  }
152  coral::Attribute const& targetBunchesAttribute = fillDataCursor.currentRow()[std::string("NTARGETBUNCHES")];
153  if (!targetBunchesAttribute.isNull()) {
154  targetBunches = targetBunchesAttribute.data<unsigned short>();
155  }
156  //RUNTIME_TYPE_ID IS NOT NULL
157  fillType =
158  static_cast<LHCInfo::FillTypeId>(fillDataCursor.currentRow()[std::string("RUNTIME_TYPE_ID")].data<int>());
159  coral::Attribute const& particleType1Attribute = fillDataCursor.currentRow()[std::string("PARTY1")];
160  if (!particleType1Attribute.isNull()) {
161  particleType1 = static_cast<LHCInfo::ParticleTypeId>(particleType1Attribute.data<int>());
162  }
163  coral::Attribute const& particleType2Attribute = fillDataCursor.currentRow()[std::string("PARTY2")];
164  if (!particleType2Attribute.isNull()) {
165  particleType2 = static_cast<LHCInfo::ParticleTypeId>(particleType2Attribute.data<int>());
166  }
167  coral::Attribute const& intensityBeam1Attribute = fillDataCursor.currentRow()[std::string("INTENSITYBEAM1")];
168  if (!intensityBeam1Attribute.isNull()) {
169  intensityBeam1 = intensityBeam1Attribute.data<float>();
170  }
171  coral::Attribute const& intensityBeam2Attribute = fillDataCursor.currentRow()[std::string("INTENSITYBEAM2")];
172  if (!intensityBeam2Attribute.isNull()) {
173  intensityBeam2 = intensityBeam2Attribute.data<float>();
174  }
175  coral::Attribute const& energyAttribute = fillDataCursor.currentRow()[std::string("ENERGY")];
176  if (!energyAttribute.isNull()) {
177  energy = energyAttribute.data<float>();
178  }
179  }
180  if (ret) {
181  //CREATETIME IS NOT NULL
183  fillDataCursor.currentRow()[std::string("CREATETIME")].data<coral::TimeStamp>().time());
184  //BEGINTIME is imposed to be NOT NULL in the WHERE clause
185  stableBeamStartTimeStamp = fillDataCursor.currentRow()[std::string("BEGINTIME")].data<coral::TimeStamp>();
186  stableBeamStartTime = cond::time::from_boost(stableBeamStartTimeStamp.time());
187  coral::Attribute const& beamDumpTimeAttribute = fillDataCursor.currentRow()[std::string("ENDTIME")];
188  if (!beamDumpTimeAttribute.isNull()) {
189  beamDumpTimeStamp = beamDumpTimeAttribute.data<coral::TimeStamp>();
190  beamDumpTime = cond::time::from_boost(beamDumpTimeStamp.time());
191  }
192  coral::Attribute const& injectionSchemeAttribute = fillDataCursor.currentRow()[std::string("INJECTIONSCHEME")];
193  if (!injectionSchemeAttribute.isNull()) {
194  injectionScheme = injectionSchemeAttribute.data<std::string>();
195  }
196  //fix an inconsistency in RunTimeLogger: if the fill type is defined, the particle type should reflect it!
197  if (fillType != LHCInfo::UNKNOWN && (particleType1 == LHCInfo::NONE || particleType2 == LHCInfo::NONE)) {
198  switch (fillType) {
199  case LHCInfo::PROTONS:
200  particleType1 = LHCInfo::PROTON;
201  particleType2 = LHCInfo::PROTON;
202  break;
203  case LHCInfo::IONS:
204  particleType1 = LHCInfo::PB82;
205  particleType2 = LHCInfo::PB82;
206  break;
207  case LHCInfo::UNKNOWN:
208  case LHCInfo::COSMICS:
209  case LHCInfo::GAP:
210  break;
211  }
212  }
213  targetPayload = std::make_unique<LHCInfo>();
214  targetPayload->setFillNumber(currentFill);
215  targetPayload->setBunchesInBeam1(bunches1);
216  targetPayload->setBunchesInBeam2(bunches2);
217  targetPayload->setCollidingBunches(collidingBunches);
218  targetPayload->setTargetBunches(targetBunches);
219  targetPayload->setFillType(fillType);
220  targetPayload->setParticleTypeForBeam1(particleType1);
221  targetPayload->setParticleTypeForBeam2(particleType2);
222  targetPayload->setIntensityForBeam1(intensityBeam1);
223  targetPayload->setIntensityForBeam2(intensityBeam2);
224  targetPayload->setEnergy(energy);
225  targetPayload->setCreationTime(creationTime);
226  targetPayload->setBeginTime(stableBeamStartTime);
227  targetPayload->setEndTime(beamDumpTime);
228  targetPayload->setInjectionScheme(injectionScheme);
229  }
230  return ret;
231  }
232 
233 } // namespace LHCInfoImpl
234 
236  const boost::posix_time::ptime& targetTime,
237  bool ended) {
238  // Prepare the WHERE clause
239  coral::AttributeList fillDataBindVariables;
240  fillDataBindVariables.extend<coral::TimeStamp>(std::string("targetTime"));
241  fillDataBindVariables[std::string("targetTime")].data<coral::TimeStamp>() =
242  coral::TimeStamp(targetTime + boost::posix_time::seconds(1));
243  //by imposing BEGINTIME IS NOT NULL, we remove fills which never went into stable beams,
244  //by additionally imposing ENDTIME IS NOT NULL, we select only finished fills
245  std::string conditionStr = "BEGINTIME IS NOT NULL AND CREATETIME > :targetTime AND LHCFILL IS NOT NULL";
246  if (ended)
247  conditionStr += " AND ENDTIME IS NOT NULL";
248  return LHCInfoImpl::makeFillDataQuery(session, conditionStr, fillDataBindVariables, m_fillPayload, m_debug);
249 }
250 
252  // Prepare the WHERE clause
253  coral::AttributeList fillDataBindVariables;
254  fillDataBindVariables.extend<unsigned short>(std::string("fillId"));
255  fillDataBindVariables[std::string("fillId")].data<unsigned short>() = fillId;
256  std::string conditionStr = "LHCFILL=:fillId";
257  return LHCInfoImpl::makeFillDataQuery(session, conditionStr, fillDataBindVariables, m_fillPayload, m_debug);
258 }
259 
261  const boost::posix_time::ptime& beginFillTime,
262  const boost::posix_time::ptime& endFillTime) {
263  coral::ISchema& runTimeLoggerSchema = session.nominalSchema();
264  //prepare the query for table 2:
265  std::unique_ptr<coral::IQuery> fillDataQuery2(runTimeLoggerSchema.newQuery());
266  //FROM clause
267  fillDataQuery2->addToTableList(std::string("LUMI_SECTIONS"));
268  //SELECT clause
269  fillDataQuery2->addToOutputList(std::string("DELIVLUMI"));
270  fillDataQuery2->addToOutputList(std::string("LIVELUMI"));
271  fillDataQuery2->addToOutputList(std::string("INSTLUMI"));
272  fillDataQuery2->addToOutputList(std::string("INSTLUMIERROR"));
273  fillDataQuery2->addToOutputList(std::string("STARTTIME"));
274  fillDataQuery2->addToOutputList(std::string("LHCFILL"));
275  //WHERE clause
276  coral::AttributeList fillDataBindVariables;
277  fillDataBindVariables.extend<coral::TimeStamp>(std::string("start"));
278  fillDataBindVariables.extend<coral::TimeStamp>(std::string("stop"));
279  fillDataBindVariables[std::string("start")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
280  fillDataBindVariables[std::string("stop")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
281  std::string conditionStr = "DELIVLUMI IS NOT NULL AND STARTTIME >= :start AND STARTTIME< :stop";
282  fillDataQuery2->setCondition(conditionStr, fillDataBindVariables);
283  //ORDER BY clause
284  fillDataQuery2->addToOrderList(std::string("STARTTIME"));
285  //define query output*/
286  coral::AttributeList fillDataOutput2;
287  fillDataOutput2.extend<float>(std::string("DELIVEREDLUMI"));
288  fillDataOutput2.extend<float>(std::string("RECORDEDLUMI"));
289  fillDataOutput2.extend<float>(std::string("INSTLUMI"));
290  fillDataOutput2.extend<float>(std::string("INSTLUMIERROR"));
291  fillDataOutput2.extend<coral::TimeStamp>(std::string("STARTTIME"));
292  fillDataOutput2.extend<int>(std::string("LHCFILL"));
293  fillDataQuery2->defineOutput(fillDataOutput2);
294  //execute the query
295  coral::ICursor& fillDataCursor2 = fillDataQuery2->execute();
296 
297  size_t nlumi = 0;
298  while (fillDataCursor2.next()) {
299  nlumi++;
300  float delivLumi = 0., recLumi = 0., instLumi = 0, instLumiErr = 0.;
301  cond::Time_t since = 0;
302  coral::Attribute const& delivLumiAttribute = fillDataCursor2.currentRow()[std::string("DELIVEREDLUMI")];
303  if (!delivLumiAttribute.isNull()) {
304  delivLumi = delivLumiAttribute.data<float>() / 1000.;
305  }
306  coral::Attribute const& recLumiAttribute = fillDataCursor2.currentRow()[std::string("RECORDEDLUMI")];
307  if (!recLumiAttribute.isNull()) {
308  recLumi = recLumiAttribute.data<float>() / 1000.;
309  }
310  coral::Attribute const& instLumiAttribute = fillDataCursor2.currentRow()[std::string("INSTLUMI")];
311  if (!instLumiAttribute.isNull()) {
312  instLumi = instLumiAttribute.data<float>() / 1000.;
313  }
314  coral::Attribute const& instLumiErrAttribute = fillDataCursor2.currentRow()[std::string("INSTLUMIERROR")];
315  if (!instLumiErrAttribute.isNull()) {
316  instLumiErr = instLumiErrAttribute.data<float>() / 1000.;
317  }
318  coral::Attribute const& startLumiSectionAttribute = fillDataCursor2.currentRow()[std::string("STARTTIME")];
319  if (!startLumiSectionAttribute.isNull()) {
320  since = cond::time::from_boost(startLumiSectionAttribute.data<coral::TimeStamp>().time());
321  }
322  LHCInfo* thisLumiSectionInfo = m_fillPayload->cloneFill();
323  m_tmpBuffer.emplace_back(std::make_pair(since, thisLumiSectionInfo));
324  LHCInfo& payload = *thisLumiSectionInfo;
325  payload.setDelivLumi(delivLumi);
326  payload.setRecLumi(recLumi);
327  payload.setInstLumi(instLumi);
328  payload.setInstLumiError(instLumiErr);
329  }
330  return nlumi;
331 }
332 
333 namespace LHCInfoImpl {
335  LumiSectionFilter(const std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo>>>& samples)
336  : currLow(samples.begin()), currUp(samples.begin()), end(samples.end()) {
337  currUp++;
338  }
339 
340  void reset(const std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo>>>& samples) {
341  currLow = samples.begin();
342  currUp = samples.begin();
343  currUp++;
344  end = samples.end();
345  currentDipTime = 0;
346  }
347 
348  bool process(cond::Time_t dipTime) {
349  if (currLow == end)
350  return false;
351  bool search = false;
352  if (currentDipTime == 0) {
353  search = true;
354  } else {
355  if (dipTime == currentDipTime)
356  return true;
357  else {
359  if (currUp != end)
360  upper = currUp->first;
361  if (dipTime < upper)
362  return false;
363  else {
364  search = true;
365  }
366  }
367  }
368  if (search) {
369  while (currUp != end and currUp->first < dipTime) {
370  currLow++;
371  currUp++;
372  }
373  currentDipTime = dipTime;
374  return currLow != end;
375  }
376  return false;
377  }
378 
379  cond::Time_t currentSince() { return currLow->first; }
380  LHCInfo& currentPayload() { return *currLow->second; }
381 
382  std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo>>>::const_iterator current() { return currLow; }
383  std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo>>>::const_iterator currLow;
384  std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo>>>::const_iterator currUp;
385  std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo>>>::const_iterator end;
387  };
388 } // namespace LHCInfoImpl
389 
391  const boost::posix_time::ptime& beginFillTime,
392  const boost::posix_time::ptime& endFillTime) {
393  //run the third and fourth query against the schema hosting detailed DIP information
394  coral::ISchema& beamCondSchema = session.coralSession().schema(m_dipSchema);
395  //start the transaction against the DIP "deep" database backend schema
396  //prepare the WHERE clause for both queries
397  coral::AttributeList bunchConfBindVariables;
398  bunchConfBindVariables.extend<coral::TimeStamp>(std::string("beginFillTime"));
399  bunchConfBindVariables.extend<coral::TimeStamp>(std::string("endFillTime"));
400  bunchConfBindVariables[std::string("beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
401  bunchConfBindVariables[std::string("endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
402  std::string conditionStr = std::string("DIPTIME >= :beginFillTime and DIPTIME< :endFillTime");
403  //define the output types for both queries
404  coral::AttributeList bunchConfOutput;
405  bunchConfOutput.extend<coral::TimeStamp>(std::string("DIPTIME"));
406  bunchConfOutput.extend<unsigned short>(std::string("BUCKET"));
407  //execute query for Beam 1
408  std::unique_ptr<coral::IQuery> bunchConf1Query(beamCondSchema.newQuery());
409  bunchConf1Query->addToTableList(std::string("LHC_CIRCBUNCHCONFIG_BEAM1"),
410  std::string("BEAMCONF\", TABLE( BEAMCONF.VALUE ) \"BUCKETS"));
411  bunchConf1Query->addToOutputList(std::string("BEAMCONF.DIPTIME"), std::string("DIPTIME"));
412  bunchConf1Query->addToOutputList(std::string("BUCKETS.COLUMN_VALUE"), std::string("BUCKET"));
413  bunchConf1Query->setCondition(conditionStr, bunchConfBindVariables);
414  bunchConf1Query->addToOrderList(std::string("DIPTIME"));
415  bunchConf1Query->limitReturnedRows(LHCInfo::availableBunchSlots); //maximum number of filled bunches
416  bunchConf1Query->defineOutput(bunchConfOutput);
417 
418  coral::ICursor& bunchConf1Cursor = bunchConf1Query->execute();
419  std::bitset<LHCInfo::bunchSlots + 1> bunchConfiguration1(0ULL);
420  bool ret = false;
421  cond::Time_t lumiSectionTime = 0;
422  while (bunchConf1Cursor.next()) {
423  if (m_debug) {
424  std::ostringstream b1s;
425  bunchConf1Cursor.currentRow().toOutputStream(b1s);
426  }
427  coral::Attribute const& dipTimeAttribute = bunchConf1Cursor.currentRow()[std::string("DIPTIME")];
428  coral::Attribute const& bunchConf1Attribute = bunchConf1Cursor.currentRow()[std::string("BUCKET")];
429  if (!dipTimeAttribute.isNull() and !bunchConf1Attribute.isNull()) {
430  cond::Time_t dipTime = cond::time::from_boost(dipTimeAttribute.data<coral::TimeStamp>().time());
431  // assuming only one sample has been selected...
432  unsigned short slot = (bunchConf1Attribute.data<unsigned short>() - 1) / 10 + 1;
433  if (lumiSectionTime == 0 or lumiSectionTime == dipTime) {
434  bunchConfiguration1[slot] = true;
435  } else
436  break;
437  lumiSectionTime = dipTime;
438  }
439  }
440  if (ret) {
441  m_fillPayload->setBunchBitsetForBeam1(bunchConfiguration1);
442  }
443 
444  //execute query for Beam 2
445  std::unique_ptr<coral::IQuery> bunchConf2Query(beamCondSchema.newQuery());
446  bunchConf2Query->addToTableList(std::string("LHC_CIRCBUNCHCONFIG_BEAM2"),
447  std::string("BEAMCONF\", TABLE( BEAMCONF.VALUE ) \"BUCKETS"));
448  bunchConf2Query->addToOutputList(std::string("BEAMCONF.DIPTIME"), std::string("DIPTIME"));
449  bunchConf2Query->addToOutputList(std::string("BUCKETS.COLUMN_VALUE"), std::string("BUCKET"));
450  bunchConf2Query->setCondition(conditionStr, bunchConfBindVariables);
451  bunchConf2Query->addToOrderList(std::string("DIPTIME"));
452  bunchConf2Query->limitReturnedRows(LHCInfo::availableBunchSlots); //maximum number of filled bunches
453  bunchConf2Query->defineOutput(bunchConfOutput);
454  coral::ICursor& bunchConf2Cursor = bunchConf2Query->execute();
455 
456  std::bitset<LHCInfo::bunchSlots + 1> bunchConfiguration2(0ULL);
457  ret = false;
458  lumiSectionTime = 0;
459  while (bunchConf2Cursor.next()) {
460  if (m_debug) {
461  std::ostringstream b2s;
462  bunchConf2Cursor.currentRow().toOutputStream(b2s);
463  }
464  coral::Attribute const& dipTimeAttribute = bunchConf2Cursor.currentRow()[std::string("DIPTIME")];
465  coral::Attribute const& bunchConf2Attribute = bunchConf2Cursor.currentRow()[std::string("BUCKET")];
466  if (!dipTimeAttribute.isNull() and !bunchConf2Attribute.isNull()) {
467  ret = true;
468  cond::Time_t dipTime = cond::time::from_boost(dipTimeAttribute.data<coral::TimeStamp>().time());
469  // assuming only one sample has been selected...
470  unsigned short slot = (bunchConf2Attribute.data<unsigned short>() - 1) / 10 + 1;
471  if (lumiSectionTime == 0 or lumiSectionTime == dipTime) {
472  bunchConfiguration2[slot] = true;
473  } else
474  break;
475  lumiSectionTime = dipTime;
476  }
477  }
478  if (ret) {
479  m_fillPayload->setBunchBitsetForBeam2(bunchConfiguration2);
480  }
481  //execute query for lumiPerBX
482  std::unique_ptr<coral::IQuery> lumiDataQuery(beamCondSchema.newQuery());
483  lumiDataQuery->addToTableList(std::string("CMS_LHC_LUMIPERBUNCH"),
484  std::string("LUMIPERBUNCH\", TABLE( LUMIPERBUNCH.LUMI_BUNCHINST ) \"VALUE"));
485  lumiDataQuery->addToOutputList(std::string("LUMIPERBUNCH.DIPTIME"), std::string("DIPTIME"));
486  lumiDataQuery->addToOutputList(std::string("VALUE.COLUMN_VALUE"), std::string("LUMI_BUNCH"));
487  coral::AttributeList lumiDataBindVariables;
488  lumiDataBindVariables.extend<coral::TimeStamp>(std::string("beginFillTime"));
489  lumiDataBindVariables.extend<coral::TimeStamp>(std::string("endFillTime"));
490  lumiDataBindVariables[std::string("beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
491  lumiDataBindVariables[std::string("endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
492  conditionStr = std::string("DIPTIME BETWEEN :beginFillTime AND :endFillTime");
493  lumiDataQuery->setCondition(conditionStr, lumiDataBindVariables);
494  lumiDataQuery->addToOrderList(std::string("DIPTIME"));
495  lumiDataQuery->limitReturnedRows(3564); //Maximum number of bunches.
496  //define query output
497  coral::AttributeList lumiDataOutput;
498  lumiDataOutput.extend<coral::TimeStamp>(std::string("DIPTIME"));
499  lumiDataOutput.extend<float>(std::string("LUMI_BUNCH"));
500  lumiDataQuery->defineOutput(lumiDataOutput);
501  //execute the query
502  coral::ICursor& lumiDataCursor = lumiDataQuery->execute();
503 
504  std::vector<float> lumiPerBX;
505  ret = false;
506  lumiSectionTime = 0;
507  while (lumiDataCursor.next()) {
508  if (m_debug) {
509  std::ostringstream lpBX;
510  lumiDataCursor.currentRow().toOutputStream(lpBX);
511  }
512  coral::Attribute const& dipTimeAttribute = lumiDataCursor.currentRow()[std::string("DIPTIME")];
513  coral::Attribute const& lumiBunchAttribute = lumiDataCursor.currentRow()[std::string("LUMI_BUNCH")];
514  if (!dipTimeAttribute.isNull() and !lumiBunchAttribute.isNull()) {
515  ret = true;
516  cond::Time_t dipTime = cond::time::from_boost(dipTimeAttribute.data<coral::TimeStamp>().time());
517  // assuming only one sample has been selected...
518  float lumi_b = lumiBunchAttribute.data<float>();
519  if (lumiSectionTime == 0 or lumiSectionTime == dipTime) {
520  if (lumi_b != 0.00)
521  lumiPerBX.push_back(lumi_b);
522  } else
523  break;
524  lumiSectionTime = dipTime;
525  }
526  }
527  if (ret) {
528  m_fillPayload->setLumiPerBX(lumiPerBX);
529  }
530  return ret;
531 }
532 
534  const boost::posix_time::ptime& beginFillTime,
535  const boost::posix_time::ptime& endFillTime) {
536  //run the fifth query against the CTPPS schema
537  //Initializing the CMS_CTP_CTPPS_COND schema.
538  coral::ISchema& CTPPS = session.coralSession().schema("CMS_CTP_CTPPS_COND");
539  //execute query for CTPPS Data
540  std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
541  //FROM clause
542  CTPPSDataQuery->addToTableList(std::string("CTPPS_LHC_MACHINE_PARAMS"));
543  //SELECT clause
544  CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME"));
545  CTPPSDataQuery->addToOutputList(std::string("LHC_STATE"));
546  CTPPSDataQuery->addToOutputList(std::string("LHC_COMMENT"));
547  CTPPSDataQuery->addToOutputList(std::string("CTPPS_STATUS"));
548  CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION"));
549  CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_URAD"));
550  CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_CMS"));
551  //WHERE CLAUSE
552  coral::AttributeList CTPPSDataBindVariables;
553  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("beginFillTime"));
554  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("endFillTime"));
555  CTPPSDataBindVariables[std::string("beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
556  CTPPSDataBindVariables[std::string("endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
557  std::string conditionStr = std::string("DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
558  CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
559  //ORDER BY clause
560  CTPPSDataQuery->addToOrderList(std::string("DIP_UPDATE_TIME"));
561  //define query output
562  coral::AttributeList CTPPSDataOutput;
563  CTPPSDataOutput.extend<coral::TimeStamp>(std::string("DIP_UPDATE_TIME"));
564  CTPPSDataOutput.extend<std::string>(std::string("LHC_STATE"));
565  CTPPSDataOutput.extend<std::string>(std::string("LHC_COMMENT"));
566  CTPPSDataOutput.extend<std::string>(std::string("CTPPS_STATUS"));
567  CTPPSDataOutput.extend<int>(std::string("LUMI_SECTION"));
568  CTPPSDataOutput.extend<float>(std::string("XING_ANGLE_URAD"));
569  CTPPSDataOutput.extend<float>(std::string("BETA_STAR_CMS"));
570  CTPPSDataQuery->defineOutput(CTPPSDataOutput);
571  //execute the query
572  coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
573  cond::Time_t dipTime = 0;
574  std::string lhcState = "", lhcComment = "", ctppsStatus = "";
575  unsigned int lumiSection = 0;
576  float crossingAngle = 0., betastar = 0.;
577 
578  bool ret = false;
580  while (CTPPSDataCursor.next()) {
581  if (m_debug) {
582  std::ostringstream CTPPS;
583  CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
584  }
585  coral::Attribute const& dipTimeAttribute = CTPPSDataCursor.currentRow()[std::string("DIP_UPDATE_TIME")];
586  if (!dipTimeAttribute.isNull()) {
587  dipTime = cond::time::from_boost(dipTimeAttribute.data<coral::TimeStamp>().time());
588  if (filter.process(dipTime)) {
589  ret = true;
590  coral::Attribute const& lhcStateAttribute = CTPPSDataCursor.currentRow()[std::string("LHC_STATE")];
591  if (!lhcStateAttribute.isNull()) {
592  lhcState = lhcStateAttribute.data<std::string>();
593  }
594  coral::Attribute const& lhcCommentAttribute = CTPPSDataCursor.currentRow()[std::string("LHC_COMMENT")];
595  if (!lhcCommentAttribute.isNull()) {
596  lhcComment = lhcCommentAttribute.data<std::string>();
597  }
598  coral::Attribute const& ctppsStatusAttribute = CTPPSDataCursor.currentRow()[std::string("CTPPS_STATUS")];
599  if (!ctppsStatusAttribute.isNull()) {
600  ctppsStatus = ctppsStatusAttribute.data<std::string>();
601  }
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& crossingAngleAttribute = CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_URAD")];
607  if (!crossingAngleAttribute.isNull()) {
608  crossingAngle = crossingAngleAttribute.data<float>();
609  }
610  coral::Attribute const& betaStarAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_CMS")];
611  if (!betaStarAttribute.isNull()) {
612  betastar = betaStarAttribute.data<float>();
613  }
614  for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) {
615  // set the current values to all of the payloads of the lumi section samples after the current since
616  LHCInfo& payload = *(it->second);
617  payload.setCrossingAngle(crossingAngle);
618  payload.setBetaStar(betastar);
619  payload.setLhcState(lhcState);
620  payload.setLhcComment(lhcComment);
621  payload.setCtppsStatus(ctppsStatus);
622  payload.setLumiSection(lumiSection);
623  }
624  }
625  }
626  }
627  return ret;
628 }
629 
630 namespace LHCInfoImpl {
631  static const std::map<std::string, int> vecMap = {
632  {"Beam1/beamPhaseMean", 1}, {"Beam2/beamPhaseMean", 2}, {"Beam1/cavPhaseMean", 3}, {"Beam2/cavPhaseMean", 4}};
634  const std::string& dipVal,
635  unsigned int elementNr,
636  float value,
637  LHCInfo& payload,
638  std::set<cond::Time_t>& initList) {
639  if (initList.find(since) == initList.end()) {
640  payload.beam1VC().resize(LHCInfo::bunchSlots, 0.);
641  payload.beam2VC().resize(LHCInfo::bunchSlots, 0.);
642  payload.beam1RF().resize(LHCInfo::bunchSlots, 0.);
643  payload.beam2RF().resize(LHCInfo::bunchSlots, 0.);
644  initList.insert(since);
645  }
646  // set the current values to all of the payloads of the lumi section samples after the current since
647  if (elementNr < LHCInfo::bunchSlots) {
648  switch (vecMap.at(dipVal)) {
649  case 1:
650  payload.beam1VC()[elementNr] = value;
651  break;
652  case 2:
653  payload.beam2VC()[elementNr] = value;
654  break;
655  case 3:
656  payload.beam1RF()[elementNr] = value;
657  break;
658  case 4:
659  payload.beam2RF()[elementNr] = value;
660  break;
661  default:
662  break;
663  }
664  }
665  }
666 } // namespace LHCInfoImpl
667 
669  const boost::posix_time::ptime& lowerTime,
670  const boost::posix_time::ptime& upperTime,
671  bool update) {
672  //run the sixth query against the CMS_DCS_ENV_PVSS_COND schema
673  //Initializing the CMS_DCS_ENV_PVSS_COND schema.
674  coral::ISchema& ECAL = session.nominalSchema();
675  //start the transaction against the fill logging schema
676  //execute query for ECAL Data
677  std::unique_ptr<coral::IQuery> ECALDataQuery(ECAL.newQuery());
678  //FROM clause
679  ECALDataQuery->addToTableList(std::string("BEAM_PHASE"));
680  //SELECT clause
681  ECALDataQuery->addToOutputList(std::string("CHANGE_DATE"));
682  ECALDataQuery->addToOutputList(std::string("DIP_value"));
683  ECALDataQuery->addToOutputList(std::string("element_nr"));
684  ECALDataQuery->addToOutputList(std::string("VALUE_NUMBER"));
685  //WHERE CLAUSE
686  coral::AttributeList ECALDataBindVariables;
687  ECALDataBindVariables.extend<coral::TimeStamp>(std::string("lowerTime"));
688  ECALDataBindVariables.extend<coral::TimeStamp>(std::string("upperTime"));
689  ECALDataBindVariables[std::string("lowerTime")].data<coral::TimeStamp>() = coral::TimeStamp(lowerTime);
690  ECALDataBindVariables[std::string("upperTime")].data<coral::TimeStamp>() = coral::TimeStamp(upperTime);
691  std::string conditionStr = std::string(
692  "(DIP_value LIKE '%beamPhaseMean%' OR DIP_value LIKE '%cavPhaseMean%') AND CHANGE_DATE >= :lowerTime AND "
693  "CHANGE_DATE < :upperTime");
694 
695  ECALDataQuery->setCondition(conditionStr, ECALDataBindVariables);
696  //ORDER BY clause
697  ECALDataQuery->addToOrderList(std::string("CHANGE_DATE"));
698  ECALDataQuery->addToOrderList(std::string("DIP_value"));
699  ECALDataQuery->addToOrderList(std::string("element_nr"));
700  //define query output
701  coral::AttributeList ECALDataOutput;
702  ECALDataOutput.extend<coral::TimeStamp>(std::string("CHANGE_DATE"));
703  ECALDataOutput.extend<std::string>(std::string("DIP_value"));
704  ECALDataOutput.extend<unsigned int>(std::string("element_nr"));
705  ECALDataOutput.extend<float>(std::string("VALUE_NUMBER"));
706  //ECALDataQuery->limitReturnedRows( 14256 ); //3564 entries per vector.
707  ECALDataQuery->defineOutput(ECALDataOutput);
708  //execute the query
709  coral::ICursor& ECALDataCursor = ECALDataQuery->execute();
710  cond::Time_t changeTime = 0;
711  cond::Time_t firstTime = 0;
712  std::string dipVal = "";
713  unsigned int elementNr = 0;
714  float value = 0.;
715  std::set<cond::Time_t> initializedVectors;
717  bool ret = false;
718  if (m_prevPayload.get()) {
719  for (auto& lumiSlot : m_tmpBuffer) {
720  lumiSlot.second->setBeam1VC(m_prevPayload->beam1VC());
721  lumiSlot.second->setBeam2VC(m_prevPayload->beam2VC());
722  lumiSlot.second->setBeam1RF(m_prevPayload->beam1RF());
723  lumiSlot.second->setBeam2RF(m_prevPayload->beam2RF());
724  }
725  }
726  std::map<cond::Time_t, cond::Time_t> iovMap;
727  cond::Time_t lowerLumi = m_tmpBuffer.front().first;
728  while (ECALDataCursor.next()) {
729  if (m_debug) {
730  std::ostringstream ECAL;
731  ECALDataCursor.currentRow().toOutputStream(ECAL);
732  }
733  coral::Attribute const& changeDateAttribute = ECALDataCursor.currentRow()[std::string("CHANGE_DATE")];
734  if (!changeDateAttribute.isNull()) {
735  ret = true;
736  boost::posix_time::ptime chTime = changeDateAttribute.data<coral::TimeStamp>().time();
737  // move the first IOV found to the start of the fill interval selected
738  if (changeTime == 0) {
739  firstTime = cond::time::from_boost(chTime);
740  }
741  changeTime = cond::time::from_boost(chTime);
742  cond::Time_t iovTime = changeTime;
743  if (!update and changeTime == firstTime)
744  iovTime = lowerLumi;
745  coral::Attribute const& dipValAttribute = ECALDataCursor.currentRow()[std::string("DIP_value")];
746  coral::Attribute const& valueNumberAttribute = ECALDataCursor.currentRow()[std::string("VALUE_NUMBER")];
747  coral::Attribute const& elementNrAttribute = ECALDataCursor.currentRow()[std::string("element_nr")];
748  if (!dipValAttribute.isNull() and !valueNumberAttribute.isNull()) {
749  dipVal = dipValAttribute.data<std::string>();
750  elementNr = elementNrAttribute.data<unsigned int>();
751  value = valueNumberAttribute.data<float>();
752  if (isnan(value))
753  value = 0.;
754  if (filter.process(iovTime)) {
755  iovMap.insert(std::make_pair(changeTime, filter.current()->first));
756  for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) {
757  LHCInfo& payload = *(it->second);
758  LHCInfoImpl::setElementData(it->first, dipVal, elementNr, value, payload, initializedVectors);
759  }
760  }
761  //}
762  }
763  }
764  }
765  if (m_debug) {
766  for (auto& im : iovMap) {
767  edm::LogInfo(m_name) << "Found iov=" << im.first << " (" << cond::time::to_boost(im.first) << " ) moved to "
768  << im.second << " ( " << cond::time::to_boost(im.second) << " )";
769  }
770  }
771  return ret;
772 }
773 
775  bool add = false;
776  if (m_to_transfer.empty()) {
777  if (!m_lastPayloadEmpty)
778  add = true;
779  } else {
780  LHCInfo* lastAdded = m_to_transfer.back().first;
781  if (lastAdded->fillNumber() != 0) {
782  add = true;
783  }
784  }
785  if (add) {
786  auto newPayload = std::make_shared<LHCInfo>();
787  m_to_transfer.push_back(std::make_pair(newPayload.get(), iov));
788  m_payloadBuffer.push_back(newPayload);
789  m_prevPayload = newPayload;
790  }
791 }
792 
793 namespace LHCInfoImpl {
794  bool comparePayloads(const LHCInfo& rhs, const LHCInfo& lhs) {
795  if (rhs.fillNumber() != lhs.fillNumber())
796  return false;
797  if (rhs.delivLumi() != lhs.delivLumi())
798  return false;
799  if (rhs.recLumi() != lhs.recLumi())
800  return false;
801  if (rhs.instLumi() != lhs.instLumi())
802  return false;
803  if (rhs.instLumiError() != lhs.instLumiError())
804  return false;
805  if (rhs.crossingAngle() != rhs.crossingAngle())
806  return false;
807  if (rhs.betaStar() != rhs.betaStar())
808  return false;
809  if (rhs.lhcState() != rhs.lhcState())
810  return false;
811  if (rhs.lhcComment() != rhs.lhcComment())
812  return false;
813  if (rhs.ctppsStatus() != rhs.ctppsStatus())
814  return false;
815  return true;
816  }
817 
818  size_t transferPayloads(const std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo>>>& buffer,
819  std::vector<std::shared_ptr<LHCInfo>>& payloadBuffer,
820  std::vector<std::pair<LHCInfo*, cond::Time_t>>& vecToTransfer,
821  std::shared_ptr<LHCInfo>& prevPayload) {
822  size_t niovs = 0;
823  for (auto& iov : buffer) {
824  bool add = false;
825  LHCInfo& payload = *iov.second;
826  cond::Time_t since = iov.first;
827  if (vecToTransfer.empty()) {
828  add = true;
829  } else {
830  LHCInfo& lastAdded = *vecToTransfer.back().first;
831  if (!comparePayloads(lastAdded, payload)) {
832  add = true;
833  }
834  }
835  if (add) {
836  niovs++;
837  vecToTransfer.push_back(std::make_pair(&payload, since));
838  payloadBuffer.push_back(iov.second);
839  prevPayload = iov.second;
840  }
841  }
842  return niovs;
843  }
844 
845 } // namespace LHCInfoImpl
846 
848  //reference to the last payload in the tag
849  Ref previousFill;
850 
851  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
852  if (tagInfo().name.empty()) {
853  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
854  } else {
855  //check what is already inside the database
856  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size
857  << ", last object valid since " << tagInfo().lastInterval.since << " ( "
858  << boost::posix_time::to_iso_extended_string(
859  cond::time::to_boost(tagInfo().lastInterval.since))
860  << " ); from " << m_name << "::getNewObjects";
861  }
862 
863  cond::Time_t lastSince = tagInfo().lastInterval.since;
864  if (lastSince == 0) {
865  // for a new or empty tag, an empty payload should be added on top with since=1
866  addEmptyPayload(1);
867  } else {
868  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
869  << m_name << "::getNewObjects";
870  }
871 
872  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
873  cond::Time_t targetSince = 0;
874  cond::Time_t endIov = cond::time::from_boost(executionTime);
875  if (!m_startTime.is_not_a_date_time()) {
876  targetSince = cond::time::from_boost(m_startTime);
877  }
878  if (lastSince > targetSince)
879  targetSince = lastSince;
880 
881  edm::LogInfo(m_name) << "Starting sampling at "
882  << boost::posix_time::to_simple_string(cond::time::to_boost(targetSince));
883 
884  //retrieve the data from the relational database source
886  //configure the connection
887  if (m_debug) {
888  connection.setMessageVerbosity(coral::Debug);
889  } else {
890  connection.setMessageVerbosity(coral::Error);
891  }
892  connection.setAuthenticationPath(m_authpath);
893  connection.configure();
894  //create the sessions
895  cond::persistency::Session session = connection.createSession(m_connectionString, false);
897  // fetch last payload when available
898  if (!tagInfo().lastInterval.payloadId.empty()) {
900  session3.transaction().start(true);
902  session3.transaction().commit();
903  }
904 
905  bool iovAdded = false;
906  while (true) {
907  if (targetSince >= endIov) {
908  edm::LogInfo(m_name) << "Sampling ended at the time "
909  << boost::posix_time::to_simple_string(cond::time::to_boost(endIov));
910  break;
911  }
912  bool updateEcal = false;
913  boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince);
914  boost::posix_time::ptime startSampleTime;
915  boost::posix_time::ptime endSampleTime;
916  if (!m_endFill and m_prevPayload->fillNumber() and m_prevPayload->endTime() == 0ULL) {
917  // execute the query for the current fill
918  session.transaction().start(true);
919  edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber();
920  bool foundFill = getFillData(session, m_prevPayload->fillNumber());
921  session.transaction().commit();
922  if (!foundFill) {
923  edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber();
924  break;
925  }
926  updateEcal = true;
927  startSampleTime = cond::time::to_boost(lastSince);
928  } else {
929  session.transaction().start(true);
930  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
931  bool foundFill = getNextFillData(session, targetTime, m_endFill);
932  session.transaction().commit();
933  if (!foundFill) {
934  edm::LogInfo(m_name) << "No fill found - END of job.";
935  if (iovAdded)
936  addEmptyPayload(targetSince);
937  break;
938  }
939  startSampleTime = cond::time::to_boost(m_fillPayload->createTime());
940  }
941  cond::Time_t startFillTime = m_fillPayload->createTime();
942  cond::Time_t endFillTime = m_fillPayload->endTime();
943  unsigned short lhcFill = m_fillPayload->fillNumber();
944  if (endFillTime == 0ULL) {
945  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime);
946  endSampleTime = executionTime;
947  targetSince = endIov;
948  } else {
949  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime)
950  << " ending at " << cond::time::to_boost(endFillTime);
951  endSampleTime = cond::time::to_boost(endFillTime);
952  targetSince = endFillTime;
953  }
954 
955  session.transaction().start(true);
956  getDipData(session, startSampleTime, endSampleTime);
957  size_t nlumi = getLumiData(session, startSampleTime, endSampleTime);
958  edm::LogInfo(m_name) << "Found " << nlumi << " lumisections during the fill " << lhcFill;
959  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
960  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
961  edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop;
962  getCTTPSData(session, startSampleTime, endSampleTime);
963  session.transaction().commit();
964  session2.transaction().start(true);
965  getEcalData(session2, startSampleTime, endSampleTime, updateEcal);
966  session2.transaction().commit();
967  //
969  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
970  m_tmpBuffer.clear();
971  iovAdded = true;
972  //if(m_prevPayload->fillNumber() and m_prevPayload->endTime()!=0ULL) addEmptyPayload( m_fillPayload->endTime() );
973  if (m_prevPayload->fillNumber() and m_fillPayload->endTime() != 0ULL)
974  addEmptyPayload(m_fillPayload->endTime());
975  }
976 }
977 
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:543
pfDeepBoostedJetPreprocessParams_cfi.upper_bound
upper_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:16
LHCInfoPopConSourceHandler::getNextFillData
bool getNextFillData(cond::persistency::Session &session, const boost::posix_time::ptime &targetTime, bool ended)
Definition: LHCInfoPopConSourceHandler.cc:235
LHCInfoImpl::LumiSectionFilter::LumiSectionFilter
LumiSectionFilter(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo >>> &samples)
Definition: LHCInfoPopConSourceHandler.cc:335
LHCInfoPopConSourceHandler::getNewObjects
void getNewObjects() override
Definition: LHCInfoPopConSourceHandler.cc:847
electrons_cff.bool
bool
Definition: electrons_cff.py:366
ConnectionPool.h
LHCInfo::UNKNOWN
Definition: LHCInfo.h:14
popcon::PopConSourceHandler< LHCInfo >::m_to_transfer
OldContainer m_to_transfer
Definition: PopConSourceHandler.h:162
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
LHCInfoPopConSourceHandler::addEmptyPayload
void addEmptyPayload(cond::Time_t iov)
Definition: LHCInfoPopConSourceHandler.cc:774
LHCInfo::GAP
Definition: LHCInfo.h:14
cond::time::to_boost
boost::posix_time::ptime to_boost(Time_t iValue)
Definition: TimeConversions.h:39
LHCInfo::lhcComment
std::string const & lhcComment() const
Definition: LHCInfo.cc:214
popcon::PopConSourceHandler< LHCInfo >::dbSession
cond::persistency::Session & dbSession() const
Definition: PopConSourceHandler.h:144
LHCInfoPopConSourceHandler::m_name
std::string m_name
Definition: LHCInfoPopConSourceHandler.h:43
LHCInfoImpl::LumiSectionFilter::end
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator end
Definition: LHCInfoPopConSourceHandler.cc:385
LHCInfoPopConSourceHandler::m_connectionString
std::string m_connectionString
Definition: LHCInfoPopConSourceHandler.h:45
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
LHCInfoImpl::LumiSectionFilter::currLow
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator currLow
Definition: LHCInfoPopConSourceHandler.cc:383
LHCInfoPopConSourceHandler::m_endTime
boost::posix_time::ptime m_endTime
Definition: LHCInfoPopConSourceHandler.h:39
LHCInfoPopConSourceHandler::getCTTPSData
bool getCTTPSData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
Definition: LHCInfoPopConSourceHandler.cc:533
LHCInfoPopConSourceHandler::getFillData
bool getFillData(cond::persistency::Session &session, unsigned short fillId)
Definition: LHCInfoPopConSourceHandler.cc:251
LHCInfoImpl::LumiSectionFilter::currentSince
cond::Time_t currentSince()
Definition: LHCInfoPopConSourceHandler.cc:379
LHCInfo
Definition: LHCInfo.h:12
protons_cff.time
time
Definition: protons_cff.py:35
LHCInfo::PROTON
Definition: LHCInfo.h:15
LHCInfoImpl::LumiSectionFilter::currUp
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator currUp
Definition: LHCInfoPopConSourceHandler.cc:384
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
LHCInfo::COSMICS
Definition: LHCInfo.h:14
LHCInfo::fillNumber
unsigned const short fillNumber() const
Definition: LHCInfo.cc:158
cond::persistency::ConnectionPool::createSession
Session createSession(const std::string &connectionString, bool writeCapable=false)
Definition: ConnectionPool.cc:174
LHCInfo::IONS
Definition: LHCInfo.h:14
LHCInfoImpl::setElementData
void setElementData(cond::Time_t since, const std::string &dipVal, unsigned int elementNr, float value, LHCInfo &payload, std::set< cond::Time_t > &initList)
Definition: LHCInfoPopConSourceHandler.cc:633
LHCInfoPopConSourceHandler::getEcalData
bool getEcalData(cond::persistency::Session &session, const boost::posix_time::ptime &lowerTime, const boost::posix_time::ptime &upperTime, bool update)
Definition: LHCInfoPopConSourceHandler.cc:668
cond::TagInfo_t::name
std::string name
Definition: Types.h:72
LHCInfoImpl::makeFillDataQuery
bool makeFillDataQuery(cond::persistency::Session &session, const std::string &conditionString, const coral::AttributeList &fillDataBindVariables, std::unique_ptr< LHCInfo > &targetPayload, bool debug)
Definition: LHCInfoPopConSourceHandler.cc:68
EgammaValidation_cff.samples
samples
Definition: EgammaValidation_cff.py:18
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
LHCInfo::availableBunchSlots
static const size_t availableBunchSlots
Definition: LHCInfo.h:61
cond::persistency::Session::fetchPayload
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
LHCInfoPopConSourceHandler::m_startTime
boost::posix_time::ptime m_startTime
Definition: LHCInfoPopConSourceHandler.h:38
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
LHCInfoPopConSourceHandler::m_payloadBuffer
std::vector< std::shared_ptr< LHCInfo > > m_payloadBuffer
Definition: LHCInfoPopConSourceHandler.h:50
LHCInfoPopConSourceHandler::m_authpath
std::string m_authpath
Definition: LHCInfoPopConSourceHandler.h:46
Debug
const bool Debug
Definition: CosmicMuonParameters.h:12
LHCInfoPopConSourceHandler.h
ECAL
Definition: HCALResponse.h:21
debug
#define debug
Definition: HDRShower.cc:19
LHCInfo::lhcState
std::string const & lhcState() const
Definition: LHCInfo.cc:212
LHCInfo::crossingAngle
const float crossingAngle() const
Definition: LHCInfo.cc:182
seconds
double seconds()
cond::persistency::ConnectionPool
Definition: ConnectionPool.h:35
CommonMethods.isnan
def isnan(num)
Definition: CommonMethods.py:97
LHCInfoImpl::comparePayloads
bool comparePayloads(const LHCInfo &rhs, const LHCInfo &lhs)
Definition: LHCInfoPopConSourceHandler.cc:794
LHCInfo::FillType
FillType
Definition: LHCInfo.h:14
writeEcalDQMStatus.since
since
Definition: writeEcalDQMStatus.py:53
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
jets_cff.payload
payload
Definition: jets_cff.py:32
LHCInfoPopConSourceHandler::getDipData
bool getDipData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
Definition: LHCInfoPopConSourceHandler.cc:390
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
LHCInfoPopConSourceHandler::m_dipSchema
std::string m_dipSchema
Definition: LHCInfoPopConSourceHandler.h:46
LHCInfoPopConSourceHandler::LHCInfoPopConSourceHandler
LHCInfoPopConSourceHandler(const edm::ParameterSet &pset)
Definition: LHCInfoPopConSourceHandler.cc:21
funct::true
true
Definition: Factorize.h:173
LHCInfoImpl
Definition: LHCInfo.cc:115
LHCInfoPopConSourceHandler::m_lastPayloadEmpty
bool m_lastPayloadEmpty
Definition: LHCInfoPopConSourceHandler.h:51
cond::persistency::ConnectionPool::setMessageVerbosity
void setMessageVerbosity(coral::MsgLevel level)
Definition: ConnectionPool.cc:188
LHCInfoImpl::vecMap
static const std::map< std::string, int > vecMap
Definition: LHCInfoPopConSourceHandler.cc:631
edm::ParameterSet
Definition: ParameterSet.h:47
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
popcon::PopConSourceHandler< LHCInfo >::tagInfo
cond::TagInfo_t const & tagInfo() const
Definition: PopConSourceHandler.h:78
LHCInfoPopConSourceHandler::~LHCInfoPopConSourceHandler
~LHCInfoPopConSourceHandler() override
Definition: LHCInfoPopConSourceHandler.cc:49
cond::Iov_t::payloadId
Hash payloadId
Definition: Types.h:55
cond::time::from_boost
Time_t from_boost(boost::posix_time::ptime bt)
Definition: TimeConversions.h:43
cond::persistency::Session::nominalSchema
coral::ISchema & nominalSchema()
Definition: Session.cc:224
PVValHelper::add
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
Definition: PVValidationHelpers.cc:12
LHCInfoPopConSourceHandler::m_prevPayload
std::shared_ptr< LHCInfo > m_prevPayload
Definition: LHCInfoPopConSourceHandler.h:48
cond::persistency::Session
Definition: Session.h:63
cond::Iov_t::since
Time_t since
Definition: Types.h:53
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
LHCInfoImpl::LumiSectionFilter::currentDipTime
cond::Time_t currentDipTime
Definition: LHCInfoPopConSourceHandler.cc:386
LHCInfo::instLumiError
const float instLumiError() const
Definition: LHCInfo.cc:198
LHCInfoImpl::LumiSectionFilter::current
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator current()
Definition: LHCInfoPopConSourceHandler.cc:382
LHCInfoImpl::LumiSectionFilter::reset
void reset(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo >>> &samples)
Definition: LHCInfoPopConSourceHandler.cc:340
leef::Error
edm::ErrorSummaryEntry Error
Definition: LogErrorEventFilter.cc:29
LHCInfo::recLumi
const float recLumi() const
Definition: LHCInfo.cc:194
createfilelist.int
int
Definition: createfilelist.py:10
cond::persistency::Transaction::commit
void commit()
Definition: Session.cc:23
cond::persistency::Session::coralSession
coral::ISessionProxy & coralSession()
Definition: Session.cc:218
cond::persistency::ConnectionPool::setAuthenticationPath
void setAuthenticationPath(const std::string &p)
Definition: ConnectionPool.cc:35
LHCInfo::instLumi
const float instLumi() const
Definition: LHCInfo.cc:196
cond::time::MAX_VAL
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
value
Definition: value.py:1
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
LHCInfo::delivLumi
const float delivLumi() const
Definition: LHCInfo.cc:192
LHCInfo::PB82
Definition: LHCInfo.h:15
BeamSpotPI::creationTime
Definition: BeamSpotPayloadInspectorHelper.h:44
cond::persistency::ConnectionPool::configure
void configure()
Definition: ConnectionPool.cc:129
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
muonGEMDigis_cfi.instLumi
instLumi
Definition: muonGEMDigis_cfi.py:10
LHCInfoImpl::transferPayloads
size_t transferPayloads(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo >>> &buffer, std::vector< std::shared_ptr< LHCInfo >> &payloadBuffer, std::vector< std::pair< LHCInfo *, cond::Time_t >> &vecToTransfer, std::shared_ptr< LHCInfo > &prevPayload)
Definition: LHCInfoPopConSourceHandler.cc:818
LHCInfoPopConSourceHandler::m_debug
bool m_debug
Definition: LHCInfoPopConSourceHandler.h:36
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LHCInfo::NONE
Definition: LHCInfo.h:15
LHCInfoImpl::LumiSectionFilter::currentPayload
LHCInfo & currentPayload()
Definition: LHCInfoPopConSourceHandler.cc:380
LHCInfoPopConSourceHandler::m_fillPayload
std::unique_ptr< LHCInfo > m_fillPayload
Definition: LHCInfoPopConSourceHandler.h:47
LHCInfo::bunchSlots
static const size_t bunchSlots
Definition: LHCInfo.h:58
cond::TagInfo_t::lastInterval
Iov_t lastInterval
Definition: Types.h:73
cond::persistency::Session::transaction
Transaction & transaction()
Definition: Session.cc:52
cond::persistency::Transaction::start
void start(bool readOnly=true)
Definition: Session.cc:18
LHCInfoPopConSourceHandler::id
std::string id() const override
Definition: LHCInfoPopConSourceHandler.cc:978
heppy_batch.val
val
Definition: heppy_batch.py:351
std
Definition: JetResolutionObject.h:76
popcon::PopConSourceHandler< LHCInfo >::add
int add(value_type *payload, Summary *summary, Time_t time)
Definition: PopConSourceHandler.h:146
reco::JetExtendedAssociation::Ref
edm::Ref< Container > Ref
Definition: JetExtendedAssociation.h:32
relativeConstraints.value
value
Definition: relativeConstraints.py:53
pileupCalc.upper
upper
Definition: pileupCalc.py:213
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
LHCInfoPopConSourceHandler::m_endFill
bool m_endFill
Definition: LHCInfoPopConSourceHandler.h:42
LHCInfoImpl::LumiSectionFilter
Definition: LHCInfoPopConSourceHandler.cc:334
LHCInfoImpl::IOVComp::operator()
bool operator()(const cond::Time_t &x, const std::pair< cond::Time_t, std::shared_ptr< LHCInfo >> &y)
Definition: LHCInfoPopConSourceHandler.cc:54
TimeConversions.h
ParameterSet.h
LHCInfoPopConSourceHandler::m_tmpBuffer
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > m_tmpBuffer
Definition: LHCInfoPopConSourceHandler.h:49
LHCInfoPopConSourceHandler::m_ecalConnectionString
std::string m_ecalConnectionString
Definition: LHCInfoPopConSourceHandler.h:45
LHCInfoImpl::LumiSectionFilter::process
bool process(cond::Time_t dipTime)
Definition: LHCInfoPopConSourceHandler.cc:348
LHCInfo::PROTONS
Definition: LHCInfo.h:14
LHCInfo::betaStar
const float betaStar() const
Definition: LHCInfo.cc:184
LHCInfoImpl::IOVComp
Definition: LHCInfoPopConSourceHandler.cc:53
LHCInfo::ParticleType
ParticleType
Definition: LHCInfo.h:15
LHCInfoImpl::search
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator search(const cond::Time_t &val, const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo >>> &container)
Definition: LHCInfoPopConSourceHandler.cc:60
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
update
#define update(a, b)
Definition: TrackClassifier.cc:10
cond::TagInfo_t::size
size_t size
Definition: Types.h:74
LHCInfoPopConSourceHandler::getLumiData
size_t getLumiData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
Definition: LHCInfoPopConSourceHandler.cc:260
LHCInfo::ctppsStatus
std::string const & ctppsStatus() const
Definition: LHCInfo.cc:216