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" 48 std::shared_ptr<LHCInfoPerLS>& prevPayload) {
50 std::stringstream condIovs;
55 if (iovsToTransfer.empty()) {
58 LHCInfoPerLS& lastAdded = *iovsToTransfer.rbegin()->second;
65 condIovs <<
since <<
" ";
67 prevPayload = iov.second;
70 edm::LogInfo(
"transferPayloads") <<
"TRANSFERED COND IOVS: " << condIovs.str();
94 boost::posix_time::ptime
now = boost::posix_time::second_clock::local_time();
113 << boost::posix_time::to_iso_extended_string(
115 <<
" ); from " <<
m_name <<
"::getNewObjects";
125 <<
m_name <<
"::getNewObjects";
128 boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
134 if (lastSince > targetSince)
135 targetSince = lastSince;
153 if (!
tagInfo().lastInterval.payloadId.empty()) {
164 query->addOutputVar(
"end_time");
166 bool foundFill =
query->execute();
171 auto endFillTime = (*
result.begin()).get<boost::posix_time::ptime>(
"end_time");
173 auto startFillTime = (*
result.begin()).get<boost::posix_time::ptime>(
"start_time");
189 if (targetSince >= executionTimeIov) {
195 boost::posix_time::ptime startSampleTime;
196 boost::posix_time::ptime endSampleTime;
206 bool foundFill =
query->execute();
215 edm::LogInfo(
m_name) <<
"Searching new fill after " << boost::posix_time::to_simple_string(targetTime);
216 query->filterNotNull(
"start_stable_beam").filterNotNull(
"fill_number");
218 query->filterGE(
"start_time", targetTime);
220 query->filterGT(
"start_time", targetTime);
225 query->filterNotNull(
"end_time");
226 bool foundFill =
query->execute();
241 endSampleTime = executionTime;
242 targetSince = executionTimeIov;
251 getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
256 edm::LogInfo(
m_name) <<
"First buffered lumi starts at " << flumiStart <<
" last lumi starts at " 286 auto lastAdded =
m_iovs.rbegin()->second;
287 if (lastAdded->fillNumber() != 0) {
292 auto newPayload = std::make_shared<LHCInfoPerLS>();
293 m_iovs.insert(std::make_pair(iov, newPayload));
304 if (!queryResult.
empty()) {
305 auto row = *queryResult.
begin();
306 auto currentFill = row.get<
unsigned short>(
"fill_number");
309 targetPayload = std::make_unique<LHCInfoPerLS>();
310 targetPayload->setFillNumber(currentFill);
317 auto lumiTime = row.
get<boost::posix_time::ptime>(
"start_time");
323 for (
auto r : queryResult) {
326 return queryResult.size();
330 for (
auto r : queryResult) {
343 unsigned short fillId,
344 const boost::posix_time::ptime& beginFillTime,
345 const boost::posix_time::ptime& endFillTime) {
347 query->addOutputVars({
"start_time",
"run_number",
"beams_stable",
"lumisection_number"});
348 query->filterEQ(
"fill_number", fillId);
349 query->filterGT(
"start_time", beginFillTime).filterLT(
"start_time", endFillTime);
352 if (
query->execute()) {
353 auto queryResult =
query->result();
356 }
else if (!queryResult.empty()) {
357 auto newestPayload = queryResult.back();
358 if (newestPayload.get<
std::string>(
"beams_stable") ==
"true") {
362 <<
" LS: " << newestPayload.get<
std::string>(
"lumisection_number")
363 <<
" run: " << newestPayload.get<
std::string>(
"run_number");
366 edm::LogInfo(
m_name) <<
"Found " << queryResult.size() <<
" lumisections during the fill " << fillId;
368 edm::LogInfo(
m_name) <<
"OMS query for lumisections of fill " << fillId <<
"failed, status:" <<
query->status();
373 const boost::posix_time::ptime& beginFillTime,
374 const boost::posix_time::ptime& endFillTime) {
377 coral::ISchema& CTPPS = session.
coralSession().schema(
"CMS_PPS_SPECT_COND");
379 std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
381 CTPPSDataQuery->addToTableList(
std::string(
"PPS_LHC_MACHINE_PARAMS"));
383 CTPPSDataQuery->addToOutputList(
std::string(
"DIP_UPDATE_TIME"));
384 CTPPSDataQuery->addToOutputList(
std::string(
"LUMI_SECTION"));
385 CTPPSDataQuery->addToOutputList(
std::string(
"RUN_NUMBER"));
386 CTPPSDataQuery->addToOutputList(
std::string(
"XING_ANGLE_P5_X_URAD"));
387 CTPPSDataQuery->addToOutputList(
std::string(
"XING_ANGLE_P5_Y_URAD"));
388 CTPPSDataQuery->addToOutputList(
std::string(
"BETA_STAR_P5_X_M"));
389 CTPPSDataQuery->addToOutputList(
std::string(
"BETA_STAR_P5_Y_M"));
391 coral::AttributeList CTPPSDataBindVariables;
392 CTPPSDataBindVariables.extend<coral::TimeStamp>(
std::string(
"beginFillTime"));
393 CTPPSDataBindVariables.extend<coral::TimeStamp>(
std::string(
"endFillTime"));
394 CTPPSDataBindVariables[
std::string(
"beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
395 CTPPSDataBindVariables[
std::string(
"endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
396 std::string conditionStr =
std::string(
"DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
397 CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
399 CTPPSDataQuery->addToOrderList(
std::string(
"DIP_UPDATE_TIME"));
401 coral::AttributeList CTPPSDataOutput;
402 CTPPSDataOutput.extend<coral::TimeStamp>(
std::string(
"DIP_UPDATE_TIME"));
403 CTPPSDataOutput.extend<
int>(
std::string(
"LUMI_SECTION"));
404 CTPPSDataOutput.extend<
int>(
std::string(
"RUN_NUMBER"));
405 CTPPSDataOutput.extend<
float>(
std::string(
"XING_ANGLE_P5_X_URAD"));
406 CTPPSDataOutput.extend<
float>(
std::string(
"XING_ANGLE_P5_Y_URAD"));
407 CTPPSDataOutput.extend<
float>(
std::string(
"BETA_STAR_P5_X_M"));
408 CTPPSDataOutput.extend<
float>(
std::string(
"BETA_STAR_P5_Y_M"));
409 CTPPSDataQuery->defineOutput(CTPPSDataOutput);
411 coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
413 unsigned int lumiSection = 0;
415 float crossingAngleX = 0., betaStarX = 0.;
416 float crossingAngleY = 0., betaStarY = 0.;
420 while (CTPPSDataCursor.next()) {
422 std::ostringstream CTPPS;
423 CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
425 coral::Attribute
const& dipTimeAttribute = CTPPSDataCursor.currentRow()[
std::string(
"DIP_UPDATE_TIME")];
426 if (!dipTimeAttribute.isNull()) {
428 if (
filter.process(dipTime)) {
430 coral::Attribute
const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[
std::string(
"LUMI_SECTION")];
431 if (!lumiSectionAttribute.isNull()) {
432 lumiSection = lumiSectionAttribute.data<
int>();
434 coral::Attribute
const& runNumberAttribute = CTPPSDataCursor.currentRow()[
std::string(
"RUN_NUMBER")];
435 if (!runNumberAttribute.isNull()) {
436 runNumber = runNumberAttribute.data<
int>();
438 coral::Attribute
const& crossingAngleXAttribute =
439 CTPPSDataCursor.currentRow()[
std::string(
"XING_ANGLE_P5_X_URAD")];
440 if (!crossingAngleXAttribute.isNull()) {
441 crossingAngleX = crossingAngleXAttribute.data<
float>();
443 coral::Attribute
const& crossingAngleYAttribute =
444 CTPPSDataCursor.currentRow()[
std::string(
"XING_ANGLE_P5_Y_URAD")];
445 if (!crossingAngleYAttribute.isNull()) {
446 crossingAngleY = crossingAngleYAttribute.data<
float>();
448 coral::Attribute
const& betaStarXAttribute = CTPPSDataCursor.currentRow()[
std::string(
"BETA_STAR_P5_X_M")];
449 if (!betaStarXAttribute.isNull()) {
450 betaStarX = betaStarXAttribute.data<
float>();
452 coral::Attribute
const& betaStarYAttribute = CTPPSDataCursor.currentRow()[
std::string(
"BETA_STAR_P5_Y_M")];
453 if (!betaStarYAttribute.isNull()) {
454 betaStarY = betaStarYAttribute.data<
float>();
459 payload.setCrossingAngleX(crossingAngleX);
460 payload.setCrossingAngleY(crossingAngleY);
461 payload.setBetaStarX(betaStarX);
462 payload.setBetaStarY(betaStarY);
463 payload.setLumiSection(lumiSection);
491 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::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)
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
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 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
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)
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)