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"
22 : m_debug(pset.getUntrackedParameter<bool>(
"debug",
false)),
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",
"")),
35 if (pset.
exists(
"startTime")) {
38 boost::posix_time::ptime
now = boost::posix_time::second_clock::local_time();
40 if (pset.
exists(
"endTime")) {
50 namespace LHCInfoImpl {
59 std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo>>>::const_iterator
search(
61 if (container.empty())
62 return container.end();
64 return (
p != container.begin()) ?
p - 1 : container.end();
69 const coral::AttributeList& fillDataBindVariables,
70 std::unique_ptr<LHCInfo>& targetPayload,
72 coral::ISchema& runTimeLoggerSchema = session.
nominalSchema();
74 std::unique_ptr<coral::IQuery> fillDataQuery(runTimeLoggerSchema.newQuery());
76 fillDataQuery->addToTableList(
std::string(
"RUNTIME_SUMMARY"));
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"));
94 fillDataQuery->setCondition(conditionString, fillDataBindVariables);
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"));
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"));
114 fillDataQuery->defineOutput(fillDataOutput);
115 fillDataQuery->limitReturnedRows(1);
117 coral::ICursor& fillDataCursor = fillDataQuery->execute();
119 unsigned short currentFill = 0;
120 unsigned short bunches1 = 0, bunches2 = 0, collidingBunches = 0, targetBunches = 0;
123 float intensityBeam1 = 0., intensityBeam2 = 0.,
energy = 0.;
124 coral::TimeStamp stableBeamStartTimeStamp, beamDumpTimeStamp;
127 std::ostringstream
ss;
129 if (fillDataCursor.next()) {
132 std::ostringstream qs;
133 fillDataCursor.currentRow().toOutputStream(qs);
135 coral::Attribute
const& fillAttribute = fillDataCursor.currentRow()[
std::string(
"LHCFILL")];
136 if (!fillAttribute.isNull()) {
137 currentFill = fillAttribute.data<
unsigned short>();
139 coral::Attribute
const& bunches1Attribute = fillDataCursor.currentRow()[
std::string(
"NBUNCHESBEAM1")];
140 if (!bunches1Attribute.isNull()) {
141 bunches1 = bunches1Attribute.data<
unsigned short>();
143 coral::Attribute
const& bunches2Attribute = fillDataCursor.currentRow()[
std::string(
"NBUNCHESBEAM2")];
144 if (!bunches2Attribute.isNull()) {
145 bunches2 = bunches2Attribute.data<
unsigned short>();
147 coral::Attribute
const& collidingBunchesAttribute = fillDataCursor.currentRow()[
std::string(
"NCOLLIDINGBUNCHES")];
148 if (!collidingBunchesAttribute.isNull()) {
149 collidingBunches = collidingBunchesAttribute.data<
unsigned short>();
151 coral::Attribute
const& targetBunchesAttribute = fillDataCursor.currentRow()[
std::string(
"NTARGETBUNCHES")];
152 if (!targetBunchesAttribute.isNull()) {
153 targetBunches = targetBunchesAttribute.data<
unsigned short>();
158 coral::Attribute
const& particleType1Attribute = fillDataCursor.currentRow()[
std::string(
"PARTY1")];
159 if (!particleType1Attribute.isNull()) {
162 coral::Attribute
const& particleType2Attribute = fillDataCursor.currentRow()[
std::string(
"PARTY2")];
163 if (!particleType2Attribute.isNull()) {
166 coral::Attribute
const& intensityBeam1Attribute = fillDataCursor.currentRow()[
std::string(
"INTENSITYBEAM1")];
167 if (!intensityBeam1Attribute.isNull()) {
168 intensityBeam1 = intensityBeam1Attribute.data<
float>();
170 coral::Attribute
const& intensityBeam2Attribute = fillDataCursor.currentRow()[
std::string(
"INTENSITYBEAM2")];
171 if (!intensityBeam2Attribute.isNull()) {
172 intensityBeam2 = intensityBeam2Attribute.data<
float>();
174 coral::Attribute
const& energyAttribute = fillDataCursor.currentRow()[
std::string(
"ENERGY")];
175 if (!energyAttribute.isNull()) {
176 energy = energyAttribute.data<
float>();
182 fillDataCursor.currentRow()[
std::string(
"CREATETIME")].data<coral::TimeStamp>().time());
184 stableBeamStartTimeStamp = fillDataCursor.currentRow()[
std::string(
"BEGINTIME")].data<coral::TimeStamp>();
186 coral::Attribute
const& beamDumpTimeAttribute = fillDataCursor.currentRow()[
std::string(
"ENDTIME")];
187 if (!beamDumpTimeAttribute.isNull()) {
188 beamDumpTimeStamp = beamDumpTimeAttribute.data<coral::TimeStamp>();
191 coral::Attribute
const& injectionSchemeAttribute = fillDataCursor.currentRow()[
std::string(
"INJECTIONSCHEME")];
192 if (!injectionSchemeAttribute.isNull()) {
193 injectionScheme = injectionSchemeAttribute.data<
std::string>();
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);
235 const boost::posix_time::ptime& targetTime,
238 coral::AttributeList fillDataBindVariables;
239 fillDataBindVariables.extend<coral::TimeStamp>(
std::string(
"targetTime"));
240 fillDataBindVariables[
std::string(
"targetTime")].data<coral::TimeStamp>() =
244 std::string conditionStr =
"BEGINTIME IS NOT NULL AND CREATETIME > :targetTime AND LHCFILL IS NOT NULL";
246 conditionStr +=
" AND ENDTIME IS NOT NULL";
252 coral::AttributeList fillDataBindVariables;
253 fillDataBindVariables.extend<
unsigned short>(
std::string(
"fillId"));
254 fillDataBindVariables[
std::string(
"fillId")].data<
unsigned short>() = fillId;
260 const boost::posix_time::ptime& beginFillTime,
261 const boost::posix_time::ptime& endFillTime) {
262 coral::ISchema& runTimeLoggerSchema = session.
nominalSchema();
264 std::unique_ptr<coral::IQuery> fillDataQuery2(runTimeLoggerSchema.newQuery());
266 fillDataQuery2->addToTableList(
std::string(
"LUMI_SECTIONS"));
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"));
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);
283 fillDataQuery2->addToOrderList(
std::string(
"STARTTIME"));
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);
294 coral::ICursor& fillDataCursor2 = fillDataQuery2->execute();
297 while (fillDataCursor2.next()) {
299 float delivLumi = 0., recLumi = 0., instLumi = 0, instLumiErr = 0.;
301 coral::Attribute
const& delivLumiAttribute = fillDataCursor2.currentRow()[
std::string(
"DELIVEREDLUMI")];
302 if (!delivLumiAttribute.isNull()) {
303 delivLumi = delivLumiAttribute.data<
float>() / 1000.;
305 coral::Attribute
const& recLumiAttribute = fillDataCursor2.currentRow()[
std::string(
"RECORDEDLUMI")];
306 if (!recLumiAttribute.isNull()) {
307 recLumi = recLumiAttribute.data<
float>() / 1000.;
309 coral::Attribute
const& instLumiAttribute = fillDataCursor2.currentRow()[
std::string(
"INSTLUMI")];
310 if (!instLumiAttribute.isNull()) {
311 instLumi = instLumiAttribute.data<
float>() / 1000.;
313 coral::Attribute
const& instLumiErrAttribute = fillDataCursor2.currentRow()[
std::string(
"INSTLUMIERROR")];
314 if (!instLumiErrAttribute.isNull()) {
315 instLumiErr = instLumiErrAttribute.data<
float>() / 1000.;
317 coral::Attribute
const& startLumiSectionAttribute = fillDataCursor2.currentRow()[
std::string(
"STARTTIME")];
318 if (!startLumiSectionAttribute.isNull()) {
322 m_tmpBuffer.emplace_back(std::make_pair(since, thisLumiSectionInfo));
332 namespace LHCInfoImpl {
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;
390 const boost::posix_time::ptime& beginFillTime,
391 const boost::posix_time::ptime& endFillTime) {
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);
403 coral::AttributeList bunchConfOutput;
404 bunchConfOutput.extend<coral::TimeStamp>(
std::string(
"DIPTIME"));
405 bunchConfOutput.extend<
unsigned short>(
std::string(
"BUCKET"));
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"));
412 bunchConf1Query->setCondition(conditionStr, bunchConfBindVariables);
413 bunchConf1Query->addToOrderList(
std::string(
"DIPTIME"));
415 bunchConf1Query->defineOutput(bunchConfOutput);
417 coral::ICursor& bunchConf1Cursor = bunchConf1Query->execute();
418 std::bitset<LHCInfo::bunchSlots + 1> bunchConfiguration1(0ULL);
421 while (bunchConf1Cursor.next()) {
423 std::ostringstream b1s;
424 bunchConf1Cursor.currentRow().toOutputStream(b1s);
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()) {
431 unsigned short slot = (bunchConf1Attribute.data<
unsigned short>() - 1) / 10 + 1;
432 if (lumiSectionTime == 0
or lumiSectionTime == dipTime) {
433 bunchConfiguration1[slot] =
true;
436 lumiSectionTime = dipTime;
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"));
449 bunchConf2Query->setCondition(conditionStr, bunchConfBindVariables);
450 bunchConf2Query->addToOrderList(
std::string(
"DIPTIME"));
452 bunchConf2Query->defineOutput(bunchConfOutput);
453 coral::ICursor& bunchConf2Cursor = bunchConf2Query->execute();
455 std::bitset<LHCInfo::bunchSlots + 1> bunchConfiguration2(0ULL);
458 while (bunchConf2Cursor.next()) {
460 std::ostringstream b2s;
461 bunchConf2Cursor.currentRow().toOutputStream(b2s);
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()) {
469 unsigned short slot = (bunchConf2Attribute.data<
unsigned short>() - 1) / 10 + 1;
470 if (lumiSectionTime == 0
or lumiSectionTime == dipTime) {
471 bunchConfiguration2[slot] =
true;
474 lumiSectionTime = dipTime;
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"));
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);
496 coral::AttributeList lumiDataOutput;
497 lumiDataOutput.extend<coral::TimeStamp>(
std::string(
"DIPTIME"));
498 lumiDataOutput.extend<
float>(
std::string(
"LUMI_BUNCH"));
499 lumiDataQuery->defineOutput(lumiDataOutput);
501 coral::ICursor& lumiDataCursor = lumiDataQuery->execute();
503 std::vector<float> lumiPerBX;
506 while (lumiDataCursor.next()) {
508 std::ostringstream lpBX;
509 lumiDataCursor.currentRow().toOutputStream(lpBX);
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()) {
517 float lumi_b = lumiBunchAttribute.data<
float>();
518 if (lumiSectionTime == 0
or lumiSectionTime == dipTime) {
520 lumiPerBX.push_back(lumi_b);
523 lumiSectionTime = dipTime;
533 const boost::posix_time::ptime& beginFillTime,
534 const boost::posix_time::ptime& endFillTime) {
537 coral::ISchema& CTPPS = session.
coralSession().schema(
"CMS_CTP_CTPPS_COND");
539 std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
541 CTPPSDataQuery->addToTableList(
std::string(
"CTPPS_LHC_MACHINE_PARAMS"));
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"));
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);
559 CTPPSDataQuery->addToOrderList(
std::string(
"DIP_UPDATE_TIME"));
561 coral::AttributeList CTPPSDataOutput;
562 CTPPSDataOutput.extend<coral::TimeStamp>(
std::string(
"DIP_UPDATE_TIME"));
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);
571 coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
573 std::string lhcState =
"", lhcComment =
"", ctppsStatus =
"";
574 unsigned int lumiSection = 0;
575 float crossingAngle = 0., betastar = 0.;
579 while (CTPPSDataCursor.next()) {
581 std::ostringstream CTPPS;
582 CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
584 coral::Attribute
const& dipTimeAttribute = CTPPSDataCursor.currentRow()[
std::string(
"DIP_UPDATE_TIME")];
585 if (!dipTimeAttribute.isNull()) {
589 coral::Attribute
const& lhcStateAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LHC_STATE")];
590 if (!lhcStateAttribute.isNull()) {
593 coral::Attribute
const& lhcCommentAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LHC_COMMENT")];
594 if (!lhcCommentAttribute.isNull()) {
595 lhcComment = lhcCommentAttribute.data<
std::string>();
597 coral::Attribute
const& ctppsStatusAttribute = CTPPSDataCursor.currentRow()[
std::string(
"CTPPS_STATUS")];
598 if (!ctppsStatusAttribute.isNull()) {
599 ctppsStatus = ctppsStatusAttribute.data<
std::string>();
601 coral::Attribute
const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LUMI_SECTION")];
602 if (!lumiSectionAttribute.isNull()) {
603 lumiSection = lumiSectionAttribute.data<
int>();
605 coral::Attribute
const& crossingAngleAttribute = CTPPSDataCursor.currentRow()[
std::string(
"XING_ANGLE_URAD")];
606 if (!crossingAngleAttribute.isNull()) {
607 crossingAngle = crossingAngleAttribute.data<
float>();
609 coral::Attribute
const& betaStarAttribute = CTPPSDataCursor.currentRow()[
std::string(
"BETA_STAR_CMS")];
610 if (!betaStarAttribute.isNull()) {
611 betastar = betaStarAttribute.data<
float>();
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}};
634 unsigned int elementNr,
637 std::set<cond::Time_t>& initList) {
638 if (initList.find(since) == initList.end()) {
643 initList.insert(since);
647 switch (
vecMap.at(dipVal)) {
668 const boost::posix_time::ptime& lowerTime,
669 const boost::posix_time::ptime& upperTime,
676 std::unique_ptr<coral::IQuery> ECALDataQuery(ECAL.newQuery());
678 ECALDataQuery->addToTableList(
std::string(
"BEAM_PHASE"));
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"));
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);
691 "(DIP_value LIKE '%beamPhaseMean%' OR DIP_value LIKE '%cavPhaseMean%') AND CHANGE_DATE >= :lowerTime AND "
692 "CHANGE_DATE < :upperTime");
694 ECALDataQuery->setCondition(conditionStr, ECALDataBindVariables);
696 ECALDataQuery->addToOrderList(
std::string(
"CHANGE_DATE"));
697 ECALDataQuery->addToOrderList(
std::string(
"DIP_value"));
698 ECALDataQuery->addToOrderList(
std::string(
"element_nr"));
700 coral::AttributeList ECALDataOutput;
701 ECALDataOutput.extend<coral::TimeStamp>(
std::string(
"CHANGE_DATE"));
703 ECALDataOutput.extend<
unsigned int>(
std::string(
"element_nr"));
704 ECALDataOutput.extend<
float>(
std::string(
"VALUE_NUMBER"));
706 ECALDataQuery->defineOutput(ECALDataOutput);
708 coral::ICursor& ECALDataCursor = ECALDataQuery->execute();
712 unsigned int elementNr = 0;
714 std::set<cond::Time_t> initializedVectors;
725 std::map<cond::Time_t, cond::Time_t> iovMap;
727 while (ECALDataCursor.next()) {
729 std::ostringstream
ECAL;
730 ECALDataCursor.currentRow().toOutputStream(ECAL);
732 coral::Attribute
const& changeDateAttribute = ECALDataCursor.currentRow()[
std::string(
"CHANGE_DATE")];
733 if (!changeDateAttribute.isNull()) {
735 boost::posix_time::ptime chTime = changeDateAttribute.data<coral::TimeStamp>().time();
737 if (changeTime == 0) {
742 if (!update and changeTime == firstTime)
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()) {
749 elementNr = elementNrAttribute.data<
unsigned int>();
750 value = valueNumberAttribute.data<
float>();
754 iovMap.insert(std::make_pair(changeTime, filter.
current()->first));
765 for (
auto& im : iovMap) {
779 auto lastAdded =
m_iovs.rbegin()->second;
780 if (lastAdded->fillNumber() != 0) {
785 auto newPayload = std::make_shared<LHCInfo>();
786 m_iovs.insert(std::make_pair(iov, newPayload));
791 namespace LHCInfoImpl {
817 std::map<
cond::Time_t, std::shared_ptr<LHCInfo>>& iovsToTransfer,
818 std::shared_ptr<LHCInfo>& prevPayload) {
820 for (
auto& iov :
buffer) {
824 if (iovsToTransfer.empty()) {
827 LHCInfo& lastAdded = *iovsToTransfer.rbegin()->second;
834 iovsToTransfer.insert(std::make_pair(since,
payload));
835 prevPayload = iov.second;
854 << boost::posix_time::to_iso_extended_string(
856 <<
" ); from " <<
m_name <<
"::getNewObjects";
860 if (lastSince == 0) {
865 <<
m_name <<
"::getNewObjects";
868 boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
874 if (lastSince > targetSince)
875 targetSince = lastSince;
894 if (!
tagInfo().lastInterval.payloadId.empty()) {
901 bool iovAdded =
false;
903 if (targetSince >= endIov) {
908 bool updateEcal =
false;
910 boost::posix_time::ptime startSampleTime;
911 boost::posix_time::ptime endSampleTime;
926 edm::LogInfo(
m_name) <<
"Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
940 if (endFillTime == 0ULL) {
942 endSampleTime = executionTime;
943 targetSince = endIov;
948 targetSince = endFillTime;
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;
957 edm::LogInfo(
m_name) <<
"First lumi starts at " << flumiStart <<
" last lumi starts at " << flumiStop;
961 getEcalData(session2, startSampleTime, endSampleTime, updateEcal);
cond::Time_t currentDipTime
std::string const & lhcState() const
cond::persistency::Session & dbSession() const
edm::ErrorSummaryEntry Error
T getUntrackedParameter(std::string const &, T const &) const
void setLumiSection(unsigned int const &lumiSection)
tuple ret
prodAgent to be discontinued
void setInstLumi(float const &instLumi)
bool getFillData(cond::persistency::Session &session, unsigned short fillId)
static const std::map< std::string, int > vecMap
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
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
std::string m_connectionString
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)
void start(bool readOnly=true)
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 ¶meterName) 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)
cond::Time_t currentSince()
void setDelivLumi(float const &delivLumi)
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
std::string const & ctppsStatus() const
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()
bool getDipData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
void setLhcComment(std::string const &lhcComment)
float const delivLumi() const
float const crossingAngle() const
float const instLumiError() const
std::string id() const override
unsigned long long Time_t
std::string const & lhcComment() const
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)
std::vector< float > const & beam1VC() const
std::vector< float > const & beam2RF() const
coral::ISchema & nominalSchema()
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
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)
void setMessageVerbosity(coral::MsgLevel level)
Time_t from_boost(boost::posix_time::ptime bt)
void setRecLumi(float const &recLumi)
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)
static size_t const availableBunchSlots
float const instLumi() const
void setElementData(cond::Time_t since, const std::string &dipVal, unsigned int elementNr, float value, LHCInfo &payload, std::set< cond::Time_t > &initList)
void addEmptyPayload(cond::Time_t iov)
std::vector< float > const & beam2VC() const
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
coral::ISessionProxy & coralSession()
void setCtppsStatus(std::string const &ctppsStatus)
std::unique_ptr< LHCInfo > Ref
float const betaStar() const
unsigned short const fillNumber() const
~LHCInfoPopConSourceHandler() override
LHCInfo & currentPayload()
std::string m_ecalConnectionString
void setAuthenticationPath(const std::string &p)
void getNewObjects() override
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
bool process(cond::Time_t dipTime)
void setCrossingAngle(float const &angle)
boost::posix_time::ptime to_boost(Time_t iValue)
static size_t const bunchSlots
bool getNextFillData(cond::persistency::Session &session, const boost::posix_time::ptime &targetTime, bool ended)
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()