44#include " CondCore/PopCon/interface/PopConSourceHandler.h"
55#include " CondFormats/Common/interface/TimeConversions.h"
66#include " CondFormats/RunInfo/interface/LHCInfoPerLS.h"
7- #include " CondTools/RunInfo/interface/LumiSectionFilter.h"
87#include " CondTools/RunInfo/interface/OMSAccess.h"
98#include " CoralBase/Attribute.h"
109#include " CoralBase/AttributeList.h"
2019#include " RelationalAccess/ISessionProxy.h"
2120#include < cmath>
2221#include < iostream>
22+ #include < map>
2323#include < memory>
2424#include < sstream>
2525#include < sstream>
2626#include < string>
2727#include < utility>
2828#include < vector>
2929
30+ using std::make_pair;
31+ using std::pair;
32+
3033class LHCInfoPerLSPopConSourceHandler ;
3134
3235typedef popcon::PopConAnalyzer<LHCInfoPerLSPopConSourceHandler> LHCInfoPerLSPopConAnalyzer;
@@ -43,11 +46,18 @@ namespace theLHCInfoPerLSImpl {
4346 return true ;
4447 }
4548
46- size_t transferPayloads (const std::vector<std:: pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>& buffer,
49+ size_t transferPayloads (const std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>& buffer,
4750 std::map<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>& iovsToTransfer,
48- std::shared_ptr<LHCInfoPerLS>& prevPayload) {
51+ std::shared_ptr<LHCInfoPerLS>& prevPayload,
52+ const std::map<pair<cond::Time_t, unsigned int >, pair<cond::Time_t, unsigned int >>& lsIdMap,
53+ cond::Time_t startStableBeamTime,
54+ cond::Time_t endStableBeamTime) {
55+ int lsMissingInPPS = 0 ;
56+ int xAngleBothZero = 0 , xAngleBothNonZero = 0 , xAngleNegative = 0 ;
57+ int betaNegative = 0 ;
4958 size_t niovs = 0 ;
5059 std::stringstream condIovs;
60+ std::stringstream missingLsList;
5161 for (auto & iov : buffer) {
5262 bool add = false ;
5363 auto payload = iov.second ;
@@ -60,13 +70,58 @@ namespace theLHCInfoPerLSImpl {
6070 add = true ;
6171 }
6272 }
63- if (add) {
73+ auto id = make_pair (payload->runNumber (), payload->lumiSection ());
74+ bool stableBeam = since >= startStableBeamTime && since <= endStableBeamTime;
75+ bool isMissing = lsIdMap.find (id) != lsIdMap.end () && id != lsIdMap.at (id);
76+ if (stableBeam && isMissing) {
77+ missingLsList << id.first << " _" << id.second << " " ;
78+ lsMissingInPPS += isMissing;
79+ }
80+ if (add && !isMissing) {
6481 niovs++;
82+ if (stableBeam) {
83+ if (payload->crossingAngleX () == 0 && payload->crossingAngleY () == 0 )
84+ xAngleBothZero++;
85+ if (payload->crossingAngleX () != 0 && payload->crossingAngleY () != 0 )
86+ xAngleBothNonZero++;
87+ if (payload->crossingAngleX () < 0 || payload->crossingAngleY () < 0 )
88+ xAngleNegative++;
89+ if (payload->betaStarX () < 0 || payload->betaStarY () < 0 )
90+ betaNegative++;
91+ }
92+
6593 condIovs << since << " " ;
66- iovsToTransfer.insert (std:: make_pair (since, payload));
94+ iovsToTransfer.insert (make_pair (since, payload));
6795 prevPayload = iov.second ;
6896 }
6997 }
98+ unsigned short fillNumber = (!buffer.empty ()) ? buffer.front ().second ->fillNumber () : 0 ;
99+ if (lsMissingInPPS > 0 ) {
100+ edm::LogWarning (" transferPayloads" )
101+ << " Number of stable beam LS in OMS without corresponding record in PPS DB for fill " << fillNumber << " : "
102+ << lsMissingInPPS;
103+ edm::LogWarning (" transferPayloads" )
104+ << " Stable beam LS in OMS without corresponding record in PPS DB (run_LS): " << missingLsList.str ();
105+ }
106+ if (xAngleBothZero > 0 ) {
107+ edm::LogWarning (" transferPayloads" )
108+ << " Number of payloads written with crossingAngle == 0 for both X and Y for fill " << fillNumber << " : "
109+ << xAngleBothZero;
110+ }
111+ if (xAngleBothNonZero > 0 ) {
112+ edm::LogWarning (" transferPayloads" )
113+ << " Number of payloads written with crossingAngle != 0 for both X and Y for fill " << fillNumber << " : "
114+ << xAngleBothNonZero;
115+ }
116+ if (xAngleNegative > 0 ) {
117+ edm::LogWarning (" transferPayloads" )
118+ << " Number of payloads written with negative crossingAngle for fill " << fillNumber << " : " << xAngleNegative;
119+ }
120+ if (betaNegative > 0 ) {
121+ edm::LogWarning (" transferPayloads" )
122+ << " Number of payloads written with negative betaSta for fill " << fillNumber << " : " << betaNegative;
123+ }
124+
70125 edm::LogInfo (" transferPayloads" ) << " TRANSFERED COND IOVS: " << condIovs.str ();
71126 return niovs;
72127 }
@@ -256,18 +311,20 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
256311 edm::LogInfo (m_name) << " First buffered lumi starts at " << flumiStart << " last lumi starts at "
257312 << flumiStop;
258313 session.transaction ().start (true );
259- getCTTPSData (session, startSampleTime, endSampleTime);
314+ getCTPPSData (session, startSampleTime, endSampleTime);
260315 session.transaction ().commit ();
261316 }
262317 }
263318
264- size_t niovs = theLHCInfoPerLSImpl::transferPayloads (m_tmpBuffer, m_iovs, m_prevPayload);
319+ size_t niovs = theLHCInfoPerLSImpl::transferPayloads (
320+ m_tmpBuffer, m_iovs, m_prevPayload, m_lsIdMap, m_startStableBeamTime, m_endStableBeamTime);
265321 edm::LogInfo (m_name) << " Added " << niovs << " iovs within the Fill time" ;
266322 if (niovs) {
267323 m_prevEndFillTime = m_endFillTime;
268324 m_prevStartFillTime = m_startFillTime;
269325 }
270326 m_tmpBuffer.clear ();
327+ m_lsIdMap.clear ();
271328 if (m_prevPayload->fillNumber () and !ongoingFill)
272329 addEmptyPayload (m_endFillTime);
273330 }
@@ -290,7 +347,7 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
290347 }
291348 if (add) {
292349 auto newPayload = std::make_shared<LHCInfoPerLS>();
293- m_iovs.insert (std:: make_pair (iov, newPayload));
350+ m_iovs.insert (make_pair (iov, newPayload));
294351 m_prevPayload = newPayload;
295352 m_prevEndFillTime = 0 ;
296353 m_prevStartFillTime = 0 ;
@@ -306,6 +363,8 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
306363 auto currentFill = row.get <unsigned short >(" fill_number" );
307364 m_startFillTime = cond::time::from_boost (row.get <boost::posix_time::ptime>(" start_time" ));
308365 m_endFillTime = cond::time::from_boost (row.get <boost::posix_time::ptime>(" end_time" ));
366+ m_startStableBeamTime = cond::time::from_boost (row.get <boost::posix_time::ptime>(" start_stable_beam" ));
367+ m_endStableBeamTime = cond::time::from_boost (row.get <boost::posix_time::ptime>(" end_stable_beam" ));
309368 targetPayload = std::make_unique<LHCInfoPerLS>();
310369 targetPayload->setFillNumber (currentFill);
311370 ret = true ;
@@ -316,7 +375,10 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
316375 void addPayloadToBuffer (cond::OMSServiceResultRef& row) {
317376 auto lumiTime = row.get <boost::posix_time::ptime>(" start_time" );
318377 LHCInfoPerLS* thisLumiSectionInfo = new LHCInfoPerLS (*m_fillPayload);
319- m_tmpBuffer.emplace_back (std::make_pair (cond::time::from_boost (lumiTime), thisLumiSectionInfo));
378+ thisLumiSectionInfo->setLumiSection (std::stoul (row.get <std::string>(" lumisection_number" )));
379+ thisLumiSectionInfo->setRunNumber (std::stoull (row.get <std::string>(" run_number" )));
380+ m_lsIdMap[make_pair (thisLumiSectionInfo->runNumber (), thisLumiSectionInfo->lumiSection ())] = make_pair (-1 , -1 );
381+ m_tmpBuffer.emplace_back (make_pair (cond::time::from_boost (lumiTime), thisLumiSectionInfo));
320382 }
321383
322384 size_t bufferAllLS (const cond::OMSServiceResult& queryResult) {
@@ -369,7 +431,7 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
369431 }
370432 return nlumi;
371433 }
372- bool getCTTPSData (cond::persistency::Session& session,
434+ bool getCTPPSData (cond::persistency::Session& session,
373435 const boost::posix_time::ptime& beginFillTime,
374436 const boost::posix_time::ptime& endFillTime) {
375437 // run the fifth query against the CTPPS schema
@@ -383,6 +445,7 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
383445 CTPPSDataQuery->addToOutputList (std::string (" DIP_UPDATE_TIME" ));
384446 CTPPSDataQuery->addToOutputList (std::string (" LUMI_SECTION" ));
385447 CTPPSDataQuery->addToOutputList (std::string (" RUN_NUMBER" ));
448+ CTPPSDataQuery->addToOutputList (std::string (" FILL_NUMBER" ));
386449 CTPPSDataQuery->addToOutputList (std::string (" XING_ANGLE_P5_X_URAD" ));
387450 CTPPSDataQuery->addToOutputList (std::string (" XING_ANGLE_P5_Y_URAD" ));
388451 CTPPSDataQuery->addToOutputList (std::string (" BETA_STAR_P5_X_M" ));
@@ -402,70 +465,89 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
402465 CTPPSDataOutput.extend <coral::TimeStamp>(std::string (" DIP_UPDATE_TIME" ));
403466 CTPPSDataOutput.extend <int >(std::string (" LUMI_SECTION" ));
404467 CTPPSDataOutput.extend <int >(std::string (" RUN_NUMBER" ));
468+ CTPPSDataOutput.extend <int >(std::string (" FILL_NUMBER" ));
405469 CTPPSDataOutput.extend <float >(std::string (" XING_ANGLE_P5_X_URAD" ));
406470 CTPPSDataOutput.extend <float >(std::string (" XING_ANGLE_P5_Y_URAD" ));
407471 CTPPSDataOutput.extend <float >(std::string (" BETA_STAR_P5_X_M" ));
408472 CTPPSDataOutput.extend <float >(std::string (" BETA_STAR_P5_Y_M" ));
409473 CTPPSDataQuery->defineOutput (CTPPSDataOutput);
410474 // execute the query
411475 coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute ();
412- cond::Time_t dipTime = 0 ;
413476 unsigned int lumiSection = 0 ;
414477 cond::Time_t runNumber = 0 ;
478+ int fillNumber = 0 ;
415479 float crossingAngleX = 0 ., betaStarX = 0 .;
416480 float crossingAngleY = 0 ., betaStarY = 0 .;
417481
418482 bool ret = false ;
419- LumiSectionFilter<LHCInfoPerLS> filter (m_tmpBuffer);
483+ int wrongFillNumbers = 0 ;
484+ std::stringstream wrongFills;
485+ std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::iterator current = m_tmpBuffer.begin ();
420486 while (CTPPSDataCursor.next ()) {
421487 if (m_debug) {
422488 std::ostringstream CTPPS;
423489 CTPPSDataCursor.currentRow ().toOutputStream (CTPPS);
424490 }
425491 coral::Attribute const & dipTimeAttribute = CTPPSDataCursor.currentRow ()[std::string (" DIP_UPDATE_TIME" )];
426492 if (!dipTimeAttribute.isNull ()) {
427- dipTime = cond::time::from_boost (dipTimeAttribute.data <coral::TimeStamp>().time ());
428- if (filter.process (dipTime)) {
429- ret = true ;
430- coral::Attribute const & lumiSectionAttribute = CTPPSDataCursor.currentRow ()[std::string (" LUMI_SECTION" )];
431- if (!lumiSectionAttribute.isNull ()) {
432- lumiSection = lumiSectionAttribute.data <int >();
433- }
434- coral::Attribute const & runNumberAttribute = CTPPSDataCursor.currentRow ()[std::string (" RUN_NUMBER" )];
435- if (!runNumberAttribute.isNull ()) {
436- runNumber = runNumberAttribute.data <int >();
437- }
438- coral::Attribute const & crossingAngleXAttribute =
439- CTPPSDataCursor.currentRow ()[std::string (" XING_ANGLE_P5_X_URAD" )];
440- if (!crossingAngleXAttribute.isNull ()) {
441- crossingAngleX = crossingAngleXAttribute.data <float >();
442- }
443- coral::Attribute const & crossingAngleYAttribute =
444- CTPPSDataCursor.currentRow ()[std::string (" XING_ANGLE_P5_Y_URAD" )];
445- if (!crossingAngleYAttribute.isNull ()) {
446- crossingAngleY = crossingAngleYAttribute.data <float >();
447- }
448- coral::Attribute const & betaStarXAttribute = CTPPSDataCursor.currentRow ()[std::string (" BETA_STAR_P5_X_M" )];
449- if (!betaStarXAttribute.isNull ()) {
450- betaStarX = betaStarXAttribute.data <float >();
451- }
452- coral::Attribute const & betaStarYAttribute = CTPPSDataCursor.currentRow ()[std::string (" BETA_STAR_P5_Y_M" )];
453- if (!betaStarYAttribute.isNull ()) {
454- betaStarY = betaStarYAttribute.data <float >();
455- }
456- for (auto it = filter.current (); it != m_tmpBuffer.end (); it++) {
457- // set the current values to all of the payloads of the lumi section samples after the current since
458- LHCInfoPerLS& payload = *(it->second );
459- payload.setCrossingAngleX (crossingAngleX);
460- payload.setCrossingAngleY (crossingAngleY);
461- payload.setBetaStarX (betaStarX);
462- payload.setBetaStarY (betaStarY);
463- payload.setLumiSection (lumiSection);
464- payload.setRunNumber (runNumber);
493+ ret = true ;
494+ coral::Attribute const & lumiSectionAttribute = CTPPSDataCursor.currentRow ()[std::string (" LUMI_SECTION" )];
495+ if (!lumiSectionAttribute.isNull ()) {
496+ lumiSection = lumiSectionAttribute.data <int >();
497+ }
498+ coral::Attribute const & runNumberAttribute = CTPPSDataCursor.currentRow ()[std::string (" RUN_NUMBER" )];
499+ if (!runNumberAttribute.isNull ()) {
500+ runNumber = runNumberAttribute.data <int >();
501+ }
502+ coral::Attribute const & fillNumberAttribute = CTPPSDataCursor.currentRow ()[std::string (" FILL_NUMBER" )];
503+ if (!fillNumberAttribute.isNull ()) {
504+ fillNumber = fillNumberAttribute.data <int >();
505+ }
506+ coral::Attribute const & crossingAngleXAttribute =
507+ CTPPSDataCursor.currentRow ()[std::string (" XING_ANGLE_P5_X_URAD" )];
508+ if (!crossingAngleXAttribute.isNull ()) {
509+ crossingAngleX = crossingAngleXAttribute.data <float >();
510+ }
511+ coral::Attribute const & crossingAngleYAttribute =
512+ CTPPSDataCursor.currentRow ()[std::string (" XING_ANGLE_P5_Y_URAD" )];
513+ if (!crossingAngleYAttribute.isNull ()) {
514+ crossingAngleY = crossingAngleYAttribute.data <float >();
515+ }
516+ coral::Attribute const & betaStarXAttribute = CTPPSDataCursor.currentRow ()[std::string (" BETA_STAR_P5_X_M" )];
517+ if (!betaStarXAttribute.isNull ()) {
518+ betaStarX = betaStarXAttribute.data <float >();
519+ }
520+ coral::Attribute const & betaStarYAttribute = CTPPSDataCursor.currentRow ()[std::string (" BETA_STAR_P5_Y_M" )];
521+ if (!betaStarYAttribute.isNull ()) {
522+ betaStarY = betaStarYAttribute.data <float >();
523+ }
524+ if (current != m_tmpBuffer.end () && current->second ->fillNumber () != fillNumber) {
525+ wrongFills << " ( " << runNumber << " _" << lumiSection << " fill: OMS: " << current->second ->fillNumber ()
526+ << " PPSdb: " << fillNumber << " ) " ;
527+ wrongFillNumbers++;
528+ }
529+ for (;
530+ current != m_tmpBuffer.end () && make_pair (current->second ->runNumber (), current->second ->lumiSection ()) <=
531+ make_pair (runNumber, lumiSection);
532+ current++) {
533+ LHCInfoPerLS& payload = *(current->second );
534+ payload.setCrossingAngleX (crossingAngleX);
535+ payload.setCrossingAngleY (crossingAngleY);
536+ payload.setBetaStarX (betaStarX);
537+ payload.setBetaStarY (betaStarY);
538+ payload.setLumiSection (lumiSection);
539+ payload.setRunNumber (runNumber);
540+ if (m_lsIdMap.find (make_pair (payload.runNumber (), payload.lumiSection ())) != m_lsIdMap.end ()) {
541+ m_lsIdMap[make_pair (payload.runNumber (), payload.lumiSection ())] = make_pair (runNumber, lumiSection);
465542 }
466543 }
467544 }
468545 }
546+ if (wrongFillNumbers) {
547+ edm::LogWarning (" getCTPPSData" ) << " Number of records from PPS DB with fillNumber different from OMS: "
548+ << wrongFillNumbers;
549+ edm::LogWarning (" getCTPPSData" ) << " Records from PPS DB with fillNumber different from OMS: " << wrongFills.str ();
550+ }
469551 return ret;
470552 }
471553
@@ -488,6 +570,11 @@ class LHCInfoPerLSPopConSourceHandler : public popcon::PopConSourceHandler<LHCIn
488570 cond::Time_t m_endFillTime;
489571 cond::Time_t m_prevEndFillTime;
490572 cond::Time_t m_prevStartFillTime;
491- std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>> m_tmpBuffer;
573+ cond::Time_t m_startStableBeamTime;
574+ cond::Time_t m_endStableBeamTime;
575+ std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>> m_tmpBuffer;
492576 bool m_lastPayloadEmpty = false ;
577+ // mapping of lumisections IDs (pairs of runnumber an LS number) found in OMS to the IDs they've been assignd from PPS DB
578+ // value pair(-1, -1) means lumisection corresponding to the key exists in OMS but no lumisection was matched from PPS
579+ std::map<pair<cond::Time_t, unsigned int >, pair<cond::Time_t, unsigned int >> m_lsIdMap;
493580};
0 commit comments