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",
""))
36 if( pset.
exists(
"startTime") ){
39 boost::posix_time::ptime
now = boost::posix_time::second_clock::local_time();
41 if( pset.
exists(
"endTime") ){
57 std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >::const_iterator
search(
const cond::Time_t&
val,
58 const std::vector<std::pair<
cond::Time_t,std::shared_ptr<LHCInfo> >>& container ){
59 if( container.empty() )
return container.end();
60 auto p = std::upper_bound( container.begin(), container.end(),
val,
IOVComp() );
61 return (
p!= container.begin()) ?
p-1 : container.end();
66 const coral::AttributeList& fillDataBindVariables,
67 std::unique_ptr<LHCInfo>& targetPayload,
69 coral::ISchema& runTimeLoggerSchema = session.
nominalSchema();
71 std::unique_ptr<coral::IQuery> fillDataQuery( runTimeLoggerSchema.newQuery() );
73 fillDataQuery->addToTableList(
std::string(
"RUNTIME_SUMMARY" ) );
75 fillDataQuery->addToOutputList(
std::string(
"LHCFILL" ) );
76 fillDataQuery->addToOutputList(
std::string(
"NBUNCHESBEAM1" ) );
77 fillDataQuery->addToOutputList(
std::string(
"NBUNCHESBEAM2" ) );
78 fillDataQuery->addToOutputList(
std::string(
"NCOLLIDINGBUNCHES" ) );
79 fillDataQuery->addToOutputList(
std::string(
"NTARGETBUNCHES" ) );
80 fillDataQuery->addToOutputList(
std::string(
"RUNTIME_TYPE_ID" ) );
81 fillDataQuery->addToOutputList(
std::string(
"PARTY1" ) );
82 fillDataQuery->addToOutputList(
std::string(
"PARTY2" ) );
83 fillDataQuery->addToOutputList(
std::string(
"INTENSITYBEAM1" ) );
84 fillDataQuery->addToOutputList(
std::string(
"INTENSITYBEAM2" ) );
85 fillDataQuery->addToOutputList(
std::string(
"ENERGY" ) );
86 fillDataQuery->addToOutputList(
std::string(
"CREATETIME" ) );
87 fillDataQuery->addToOutputList(
std::string(
"BEGINTIME" ) );
88 fillDataQuery->addToOutputList(
std::string(
"ENDTIME" ) );
89 fillDataQuery->addToOutputList(
std::string(
"INJECTIONSCHEME" ) );
91 fillDataQuery->setCondition( conditionString, fillDataBindVariables );
95 coral::AttributeList fillDataOutput;
96 fillDataOutput.extend<
unsigned short>(
std::string(
"LHCFILL" ) );
97 fillDataOutput.extend<
unsigned short>(
std::string(
"NBUNCHESBEAM1" ) );
98 fillDataOutput.extend<
unsigned short>(
std::string(
"NBUNCHESBEAM2" ) );
99 fillDataOutput.extend<
unsigned short>(
std::string(
"NCOLLIDINGBUNCHES" ) );
100 fillDataOutput.extend<
unsigned short>(
std::string(
"NTARGETBUNCHES" ) );
101 fillDataOutput.extend<
int>(
std::string(
"RUNTIME_TYPE_ID" ) );
102 fillDataOutput.extend<
int>(
std::string(
"PARTY1" ) );
103 fillDataOutput.extend<
int>(
std::string(
"PARTY2" ) );
104 fillDataOutput.extend<
float>(
std::string(
"INTENSITYBEAM1" ) );
105 fillDataOutput.extend<
float>(
std::string(
"INTENSITYBEAM2" ) );
106 fillDataOutput.extend<
float>(
std::string(
"ENERGY" ) );
107 fillDataOutput.extend<coral::TimeStamp>(
std::string(
"CREATETIME" ) );
108 fillDataOutput.extend<coral::TimeStamp>(
std::string(
"BEGINTIME" ) );
109 fillDataOutput.extend<coral::TimeStamp>(
std::string(
"ENDTIME" ) );
111 fillDataQuery->defineOutput( fillDataOutput );
112 fillDataQuery->limitReturnedRows( 1 );
114 coral::ICursor& fillDataCursor = fillDataQuery->execute();
116 unsigned short currentFill = 0;
117 unsigned short bunches1 = 0, bunches2 = 0, collidingBunches = 0, targetBunches = 0;
120 float intensityBeam1 = 0., intensityBeam2 = 0., energy = 0.;
121 coral::TimeStamp stableBeamStartTimeStamp, beamDumpTimeStamp;
122 cond::Time_t creationTime = 0ULL, stableBeamStartTime = 0ULL, beamDumpTime = 0ULL;
124 std::ostringstream ss;
126 if( fillDataCursor.next() ) {
129 std::ostringstream qs;
130 fillDataCursor.currentRow().toOutputStream( qs );
132 coral::Attribute
const & fillAttribute = fillDataCursor.currentRow()[
std::string(
"LHCFILL" ) ];
133 if( !fillAttribute.isNull() ){
134 currentFill = fillAttribute.data<
unsigned short>();
136 coral::Attribute
const & bunches1Attribute = fillDataCursor.currentRow()[
std::string(
"NBUNCHESBEAM1" ) ];
137 if( !bunches1Attribute.isNull() ) {
138 bunches1 = bunches1Attribute.data<
unsigned short>();
140 coral::Attribute
const & bunches2Attribute = fillDataCursor.currentRow()[
std::string(
"NBUNCHESBEAM2" ) ];
141 if( !bunches2Attribute.isNull() ) {
142 bunches2 = bunches2Attribute.data<
unsigned short>();
144 coral::Attribute
const & collidingBunchesAttribute = fillDataCursor.currentRow()[
std::string(
"NCOLLIDINGBUNCHES" ) ];
145 if( !collidingBunchesAttribute.isNull() ) {
146 collidingBunches = collidingBunchesAttribute.data<
unsigned short>();
148 coral::Attribute
const & targetBunchesAttribute = fillDataCursor.currentRow()[
std::string(
"NTARGETBUNCHES" ) ];
149 if( !targetBunchesAttribute.isNull() ) {
150 targetBunches = targetBunchesAttribute.data<
unsigned short>();
154 coral::Attribute
const & particleType1Attribute = fillDataCursor.currentRow()[
std::string(
"PARTY1" ) ];
155 if( !particleType1Attribute.isNull() ) {
158 coral::Attribute
const & particleType2Attribute = fillDataCursor.currentRow()[
std::string(
"PARTY2" ) ];
159 if( !particleType2Attribute.isNull() ) {
162 coral::Attribute
const & intensityBeam1Attribute = fillDataCursor.currentRow()[
std::string(
"INTENSITYBEAM1" ) ];
163 if( !intensityBeam1Attribute.isNull() ) {
164 intensityBeam1 = intensityBeam1Attribute.data<
float>();
166 coral::Attribute
const & intensityBeam2Attribute = fillDataCursor.currentRow()[
std::string(
"INTENSITYBEAM2" ) ];
167 if( !intensityBeam2Attribute.isNull() ) {
168 intensityBeam2 = intensityBeam2Attribute.data<
float>();
170 coral::Attribute
const & energyAttribute = fillDataCursor.currentRow()[
std::string(
"ENERGY" ) ];
171 if( !energyAttribute.isNull() ){
172 energy = energyAttribute.data<
float>();
179 stableBeamStartTimeStamp = fillDataCursor.currentRow()[
std::string(
"BEGINTIME" ) ].data<coral::TimeStamp>();
181 coral::Attribute
const & beamDumpTimeAttribute = fillDataCursor.currentRow()[
std::string(
"ENDTIME" ) ];
182 if( !beamDumpTimeAttribute.isNull() ) {
183 beamDumpTimeStamp = beamDumpTimeAttribute.data<coral::TimeStamp>();
186 coral::Attribute
const & injectionSchemeAttribute = fillDataCursor.currentRow()[
std::string(
"INJECTIONSCHEME" ) ];
187 if( !injectionSchemeAttribute.isNull() ) {
188 injectionScheme = injectionSchemeAttribute.data<
std::string>();
207 targetPayload.reset(
new LHCInfo() );
208 targetPayload->setFillNumber( currentFill );
209 targetPayload->setBunchesInBeam1( bunches1 );
210 targetPayload->setBunchesInBeam2( bunches2 );
211 targetPayload->setCollidingBunches( collidingBunches );
212 targetPayload->setTargetBunches( targetBunches );
213 targetPayload->setFillType( fillType );
214 targetPayload->setParticleTypeForBeam1( particleType1 );
215 targetPayload->setParticleTypeForBeam2( particleType2 );
216 targetPayload->setIntensityForBeam1( intensityBeam1 );
217 targetPayload->setIntensityForBeam2( intensityBeam2 );
218 targetPayload->setEnergy( energy );
219 targetPayload->setCreationTime( creationTime );
220 targetPayload->setBeginTime( stableBeamStartTime );
221 targetPayload->setEndTime( beamDumpTime );
222 targetPayload->setInjectionScheme( injectionScheme );
230 const boost::posix_time::ptime& targetTime,
233 coral::AttributeList fillDataBindVariables;
234 fillDataBindVariables.extend<coral::TimeStamp>(
std::string(
"targetTime"));
238 std::string conditionStr =
"BEGINTIME IS NOT NULL AND CREATETIME > :targetTime AND LHCFILL IS NOT NULL";
239 if( ended ) conditionStr +=
" AND ENDTIME IS NOT NULL";
244 unsigned short fillId ){
246 coral::AttributeList fillDataBindVariables;
247 fillDataBindVariables.extend<
unsigned short>(
std::string(
"fillId"));
248 fillDataBindVariables[
std::string(
"fillId")].data<
unsigned short>()= fillId;
254 const boost::posix_time::ptime& beginFillTime,
255 const boost::posix_time::ptime& endFillTime ){
256 coral::ISchema& runTimeLoggerSchema = session.
nominalSchema();
258 std::unique_ptr<coral::IQuery> fillDataQuery2( runTimeLoggerSchema.newQuery() );
260 fillDataQuery2->addToTableList(
std::string(
"LUMI_SECTIONS" ) );
262 fillDataQuery2->addToOutputList(
std::string(
"DELIVLUMI" ) );
263 fillDataQuery2->addToOutputList(
std::string(
"LIVELUMI" ) );
264 fillDataQuery2->addToOutputList(
std::string(
"INSTLUMI" ) );
265 fillDataQuery2->addToOutputList(
std::string(
"INSTLUMIERROR" ) );
266 fillDataQuery2->addToOutputList(
std::string(
"STARTTIME" ) );
267 fillDataQuery2->addToOutputList(
std::string(
"LHCFILL" ) );
269 coral::AttributeList fillDataBindVariables;
270 fillDataBindVariables.extend<coral::TimeStamp>(
std::string(
"start"));
271 fillDataBindVariables.extend<coral::TimeStamp>(
std::string(
"stop"));
272 fillDataBindVariables[
std::string(
"start")].data<coral::TimeStamp>()= coral::TimeStamp( beginFillTime );
273 fillDataBindVariables[
std::string(
"stop")].data<coral::TimeStamp>()= coral::TimeStamp( endFillTime );
274 std::string conditionStr =
"DELIVLUMI IS NOT NULL AND STARTTIME >= :start AND STARTTIME< :stop";
275 fillDataQuery2->setCondition( conditionStr, fillDataBindVariables );
277 fillDataQuery2->addToOrderList(
std::string(
"STARTTIME" ) );
279 coral::AttributeList fillDataOutput2;
280 fillDataOutput2.extend<
float>(
std::string(
"DELIVEREDLUMI" ) );
281 fillDataOutput2.extend<
float>(
std::string(
"RECORDEDLUMI" ) );
282 fillDataOutput2.extend<
float>(
std::string(
"INSTLUMI" ) );
283 fillDataOutput2.extend<
float>(
std::string(
"INSTLUMIERROR" ) );
284 fillDataOutput2.extend<coral::TimeStamp>(
std::string(
"STARTTIME" ) );
285 fillDataOutput2.extend<
int>(
std::string(
"LHCFILL" ) );
286 fillDataQuery2->defineOutput( fillDataOutput2 );
288 coral::ICursor& fillDataCursor2 = fillDataQuery2->execute();
291 while( fillDataCursor2.next()){
293 float delivLumi = 0., recLumi = 0.,
instLumi = 0, instLumiErr = 0.;
295 coral::Attribute
const & delivLumiAttribute = fillDataCursor2.currentRow()[
std::string(
"DELIVEREDLUMI" ) ];
296 if( !delivLumiAttribute.isNull() ){
297 delivLumi = delivLumiAttribute.data<
float>() / 1000.;
299 coral::Attribute
const & recLumiAttribute = fillDataCursor2.currentRow()[
std::string(
"RECORDEDLUMI" ) ];
300 if( !recLumiAttribute.isNull() ){
301 recLumi = recLumiAttribute.data<
float>() / 1000.;
303 coral::Attribute
const & instLumiAttribute = fillDataCursor2.currentRow()[
std::string(
"INSTLUMI" ) ];
304 if( !instLumiAttribute.isNull() ){
305 instLumi = instLumiAttribute.data<
float>() / 1000.;
307 coral::Attribute
const & instLumiErrAttribute = fillDataCursor2.currentRow()[
std::string(
"INSTLUMIERROR" ) ];
308 if( !instLumiErrAttribute.isNull() ){
309 instLumiErr = instLumiErrAttribute.data<
float>() / 1000.;
311 coral::Attribute
const & startLumiSectionAttribute = fillDataCursor2.currentRow()[
std::string(
"STARTTIME" ) ];
312 if( !startLumiSectionAttribute.isNull() ) {
316 m_tmpBuffer.emplace_back(std::make_pair(since,thisLumiSectionInfo));
345 if( currLow ==
end )
return false;
347 if( currentDipTime == 0 ){
350 if( dipTime == currentDipTime )
return true;
353 if(currUp !=
end ) upper = currUp->first;
354 if( dipTime < upper )
return false;
361 while(currUp !=
end and currUp->first < dipTime ){
365 currentDipTime = dipTime;
366 return currLow !=
end;
374 std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >::const_iterator
current(){
377 std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >::const_iterator
currLow;
378 std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >::const_iterator
currUp;
379 std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >::const_iterator
end;
385 const boost::posix_time::ptime& beginFillTime,
386 const boost::posix_time::ptime& endFillTime ){
391 coral::AttributeList bunchConfBindVariables;
392 bunchConfBindVariables.extend<coral::TimeStamp>(
std::string(
"beginFillTime"));
393 bunchConfBindVariables.extend<coral::TimeStamp>(
std::string(
"endFillTime"));
394 bunchConfBindVariables[
std::string(
"beginFillTime")].data<coral::TimeStamp>()= coral::TimeStamp( beginFillTime );
395 bunchConfBindVariables[
std::string(
"endFillTime")].data<coral::TimeStamp>()= coral::TimeStamp( endFillTime );
398 coral::AttributeList bunchConfOutput;
399 bunchConfOutput.extend<coral::TimeStamp>(
std::string(
"DIPTIME" ) );
400 bunchConfOutput.extend<
unsigned short>(
std::string(
"BUCKET" ) );
402 std::unique_ptr<coral::IQuery> bunchConf1Query(beamCondSchema.newQuery());
403 bunchConf1Query->addToTableList(
std::string(
"LHC_CIRCBUNCHCONFIG_BEAM1" ),
std::string(
"BEAMCONF\", TABLE( BEAMCONF.VALUE ) \"BUCKETS" ) );
406 bunchConf1Query->setCondition( conditionStr, bunchConfBindVariables );
407 bunchConf1Query->addToOrderList(
std::string(
"DIPTIME" ) );
409 bunchConf1Query->defineOutput( bunchConfOutput );
411 coral::ICursor& bunchConf1Cursor = bunchConf1Query->execute();
412 std::bitset<LHCInfo::bunchSlots+1> bunchConfiguration1( 0ULL );
415 while( bunchConf1Cursor.next() ) {
417 std::ostringstream b1s;
418 bunchConf1Cursor.currentRow().toOutputStream( b1s );
420 coral::Attribute
const & dipTimeAttribute = bunchConf1Cursor.currentRow()[
std::string(
"DIPTIME" ) ];
421 coral::Attribute
const & bunchConf1Attribute = bunchConf1Cursor.currentRow()[
std::string(
"BUCKET" ) ];
422 if( !dipTimeAttribute.isNull() and !bunchConf1Attribute.isNull() ){
425 unsigned short slot = ( bunchConf1Attribute.data<
unsigned short>() - 1 ) / 10 + 1;
426 if( lumiSectionTime == 0
or lumiSectionTime == dipTime){
427 bunchConfiguration1[slot] =
true;
429 lumiSectionTime = dipTime;
437 std::unique_ptr<coral::IQuery> bunchConf2Query(beamCondSchema.newQuery());
438 bunchConf2Query->addToTableList(
std::string(
"LHC_CIRCBUNCHCONFIG_BEAM2" ),
std::string(
"BEAMCONF\", TABLE( BEAMCONF.VALUE ) \"BUCKETS" ) );
441 bunchConf2Query->setCondition( conditionStr, bunchConfBindVariables );
442 bunchConf2Query->addToOrderList(
std::string(
"DIPTIME" ) );
444 bunchConf2Query->defineOutput( bunchConfOutput );
445 coral::ICursor& bunchConf2Cursor = bunchConf2Query->execute();
447 std::bitset<LHCInfo::bunchSlots+1> bunchConfiguration2( 0ULL );
450 while( bunchConf2Cursor.next() ) {
452 std::ostringstream b2s;
453 bunchConf2Cursor.currentRow().toOutputStream( b2s );
455 coral::Attribute
const & dipTimeAttribute = bunchConf2Cursor.currentRow()[
std::string(
"DIPTIME" ) ];
456 coral::Attribute
const & bunchConf2Attribute = bunchConf2Cursor.currentRow()[
std::string(
"BUCKET" ) ];
457 if( !dipTimeAttribute.isNull() and !bunchConf2Attribute.isNull() ){
461 unsigned short slot = ( bunchConf2Attribute.data<
unsigned short>() - 1 ) / 10 + 1;
462 if( lumiSectionTime == 0
or lumiSectionTime == dipTime){
463 bunchConfiguration2[slot] =
true;
465 lumiSectionTime = dipTime;
469 m_fillPayload->setBunchBitsetForBeam2( bunchConfiguration2 );
472 std::unique_ptr<coral::IQuery> lumiDataQuery(beamCondSchema.newQuery());
473 lumiDataQuery->addToTableList(
std::string(
"CMS_LHC_LUMIPERBUNCH" ),
std::string(
"LUMIPERBUNCH\", TABLE( LUMIPERBUNCH.LUMI_BUNCHINST ) \"VALUE" ) );
476 coral::AttributeList lumiDataBindVariables;
477 lumiDataBindVariables.extend<coral::TimeStamp>(
std::string(
"beginFillTime" ) );
478 lumiDataBindVariables.extend<coral::TimeStamp>(
std::string(
"endFillTime" ) );
479 lumiDataBindVariables[
std::string(
"beginFillTime" ) ].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
480 lumiDataBindVariables[
std::string(
"endFillTime" ) ].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
481 conditionStr =
std::string(
"DIPTIME BETWEEN :beginFillTime AND :endFillTime" );
482 lumiDataQuery->setCondition( conditionStr, lumiDataBindVariables );
483 lumiDataQuery->addToOrderList(
std::string(
"DIPTIME" ) );
484 lumiDataQuery->limitReturnedRows(3564);
486 coral::AttributeList lumiDataOutput;
487 lumiDataOutput.extend<coral::TimeStamp>(
std::string(
"DIPTIME" ) );
488 lumiDataOutput.extend<
float>(
std::string(
"LUMI_BUNCH" ) );
489 lumiDataQuery->defineOutput( lumiDataOutput );
491 coral::ICursor& lumiDataCursor = lumiDataQuery->execute();
493 std::vector<float> lumiPerBX;
496 while( lumiDataCursor.next() ) {
498 std::ostringstream lpBX;
499 lumiDataCursor.currentRow().toOutputStream( lpBX );
501 coral::Attribute
const & dipTimeAttribute = lumiDataCursor.currentRow()[
std::string(
"DIPTIME" ) ];
502 coral::Attribute
const & lumiBunchAttribute = lumiDataCursor.currentRow()[
std::string(
"LUMI_BUNCH" ) ];
503 if( !dipTimeAttribute.isNull() and !lumiBunchAttribute.isNull() ){
507 float lumi_b = lumiBunchAttribute.data<
float>();
508 if( lumiSectionTime == 0
or lumiSectionTime == dipTime){
509 if( lumi_b != 0.00 ) lumiPerBX.push_back( lumi_b );
511 lumiSectionTime = dipTime;
521 const boost::posix_time::ptime& beginFillTime,
522 const boost::posix_time::ptime& endFillTime ){
525 coral::ISchema& CTPPS = session.
coralSession().schema(
"CMS_CTP_CTPPS_COND");
527 std::unique_ptr<coral::IQuery> CTPPSDataQuery( CTPPS.newQuery() );
529 CTPPSDataQuery->addToTableList(
std::string(
"CTPPS_LHC_MACHINE_PARAMS" ) );
531 CTPPSDataQuery->addToOutputList(
std::string(
"DIP_UPDATE_TIME" ) );
532 CTPPSDataQuery->addToOutputList(
std::string(
"LHC_STATE" ) );
533 CTPPSDataQuery->addToOutputList(
std::string(
"LHC_COMMENT" ) );
534 CTPPSDataQuery->addToOutputList(
std::string(
"CTPPS_STATUS" ) );
535 CTPPSDataQuery->addToOutputList(
std::string(
"LUMI_SECTION" ) );
536 CTPPSDataQuery->addToOutputList(
std::string(
"XING_ANGLE_URAD" ) );
537 CTPPSDataQuery->addToOutputList(
std::string(
"BETA_STAR_CMS" ) );
539 coral::AttributeList CTPPSDataBindVariables;
540 CTPPSDataBindVariables.extend<coral::TimeStamp>(
std::string(
"beginFillTime" ) );
541 CTPPSDataBindVariables.extend<coral::TimeStamp>(
std::string(
"endFillTime" ) );
542 CTPPSDataBindVariables[
std::string(
"beginFillTime" ) ].data<coral::TimeStamp>() = coral::TimeStamp( beginFillTime );
543 CTPPSDataBindVariables[
std::string(
"endFillTime" ) ].data<coral::TimeStamp>() = coral::TimeStamp( endFillTime );
544 std::string conditionStr =
std::string(
"DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime" );
545 CTPPSDataQuery->setCondition( conditionStr, CTPPSDataBindVariables );
547 CTPPSDataQuery->addToOrderList(
std::string(
"DIP_UPDATE_TIME" ) );
549 coral::AttributeList CTPPSDataOutput;
550 CTPPSDataOutput.extend<coral::TimeStamp>(
std::string(
"DIP_UPDATE_TIME" ) );
554 CTPPSDataOutput.extend<
int>(
std::string(
"LUMI_SECTION" ) );
555 CTPPSDataOutput.extend<
float>(
std::string(
"XING_ANGLE_URAD" ) );
556 CTPPSDataOutput.extend<
float>(
std::string(
"BETA_STAR_CMS" ) );
557 CTPPSDataQuery->defineOutput( CTPPSDataOutput );
559 coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
561 std::string lhcState =
"", lhcComment =
"", ctppsStatus =
"";
562 unsigned int lumiSection = 0;
563 float crossingAngle = 0., betastar = 0.;
567 while( CTPPSDataCursor.next() ) {
569 std::ostringstream CTPPS;
570 CTPPSDataCursor.currentRow().toOutputStream( CTPPS );
572 coral::Attribute
const & dipTimeAttribute = CTPPSDataCursor.currentRow()[
std::string(
"DIP_UPDATE_TIME" ) ];
573 if( !dipTimeAttribute.isNull() ) {
575 if( filter.
process( dipTime ) ){
577 coral::Attribute
const & lhcStateAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LHC_STATE" ) ];
578 if( !lhcStateAttribute.isNull() ) {
581 coral::Attribute
const & lhcCommentAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LHC_COMMENT" ) ];
582 if( !lhcCommentAttribute.isNull() ) {
583 lhcComment = lhcCommentAttribute.data<
std::string>();
585 coral::Attribute
const & ctppsStatusAttribute = CTPPSDataCursor.currentRow()[
std::string(
"CTPPS_STATUS" ) ];
586 if( !ctppsStatusAttribute.isNull() ) {
587 ctppsStatus = ctppsStatusAttribute.data<
std::string>();
589 coral::Attribute
const & lumiSectionAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LUMI_SECTION" ) ];
590 if( !lumiSectionAttribute.isNull() ) {
591 lumiSection = lumiSectionAttribute.data<
int>();
593 coral::Attribute
const & crossingAngleAttribute = CTPPSDataCursor.currentRow()[
std::string(
"XING_ANGLE_URAD" ) ];
594 if( !crossingAngleAttribute.isNull() ) {
595 crossingAngle = crossingAngleAttribute.data<
float>();
597 coral::Attribute
const & betaStarAttribute = CTPPSDataCursor.currentRow()[
std::string(
"BETA_STAR_CMS" ) ];
598 if( !betaStarAttribute.isNull() ) {
599 betastar = betaStarAttribute.data<
float>();
618 static const std::map<std::string, int>
vecMap = {{
"Beam1/beamPhaseMean",1},{
"Beam2/beamPhaseMean",2},{
"Beam1/cavPhaseMean",3},{
"Beam2/cavPhaseMean",4}};
620 unsigned int elementNr,
float value,
622 if( initList.find(since)==initList.end() ){
627 initList.insert(since);
631 switch( vecMap.at(dipVal) ){
652 const boost::posix_time::ptime& lowerTime,
653 const boost::posix_time::ptime& upperTime,
660 std::unique_ptr<coral::IQuery> ECALDataQuery( ECAL.newQuery() );
662 ECALDataQuery->addToTableList(
std::string(
"BEAM_PHASE" ) );
664 ECALDataQuery->addToOutputList(
std::string(
"CHANGE_DATE" ) );
665 ECALDataQuery->addToOutputList(
std::string(
"DIP_value" ) );
666 ECALDataQuery->addToOutputList(
std::string(
"element_nr" ) );
667 ECALDataQuery->addToOutputList(
std::string(
"VALUE_NUMBER" ) );
669 coral::AttributeList ECALDataBindVariables;
670 ECALDataBindVariables.extend<coral::TimeStamp>(
std::string(
"lowerTime" ) );
671 ECALDataBindVariables.extend<coral::TimeStamp>(
std::string(
"upperTime" ) );
672 ECALDataBindVariables[
std::string(
"lowerTime" ) ].data<coral::TimeStamp>() = coral::TimeStamp( lowerTime );
673 ECALDataBindVariables[
std::string(
"upperTime" ) ].data<coral::TimeStamp>() = coral::TimeStamp( upperTime );
675 std::string(
"(DIP_value LIKE '%beamPhaseMean%' OR DIP_value LIKE '%cavPhaseMean%') AND CHANGE_DATE >= :lowerTime AND CHANGE_DATE < :upperTime" );
677 ECALDataQuery->setCondition( conditionStr, ECALDataBindVariables );
679 ECALDataQuery->addToOrderList(
std::string(
"CHANGE_DATE" ) );
680 ECALDataQuery->addToOrderList(
std::string(
"DIP_value" ) );
681 ECALDataQuery->addToOrderList(
std::string(
"element_nr" ) );
683 coral::AttributeList ECALDataOutput;
684 ECALDataOutput.extend<coral::TimeStamp>(
std::string(
"CHANGE_DATE" ) );
686 ECALDataOutput.extend<
unsigned int>(
std::string(
"element_nr" ) );
687 ECALDataOutput.extend<
float>(
std::string(
"VALUE_NUMBER" ) );
689 ECALDataQuery->defineOutput( ECALDataOutput );
691 coral::ICursor& ECALDataCursor = ECALDataQuery->execute();
695 unsigned int elementNr = 0;
697 std::set<cond::Time_t> initializedVectors;
708 std::map<cond::Time_t,cond::Time_t> iovMap;
710 while( ECALDataCursor.next() ) {
712 std::ostringstream
ECAL;
713 ECALDataCursor.currentRow().toOutputStream( ECAL );
715 coral::Attribute
const & changeDateAttribute = ECALDataCursor.currentRow()[
std::string(
"CHANGE_DATE" ) ];
716 if( !changeDateAttribute.isNull() ) {
718 boost::posix_time::ptime chTime = changeDateAttribute.data<coral::TimeStamp>().
time();
720 if( changeTime == 0 ) {
725 if( !update and changeTime == firstTime ) iovTime = lowerLumi;
726 coral::Attribute
const & dipValAttribute = ECALDataCursor.currentRow()[
std::string(
"DIP_value" ) ];
727 coral::Attribute
const & valueNumberAttribute = ECALDataCursor.currentRow()[
std::string(
"VALUE_NUMBER" ) ];
728 coral::Attribute
const & elementNrAttribute = ECALDataCursor.currentRow()[
std::string(
"element_nr" ) ];
729 if( !dipValAttribute.isNull() and !valueNumberAttribute.isNull() ) {
731 elementNr = elementNrAttribute.data<
unsigned int>();
732 value = valueNumberAttribute.data<
float>();
733 if(
isnan( value ) ) value = 0.;
734 if( filter.
process( iovTime ) ){
735 iovMap.insert(std::make_pair( changeTime, filter.
current()->first ) );
746 for(
auto& im: iovMap ){
765 auto newPayload = std::make_shared<LHCInfo>();
766 m_to_transfer.push_back( std::make_pair( newPayload.get(), iov ) );
788 std::vector<std::shared_ptr<LHCInfo> >& payloadBuffer,
789 std::vector<std::pair<LHCInfo*,cond::Time_t> >& vecToTransfer,
790 std::shared_ptr<LHCInfo>& prevPayload ){
796 if( vecToTransfer.empty() ){
799 LHCInfo& lastAdded = *vecToTransfer.back().first;
806 vecToTransfer.push_back( std::make_pair( &payload, since ) );
807 payloadBuffer.push_back( iov.second );
808 prevPayload = iov.second;
830 <<
" ); from " <<
m_name <<
"::getNewObjects";
834 if( lastSince == 0 ){
839 <<
" valid since " << lastSince
840 <<
"from " <<
m_name <<
"::getNewObjects";
843 boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
849 if( lastSince > targetSince ) targetSince = lastSince;
867 if( !
tagInfo().lastPayloadToken.empty() ){
874 bool iovAdded =
false;
876 if( targetSince >= endIov ){
880 bool updateEcal=
false;
882 boost::posix_time::ptime startSampleTime;
883 boost::posix_time::ptime endSampleTime;
898 edm::LogInfo(
m_name ) <<
"Searching new fill after "<<boost::posix_time::to_simple_string(targetTime);
911 if( endFillTime == 0ULL ){
913 endSampleTime = executionTime;
914 targetSince = endIov;
918 targetSince = endFillTime;
922 getDipData( session, startSampleTime, endSampleTime );
923 size_t nlumi =
getLumiData( session, startSampleTime, endSampleTime );
927 edm::LogInfo(
m_name ) <<
"First lumi starts at "<<flumiStart<<
" last lumi starts at "<<flumiStop;
928 getCTTPSData( session, startSampleTime, endSampleTime );
931 getEcalData( session2, startSampleTime, endSampleTime, updateEcal );
bool operator()(const cond::Time_t &x, const std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > &y)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator end
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)
void setInstLumi(float const &instLumi)
edm::Ref< Container > Ref
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::string m_connectionString
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator currLow
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
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 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
bool getEcalData(cond::persistency::Session &session, const boost::posix_time::ptime &lowerTime, const boost::posix_time::ptime &upperTime, bool update)
cond::Time_t currentSince()
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator current()
void setDelivLumi(float const &delivLumi)
std::string const & ctppsStatus() const
std::shared_ptr< LHCInfo > m_prevPayload
Transaction & transaction()
OldContainer m_to_transfer
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)
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
cond::ValidityInterval lastInterval
std::vector< std::shared_ptr< LHCInfo > > m_payloadBuffer
unsigned long long Time_t
std::string const & lhcComment() const
boost::posix_time::ptime m_endTime
void setBetaStar(float const &betaStar)
std::vector< float > const & beam1VC() const
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
std::vector< float > const & beam2RF() const
coral::ISchema & nominalSchema()
Session createSession(const std::string &connectionString, bool writeCapable=false)
std::vector< float > const & beam1RF() const
void setLhcState(std::string const &lhcState)
void setMessageVerbosity(coral::MsgLevel level)
Time_t from_boost(boost::posix_time::ptime bt)
LumiSectionFilter(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > &samples)
void setRecLumi(float const &recLumi)
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< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator currUp
std::string lastPayloadToken
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)
float const betaStar() const
unsigned short const fillNumber() const
~LHCInfoPopConSourceHandler() override
LHCInfo & currentPayload()
std::string id() const override
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)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > m_tmpBuffer
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)
int add(value_type *payload, Summary *summary, Time_t time)
cond::TagInfo_t const & tagInfo() const
LHCInfoPopConSourceHandler(const edm::ParameterSet &pset)
std::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)