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"
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",
"")),
36 if (
pset.exists(
"startTime")) {
39 boost::posix_time::ptime
now = boost::posix_time::second_clock::local_time();
41 if (
pset.exists(
"endTime")) {
60 std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo>>>::const_iterator
search(
62 if (container.empty())
63 return container.end();
65 return (
p != container.begin()) ?
p - 1 : container.end();
70 const coral::AttributeList& fillDataBindVariables,
71 std::unique_ptr<LHCInfo>& targetPayload,
73 coral::ISchema& runTimeLoggerSchema = session.
nominalSchema();
75 std::unique_ptr<coral::IQuery> fillDataQuery(runTimeLoggerSchema.newQuery());
77 fillDataQuery->addToTableList(
std::string(
"RUNTIME_SUMMARY"));
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"));
95 fillDataQuery->setCondition(conditionString, fillDataBindVariables);
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"));
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"));
115 fillDataQuery->defineOutput(fillDataOutput);
116 fillDataQuery->limitReturnedRows(1);
118 coral::ICursor& fillDataCursor = fillDataQuery->execute();
120 unsigned short currentFill = 0;
121 unsigned short bunches1 = 0, bunches2 = 0, collidingBunches = 0, targetBunches = 0;
124 float intensityBeam1 = 0., intensityBeam2 = 0.,
energy = 0.;
125 coral::TimeStamp stableBeamStartTimeStamp, beamDumpTimeStamp;
126 cond::Time_t creationTime = 0ULL, stableBeamStartTime = 0ULL, beamDumpTime = 0ULL;
128 std::ostringstream
ss;
130 if (fillDataCursor.next()) {
133 std::ostringstream qs;
134 fillDataCursor.currentRow().toOutputStream(qs);
136 coral::Attribute
const& fillAttribute = fillDataCursor.currentRow()[
std::string(
"LHCFILL")];
137 if (!fillAttribute.isNull()) {
138 currentFill = fillAttribute.data<
unsigned short>();
140 coral::Attribute
const& bunches1Attribute = fillDataCursor.currentRow()[
std::string(
"NBUNCHESBEAM1")];
141 if (!bunches1Attribute.isNull()) {
142 bunches1 = bunches1Attribute.data<
unsigned short>();
144 coral::Attribute
const& bunches2Attribute = fillDataCursor.currentRow()[
std::string(
"NBUNCHESBEAM2")];
145 if (!bunches2Attribute.isNull()) {
146 bunches2 = bunches2Attribute.data<
unsigned short>();
148 coral::Attribute
const& collidingBunchesAttribute = fillDataCursor.currentRow()[
std::string(
"NCOLLIDINGBUNCHES")];
149 if (!collidingBunchesAttribute.isNull()) {
150 collidingBunches = collidingBunchesAttribute.data<
unsigned short>();
152 coral::Attribute
const& targetBunchesAttribute = fillDataCursor.currentRow()[
std::string(
"NTARGETBUNCHES")];
153 if (!targetBunchesAttribute.isNull()) {
154 targetBunches = targetBunchesAttribute.data<
unsigned short>();
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>());
163 coral::Attribute
const& particleType2Attribute = fillDataCursor.currentRow()[
std::string(
"PARTY2")];
164 if (!particleType2Attribute.isNull()) {
165 particleType2 = static_cast<LHCInfo::ParticleTypeId>(particleType2Attribute.data<
int>());
167 coral::Attribute
const& intensityBeam1Attribute = fillDataCursor.currentRow()[
std::string(
"INTENSITYBEAM1")];
168 if (!intensityBeam1Attribute.isNull()) {
169 intensityBeam1 = intensityBeam1Attribute.data<
float>();
171 coral::Attribute
const& intensityBeam2Attribute = fillDataCursor.currentRow()[
std::string(
"INTENSITYBEAM2")];
172 if (!intensityBeam2Attribute.isNull()) {
173 intensityBeam2 = intensityBeam2Attribute.data<
float>();
175 coral::Attribute
const& energyAttribute = fillDataCursor.currentRow()[
std::string(
"ENERGY")];
176 if (!energyAttribute.isNull()) {
177 energy = energyAttribute.data<
float>();
183 fillDataCursor.currentRow()[
std::string(
"CREATETIME")].data<coral::TimeStamp>().
time());
185 stableBeamStartTimeStamp = fillDataCursor.currentRow()[
std::string(
"BEGINTIME")].data<coral::TimeStamp>();
187 coral::Attribute
const& beamDumpTimeAttribute = fillDataCursor.currentRow()[
std::string(
"ENDTIME")];
188 if (!beamDumpTimeAttribute.isNull()) {
189 beamDumpTimeStamp = beamDumpTimeAttribute.data<coral::TimeStamp>();
192 coral::Attribute
const& injectionSchemeAttribute = fillDataCursor.currentRow()[
std::string(
"INJECTIONSCHEME")];
193 if (!injectionSchemeAttribute.isNull()) {
194 injectionScheme = injectionSchemeAttribute.data<
std::string>();
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);
236 const boost::posix_time::ptime& targetTime,
239 coral::AttributeList fillDataBindVariables;
240 fillDataBindVariables.extend<coral::TimeStamp>(
std::string(
"targetTime"));
241 fillDataBindVariables[
std::string(
"targetTime")].data<coral::TimeStamp>() =
245 std::string conditionStr =
"BEGINTIME IS NOT NULL AND CREATETIME > :targetTime AND LHCFILL IS NOT NULL";
247 conditionStr +=
" AND ENDTIME IS NOT NULL";
253 coral::AttributeList fillDataBindVariables;
254 fillDataBindVariables.extend<
unsigned short>(
std::string(
"fillId"));
255 fillDataBindVariables[
std::string(
"fillId")].data<
unsigned short>() = fillId;
261 const boost::posix_time::ptime& beginFillTime,
262 const boost::posix_time::ptime& endFillTime) {
263 coral::ISchema& runTimeLoggerSchema = session.
nominalSchema();
265 std::unique_ptr<coral::IQuery> fillDataQuery2(runTimeLoggerSchema.newQuery());
267 fillDataQuery2->addToTableList(
std::string(
"LUMI_SECTIONS"));
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"));
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);
284 fillDataQuery2->addToOrderList(
std::string(
"STARTTIME"));
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);
295 coral::ICursor& fillDataCursor2 = fillDataQuery2->execute();
298 while (fillDataCursor2.next()) {
300 float delivLumi = 0., recLumi = 0.,
instLumi = 0, instLumiErr = 0.;
302 coral::Attribute
const& delivLumiAttribute = fillDataCursor2.currentRow()[
std::string(
"DELIVEREDLUMI")];
303 if (!delivLumiAttribute.isNull()) {
304 delivLumi = delivLumiAttribute.data<
float>() / 1000.;
306 coral::Attribute
const& recLumiAttribute = fillDataCursor2.currentRow()[
std::string(
"RECORDEDLUMI")];
307 if (!recLumiAttribute.isNull()) {
308 recLumi = recLumiAttribute.data<
float>() / 1000.;
310 coral::Attribute
const& instLumiAttribute = fillDataCursor2.currentRow()[
std::string(
"INSTLUMI")];
311 if (!instLumiAttribute.isNull()) {
312 instLumi = instLumiAttribute.data<
float>() / 1000.;
314 coral::Attribute
const& instLumiErrAttribute = fillDataCursor2.currentRow()[
std::string(
"INSTLUMIERROR")];
315 if (!instLumiErrAttribute.isNull()) {
316 instLumiErr = instLumiErrAttribute.data<
float>() / 1000.;
318 coral::Attribute
const& startLumiSectionAttribute = fillDataCursor2.currentRow()[
std::string(
"STARTTIME")];
319 if (!startLumiSectionAttribute.isNull()) {
325 payload.setDelivLumi(delivLumi);
328 payload.setInstLumiError(instLumiErr);
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;
391 const boost::posix_time::ptime& beginFillTime,
392 const boost::posix_time::ptime& endFillTime) {
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);
404 coral::AttributeList bunchConfOutput;
405 bunchConfOutput.extend<coral::TimeStamp>(
std::string(
"DIPTIME"));
406 bunchConfOutput.extend<
unsigned short>(
std::string(
"BUCKET"));
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"));
413 bunchConf1Query->setCondition(conditionStr, bunchConfBindVariables);
414 bunchConf1Query->addToOrderList(
std::string(
"DIPTIME"));
416 bunchConf1Query->defineOutput(bunchConfOutput);
418 coral::ICursor& bunchConf1Cursor = bunchConf1Query->execute();
419 std::bitset<LHCInfo::bunchSlots + 1> bunchConfiguration1(0ULL);
422 while (bunchConf1Cursor.next()) {
424 std::ostringstream b1s;
425 bunchConf1Cursor.currentRow().toOutputStream(b1s);
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()) {
432 unsigned short slot = (bunchConf1Attribute.data<
unsigned short>() - 1) / 10 + 1;
433 if (lumiSectionTime == 0
or lumiSectionTime == dipTime) {
434 bunchConfiguration1[slot] =
true;
437 lumiSectionTime = dipTime;
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"));
450 bunchConf2Query->setCondition(conditionStr, bunchConfBindVariables);
451 bunchConf2Query->addToOrderList(
std::string(
"DIPTIME"));
453 bunchConf2Query->defineOutput(bunchConfOutput);
454 coral::ICursor& bunchConf2Cursor = bunchConf2Query->execute();
456 std::bitset<LHCInfo::bunchSlots + 1> bunchConfiguration2(0ULL);
459 while (bunchConf2Cursor.next()) {
461 std::ostringstream b2s;
462 bunchConf2Cursor.currentRow().toOutputStream(b2s);
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()) {
470 unsigned short slot = (bunchConf2Attribute.data<
unsigned short>() - 1) / 10 + 1;
471 if (lumiSectionTime == 0
or lumiSectionTime == dipTime) {
472 bunchConfiguration2[slot] =
true;
475 lumiSectionTime = dipTime;
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"));
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);
497 coral::AttributeList lumiDataOutput;
498 lumiDataOutput.extend<coral::TimeStamp>(
std::string(
"DIPTIME"));
499 lumiDataOutput.extend<
float>(
std::string(
"LUMI_BUNCH"));
500 lumiDataQuery->defineOutput(lumiDataOutput);
502 coral::ICursor& lumiDataCursor = lumiDataQuery->execute();
504 std::vector<float> lumiPerBX;
507 while (lumiDataCursor.next()) {
509 std::ostringstream lpBX;
510 lumiDataCursor.currentRow().toOutputStream(lpBX);
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()) {
518 float lumi_b = lumiBunchAttribute.data<
float>();
519 if (lumiSectionTime == 0
or lumiSectionTime == dipTime) {
521 lumiPerBX.push_back(lumi_b);
524 lumiSectionTime = dipTime;
534 const boost::posix_time::ptime& beginFillTime,
535 const boost::posix_time::ptime& endFillTime) {
538 coral::ISchema& CTPPS = session.
coralSession().schema(
"CMS_CTP_CTPPS_COND");
540 std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
542 CTPPSDataQuery->addToTableList(
std::string(
"CTPPS_LHC_MACHINE_PARAMS"));
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"));
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);
560 CTPPSDataQuery->addToOrderList(
std::string(
"DIP_UPDATE_TIME"));
562 coral::AttributeList CTPPSDataOutput;
563 CTPPSDataOutput.extend<coral::TimeStamp>(
std::string(
"DIP_UPDATE_TIME"));
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);
572 coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
574 std::string lhcState =
"", lhcComment =
"", ctppsStatus =
"";
575 unsigned int lumiSection = 0;
576 float crossingAngle = 0., betastar = 0.;
580 while (CTPPSDataCursor.next()) {
582 std::ostringstream CTPPS;
583 CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
585 coral::Attribute
const& dipTimeAttribute = CTPPSDataCursor.currentRow()[
std::string(
"DIP_UPDATE_TIME")];
586 if (!dipTimeAttribute.isNull()) {
588 if (
filter.process(dipTime)) {
590 coral::Attribute
const& lhcStateAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LHC_STATE")];
591 if (!lhcStateAttribute.isNull()) {
594 coral::Attribute
const& lhcCommentAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LHC_COMMENT")];
595 if (!lhcCommentAttribute.isNull()) {
596 lhcComment = lhcCommentAttribute.data<
std::string>();
598 coral::Attribute
const& ctppsStatusAttribute = CTPPSDataCursor.currentRow()[
std::string(
"CTPPS_STATUS")];
599 if (!ctppsStatusAttribute.isNull()) {
600 ctppsStatus = ctppsStatusAttribute.data<
std::string>();
602 coral::Attribute
const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LUMI_SECTION")];
603 if (!lumiSectionAttribute.isNull()) {
604 lumiSection = lumiSectionAttribute.data<
int>();
606 coral::Attribute
const& crossingAngleAttribute = CTPPSDataCursor.currentRow()[
std::string(
"XING_ANGLE_URAD")];
607 if (!crossingAngleAttribute.isNull()) {
608 crossingAngle = crossingAngleAttribute.data<
float>();
610 coral::Attribute
const& betaStarAttribute = CTPPSDataCursor.currentRow()[
std::string(
"BETA_STAR_CMS")];
611 if (!betaStarAttribute.isNull()) {
612 betastar = betaStarAttribute.data<
float>();
617 payload.setCrossingAngle(crossingAngle);
620 payload.setLhcComment(lhcComment);
621 payload.setCtppsStatus(ctppsStatus);
622 payload.setLumiSection(lumiSection);
631 static const std::map<std::string, int>
vecMap = {
632 {
"Beam1/beamPhaseMean", 1}, {
"Beam2/beamPhaseMean", 2}, {
"Beam1/cavPhaseMean", 3}, {
"Beam2/cavPhaseMean", 4}};
635 unsigned int elementNr,
638 std::set<cond::Time_t>& initList) {
639 if (initList.find(
since) == initList.end()) {
644 initList.insert(
since);
648 switch (
vecMap.at(dipVal)) {
669 const boost::posix_time::ptime& lowerTime,
670 const boost::posix_time::ptime& upperTime,
677 std::unique_ptr<coral::IQuery> ECALDataQuery(
ECAL.newQuery());
679 ECALDataQuery->addToTableList(
std::string(
"BEAM_PHASE"));
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"));
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);
692 "(DIP_value LIKE '%beamPhaseMean%' OR DIP_value LIKE '%cavPhaseMean%') AND CHANGE_DATE >= :lowerTime AND "
693 "CHANGE_DATE < :upperTime");
695 ECALDataQuery->setCondition(conditionStr, ECALDataBindVariables);
697 ECALDataQuery->addToOrderList(
std::string(
"CHANGE_DATE"));
698 ECALDataQuery->addToOrderList(
std::string(
"DIP_value"));
699 ECALDataQuery->addToOrderList(
std::string(
"element_nr"));
701 coral::AttributeList ECALDataOutput;
702 ECALDataOutput.extend<coral::TimeStamp>(
std::string(
"CHANGE_DATE"));
704 ECALDataOutput.extend<
unsigned int>(
std::string(
"element_nr"));
705 ECALDataOutput.extend<
float>(
std::string(
"VALUE_NUMBER"));
707 ECALDataQuery->defineOutput(ECALDataOutput);
709 coral::ICursor& ECALDataCursor = ECALDataQuery->execute();
713 unsigned int elementNr = 0;
715 std::set<cond::Time_t> initializedVectors;
726 std::map<cond::Time_t, cond::Time_t> iovMap;
728 while (ECALDataCursor.next()) {
730 std::ostringstream
ECAL;
731 ECALDataCursor.currentRow().toOutputStream(
ECAL);
733 coral::Attribute
const& changeDateAttribute = ECALDataCursor.currentRow()[
std::string(
"CHANGE_DATE")];
734 if (!changeDateAttribute.isNull()) {
736 boost::posix_time::ptime chTime = changeDateAttribute.data<coral::TimeStamp>().
time();
738 if (changeTime == 0) {
743 if (!
update and changeTime == firstTime)
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()) {
750 elementNr = elementNrAttribute.data<
unsigned int>();
751 value = valueNumberAttribute.data<
float>();
754 if (
filter.process(iovTime)) {
755 iovMap.insert(std::make_pair(changeTime,
filter.current()->first));
766 for (
auto& im : iovMap) {
786 auto newPayload = std::make_shared<LHCInfo>();
787 m_to_transfer.push_back(std::make_pair(newPayload.get(), iov));
819 std::vector<std::shared_ptr<LHCInfo>>& payloadBuffer,
820 std::vector<std::pair<LHCInfo*, cond::Time_t>>& vecToTransfer,
821 std::shared_ptr<LHCInfo>& prevPayload) {
823 for (
auto& iov :
buffer) {
827 if (vecToTransfer.empty()) {
830 LHCInfo& lastAdded = *vecToTransfer.back().first;
837 vecToTransfer.push_back(std::make_pair(&
payload,
since));
838 payloadBuffer.push_back(iov.second);
839 prevPayload = iov.second;
858 << boost::posix_time::to_iso_extended_string(
860 <<
" ); from " <<
m_name <<
"::getNewObjects";
864 if (lastSince == 0) {
869 <<
m_name <<
"::getNewObjects";
872 boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
878 if (lastSince > targetSince)
879 targetSince = lastSince;
898 if (!
tagInfo().lastInterval.payloadId.empty()) {
905 bool iovAdded =
false;
907 if (targetSince >= endIov) {
912 bool updateEcal =
false;
914 boost::posix_time::ptime startSampleTime;
915 boost::posix_time::ptime endSampleTime;
930 edm::LogInfo(
m_name) <<
"Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
944 if (endFillTime == 0ULL) {
946 endSampleTime = executionTime;
947 targetSince = endIov;
952 targetSince = endFillTime;
956 getDipData(session, startSampleTime, endSampleTime);
957 size_t nlumi =
getLumiData(session, startSampleTime, endSampleTime);
958 edm::LogInfo(
m_name) <<
"Found " << nlumi <<
" lumisections during the fill " << lhcFill;
961 edm::LogInfo(
m_name) <<
"First lumi starts at " << flumiStart <<
" last lumi starts at " << flumiStop;
965 getEcalData(session2, startSampleTime, endSampleTime, updateEcal);