8 #include "CoralBase/Attribute.h" 9 #include "CoralBase/AttributeList.h" 10 #include "CoralBase/AttributeSpecification.h" 11 #include "CoralBase/TimeStamp.h" 16 #include "RelationalAccess/ICursor.h" 17 #include "RelationalAccess/IQuery.h" 18 #include "RelationalAccess/ISchema.h" 19 #include "RelationalAccess/ISessionProxy.h" 51 std::shared_ptr<LHCInfoPerLS>& prevPayload,
52 const std::map<pair<cond::Time_t, unsigned int>, pair<cond::Time_t, unsigned int>>& lsIdMap,
55 int lsMissingInPPS = 0;
56 int xAngleBothZero = 0, xAngleBothNonZero = 0, xAngleNegative = 0;
59 std::stringstream condIovs;
60 std::stringstream missingLsList;
65 if (iovsToTransfer.empty()) {
68 LHCInfoPerLS& lastAdded = *iovsToTransfer.rbegin()->second;
75 bool isMissing = lsIdMap.find(
id) != lsIdMap.end() &&
id != lsIdMap.at(
id);
77 missingLsList <<
id.first <<
"_" <<
id.second <<
" ";
78 lsMissingInPPS += isMissing;
80 if (
add && !isMissing) {
83 if (
payload->crossingAngleX() == 0 &&
payload->crossingAngleY() == 0)
85 if (
payload->crossingAngleX() != 0 &&
payload->crossingAngleY() != 0)
87 if (
payload->crossingAngleX() < 0 ||
payload->crossingAngleY() < 0)
93 condIovs <<
since <<
" ";
95 prevPayload = iov.second;
98 unsigned short fillNumber = (!
buffer.empty()) ?
buffer.front().second->fillNumber() : 0;
99 if (lsMissingInPPS > 0) {
101 <<
"Number of stable beam LS in OMS without corresponding record in PPS DB for fill " << fillNumber <<
": " 104 <<
"Stable beam LS in OMS without corresponding record in PPS DB (run_LS): " << missingLsList.str();
106 if (xAngleBothZero > 0) {
108 <<
"Number of payloads written with crossingAngle == 0 for both X and Y for fill " << fillNumber <<
": " 111 if (xAngleBothNonZero > 0) {
113 <<
"Number of payloads written with crossingAngle != 0 for both X and Y for fill " << fillNumber <<
": " 114 << xAngleBothNonZero;
116 if (xAngleNegative > 0) {
118 <<
"Number of payloads written with negative crossingAngle for fill " << fillNumber <<
": " << xAngleNegative;
120 if (betaNegative > 0) {
122 <<
"Number of payloads written with negative betaSta for fill " << fillNumber <<
": " << betaNegative;
125 edm::LogInfo(
"transferPayloads") <<
"TRANSFERED COND IOVS: " << condIovs.str();
138 m_name(
pset.getUntrackedParameter<
std::
string>(
"name",
"LHCInfoPerLSPopConSourceHandler")),
149 boost::posix_time::ptime
now = boost::posix_time::second_clock::local_time();
168 << boost::posix_time::to_iso_extended_string(
170 <<
" ); from " <<
m_name <<
"::getNewObjects";
180 <<
m_name <<
"::getNewObjects";
183 boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
189 if (lastSince > targetSince)
190 targetSince = lastSince;
208 if (!
tagInfo().lastInterval.payloadId.empty()) {
219 query->addOutputVar(
"end_time");
220 query->addOutputVar(
"start_time");
222 bool foundFill =
query->execute();
229 (endTimeStr ==
"null")
232 auto startFillTime = (*
result.begin()).get<boost::posix_time::ptime>(
"start_time");
248 if (targetSince >= executionTimeIov) {
254 boost::posix_time::ptime startSampleTime;
255 boost::posix_time::ptime endSampleTime;
265 bool foundFill =
query->execute();
274 edm::LogInfo(
m_name) <<
"Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
275 query->filterNotNull(
"start_stable_beam").filterNotNull(
"fill_number");
277 query->filterGE(
"start_time", targetTime);
279 query->filterGT(
"start_time", targetTime);
284 query->filterNotNull(
"end_time");
285 bool foundFill =
query->execute();
300 endSampleTime = executionTime;
301 targetSince = executionTimeIov;
310 getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
315 edm::LogInfo(
m_name) <<
"First buffered lumi starts at " << flumiStart <<
" last lumi starts at " 347 auto lastAdded =
m_iovs.rbegin()->second;
348 if (lastAdded->fillNumber() != 0) {
353 auto newPayload = std::make_shared<LHCInfoPerLS>();
354 m_iovs.insert(make_pair(iov, newPayload));
365 if (!queryResult.
empty()) {
366 auto row = *queryResult.
begin();
367 auto currentFill = row.get<
unsigned short>(
"fill_number");
374 targetPayload = std::make_unique<LHCInfoPerLS>();
375 targetPayload->setFillNumber(currentFill);
382 auto lumiTime = row.
get<boost::posix_time::ptime>(
"start_time");
384 thisLumiSectionInfo->setLumiSection(std::stoul(row.
get<
std::string>(
"lumisection_number")));
385 thisLumiSectionInfo->setRunNumber(std::stoull(row.
get<
std::string>(
"run_number")));
386 m_lsIdMap[make_pair(thisLumiSectionInfo->runNumber(), thisLumiSectionInfo->lumiSection())] = make_pair(-1, -1);
391 for (
auto r : queryResult) {
394 return queryResult.size();
398 for (
auto r : queryResult) {
411 unsigned short fillId,
412 const boost::posix_time::ptime& beginFillTime,
413 const boost::posix_time::ptime& endFillTime) {
415 query->addOutputVars({
"start_time",
"run_number",
"beams_stable",
"lumisection_number"});
416 query->filterEQ(
"fill_number", fillId);
417 query->filterGT(
"start_time", beginFillTime).filterLT(
"start_time", endFillTime);
420 if (
query->execute()) {
421 auto queryResult =
query->result();
424 }
else if (!queryResult.empty()) {
425 auto newestPayload = queryResult.back();
426 if (newestPayload.get<
std::string>(
"beams_stable") ==
"true") {
430 <<
" LS: " << newestPayload.get<
std::string>(
"lumisection_number")
431 <<
" run: " << newestPayload.get<
std::string>(
"run_number");
434 edm::LogInfo(
m_name) <<
"Found " << queryResult.size() <<
" lumisections during the fill " << fillId;
436 edm::LogInfo(
m_name) <<
"OMS query for lumisections of fill " << fillId <<
"failed, status:" <<
query->status();
442 const boost::posix_time::ptime& beginFillTime,
443 const boost::posix_time::ptime& endFillTime) {
446 coral::ISchema& CTPPS = session.
coralSession().schema(
"CMS_PPS_SPECT_COND");
448 std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
450 CTPPSDataQuery->addToTableList(
std::string(
"PPS_LHC_MACHINE_PARAMS"));
452 CTPPSDataQuery->addToOutputList(
std::string(
"DIP_UPDATE_TIME"));
453 CTPPSDataQuery->addToOutputList(
std::string(
"LUMI_SECTION"));
454 CTPPSDataQuery->addToOutputList(
std::string(
"RUN_NUMBER"));
455 CTPPSDataQuery->addToOutputList(
std::string(
"FILL_NUMBER"));
456 CTPPSDataQuery->addToOutputList(
std::string(
"XING_ANGLE_P5_X_URAD"));
457 CTPPSDataQuery->addToOutputList(
std::string(
"XING_ANGLE_P5_Y_URAD"));
458 CTPPSDataQuery->addToOutputList(
std::string(
"BETA_STAR_P5_X_M"));
459 CTPPSDataQuery->addToOutputList(
std::string(
"BETA_STAR_P5_Y_M"));
461 coral::AttributeList CTPPSDataBindVariables;
462 CTPPSDataBindVariables.extend<coral::TimeStamp>(
std::string(
"beginFillTime"));
463 CTPPSDataBindVariables.extend<coral::TimeStamp>(
std::string(
"endFillTime"));
464 CTPPSDataBindVariables[
std::string(
"beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
465 CTPPSDataBindVariables[
std::string(
"endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
466 std::string conditionStr =
std::string(
"DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
467 CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
469 CTPPSDataQuery->addToOrderList(
std::string(
"DIP_UPDATE_TIME"));
471 coral::AttributeList CTPPSDataOutput;
472 CTPPSDataOutput.extend<coral::TimeStamp>(
std::string(
"DIP_UPDATE_TIME"));
473 CTPPSDataOutput.extend<
int>(
std::string(
"LUMI_SECTION"));
474 CTPPSDataOutput.extend<
int>(
std::string(
"RUN_NUMBER"));
475 CTPPSDataOutput.extend<
int>(
std::string(
"FILL_NUMBER"));
476 CTPPSDataOutput.extend<
float>(
std::string(
"XING_ANGLE_P5_X_URAD"));
477 CTPPSDataOutput.extend<
float>(
std::string(
"XING_ANGLE_P5_Y_URAD"));
478 CTPPSDataOutput.extend<
float>(
std::string(
"BETA_STAR_P5_X_M"));
479 CTPPSDataOutput.extend<
float>(
std::string(
"BETA_STAR_P5_Y_M"));
480 CTPPSDataQuery->defineOutput(CTPPSDataOutput);
482 coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
483 unsigned int lumiSection = 0;
486 float crossingAngleX = 0., betaStarX = 0.;
487 float crossingAngleY = 0., betaStarY = 0.;
490 int wrongFillNumbers = 0;
491 std::stringstream wrongFills;
492 std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::iterator current =
m_tmpBuffer.begin();
493 while (CTPPSDataCursor.next()) {
495 std::ostringstream CTPPS;
496 CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
498 coral::Attribute
const& dipTimeAttribute = CTPPSDataCursor.currentRow()[
std::string(
"DIP_UPDATE_TIME")];
499 if (!dipTimeAttribute.isNull()) {
501 coral::Attribute
const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LUMI_SECTION")];
502 if (!lumiSectionAttribute.isNull()) {
503 lumiSection = lumiSectionAttribute.data<
int>();
505 coral::Attribute
const& runNumberAttribute = CTPPSDataCursor.currentRow()[
std::string(
"RUN_NUMBER")];
506 if (!runNumberAttribute.isNull()) {
507 runNumber = runNumberAttribute.data<
int>();
509 coral::Attribute
const& fillNumberAttribute = CTPPSDataCursor.currentRow()[
std::string(
"FILL_NUMBER")];
510 if (!fillNumberAttribute.isNull()) {
511 fillNumber = fillNumberAttribute.data<
int>();
513 coral::Attribute
const& crossingAngleXAttribute =
514 CTPPSDataCursor.currentRow()[
std::string(
"XING_ANGLE_P5_X_URAD")];
515 if (!crossingAngleXAttribute.isNull()) {
516 crossingAngleX = crossingAngleXAttribute.data<
float>();
518 coral::Attribute
const& crossingAngleYAttribute =
519 CTPPSDataCursor.currentRow()[
std::string(
"XING_ANGLE_P5_Y_URAD")];
520 if (!crossingAngleYAttribute.isNull()) {
521 crossingAngleY = crossingAngleYAttribute.data<
float>();
523 coral::Attribute
const& betaStarXAttribute = CTPPSDataCursor.currentRow()[
std::string(
"BETA_STAR_P5_X_M")];
524 if (!betaStarXAttribute.isNull()) {
525 betaStarX = betaStarXAttribute.data<
float>();
527 coral::Attribute
const& betaStarYAttribute = CTPPSDataCursor.currentRow()[
std::string(
"BETA_STAR_P5_Y_M")];
528 if (!betaStarYAttribute.isNull()) {
529 betaStarY = betaStarYAttribute.data<
float>();
531 if (current !=
m_tmpBuffer.end() && current->second->fillNumber() != fillNumber) {
532 wrongFills <<
"( " <<
runNumber <<
"_" << lumiSection <<
" fill: OMS: " << current->second->fillNumber()
533 <<
" PPSdb: " << fillNumber <<
" ) ";
537 current !=
m_tmpBuffer.end() && make_pair(current->second->runNumber(), current->second->lumiSection()) <=
541 payload.setCrossingAngleX(crossingAngleX);
542 payload.setCrossingAngleY(crossingAngleY);
543 payload.setBetaStarX(betaStarX);
544 payload.setBetaStarY(betaStarY);
545 payload.setLumiSection(lumiSection);
553 if (wrongFillNumbers) {
554 edm::LogWarning(
"getCTPPSData") <<
"Number of records from PPS DB with fillNumber different from OMS: " 556 edm::LogWarning(
"getCTPPSData") <<
"Records from PPS DB with fillNumber different from OMS: " << wrongFills.str();
582 std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>
m_tmpBuffer;
586 std::map<pair<cond::Time_t, unsigned int>, pair<cond::Time_t, unsigned int>>
m_lsIdMap;
cond::Time_t m_startFillTime
edm::ErrorSummaryEntry Error
size_t transferPayloads(const std::vector< pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS >>> &buffer, std::map< cond::Time_t, std::shared_ptr< LHCInfoPerLS >> &iovsToTransfer, std::shared_ptr< LHCInfoPerLS > &prevPayload, const std::map< pair< cond::Time_t, unsigned int >, pair< cond::Time_t, unsigned int >> &lsIdMap, cond::Time_t startStableBeamTime, cond::Time_t endStableBeamTime)
bool makeFillPayload(std::unique_ptr< LHCInfoPerLS > &targetPayload, const cond::OMSServiceResult &queryResult)
cond::Time_t runNumber() const
boost::posix_time::ptime m_startTime
unsigned int m_samplingInterval
void getNewObjects() override
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
T get(const std::string &attributeName)
std::shared_ptr< LHCInfoPerLS > m_prevPayload
std::string m_ecalConnectionString
ret
prodAgent to be discontinued
void start(bool readOnly=true)
std::string id() const override
~LHCInfoPerLSPopConSourceHandler() override=default
size_t bufferFirstStableBeamLS(const cond::OMSServiceResult &queryResult)
LHCInfoPerLSPopConSourceHandler(edm::ParameterSet const &pset)
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Log< level::Error, false > LogError
Transaction & transaction()
float const betaStarY() const
cond::Time_t m_prevEndFillTime
cond::TagInfo_t const & tagInfo() const
popcon::PopConAnalyzer< LHCInfoPerLSPopConSourceHandler > LHCInfoPerLSPopConAnalyzer
float const crossingAngleX() const
unsigned long long Time_t
Time_t lumiTime(unsigned int run, unsigned int lumiId)
size_t bufferAllLS(const cond::OMSServiceResult &queryResult)
cond::Time_t m_endFillTime
Session createSession(const std::string &connectionString, bool writeCapable=false)
#define DEFINE_FWK_MODULE(type)
std::string m_connectionString
void addPayloadToBuffer(cond::OMSServiceResultRef &row)
void setMessageVerbosity(coral::MsgLevel level)
Time_t from_boost(boost::posix_time::ptime bt)
float const crossingAngleY() const
Log< level::Info, false > LogInfo
std::map< pair< cond::Time_t, unsigned int >, pair< cond::Time_t, unsigned int > > m_lsIdMap
boost::posix_time::ptime m_endTime
cond::persistency::Session & dbSession() const
coral::ISessionProxy & coralSession()
cond::Time_t m_endStableBeamTime
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
std::unique_ptr< LHCInfoPerLS > m_fillPayload
static constexpr unsigned int kLumisectionsQueryLimit
void connect(const std::string &baseUrl)
void addEmptyPayload(cond::Time_t iov)
OMSServiceResultIterator begin() const
Log< level::Warning, false > LogWarning
bool getCTPPSData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
unsigned short const fillNumber() const
float const betaStarX() const
void setAuthenticationPath(const std::string &p)
cond::Time_t m_startStableBeamTime
std::vector< pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > > m_tmpBuffer
boost::posix_time::ptime to_boost(Time_t iValue)
bool comparePayloads(const LHCInfoPerLS &rhs, const LHCInfoPerLS &lhs)
cond::Time_t m_prevStartFillTime
size_t getLumiData(const cond::OMSService &oms, unsigned short fillId, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)