CMS 3D CMS Logo

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