Skip to content

Commit 8922daa

Browse files
authored
Merge pull request cms-sw#42629 from CTPPS/jc_LHCInfoPerLS_PopCon_IOV_misalignment_fix
Fix LHCInfoPerLS PopCon incorrectly matching LS between OMS and PPS db
2 parents 2c973b1 + dbe2cd1 commit 8922daa

File tree

6 files changed

+168
-62
lines changed

6 files changed

+168
-62
lines changed

CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LHCInfoPopConSourceHandler : public popcon::PopConSourceHandler<LHCInfo> {
3030
void getDipData(const cond::OMSService& service,
3131
const boost::posix_time::ptime& beginFillTime,
3232
const boost::posix_time::ptime& endFillTime);
33-
bool getCTTPSData(cond::persistency::Session& session,
33+
bool getCTPPSData(cond::persistency::Session& session,
3434
const boost::posix_time::ptime& beginFillTime,
3535
const boost::posix_time::ptime& endFillTime);
3636
bool getEcalData(cond::persistency::Session& session,

CondTools/RunInfo/plugins/LHCInfoPerFillPopConAnalyzer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
354354
boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
355355
edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop;
356356
session.transaction().start(true);
357-
getCTTPSData(session, startSampleTime, endSampleTime);
357+
getCTPPSData(session, startSampleTime, endSampleTime);
358358
session.transaction().commit();
359359
session2.transaction().start(true);
360360
getEcalData(session2, startSampleTime, endSampleTime, updateEcal);
@@ -497,7 +497,7 @@ class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHC
497497
}
498498
}
499499

500-
bool getCTTPSData(cond::persistency::Session& session,
500+
bool getCTPPSData(cond::persistency::Session& session,
501501
const boost::posix_time::ptime& beginFillTime,
502502
const boost::posix_time::ptime& endFillTime) {
503503
//run the fifth query against the CTPPS schema

CondTools/RunInfo/plugins/LHCInfoPerLSPopConAnalyzer.cc

Lines changed: 138 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
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"
@@ -20,13 +19,17 @@
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+
3033
class LHCInfoPerLSPopConSourceHandler;
3134

3235
typedef 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
};

CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void LHCInfoPopConSourceHandler::getDipData(const cond::OMSService& oms,
240240
}
241241
}
242242

243-
bool LHCInfoPopConSourceHandler::getCTTPSData(cond::persistency::Session& session,
243+
bool LHCInfoPopConSourceHandler::getCTPPSData(cond::persistency::Session& session,
244244
const boost::posix_time::ptime& beginFillTime,
245245
const boost::posix_time::ptime& endFillTime) {
246246
//run the fifth query against the CTPPS schema
@@ -665,7 +665,7 @@ void LHCInfoPopConSourceHandler::getNewObjects() {
665665
boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
666666
edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop;
667667
session.transaction().start(true);
668-
getCTTPSData(session, startSampleTime, endSampleTime);
668+
getCTPPSData(session, startSampleTime, endSampleTime);
669669
session.transaction().commit();
670670
session2.transaction().start(true);
671671
getEcalData(session2, startSampleTime, endSampleTime, updateEcal);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
LOG_FILE=$1
2+
echo "Number of invalid payloads found in the logs"
3+
for CONDITION in "crossingAngle == 0 for both X and Y" "crossingAngle != 0 for both X and Y" \
4+
"negative crossingAngle: " "negative betaStar" "Number of records from PPS DB with fillNumber different from OMS" \
5+
"Number of stable beam LS in OMS without corresponding record in PPS DB" ; do
6+
echo -n "$CONDITION: max in one fill: "
7+
(cat $LOG_FILE | grep -E "$CONDITION" | awk '{print $NF}' ; echo 0) | sort -gr | head -n 1
8+
echo -n "$CONDITION: total: "
9+
(cat $LOG_FILE | grep -E "$CONDITION" | awk '{print $NF}'; echo 0) | paste -sd+ | bc
10+
done

0 commit comments

Comments
 (0)