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" 68 if (dipTime < upper && currentDipTime >=
currLow->first)
89 std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::const_iterator
current() {
return currLow; }
90 std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::const_iterator
currLow;
91 std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::const_iterator
currUp;
92 std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::const_iterator
end;
114 std::shared_ptr<LHCInfoPerLS>& prevPayload,
115 const std::map<pair<cond::Time_t, unsigned int>, pair<cond::Time_t, unsigned int>>& lsIdMap,
118 int lsMissingInPPS = 0;
119 int xAngleBothZero = 0, xAngleBothNonZero = 0, xAngleNegative = 0;
120 int betaNegative = 0;
122 std::stringstream condIovs;
123 std::stringstream missingLsList;
124 for (
auto& iov :
buffer) {
128 if (iovsToTransfer.empty()) {
131 LHCInfoPerLS& lastAdded = *iovsToTransfer.rbegin()->second;
136 auto id = make_pair(
payload->runNumber(),
payload->lumiSection());
138 bool isMissing = lsIdMap.find(
id) != lsIdMap.end() &&
id != lsIdMap.at(
id);
140 missingLsList <<
id.first <<
"_" <<
id.second <<
" ";
141 lsMissingInPPS += isMissing;
143 if (
add && !isMissing) {
146 if (
payload->crossingAngleX() == 0 &&
payload->crossingAngleY() == 0)
148 if (
payload->crossingAngleX() != 0 &&
payload->crossingAngleY() != 0)
150 if (
payload->crossingAngleX() < 0 ||
payload->crossingAngleY() < 0)
156 condIovs <<
since <<
" ";
158 prevPayload = iov.second;
161 unsigned short fillNumber = (!
buffer.empty()) ?
buffer.front().second->fillNumber() : 0;
162 if (lsMissingInPPS > 0) {
164 <<
"Number of stable beam LS in OMS without corresponding record in PPS DB for fill " << fillNumber <<
": " 167 <<
"Stable beam LS in OMS without corresponding record in PPS DB (run_LS): " << missingLsList.str();
169 if (xAngleBothZero > 0) {
171 <<
"Number of payloads written with crossingAngle == 0 for both X and Y for fill " << fillNumber <<
": " 174 if (xAngleBothNonZero > 0) {
176 <<
"Number of payloads written with crossingAngle != 0 for both X and Y for fill " << fillNumber <<
": " 177 << xAngleBothNonZero;
179 if (xAngleNegative > 0) {
181 <<
"Number of payloads written with negative crossingAngle for fill " << fillNumber <<
": " << xAngleNegative;
183 if (betaNegative > 0) {
185 <<
"Number of payloads written with negative betaSta for fill " << fillNumber <<
": " << betaNegative;
188 edm::LogInfo(
"transferPayloads") <<
"TRANSFERED COND IOVS: " << condIovs.str();
201 m_name(
pset.getUntrackedParameter<
std::
string>(
"name",
"LHCInfoPerLSPopConSourceHandler")),
212 boost::posix_time::ptime
now = boost::posix_time::second_clock::local_time();
231 << boost::posix_time::to_iso_extended_string(
233 <<
" ); from " <<
m_name <<
"::getNewObjects";
243 <<
m_name <<
"::getNewObjects";
246 boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
252 if (lastSince > targetSince)
253 targetSince = lastSince;
271 if (!
tagInfo().lastInterval.payloadId.empty()) {
282 query->addOutputVar(
"end_time");
283 query->addOutputVar(
"start_time");
285 bool foundFill =
query->execute();
292 (endTimeStr ==
"null")
295 auto startFillTime = (*
result.begin()).get<boost::posix_time::ptime>(
"start_time");
311 if (targetSince >= executionTimeIov) {
317 boost::posix_time::ptime startSampleTime;
318 boost::posix_time::ptime endSampleTime;
328 bool foundFill =
query->execute();
337 edm::LogInfo(
m_name) <<
"Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
338 query->filterNotNull(
"start_stable_beam").filterNotNull(
"fill_number");
340 query->filterGE(
"start_time", targetTime);
342 query->filterGT(
"start_time", targetTime);
347 query->filterNotNull(
"end_time");
348 bool foundFill =
query->execute();
363 endSampleTime = executionTime;
364 targetSince = executionTimeIov;
373 getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
378 edm::LogInfo(
m_name) <<
"First buffered lumi starts at " << flumiStart <<
" last lumi starts at " 410 auto lastAdded =
m_iovs.rbegin()->second;
411 if (lastAdded->fillNumber() != 0) {
416 auto newPayload = std::make_shared<LHCInfoPerLS>();
417 m_iovs.insert(make_pair(iov, newPayload));
428 if (!queryResult.
empty()) {
429 auto row = *queryResult.
begin();
430 auto currentFill = row.get<
unsigned short>(
"fill_number");
437 targetPayload = std::make_unique<LHCInfoPerLS>();
438 targetPayload->setFillNumber(currentFill);
445 auto lumiTime = row.
get<boost::posix_time::ptime>(
"start_time");
447 thisLumiSectionInfo->setLumiSection(std::stoul(row.
get<
std::string>(
"lumisection_number")));
448 thisLumiSectionInfo->setRunNumber(std::stoull(row.
get<
std::string>(
"run_number")));
449 m_lsIdMap[make_pair(thisLumiSectionInfo->runNumber(), thisLumiSectionInfo->lumiSection())] = make_pair(-1, -1);
454 for (
auto r : queryResult) {
457 return queryResult.size();
461 for (
auto r : queryResult) {
474 unsigned short fillId,
475 const boost::posix_time::ptime& beginFillTime,
476 const boost::posix_time::ptime& endFillTime) {
478 query->addOutputVars({
"start_time",
"run_number",
"beams_stable",
"lumisection_number"});
479 query->filterEQ(
"fill_number", fillId);
480 query->filterGT(
"start_time", beginFillTime).filterLT(
"start_time", endFillTime);
483 if (
query->execute()) {
484 auto queryResult =
query->result();
487 }
else if (!queryResult.empty()) {
488 auto newestPayload = queryResult.back();
489 if (newestPayload.get<
std::string>(
"beams_stable") ==
"true") {
493 <<
" LS: " << newestPayload.get<
std::string>(
"lumisection_number")
494 <<
" run: " << newestPayload.get<
std::string>(
"run_number");
497 edm::LogInfo(
m_name) <<
"Found " << queryResult.size() <<
" lumisections during the fill " << fillId;
499 edm::LogInfo(
m_name) <<
"OMS query for lumisections of fill " << fillId <<
"failed, status:" <<
query->status();
505 const boost::posix_time::ptime& beginFillTime,
506 const boost::posix_time::ptime& endFillTime) {
509 coral::ISchema& CTPPS = session.
coralSession().schema(
"CMS_PPS_SPECT_COND");
511 std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
513 CTPPSDataQuery->addToTableList(
std::string(
"PPS_LHC_MACHINE_PARAMS"));
515 CTPPSDataQuery->addToOutputList(
std::string(
"DIP_UPDATE_TIME"));
516 CTPPSDataQuery->addToOutputList(
std::string(
"LUMI_SECTION"));
517 CTPPSDataQuery->addToOutputList(
std::string(
"RUN_NUMBER"));
518 CTPPSDataQuery->addToOutputList(
std::string(
"FILL_NUMBER"));
519 CTPPSDataQuery->addToOutputList(
std::string(
"XING_ANGLE_P5_X_URAD"));
520 CTPPSDataQuery->addToOutputList(
std::string(
"XING_ANGLE_P5_Y_URAD"));
521 CTPPSDataQuery->addToOutputList(
std::string(
"BETA_STAR_P5_X_M"));
522 CTPPSDataQuery->addToOutputList(
std::string(
"BETA_STAR_P5_Y_M"));
524 coral::AttributeList CTPPSDataBindVariables;
525 CTPPSDataBindVariables.extend<coral::TimeStamp>(
std::string(
"beginFillTime"));
526 CTPPSDataBindVariables.extend<coral::TimeStamp>(
std::string(
"endFillTime"));
527 CTPPSDataBindVariables[
std::string(
"beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
528 CTPPSDataBindVariables[
std::string(
"endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
529 std::string conditionStr =
std::string(
"DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
530 CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
532 CTPPSDataQuery->addToOrderList(
std::string(
"DIP_UPDATE_TIME"));
534 coral::AttributeList CTPPSDataOutput;
535 CTPPSDataOutput.extend<coral::TimeStamp>(
std::string(
"DIP_UPDATE_TIME"));
536 CTPPSDataOutput.extend<
int>(
std::string(
"LUMI_SECTION"));
537 CTPPSDataOutput.extend<
int>(
std::string(
"RUN_NUMBER"));
538 CTPPSDataOutput.extend<
int>(
std::string(
"FILL_NUMBER"));
539 CTPPSDataOutput.extend<
float>(
std::string(
"XING_ANGLE_P5_X_URAD"));
540 CTPPSDataOutput.extend<
float>(
std::string(
"XING_ANGLE_P5_Y_URAD"));
541 CTPPSDataOutput.extend<
float>(
std::string(
"BETA_STAR_P5_X_M"));
542 CTPPSDataOutput.extend<
float>(
std::string(
"BETA_STAR_P5_Y_M"));
543 CTPPSDataQuery->defineOutput(CTPPSDataOutput);
545 coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
546 unsigned int lumiSection = 0;
549 float crossingAngleX = 0., betaStarX = 0.;
550 float crossingAngleY = 0., betaStarY = 0.;
553 int wrongFillNumbers = 0;
554 std::stringstream wrongFills;
555 std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::iterator current =
m_tmpBuffer.begin();
556 while (CTPPSDataCursor.next()) {
558 std::ostringstream CTPPS;
559 CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
561 coral::Attribute
const& dipTimeAttribute = CTPPSDataCursor.currentRow()[
std::string(
"DIP_UPDATE_TIME")];
562 if (!dipTimeAttribute.isNull()) {
564 coral::Attribute
const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LUMI_SECTION")];
565 if (!lumiSectionAttribute.isNull()) {
566 lumiSection = lumiSectionAttribute.data<
int>();
568 coral::Attribute
const& runNumberAttribute = CTPPSDataCursor.currentRow()[
std::string(
"RUN_NUMBER")];
569 if (!runNumberAttribute.isNull()) {
570 runNumber = runNumberAttribute.data<
int>();
572 coral::Attribute
const& fillNumberAttribute = CTPPSDataCursor.currentRow()[
std::string(
"FILL_NUMBER")];
573 if (!fillNumberAttribute.isNull()) {
574 fillNumber = fillNumberAttribute.data<
int>();
576 coral::Attribute
const& crossingAngleXAttribute =
577 CTPPSDataCursor.currentRow()[
std::string(
"XING_ANGLE_P5_X_URAD")];
578 if (!crossingAngleXAttribute.isNull()) {
579 crossingAngleX = crossingAngleXAttribute.data<
float>();
581 coral::Attribute
const& crossingAngleYAttribute =
582 CTPPSDataCursor.currentRow()[
std::string(
"XING_ANGLE_P5_Y_URAD")];
583 if (!crossingAngleYAttribute.isNull()) {
584 crossingAngleY = crossingAngleYAttribute.data<
float>();
586 coral::Attribute
const& betaStarXAttribute = CTPPSDataCursor.currentRow()[
std::string(
"BETA_STAR_P5_X_M")];
587 if (!betaStarXAttribute.isNull()) {
588 betaStarX = betaStarXAttribute.data<
float>();
590 coral::Attribute
const& betaStarYAttribute = CTPPSDataCursor.currentRow()[
std::string(
"BETA_STAR_P5_Y_M")];
591 if (!betaStarYAttribute.isNull()) {
592 betaStarY = betaStarYAttribute.data<
float>();
594 if (current !=
m_tmpBuffer.end() && current->second->fillNumber() != fillNumber) {
595 wrongFills <<
"( " <<
runNumber <<
"_" << lumiSection <<
" fill: OMS: " << current->second->fillNumber()
596 <<
" PPSdb: " << fillNumber <<
" ) ";
600 current !=
m_tmpBuffer.end() && make_pair(current->second->runNumber(), current->second->lumiSection()) <=
604 payload.setCrossingAngleX(crossingAngleX);
605 payload.setCrossingAngleY(crossingAngleY);
606 payload.setBetaStarX(betaStarX);
607 payload.setBetaStarY(betaStarY);
608 payload.setLumiSection(lumiSection);
616 if (wrongFillNumbers) {
617 edm::LogWarning(
"getCTPPSData") <<
"Number of records from PPS DB with fillNumber different from OMS: " 619 edm::LogWarning(
"getCTPPSData") <<
"Records from PPS DB with fillNumber different from OMS: " << wrongFills.str();
645 std::vector<pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>
m_tmpBuffer;
649 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::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > >::const_iterator currLow
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
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
void start(bool readOnly=true)
std::string id() const override
~LHCInfoPerLSPopConSourceHandler() override=default
cond::Time_t currentSince()
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
LHCInfoPerLS & currentPayload()
LumiSectionFilter(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS >>> &samples)
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 currentDipTime
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > >::const_iterator end
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::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > >::const_iterator current()
void reset(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS >>> &samples)
std::map< pair< cond::Time_t, unsigned int >, pair< cond::Time_t, unsigned int > > m_lsIdMap
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > >::const_iterator currUp
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
bool process(cond::Time_t dipTime)
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
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)