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
182  creationTime = cond::time::from_boost(
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.reset(new 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;
386  cond::Time_t currentDipTime = 0;
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 << ", IOVSequence token " << tagInfo().token
857  << ": size " << tagInfo().size << ", last object valid since " << tagInfo().lastInterval.first
858  << " ( "
859  << boost::posix_time::to_iso_extended_string(
860  cond::time::to_boost(tagInfo().lastInterval.first))
861  << " ); from " << m_name << "::getNewObjects";
862  }
863 
864  cond::Time_t lastSince = tagInfo().lastInterval.first;
865  if (lastSince == 0) {
866  // for a new or empty tag, an empty payload should be added on top with since=1
867  addEmptyPayload(1);
868  } else {
869  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
870  << m_name << "::getNewObjects";
871  }
872 
873  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
874  cond::Time_t targetSince = 0;
875  cond::Time_t endIov = cond::time::from_boost(executionTime);
876  if (!m_startTime.is_not_a_date_time()) {
877  targetSince = cond::time::from_boost(m_startTime);
878  }
879  if (lastSince > targetSince)
880  targetSince = lastSince;
881 
882  edm::LogInfo(m_name) << "Starting sampling at "
883  << boost::posix_time::to_simple_string(cond::time::to_boost(targetSince));
884 
885  //retrieve the data from the relational database source
887  //configure the connection
888  if (m_debug) {
889  connection.setMessageVerbosity(coral::Debug);
890  } else {
891  connection.setMessageVerbosity(coral::Error);
892  }
893  connection.setAuthenticationPath(m_authpath);
894  connection.configure();
895  //create the sessions
896  cond::persistency::Session session = connection.createSession(m_connectionString, false);
898  // fetch last payload when available
899  if (!tagInfo().lastPayloadToken.empty()) {
901  session3.transaction().start(true);
903  session3.transaction().commit();
904  }
905 
906  bool iovAdded = false;
907  while (true) {
908  if (targetSince >= endIov) {
909  edm::LogInfo(m_name) << "Sampling ended at the time "
910  << boost::posix_time::to_simple_string(cond::time::to_boost(endIov));
911  break;
912  }
913  bool updateEcal = false;
914  boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince);
915  boost::posix_time::ptime startSampleTime;
916  boost::posix_time::ptime endSampleTime;
917  if (!m_endFill and m_prevPayload->fillNumber() and m_prevPayload->endTime() == 0ULL) {
918  // execute the query for the current fill
919  session.transaction().start(true);
920  edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber();
921  bool foundFill = getFillData(session, m_prevPayload->fillNumber());
922  session.transaction().commit();
923  if (!foundFill) {
924  edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber();
925  break;
926  }
927  updateEcal = true;
928  startSampleTime = cond::time::to_boost(lastSince);
929  } else {
930  session.transaction().start(true);
931  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
932  bool foundFill = getNextFillData(session, targetTime, m_endFill);
933  session.transaction().commit();
934  if (!foundFill) {
935  edm::LogInfo(m_name) << "No fill found - END of job.";
936  if (iovAdded)
937  addEmptyPayload(targetSince);
938  break;
939  }
940  startSampleTime = cond::time::to_boost(m_fillPayload->createTime());
941  }
942  cond::Time_t startFillTime = m_fillPayload->createTime();
943  cond::Time_t endFillTime = m_fillPayload->endTime();
944  unsigned short lhcFill = m_fillPayload->fillNumber();
945  if (endFillTime == 0ULL) {
946  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime);
947  endSampleTime = executionTime;
948  targetSince = endIov;
949  } else {
950  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime)
951  << " ending at " << cond::time::to_boost(endFillTime);
952  endSampleTime = cond::time::to_boost(endFillTime);
953  targetSince = endFillTime;
954  }
955 
956  session.transaction().start(true);
957  getDipData(session, startSampleTime, endSampleTime);
958  size_t nlumi = getLumiData(session, startSampleTime, endSampleTime);
959  edm::LogInfo(m_name) << "Found " << nlumi << " lumisections during the fill " << lhcFill;
960  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
961  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
962  edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop;
963  getCTTPSData(session, startSampleTime, endSampleTime);
964  session.transaction().commit();
965  session2.transaction().start(true);
966  getEcalData(session2, startSampleTime, endSampleTime, updateEcal);
967  session2.transaction().commit();
968  //
970  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
971  m_tmpBuffer.clear();
972  iovAdded = true;
973  //if(m_prevPayload->fillNumber() and m_prevPayload->endTime()!=0ULL) addEmptyPayload( m_fillPayload->endTime() );
974  if (m_prevPayload->fillNumber() and m_fillPayload->endTime() != 0ULL)
975  addEmptyPayload(m_fillPayload->endTime());
976  }
977 }
978 
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
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)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > m_tmpBuffer
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
ret
prodAgent to be discontinued
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)
bool exists(std::string const &parameterName) const
checks if a parameter exists
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:76
void setDelivLumi(float const &delivLumi)
Definition: LHCInfo.cc:312
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:224
std::string const & ctppsStatus() const
Definition: LHCInfo.cc:216
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:43
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)
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
cond::ValidityInterval lastInterval
Definition: Types.h:74
std::vector< std::shared_ptr< LHCInfo > > m_payloadBuffer
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
bool isnan(float x)
Definition: math.h:13
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
std::vector< float > const & beam2RF() const
Definition: LHCInfo.cc:226
coral::ISchema & nominalSchema()
Definition: Session.cc:224
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
#define end
Definition: vmac.h:39
Definition: value.py:1
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
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)
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::string lastPayloadToken
Definition: Types.h:75
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
#define begin
Definition: vmac.h:32
float const betaStar() const
Definition: LHCInfo.cc:184
#define update(a, b)
unsigned short const fillNumber() const
Definition: LHCInfo.cc:158
std::string id() const override
void setAuthenticationPath(const std::string &p)
const bool Debug
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
std::string token
Definition: Types.h:73
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
int add(value_type *payload, Summary *summary, Time_t time)
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()