9 #include "CoralBase/Attribute.h" 10 #include "CoralBase/AttributeList.h" 11 #include "CoralBase/AttributeSpecification.h" 12 #include "CoralBase/TimeStamp.h" 17 #include "RelationalAccess/ICursor.h" 18 #include "RelationalAccess/IQuery.h" 19 #include "RelationalAccess/ISchema.h" 20 #include "RelationalAccess/ISessionProxy.h" 65 if (dipTime < upper && currentDipTime >=
currLow->first)
86 std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::const_iterator
current() {
return currLow; }
87 std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::const_iterator
currLow;
88 std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::const_iterator
currUp;
89 std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>::const_iterator
end;
111 std::shared_ptr<LHCInfoPerLS>& prevPayload) {
113 std::stringstream condIovs;
114 for (
auto& iov :
buffer) {
118 if (iovsToTransfer.empty()) {
121 LHCInfoPerLS& lastAdded = *iovsToTransfer.rbegin()->second;
128 condIovs <<
since <<
" ";
130 prevPayload = iov.second;
133 edm::LogInfo(
"transferPayloads") <<
"TRANSFERED COND IOVS: " << condIovs.str();
146 m_name(
pset.getUntrackedParameter<
std::
string>(
"name",
"LHCInfoPerLSPopConSourceHandler")),
157 boost::posix_time::ptime
now = boost::posix_time::second_clock::local_time();
176 << boost::posix_time::to_iso_extended_string(
178 <<
" ); from " <<
m_name <<
"::getNewObjects";
188 <<
m_name <<
"::getNewObjects";
191 boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
197 if (lastSince > targetSince)
198 targetSince = lastSince;
216 if (!
tagInfo().lastInterval.payloadId.empty()) {
227 query->addOutputVar(
"end_time");
229 bool foundFill =
query->execute();
234 auto endFillTime = (*
result.begin()).get<boost::posix_time::ptime>(
"end_time");
236 auto startFillTime = (*
result.begin()).get<boost::posix_time::ptime>(
"start_time");
252 if (targetSince >= executionTimeIov) {
258 boost::posix_time::ptime startSampleTime;
259 boost::posix_time::ptime endSampleTime;
269 bool foundFill =
query->execute();
278 edm::LogInfo(
m_name) <<
"Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
279 query->filterNotNull(
"start_stable_beam").filterNotNull(
"fill_number");
281 query->filterGE(
"start_time", targetTime);
283 query->filterGT(
"start_time", targetTime);
288 query->filterNotNull(
"end_time");
289 bool foundFill =
query->execute();
304 endSampleTime = executionTime;
305 targetSince = executionTimeIov;
314 getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
319 edm::LogInfo(
m_name) <<
"First buffered lumi starts at " << flumiStart <<
" last lumi starts at " 349 auto lastAdded =
m_iovs.rbegin()->second;
350 if (lastAdded->fillNumber() != 0) {
355 auto newPayload = std::make_shared<LHCInfoPerLS>();
356 m_iovs.insert(std::make_pair(iov, newPayload));
367 if (!queryResult.
empty()) {
368 auto row = *queryResult.
begin();
369 auto currentFill = row.get<
unsigned short>(
"fill_number");
372 targetPayload = std::make_unique<LHCInfoPerLS>();
373 targetPayload->setFillNumber(currentFill);
380 auto lumiTime = row.
get<boost::posix_time::ptime>(
"start_time");
386 for (
auto r : queryResult) {
389 return queryResult.size();
393 for (
auto r : queryResult) {
406 unsigned short fillId,
407 const boost::posix_time::ptime& beginFillTime,
408 const boost::posix_time::ptime& endFillTime) {
410 query->addOutputVars({
"start_time",
"run_number",
"beams_stable",
"lumisection_number"});
411 query->filterEQ(
"fill_number", fillId);
412 query->filterGT(
"start_time", beginFillTime).filterLT(
"start_time", endFillTime);
415 if (
query->execute()) {
416 auto queryResult =
query->result();
419 }
else if (!queryResult.empty()) {
420 auto newestPayload = queryResult.back();
421 if (newestPayload.get<
std::string>(
"beams_stable") ==
"true") {
425 <<
" LS: " << newestPayload.get<
std::string>(
"lumisection_number")
426 <<
" run: " << newestPayload.get<
std::string>(
"run_number");
429 edm::LogInfo(
m_name) <<
"Found " << queryResult.size() <<
" lumisections during the fill " << fillId;
431 edm::LogInfo(
m_name) <<
"OMS query for lumisections of fill " << fillId <<
"failed, status:" <<
query->status();
436 const boost::posix_time::ptime& beginFillTime,
437 const boost::posix_time::ptime& endFillTime) {
440 coral::ISchema& CTPPS = session.
coralSession().schema(
"CMS_PPS_SPECT_COND");
442 std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
444 CTPPSDataQuery->addToTableList(
std::string(
"PPS_LHC_MACHINE_PARAMS"));
446 CTPPSDataQuery->addToOutputList(
std::string(
"DIP_UPDATE_TIME"));
447 CTPPSDataQuery->addToOutputList(
std::string(
"LUMI_SECTION"));
448 CTPPSDataQuery->addToOutputList(
std::string(
"RUN_NUMBER"));
449 CTPPSDataQuery->addToOutputList(
std::string(
"XING_ANGLE_P5_X_URAD"));
450 CTPPSDataQuery->addToOutputList(
std::string(
"XING_ANGLE_P5_Y_URAD"));
451 CTPPSDataQuery->addToOutputList(
std::string(
"BETA_STAR_P5_X_M"));
452 CTPPSDataQuery->addToOutputList(
std::string(
"BETA_STAR_P5_Y_M"));
454 coral::AttributeList CTPPSDataBindVariables;
455 CTPPSDataBindVariables.extend<coral::TimeStamp>(
std::string(
"beginFillTime"));
456 CTPPSDataBindVariables.extend<coral::TimeStamp>(
std::string(
"endFillTime"));
457 CTPPSDataBindVariables[
std::string(
"beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
458 CTPPSDataBindVariables[
std::string(
"endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
459 std::string conditionStr =
std::string(
"DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
460 CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
462 CTPPSDataQuery->addToOrderList(
std::string(
"DIP_UPDATE_TIME"));
464 coral::AttributeList CTPPSDataOutput;
465 CTPPSDataOutput.extend<coral::TimeStamp>(
std::string(
"DIP_UPDATE_TIME"));
466 CTPPSDataOutput.extend<
int>(
std::string(
"LUMI_SECTION"));
467 CTPPSDataOutput.extend<
int>(
std::string(
"RUN_NUMBER"));
468 CTPPSDataOutput.extend<
float>(
std::string(
"XING_ANGLE_P5_X_URAD"));
469 CTPPSDataOutput.extend<
float>(
std::string(
"XING_ANGLE_P5_Y_URAD"));
470 CTPPSDataOutput.extend<
float>(
std::string(
"BETA_STAR_P5_X_M"));
471 CTPPSDataOutput.extend<
float>(
std::string(
"BETA_STAR_P5_Y_M"));
472 CTPPSDataQuery->defineOutput(CTPPSDataOutput);
474 coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
476 unsigned int lumiSection = 0;
478 float crossingAngleX = 0., betaStarX = 0.;
479 float crossingAngleY = 0., betaStarY = 0.;
483 while (CTPPSDataCursor.next()) {
485 std::ostringstream CTPPS;
486 CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
488 coral::Attribute
const& dipTimeAttribute = CTPPSDataCursor.currentRow()[
std::string(
"DIP_UPDATE_TIME")];
489 if (!dipTimeAttribute.isNull()) {
491 if (
filter.process(dipTime)) {
493 coral::Attribute
const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LUMI_SECTION")];
494 if (!lumiSectionAttribute.isNull()) {
495 lumiSection = lumiSectionAttribute.data<
int>();
497 coral::Attribute
const& runNumberAttribute = CTPPSDataCursor.currentRow()[
std::string(
"RUN_NUMBER")];
498 if (!runNumberAttribute.isNull()) {
499 runNumber = runNumberAttribute.data<
int>();
501 coral::Attribute
const& crossingAngleXAttribute =
502 CTPPSDataCursor.currentRow()[
std::string(
"XING_ANGLE_P5_X_URAD")];
503 if (!crossingAngleXAttribute.isNull()) {
504 crossingAngleX = crossingAngleXAttribute.data<
float>();
506 coral::Attribute
const& crossingAngleYAttribute =
507 CTPPSDataCursor.currentRow()[
std::string(
"XING_ANGLE_P5_Y_URAD")];
508 if (!crossingAngleYAttribute.isNull()) {
509 crossingAngleY = crossingAngleYAttribute.data<
float>();
511 coral::Attribute
const& betaStarXAttribute = CTPPSDataCursor.currentRow()[
std::string(
"BETA_STAR_P5_X_M")];
512 if (!betaStarXAttribute.isNull()) {
513 betaStarX = betaStarXAttribute.data<
float>();
515 coral::Attribute
const& betaStarYAttribute = CTPPSDataCursor.currentRow()[
std::string(
"BETA_STAR_P5_Y_M")];
516 if (!betaStarYAttribute.isNull()) {
517 betaStarY = betaStarYAttribute.data<
float>();
522 payload.setCrossingAngleX(crossingAngleX);
523 payload.setCrossingAngleY(crossingAngleY);
524 payload.setBetaStarX(betaStarX);
525 payload.setBetaStarY(betaStarY);
526 payload.setLumiSection(lumiSection);
554 std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerLS>>>
m_tmpBuffer;
cond::Time_t m_startFillTime
edm::ErrorSummaryEntry Error
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)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS > > > m_tmpBuffer
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
bool getCTTPSData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
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
size_t transferPayloads(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerLS >>> &buffer, std::map< cond::Time_t, std::shared_ptr< LHCInfoPerLS >> &iovsToTransfer, std::shared_ptr< LHCInfoPerLS > &prevPayload)
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::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()
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
unsigned short const fillNumber() const
float const betaStarX() const
void setAuthenticationPath(const std::string &p)
bool process(cond::Time_t dipTime)
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
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)