From 7ea27bd777c21de3acc68bcdc36bbc8c6a384087 Mon Sep 17 00:00:00 2001 From: Giacomo Govi Date: Mon, 14 Feb 2022 13:45:47 +0100 Subject: [PATCH 1/6] Added Util class for data access on web services --- CondCore/CondDB/BuildFile.xml | 1 + CondCore/CondDB/interface/Types.h | 2 +- CondCore/CondDB/interface/WebUtils.h | 12 +++++++ CondCore/CondDB/src/WebUtils.cc | 49 ++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 CondCore/CondDB/interface/WebUtils.h create mode 100644 CondCore/CondDB/src/WebUtils.cc diff --git a/CondCore/CondDB/BuildFile.xml b/CondCore/CondDB/BuildFile.xml index 5f7f052938bde..0ac44e083e398 100644 --- a/CondCore/CondDB/BuildFile.xml +++ b/CondCore/CondDB/BuildFile.xml @@ -3,6 +3,7 @@ + diff --git a/CondCore/CondDB/interface/Types.h b/CondCore/CondDB/interface/Types.h index ac597f32509e9..f544e9c8472b0 100644 --- a/CondCore/CondDB/interface/Types.h +++ b/CondCore/CondDB/interface/Types.h @@ -72,7 +72,7 @@ namespace cond { std::string name; Iov_t lastInterval; size_t size = 0; - bool isEmpty() const { return lastInterval.since != time::MAX_VAL; } + bool isEmpty() const { return lastInterval.since == time::MAX_VAL; } }; struct TagMetadata_t { diff --git a/CondCore/CondDB/interface/WebUtils.h b/CondCore/CondDB/interface/WebUtils.h new file mode 100644 index 0000000000000..e3423d8093a58 --- /dev/null +++ b/CondCore/CondDB/interface/WebUtils.h @@ -0,0 +1,12 @@ +#ifndef CondCore_CondDB_WebUtils_h +#define CondCore_CondDB_WebUtils_h + +#include + +namespace cond { + + unsigned long httpGet(const std::string& urlString, std::string& info); + +} + +#endif diff --git a/CondCore/CondDB/src/WebUtils.cc b/CondCore/CondDB/src/WebUtils.cc new file mode 100644 index 0000000000000..90c36f1ea75e5 --- /dev/null +++ b/CondCore/CondDB/src/WebUtils.cc @@ -0,0 +1,49 @@ +#include "CondCore/CondDB/interface/WebUtils.h" +// +#include +#include +#include + +namespace cond { + + // + static size_t getBodyCallback(void* contents, size_t size, size_t nmemb, void* ptr) { + // Cast ptr to std::string pointer and append contents to that string + ((std::string*)ptr)->append((char*)contents, size * nmemb); + return size * nmemb; + } + + unsigned long httpGet(const std::string& urlString, std::string& info) { + CURL* curl; + CURLcode res; + std::string body; + char errbuf[CURL_ERROR_SIZE]; + + curl = curl_easy_init(); + unsigned long ret = false; + if (curl) { + struct curl_slist* chunk = nullptr; + chunk = curl_slist_append(chunk, "content-type:application/json"); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); + curl_easy_setopt(curl, CURLOPT_URL, urlString.c_str()); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, getBodyCallback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &body); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); + res = curl_easy_perform(curl); + curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &ret); + if (CURLE_OK == res) { + info = body; + } else { + size_t len = strlen(errbuf); + fprintf(stderr, "\nlibcurl: (%d) ", res); + if (len) + fprintf(stderr, "%s%s", errbuf, ((errbuf[len - 1] != '\n') ? "\n" : "")); + else + fprintf(stderr, "%s\n", curl_easy_strerror(res)); + } + curl_easy_cleanup(curl); + } + return ret; + } + +} From fa4a518026ae6903f34302de19ad00893a147fac Mon Sep 17 00:00:00 2001 From: Giacomo Govi Date: Mon, 14 Feb 2022 13:47:21 +0100 Subject: [PATCH 2/6] Expanded LHCInfo type to host new versions of Xing_angle and BetaStar params --- CondFormats/RunInfo/interface/LHCInfo.h | 18 +++++++++++++++++- CondFormats/RunInfo/src/LHCInfo.cc | 12 ++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CondFormats/RunInfo/interface/LHCInfo.h b/CondFormats/RunInfo/interface/LHCInfo.h index 0589d1e627069..7ce07704c6072 100644 --- a/CondFormats/RunInfo/interface/LHCInfo.h +++ b/CondFormats/RunInfo/interface/LHCInfo.h @@ -41,7 +41,11 @@ class LHCInfo { BEAM2_RF = 12, INST_LUMI = 13, INST_LUMI_ERR = 14, - FSIZE = 15 + XING_ANGLE_P5_X = 15, + XING_ANGLE_P5_Y = 16, + BETA_STAR_P5_X = 17, + BETA_STAR_P5_Y = 18, + FSIZE = 19 }; enum TimeParamIndex { CREATE_TIME = 0, BEGIN_TIME = 1, END_TIME = 2, TSIZE = 3 }; enum StringParamIndex { INJECTION_SCHEME = 0, LHC_STATE = 1, LHC_COMMENT = 2, CTPPS_STATUS = 3, SSIZE = 4 }; @@ -97,6 +101,12 @@ class LHCInfo { float const instLumiError() const; + float const xingAngleP5X() const; + float const xingAngleP5Y() const; + + float const betaStarP5X() const; + float const betaStarP5Y() const; + cond::Time_t const createTime() const; cond::Time_t const beginTime() const; @@ -164,6 +174,12 @@ class LHCInfo { void setBetaStar(float const& betaStar); + void setXingAngleP5X(float const& angle); + void setXingAngleP5Y(float const& angle); + + void setBetaStarP5X(float const& betaStar); + void setBetaStarP5Y(float const& betaStar); + void setIntensityForBeam1(float const& intensity); void setIntensityForBeam2(float const& intensity); diff --git a/CondFormats/RunInfo/src/LHCInfo.cc b/CondFormats/RunInfo/src/LHCInfo.cc index 59173a633b1ab..ca3659dad3264 100644 --- a/CondFormats/RunInfo/src/LHCInfo.cc +++ b/CondFormats/RunInfo/src/LHCInfo.cc @@ -183,6 +183,12 @@ float const LHCInfo::crossingAngle() const { return LHCInfoImpl::getOneParam(m_f float const LHCInfo::betaStar() const { return LHCInfoImpl::getOneParam(m_floatParams, BETA_STAR); } +float const LHCInfo::xingAngleP5X() const { return LHCInfoImpl::getOneParam(m_floatParams, XING_ANGLE_P5_X); } +float const LHCInfo::xingAngleP5Y() const { return LHCInfoImpl::getOneParam(m_floatParams, XING_ANGLE_P5_Y); } + +float const LHCInfo::betaStarP5X() const { return LHCInfoImpl::getOneParam(m_floatParams, BETA_STAR_P5_X); } +float const LHCInfo::betaStarP5Y() const { return LHCInfoImpl::getOneParam(m_floatParams, BETA_STAR_P5_Y); } + float const LHCInfo::intensityForBeam1() const { return LHCInfoImpl::getOneParam(m_floatParams, INTENSITY_1); } float const LHCInfo::intensityForBeam2() const { return LHCInfoImpl::getOneParam(m_floatParams, INTENSITY_2); } @@ -299,6 +305,12 @@ void LHCInfo::setCrossingAngle(float const& angle) { LHCInfoImpl::setOneParam(m_ void LHCInfo::setBetaStar(float const& betaStar) { LHCInfoImpl::setOneParam(m_floatParams, BETA_STAR, betaStar); } +void LHCInfo::setXingAngleP5X(float const& angle) { LHCInfoImpl::setOneParam(m_floatParams, XING_ANGLE_P5_X, angle); } +void LHCInfo::setXingAngleP5Y(float const& angle) { LHCInfoImpl::setOneParam(m_floatParams, XING_ANGLE_P5_Y, angle); } + +void LHCInfo::setBetaStarP5X(float const& betaStar){ LHCInfoImpl::setOneParam(m_floatParams, BETA_STAR_P5_X, betaStar); } +void LHCInfo::setBetaStarP5Y(float const& betaStar){ LHCInfoImpl::setOneParam(m_floatParams, BETA_STAR_P5_Y, betaStar); } + void LHCInfo::setIntensityForBeam1(float const& intensity) { LHCInfoImpl::setOneParam(m_floatParams, INTENSITY_1, intensity); } From b96ab48c17a8ecd33d943190d2d6f6c117a5b668 Mon Sep 17 00:00:00 2001 From: Giacomo Govi Date: Mon, 14 Feb 2022 13:48:23 +0100 Subject: [PATCH 3/6] Prepared data access to OMS Service --- CondTools/RunInfo/interface/OMSAccess.h | 252 ++++++++++++++++++++++++ CondTools/RunInfo/src/OMSAccess.cc | 128 ++++++++++++ 2 files changed, 380 insertions(+) create mode 100644 CondTools/RunInfo/interface/OMSAccess.h create mode 100644 CondTools/RunInfo/src/OMSAccess.cc diff --git a/CondTools/RunInfo/interface/OMSAccess.h b/CondTools/RunInfo/interface/OMSAccess.h new file mode 100644 index 0000000000000..6032fcb796cb9 --- /dev/null +++ b/CondTools/RunInfo/interface/OMSAccess.h @@ -0,0 +1,252 @@ +#ifndef CondTools_RunInfo_OMSAccess_h +#define CondTools_RunInfo_OMSAccess_h + +#include +#include +#include +#include +#include +#include + +namespace cond { + + // implementation details for data extraction from json/ data conversion to build query urls + namespace impl { + + static constexpr const char* const OMS_TIME_FMT = "%Y-%m-%dT%H:%M:%SZ"; + + template + inline T from_string_impl(const std::string& attributeValue, T zero ){ + T ret = zero; + if(not attributeValue.empty() && attributeValue!="null"){ + ret = fun(attributeValue); + } + return ret; + } + + template + inline T from_string(const std::string& attributeValue){ + throw std::invalid_argument( "" ); + } + + template <> + inline std::string from_string(const std::string& attributeValue){ + return std::string(attributeValue); + } + + inline float s_to_f(const std::string& val){ + return std::stof(val); + } + template <> + inline float from_string(const std::string& attributeValue){ + return from_string_impl(attributeValue,0.); + } + + inline int s_to_i(const std::string& val){ + return std::stoi(val); + } + template <> + inline int from_string(const std::string& attributeValue){ + return from_string_impl(attributeValue,0); + } + + inline unsigned long s_to_ul(const std::string& val){ + return std::stoul(val); + } + template <> + inline unsigned short from_string(const std::string& attributeValue){ + unsigned long int_val = from_string_impl(attributeValue,0); + return (unsigned short)int_val; + } + + inline boost::posix_time::ptime s_to_time(const std::string& val){ + boost::posix_time::time_input_facet* facet = new boost::posix_time::time_input_facet(OMS_TIME_FMT); + std::stringstream ss; + ss.imbue(std::locale(std::locale(), facet)); + ss << val; + boost::posix_time::ptime time; + ss >> time; + return time; + } + template <> + inline boost::posix_time::ptime from_string(const std::string& attributeValue){ + return from_string_impl(attributeValue,boost::posix_time::ptime()); + } + + template + inline std::string to_string( const V& value ){ + return std::to_string(value); + } + template + inline std::string to_string( const V* value ){ + return std::to_string(*value); + } + template <> + inline std::string to_string( const std::string& value ){ + return std::string(value); + } + template <> + inline std::string to_string( const char* value ){ + return std::string(value); + } + template <> + inline std::string to_string( const boost::posix_time::ptime& value ){ + boost::posix_time::time_facet* facet = new boost::posix_time::time_facet(); + facet->format(OMS_TIME_FMT); + std::stringstream stream; + stream.imbue(std::locale(std::locale::classic(), facet)); + stream << value; + return stream.str(); + } + + } + + // reference of a result set row. it does not own/hold data. + class OMSServiceResultRef { + public: + OMSServiceResultRef() = delete; + OMSServiceResultRef( const boost::property_tree::ptree* row ); + + // return true if no attribute is available + bool empty(); + // typed getter for single param + template + inline T get(const std::string& attributeName ){ + return impl::from_string(getAttribute(attributeName)); + } + // getter for arrays + template std::vector getArray( const std::string& attributeName ){ + std::vector ret; + for(auto& item: m_row->get_child(attributeName)){ + ret.push_back(item.second.get_value()); + } + return ret; + } + + private: + std::string getAttribute(const std::string& attributeName); + const boost::property_tree::ptree* m_row = nullptr; + }; + + // iterator object for result + class OMSServiceResultIterator { + public: + OMSServiceResultIterator() = delete; + OMSServiceResultIterator( boost::property_tree::ptree::const_iterator iter ); + + OMSServiceResultRef operator*(); + OMSServiceResultIterator& operator++(); + + bool operator==(const OMSServiceResultIterator& rhs); + bool operator!=(const OMSServiceResultIterator& rhs); + + private: + boost::property_tree::ptree::const_iterator m_iter; + }; + + // container wrapping the query result, based on boost property tree + class OMSServiceResult { + public: + OMSServiceResult(); + // basic iterators, to enable the C++11 for loop semantics + OMSServiceResultIterator begin() const; + OMSServiceResultIterator end() const; + + // parse json returned from curl, filling the property tree + size_t parseData( const std::string& data); + + // returns the number of top level elements of the tree ( result set "rows" ) + size_t size() const; + + // returns size()==0 + bool empty() const; + private: + boost::property_tree::ptree m_root; + boost::property_tree::ptree* m_data; + }; + + // Query object + class OMSServiceQuery { + public: + // comparison operator label, used in query urls + static constexpr const char* const NEQ = "NEQ"; + static constexpr const char* const EQ = "EQ"; + static constexpr const char* const LT = "LT"; + static constexpr const char* const GT = "GT"; + static constexpr const char* const SNULL = "null"; + public: + OMSServiceQuery()= delete; + OMSServiceQuery(const std::string& baseUrl, const std::string& function); + + // functions to restring query output to specific variables + OMSServiceQuery& addOutputVar(const std::string& varName); + OMSServiceQuery& addOutputVars( const std::initializer_list& varNames); + + // generic query filter + template + inline OMSServiceQuery& filter( const char* cmp, const std::string& varName, const T& value ){ + std::stringstream filter; + if(m_filter.empty()) { + filter << "?"; + } else { + filter << m_filter << "&"; + } + filter << "filter[" << varName <<"]["<< cmp <<"]=" < + inline OMSServiceQuery& filterEQ( const std::string& varName, const T& value ){ + return filter(EQ,varName,value); + } + template + inline OMSServiceQuery& filterNEQ( const std::string& varName, const T& value ){ + return filter(NEQ,varName,value); + } + template + inline OMSServiceQuery& filterGT( const std::string& varName, const T& value ){ + return filter(GT,varName,value); + } + template + inline OMSServiceQuery& filterLT( const std::string& varName, const T& value ){ + return filter(LT,varName,value); + } + // not null filter + inline OMSServiceQuery& filterNotNull( const std::string& varName ){ return filterNEQ(varName,SNULL); } + + // triggers the execution of the query ( calling curl functions ) + bool execute(); + + // return code from curl + unsigned long status(); + + // result from the query. memory allocated for data is owned by the query object itself + OMSServiceResult& result(); + + // the url constructed and used for the query + std::string url(); + private: + void addVar(const std::string& varName); + private: + std::string m_url; + std::string m_filter; + std::string m_varList; + std::unique_ptr m_result; + unsigned long m_status = 0; + }; + + // provides query access to OMS Web services + class OMSService { + public: + OMSService(); + + void connect(const std::string& baseUrl); + std::unique_ptr query( const std::string& function ) const; + + private: + std::string m_baseUrl; + }; +} + +#endif diff --git a/CondTools/RunInfo/src/OMSAccess.cc b/CondTools/RunInfo/src/OMSAccess.cc new file mode 100644 index 0000000000000..bd0c7ac1f4582 --- /dev/null +++ b/CondTools/RunInfo/src/OMSAccess.cc @@ -0,0 +1,128 @@ +#include "CondTools/RunInfo/interface/OMSAccess.h" +#include "CondCore/CondDB/interface/WebUtils.h" +#include "CondCore/CondDB/interface/Exception.h" + +namespace cond { + + OMSServiceResultRef::OMSServiceResultRef( const boost::property_tree::ptree* row ): m_row(row){} + + bool OMSServiceResultRef::empty(){ return m_row == nullptr; } + + std::string OMSServiceResultRef::getAttribute(const std::string& attributeName){ + return m_row->get(attributeName); + } + + OMSServiceResultIterator::OMSServiceResultIterator( boost::property_tree::ptree::const_iterator iter ): m_iter(iter){} + + OMSServiceResultRef OMSServiceResultIterator::operator*(){ + auto& attributeList = m_iter->second.get_child("attributes"); + return OMSServiceResultRef(&attributeList); + } + + OMSServiceResultIterator& OMSServiceResultIterator::operator++(){ + m_iter++; + return *this; + } + + bool OMSServiceResultIterator::operator==(const OMSServiceResultIterator& rhs){ + return m_iter==rhs.m_iter; + } + bool OMSServiceResultIterator::operator!=(const OMSServiceResultIterator& rhs){ + return m_iter!=rhs.m_iter; + } + + OMSServiceResult::OMSServiceResult(){} + + OMSServiceResultIterator OMSServiceResult::begin() const { + return OMSServiceResultIterator(m_data->begin()); + } + + OMSServiceResultIterator OMSServiceResult::end() const { + return OMSServiceResultIterator(m_data->end()); + } + + size_t OMSServiceResult::parseData( const std::string& data){ + m_data = nullptr; + std::stringstream sout; + sout << data; + try { + boost::property_tree::read_json(sout, m_root); + } catch (boost::property_tree::json_parser_error const&ex) { + throw cond::Exception(ex.what(),"OMSServiceResult::parseData"); + } + if(m_root.size()>0) { + m_data = &m_root.get_child("data"); + } + return m_root.size(); + } + + size_t OMSServiceResult::size() const { + size_t ret = 0; + if(m_data){ + ret = m_data->size(); + } + return ret; + } + + bool OMSServiceResult::empty() const { + return size()==0; + } + + void OMSServiceQuery::addVar(const std::string& varName){ + std::stringstream varList; + if(m_varList.empty()){ + varList <<"&fields="; + } else { + varList << m_varList <<","; + } + varList <& varNames){ + for(auto v: varNames)addVar(v); + return *this; + } + + bool OMSServiceQuery::execute(){ + bool ret = false; + std::string out; + m_status = cond::httpGet(url(), out); + if (m_status==200 || m_status==201) { + m_result = std::make_unique(); + m_result->parseData(out); + ret = true; + } + return ret; + } + + unsigned long OMSServiceQuery::status(){ + return m_status; + } + + OMSServiceResult& OMSServiceQuery::result(){ + return *m_result; + } + + std::string OMSServiceQuery::url(){ + return m_url+m_filter+m_varList; + } + + OMSService::OMSService():m_baseUrl(){} + + void OMSService::connect(const std::string& baseUrl){ + m_baseUrl=baseUrl; + } + std::unique_ptr OMSService::query( const std::string& function ) const { + return std::make_unique(m_baseUrl,function); + } +} + From ca4b3baab0c32c1e613ec767afee81467fc3d07c Mon Sep 17 00:00:00 2001 From: Giacomo Govi Date: Mon, 14 Feb 2022 13:49:53 +0100 Subject: [PATCH 4/6] Data access for Fill, Lumisection and various DIP information moved from direct Oracle access to OMS Service --- .../interface/LHCInfoPopConSourceHandler.h | 13 +- .../python/LHCInfoPopConAnalyzerEndFill.py | 3 +- .../python/LHCInfoPopConAnalyzerStartFill.py | 1 + .../RunInfo/src/LHCInfoPopConSourceHandler.cc | 586 ++++++------------ 4 files changed, 197 insertions(+), 406 deletions(-) diff --git a/CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h b/CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h index 9a96c57765066..e7451b3a4a185 100644 --- a/CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h +++ b/CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h @@ -7,6 +7,10 @@ #include "CondFormats/RunInfo/interface/LHCInfo.h" #include "FWCore/ParameterSet/interface/ParameterSetfwd.h" +namespace cond { + class OMSService; +} + class LHCInfoPopConSourceHandler : public popcon::PopConSourceHandler { public: LHCInfoPopConSourceHandler(const edm::ParameterSet& pset); @@ -16,12 +20,12 @@ class LHCInfoPopConSourceHandler : public popcon::PopConSourceHandler { private: void addEmptyPayload(cond::Time_t iov); - bool getNextFillData(cond::persistency::Session& session, const boost::posix_time::ptime& targetTime, bool ended); - bool getFillData(cond::persistency::Session& session, unsigned short fillId); - size_t getLumiData(cond::persistency::Session& session, + + size_t getLumiData(const cond::OMSService& service, + unsigned short fillId, const boost::posix_time::ptime& beginFillTime, const boost::posix_time::ptime& endFillTime); - bool getDipData(cond::persistency::Session& session, + void getDipData(const cond::OMSService& service, const boost::posix_time::ptime& beginFillTime, const boost::posix_time::ptime& endFillTime); bool getCTTPSData(cond::persistency::Session& session, @@ -44,6 +48,7 @@ class LHCInfoPopConSourceHandler : public popcon::PopConSourceHandler { //for reading from relational database source std::string m_connectionString, m_ecalConnectionString; std::string m_dipSchema, m_authpath; + std::string m_omsBaseUrl; std::unique_ptr m_fillPayload; std::shared_ptr m_prevPayload; std::vector > > m_tmpBuffer; diff --git a/CondTools/RunInfo/python/LHCInfoPopConAnalyzerEndFill.py b/CondTools/RunInfo/python/LHCInfoPopConAnalyzerEndFill.py index 19b96fa40bc77..01e4cb459e654 100644 --- a/CondTools/RunInfo/python/LHCInfoPopConAnalyzerEndFill.py +++ b/CondTools/RunInfo/python/LHCInfoPopConAnalyzerEndFill.py @@ -70,13 +70,14 @@ record = cms.string('LHCInfoRcd'), name = cms.untracked.string('LHCInfo'), Source = cms.PSet(fill = cms.untracked.uint32(6417), - startTime = cms.untracked.string('2018-05-31 00:00:00.000'), + startTime = cms.untracked.string('2021-09-10 03:10:18.000'), #endTime = cms.untracked.string('2018-05-31 20:13:59.000'), samplingInterval = cms.untracked.uint32( 600 ), endFill = cms.untracked.bool(True), connectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_RUNTIME_LOGGER"), ecalConnectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_DCS_ENV_PVSS_COND"), DIPSchema = cms.untracked.string("CMS_BEAM_COND"), + omsBaseUrl = cms.untracked.string("http://vocms0184.cern.ch/agg/api/v1"), debug=cms.untracked.bool(False) ), loggingOn = cms.untracked.bool(True), diff --git a/CondTools/RunInfo/python/LHCInfoPopConAnalyzerStartFill.py b/CondTools/RunInfo/python/LHCInfoPopConAnalyzerStartFill.py index d885f5c1c0bf2..79166c5b8bace 100644 --- a/CondTools/RunInfo/python/LHCInfoPopConAnalyzerStartFill.py +++ b/CondTools/RunInfo/python/LHCInfoPopConAnalyzerStartFill.py @@ -77,6 +77,7 @@ connectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_RUNTIME_LOGGER"), ecalConnectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_DCS_ENV_PVSS_COND"), DIPSchema = cms.untracked.string("CMS_BEAM_COND"), + omsBaseUrl = cms.untracked.string("http://vocms0184.cern.ch/agg/api/v1"), #authenticationPath = cms.untracked.string("."), debug=cms.untracked.bool(False) ), diff --git a/CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc b/CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc index 90b24d76b1ec6..43ae68b01ef4b 100644 --- a/CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc +++ b/CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc @@ -3,6 +3,7 @@ #include "CondCore/CondDB/interface/ConnectionPool.h" #include "CondFormats/Common/interface/TimeConversions.h" #include "CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h" +#include "CondTools/RunInfo/interface/OMSAccess.h" #include "RelationalAccess/ISessionProxy.h" #include "RelationalAccess/ISchema.h" #include "RelationalAccess/IQuery.h" @@ -18,6 +19,45 @@ #include #include +namespace cond { + static const std::pair s_fillTypeMap[] = {std::make_pair("PROTONS", LHCInfo::PROTONS), + std::make_pair("IONS", LHCInfo::IONS), + std::make_pair("COSMICS", LHCInfo::COSMICS), + std::make_pair("GAP", LHCInfo::GAP)}; + + static const std::pair s_particleTypeMap[] = {std::make_pair("PROTON", LHCInfo::PROTON), + std::make_pair("PB82", LHCInfo::PB82), + std::make_pair("AR18", LHCInfo::AR18), + std::make_pair("D", LHCInfo::D), + std::make_pair("XE54", LHCInfo::XE54)}; + + LHCInfo::FillType fillTypeFromString(const std::string& s_fill_type) { + for (auto const& i : s_fillTypeMap) + if (s_fill_type == i.first) + return i.second; + return LHCInfo::UNKNOWN; + } + + LHCInfo::ParticleType particleTypeFromString(const std::string& s_particle_type) { + for (auto const& i : s_particleTypeMap) + if (s_particle_type == i.first) + return i.second; + return LHCInfo::NONE; + } + + namespace impl { + + template <> LHCInfo::FillType from_string(const std::string& attributeValue){ + return from_string_impl(attributeValue,LHCInfo::UNKNOWN); + } + + template <> LHCInfo::ParticleType from_string(const std::string& attributeValue){ + return from_string_impl(attributeValue,LHCInfo::NONE); + } + + } +} + LHCInfoPopConSourceHandler::LHCInfoPopConSourceHandler(edm::ParameterSet const& pset) : m_debug(pset.getUntrackedParameter("debug", false)), m_startTime(), @@ -29,6 +69,7 @@ LHCInfoPopConSourceHandler::LHCInfoPopConSourceHandler(edm::ParameterSet const& m_ecalConnectionString(pset.getUntrackedParameter("ecalConnectionString", "")), m_dipSchema(pset.getUntrackedParameter("DIPSchema", "")), m_authpath(pset.getUntrackedParameter("authenticationPath", "")), + m_omsBaseUrl(pset.getUntrackedParameter("omsBaseUrl", "")), m_fillPayload(), m_prevPayload(), m_tmpBuffer() { @@ -64,151 +105,25 @@ namespace LHCInfoImpl { return (p != container.begin()) ? p - 1 : container.end(); } - bool makeFillDataQuery(cond::persistency::Session& session, - const std::string& conditionString, - const coral::AttributeList& fillDataBindVariables, - std::unique_ptr& targetPayload, - bool debug) { - coral::ISchema& runTimeLoggerSchema = session.nominalSchema(); - //prepare the query for table 1: - std::unique_ptr fillDataQuery(runTimeLoggerSchema.newQuery()); - //FROM clause - fillDataQuery->addToTableList(std::string("RUNTIME_SUMMARY")); - //SELECT clause - fillDataQuery->addToOutputList(std::string("LHCFILL")); - fillDataQuery->addToOutputList(std::string("NBUNCHESBEAM1")); - fillDataQuery->addToOutputList(std::string("NBUNCHESBEAM2")); - fillDataQuery->addToOutputList(std::string("NCOLLIDINGBUNCHES")); - fillDataQuery->addToOutputList(std::string("NTARGETBUNCHES")); - fillDataQuery->addToOutputList(std::string("RUNTIME_TYPE_ID")); - fillDataQuery->addToOutputList(std::string("PARTY1")); - fillDataQuery->addToOutputList(std::string("PARTY2")); - fillDataQuery->addToOutputList(std::string("INTENSITYBEAM1")); - fillDataQuery->addToOutputList(std::string("INTENSITYBEAM2")); - fillDataQuery->addToOutputList(std::string("ENERGY")); - fillDataQuery->addToOutputList(std::string("CREATETIME")); - fillDataQuery->addToOutputList(std::string("BEGINTIME")); - fillDataQuery->addToOutputList(std::string("ENDTIME")); - fillDataQuery->addToOutputList(std::string("INJECTIONSCHEME")); - //WHERE clause - fillDataQuery->setCondition(conditionString, fillDataBindVariables); - //ORDER BY clause - std::string orderStr("BEGINTIME"); - //define query output - coral::AttributeList fillDataOutput; - fillDataOutput.extend(std::string("LHCFILL")); - fillDataOutput.extend(std::string("NBUNCHESBEAM1")); - fillDataOutput.extend(std::string("NBUNCHESBEAM2")); - fillDataOutput.extend(std::string("NCOLLIDINGBUNCHES")); - fillDataOutput.extend(std::string("NTARGETBUNCHES")); - fillDataOutput.extend(std::string("RUNTIME_TYPE_ID")); - fillDataOutput.extend(std::string("PARTY1")); - fillDataOutput.extend(std::string("PARTY2")); - fillDataOutput.extend(std::string("INTENSITYBEAM1")); - fillDataOutput.extend(std::string("INTENSITYBEAM2")); - fillDataOutput.extend(std::string("ENERGY")); - fillDataOutput.extend(std::string("CREATETIME")); - fillDataOutput.extend(std::string("BEGINTIME")); - fillDataOutput.extend(std::string("ENDTIME")); - fillDataOutput.extend(std::string("INJECTIONSCHEME")); - fillDataQuery->defineOutput(fillDataOutput); - fillDataQuery->limitReturnedRows(1); - //execute the query - coral::ICursor& fillDataCursor = fillDataQuery->execute(); - // - unsigned short currentFill = 0; - unsigned short bunches1 = 0, bunches2 = 0, collidingBunches = 0, targetBunches = 0; - LHCInfo::FillTypeId fillType = LHCInfo::UNKNOWN; - LHCInfo::ParticleTypeId particleType1 = LHCInfo::NONE, particleType2 = LHCInfo::NONE; - float intensityBeam1 = 0., intensityBeam2 = 0., energy = 0.; - coral::TimeStamp stableBeamStartTimeStamp, beamDumpTimeStamp; - cond::Time_t creationTime = 0ULL, stableBeamStartTime = 0ULL, beamDumpTime = 0ULL; - std::string injectionScheme("None"); - std::ostringstream ss; + bool makeFillPayload( std::unique_ptr& targetPayload, const cond::OMSServiceResult& queryResult ){ bool ret = false; - if (fillDataCursor.next()) { - ret = true; - if (debug) { - std::ostringstream qs; - fillDataCursor.currentRow().toOutputStream(qs); - } - coral::Attribute const& fillAttribute = fillDataCursor.currentRow()[std::string("LHCFILL")]; - if (!fillAttribute.isNull()) { - currentFill = fillAttribute.data(); - } - coral::Attribute const& bunches1Attribute = fillDataCursor.currentRow()[std::string("NBUNCHESBEAM1")]; - if (!bunches1Attribute.isNull()) { - bunches1 = bunches1Attribute.data(); - } - coral::Attribute const& bunches2Attribute = fillDataCursor.currentRow()[std::string("NBUNCHESBEAM2")]; - if (!bunches2Attribute.isNull()) { - bunches2 = bunches2Attribute.data(); - } - coral::Attribute const& collidingBunchesAttribute = fillDataCursor.currentRow()[std::string("NCOLLIDINGBUNCHES")]; - if (!collidingBunchesAttribute.isNull()) { - collidingBunches = collidingBunchesAttribute.data(); - } - coral::Attribute const& targetBunchesAttribute = fillDataCursor.currentRow()[std::string("NTARGETBUNCHES")]; - if (!targetBunchesAttribute.isNull()) { - targetBunches = targetBunchesAttribute.data(); - } - //RUNTIME_TYPE_ID IS NOT NULL - fillType = - static_cast(fillDataCursor.currentRow()[std::string("RUNTIME_TYPE_ID")].data()); - coral::Attribute const& particleType1Attribute = fillDataCursor.currentRow()[std::string("PARTY1")]; - if (!particleType1Attribute.isNull()) { - particleType1 = static_cast(particleType1Attribute.data()); - } - coral::Attribute const& particleType2Attribute = fillDataCursor.currentRow()[std::string("PARTY2")]; - if (!particleType2Attribute.isNull()) { - particleType2 = static_cast(particleType2Attribute.data()); - } - coral::Attribute const& intensityBeam1Attribute = fillDataCursor.currentRow()[std::string("INTENSITYBEAM1")]; - if (!intensityBeam1Attribute.isNull()) { - intensityBeam1 = intensityBeam1Attribute.data(); - } - coral::Attribute const& intensityBeam2Attribute = fillDataCursor.currentRow()[std::string("INTENSITYBEAM2")]; - if (!intensityBeam2Attribute.isNull()) { - intensityBeam2 = intensityBeam2Attribute.data(); - } - coral::Attribute const& energyAttribute = fillDataCursor.currentRow()[std::string("ENERGY")]; - if (!energyAttribute.isNull()) { - energy = energyAttribute.data(); - } - } - if (ret) { - //CREATETIME IS NOT NULL - creationTime = cond::time::from_boost( - fillDataCursor.currentRow()[std::string("CREATETIME")].data().time()); - //BEGINTIME is imposed to be NOT NULL in the WHERE clause - stableBeamStartTimeStamp = fillDataCursor.currentRow()[std::string("BEGINTIME")].data(); - stableBeamStartTime = cond::time::from_boost(stableBeamStartTimeStamp.time()); - coral::Attribute const& beamDumpTimeAttribute = fillDataCursor.currentRow()[std::string("ENDTIME")]; - if (!beamDumpTimeAttribute.isNull()) { - beamDumpTimeStamp = beamDumpTimeAttribute.data(); - beamDumpTime = cond::time::from_boost(beamDumpTimeStamp.time()); - } - coral::Attribute const& injectionSchemeAttribute = fillDataCursor.currentRow()[std::string("INJECTIONSCHEME")]; - if (!injectionSchemeAttribute.isNull()) { - injectionScheme = injectionSchemeAttribute.data(); - } - //fix an inconsistency in RunTimeLogger: if the fill type is defined, the particle type should reflect it! - if (fillType != LHCInfo::UNKNOWN && (particleType1 == LHCInfo::NONE || particleType2 == LHCInfo::NONE)) { - switch (fillType) { - case LHCInfo::PROTONS: - particleType1 = LHCInfo::PROTON; - particleType2 = LHCInfo::PROTON; - break; - case LHCInfo::IONS: - particleType1 = LHCInfo::PB82; - particleType2 = LHCInfo::PB82; - break; - case LHCInfo::UNKNOWN: - case LHCInfo::COSMICS: - case LHCInfo::GAP: - break; - } - } + if(!queryResult.empty()){ + auto row = *queryResult.begin(); + auto currentFill = row.get("fill_number"); + auto bunches1 = row.get("bunches_beam1"); + auto bunches2 = row.get("bunches_beam2"); + auto collidingBunches = row.get("bunches_colliding"); + auto targetBunches = row.get("bunches_target"); + auto fillType = row.get("fill_type_runtime"); + auto particleType1 = row.get("fill_type_party1"); + auto particleType2 = row.get("fill_type_party2"); + auto intensityBeam1 = row.get("intensity_beam1"); + auto intensityBeam2 = row.get("intensity_beam2"); + auto energy = row.get("energy"); + auto creationTime = row.get("start_time"); + auto stableBeamStartTime = row.get("start_stable_beam"); + auto beamDumpTime = row.get("end_time"); + auto injectionScheme = row.get("injection_scheme"); targetPayload = std::make_unique(); targetPayload->setFillNumber(currentFill); targetPayload->setBunchesInBeam1(bunches1); @@ -221,110 +136,39 @@ namespace LHCInfoImpl { targetPayload->setIntensityForBeam1(intensityBeam1); targetPayload->setIntensityForBeam2(intensityBeam2); targetPayload->setEnergy(energy); - targetPayload->setCreationTime(creationTime); - targetPayload->setBeginTime(stableBeamStartTime); - targetPayload->setEndTime(beamDumpTime); + targetPayload->setCreationTime(cond::time::from_boost(creationTime)); + targetPayload->setBeginTime(cond::time::from_boost(stableBeamStartTime)); + targetPayload->setEndTime(cond::time::from_boost(beamDumpTime)); targetPayload->setInjectionScheme(injectionScheme); + ret = true; } return ret; } } // namespace LHCInfoImpl -bool LHCInfoPopConSourceHandler::getNextFillData(cond::persistency::Session& session, - const boost::posix_time::ptime& targetTime, - bool ended) { - // Prepare the WHERE clause - coral::AttributeList fillDataBindVariables; - fillDataBindVariables.extend(std::string("targetTime")); - fillDataBindVariables[std::string("targetTime")].data() = - coral::TimeStamp(targetTime + boost::posix_time::seconds(1)); - //by imposing BEGINTIME IS NOT NULL, we remove fills which never went into stable beams, - //by additionally imposing ENDTIME IS NOT NULL, we select only finished fills - std::string conditionStr = "BEGINTIME IS NOT NULL AND CREATETIME > :targetTime AND LHCFILL IS NOT NULL"; - if (ended) - conditionStr += " AND ENDTIME IS NOT NULL"; - return LHCInfoImpl::makeFillDataQuery(session, conditionStr, fillDataBindVariables, m_fillPayload, m_debug); -} - -bool LHCInfoPopConSourceHandler::getFillData(cond::persistency::Session& session, unsigned short fillId) { - // Prepare the WHERE clause - coral::AttributeList fillDataBindVariables; - fillDataBindVariables.extend(std::string("fillId")); - fillDataBindVariables[std::string("fillId")].data() = fillId; - std::string conditionStr = "LHCFILL=:fillId"; - return LHCInfoImpl::makeFillDataQuery(session, conditionStr, fillDataBindVariables, m_fillPayload, m_debug); -} - -size_t LHCInfoPopConSourceHandler::getLumiData(cond::persistency::Session& session, +size_t LHCInfoPopConSourceHandler::getLumiData(const cond::OMSService& oms, + unsigned short fillId, const boost::posix_time::ptime& beginFillTime, const boost::posix_time::ptime& endFillTime) { - coral::ISchema& runTimeLoggerSchema = session.nominalSchema(); - //prepare the query for table 2: - std::unique_ptr fillDataQuery2(runTimeLoggerSchema.newQuery()); - //FROM clause - fillDataQuery2->addToTableList(std::string("LUMI_SECTIONS")); - //SELECT clause - fillDataQuery2->addToOutputList(std::string("DELIVLUMI")); - fillDataQuery2->addToOutputList(std::string("LIVELUMI")); - fillDataQuery2->addToOutputList(std::string("INSTLUMI")); - fillDataQuery2->addToOutputList(std::string("INSTLUMIERROR")); - fillDataQuery2->addToOutputList(std::string("STARTTIME")); - fillDataQuery2->addToOutputList(std::string("LHCFILL")); - //WHERE clause - coral::AttributeList fillDataBindVariables; - fillDataBindVariables.extend(std::string("start")); - fillDataBindVariables.extend(std::string("stop")); - fillDataBindVariables[std::string("start")].data() = coral::TimeStamp(beginFillTime); - fillDataBindVariables[std::string("stop")].data() = coral::TimeStamp(endFillTime); - std::string conditionStr = "DELIVLUMI IS NOT NULL AND STARTTIME >= :start AND STARTTIME< :stop"; - fillDataQuery2->setCondition(conditionStr, fillDataBindVariables); - //ORDER BY clause - fillDataQuery2->addToOrderList(std::string("STARTTIME")); - //define query output*/ - coral::AttributeList fillDataOutput2; - fillDataOutput2.extend(std::string("DELIVEREDLUMI")); - fillDataOutput2.extend(std::string("RECORDEDLUMI")); - fillDataOutput2.extend(std::string("INSTLUMI")); - fillDataOutput2.extend(std::string("INSTLUMIERROR")); - fillDataOutput2.extend(std::string("STARTTIME")); - fillDataOutput2.extend(std::string("LHCFILL")); - fillDataQuery2->defineOutput(fillDataOutput2); - //execute the query - coral::ICursor& fillDataCursor2 = fillDataQuery2->execute(); + auto query = oms.query("lumisections"); + query->addOutputVars({"start_time","delivered_lumi","recorded_lumi"}); + query->filterEQ("fill_number",fillId).filterGT("start_time",beginFillTime).filterLT("start_time",endFillTime); size_t nlumi = 0; - while (fillDataCursor2.next()) { - nlumi++; - float delivLumi = 0., recLumi = 0., instLumi = 0, instLumiErr = 0.; - cond::Time_t since = 0; - coral::Attribute const& delivLumiAttribute = fillDataCursor2.currentRow()[std::string("DELIVEREDLUMI")]; - if (!delivLumiAttribute.isNull()) { - delivLumi = delivLumiAttribute.data() / 1000.; - } - coral::Attribute const& recLumiAttribute = fillDataCursor2.currentRow()[std::string("RECORDEDLUMI")]; - if (!recLumiAttribute.isNull()) { - recLumi = recLumiAttribute.data() / 1000.; - } - coral::Attribute const& instLumiAttribute = fillDataCursor2.currentRow()[std::string("INSTLUMI")]; - if (!instLumiAttribute.isNull()) { - instLumi = instLumiAttribute.data() / 1000.; - } - coral::Attribute const& instLumiErrAttribute = fillDataCursor2.currentRow()[std::string("INSTLUMIERROR")]; - if (!instLumiErrAttribute.isNull()) { - instLumiErr = instLumiErrAttribute.data() / 1000.; - } - coral::Attribute const& startLumiSectionAttribute = fillDataCursor2.currentRow()[std::string("STARTTIME")]; - if (!startLumiSectionAttribute.isNull()) { - since = cond::time::from_boost(startLumiSectionAttribute.data().time()); - } - LHCInfo* thisLumiSectionInfo = m_fillPayload->cloneFill(); - m_tmpBuffer.emplace_back(std::make_pair(since, thisLumiSectionInfo)); - LHCInfo& payload = *thisLumiSectionInfo; - payload.setDelivLumi(delivLumi); - payload.setRecLumi(recLumi); - payload.setInstLumi(instLumi); - payload.setInstLumiError(instLumiErr); + if(query->execute()){ + auto res = query->result(); + for( auto r: res ){ + nlumi++; + auto lumiTime = r.get("start_time"); + auto delivLumi = r.get("delivered_lumi"); + auto recLumi = r.get("recorded_lumi"); + LHCInfo* thisLumiSectionInfo = m_fillPayload->cloneFill(); + m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo)); + LHCInfo& payload = *thisLumiSectionInfo; + payload.setDelivLumi(delivLumi); + payload.setRecLumi(recLumi); + } } return nlumi; } @@ -386,147 +230,65 @@ namespace LHCInfoImpl { }; } // namespace LHCInfoImpl -bool LHCInfoPopConSourceHandler::getDipData(cond::persistency::Session& session, +void LHCInfoPopConSourceHandler::getDipData(const cond::OMSService& oms, const boost::posix_time::ptime& beginFillTime, const boost::posix_time::ptime& endFillTime) { - //run the third and fourth query against the schema hosting detailed DIP information - coral::ISchema& beamCondSchema = session.coralSession().schema(m_dipSchema); - //start the transaction against the DIP "deep" database backend schema - //prepare the WHERE clause for both queries - coral::AttributeList bunchConfBindVariables; - bunchConfBindVariables.extend(std::string("beginFillTime")); - bunchConfBindVariables.extend(std::string("endFillTime")); - bunchConfBindVariables[std::string("beginFillTime")].data() = coral::TimeStamp(beginFillTime); - bunchConfBindVariables[std::string("endFillTime")].data() = coral::TimeStamp(endFillTime); - std::string conditionStr = std::string("DIPTIME >= :beginFillTime and DIPTIME< :endFillTime"); - //define the output types for both queries - coral::AttributeList bunchConfOutput; - bunchConfOutput.extend(std::string("DIPTIME")); - bunchConfOutput.extend(std::string("BUCKET")); - //execute query for Beam 1 - std::unique_ptr bunchConf1Query(beamCondSchema.newQuery()); - bunchConf1Query->addToTableList(std::string("LHC_CIRCBUNCHCONFIG_BEAM1"), - std::string("BEAMCONF\", TABLE( BEAMCONF.VALUE ) \"BUCKETS")); - bunchConf1Query->addToOutputList(std::string("BEAMCONF.DIPTIME"), std::string("DIPTIME")); - bunchConf1Query->addToOutputList(std::string("BUCKETS.COLUMN_VALUE"), std::string("BUCKET")); - bunchConf1Query->setCondition(conditionStr, bunchConfBindVariables); - bunchConf1Query->addToOrderList(std::string("DIPTIME")); - bunchConf1Query->limitReturnedRows(LHCInfo::availableBunchSlots); //maximum number of filled bunches - bunchConf1Query->defineOutput(bunchConfOutput); - - coral::ICursor& bunchConf1Cursor = bunchConf1Query->execute(); - std::bitset bunchConfiguration1(0ULL); - bool ret = false; - cond::Time_t lumiSectionTime = 0; - while (bunchConf1Cursor.next()) { - if (m_debug) { - std::ostringstream b1s; - bunchConf1Cursor.currentRow().toOutputStream(b1s); - } - coral::Attribute const& dipTimeAttribute = bunchConf1Cursor.currentRow()[std::string("DIPTIME")]; - coral::Attribute const& bunchConf1Attribute = bunchConf1Cursor.currentRow()[std::string("BUCKET")]; - if (!dipTimeAttribute.isNull() and !bunchConf1Attribute.isNull()) { - cond::Time_t dipTime = cond::time::from_boost(dipTimeAttribute.data().time()); - // assuming only one sample has been selected... - unsigned short slot = (bunchConf1Attribute.data() - 1) / 10 + 1; - if (lumiSectionTime == 0 or lumiSectionTime == dipTime) { - bunchConfiguration1[slot] = true; - } else - break; - lumiSectionTime = dipTime; + // unsure how to handle this. + // the old implementation is not helping: apparently it is checking only the bunchconfiguration for the first diptime set of values... + auto query1 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam1"); + query1->filterGT("dip_time",beginFillTime).filterLT("dip_time",endFillTime); + if(query1->execute()){ + auto res = query1->result(); + if(!res.empty()){ + std::bitset bunchConfiguration1(0ULL); + auto row = *res.begin(); + //auto dipTime = row.get("dip_time"); + auto vbunchConf1 = row.getArray("value"); + for( auto vb: vbunchConf1 ){ + if( vb!=0){ + unsigned short slot = (vb - 1) / 10 + 1; + bunchConfiguration1[slot] = true; + } + } + m_fillPayload->setBunchBitsetForBeam1(bunchConfiguration1); } } - if (ret) { - m_fillPayload->setBunchBitsetForBeam1(bunchConfiguration1); - } - - //execute query for Beam 2 - std::unique_ptr bunchConf2Query(beamCondSchema.newQuery()); - bunchConf2Query->addToTableList(std::string("LHC_CIRCBUNCHCONFIG_BEAM2"), - std::string("BEAMCONF\", TABLE( BEAMCONF.VALUE ) \"BUCKETS")); - bunchConf2Query->addToOutputList(std::string("BEAMCONF.DIPTIME"), std::string("DIPTIME")); - bunchConf2Query->addToOutputList(std::string("BUCKETS.COLUMN_VALUE"), std::string("BUCKET")); - bunchConf2Query->setCondition(conditionStr, bunchConfBindVariables); - bunchConf2Query->addToOrderList(std::string("DIPTIME")); - bunchConf2Query->limitReturnedRows(LHCInfo::availableBunchSlots); //maximum number of filled bunches - bunchConf2Query->defineOutput(bunchConfOutput); - coral::ICursor& bunchConf2Cursor = bunchConf2Query->execute(); - - std::bitset bunchConfiguration2(0ULL); - ret = false; - lumiSectionTime = 0; - while (bunchConf2Cursor.next()) { - if (m_debug) { - std::ostringstream b2s; - bunchConf2Cursor.currentRow().toOutputStream(b2s); - } - coral::Attribute const& dipTimeAttribute = bunchConf2Cursor.currentRow()[std::string("DIPTIME")]; - coral::Attribute const& bunchConf2Attribute = bunchConf2Cursor.currentRow()[std::string("BUCKET")]; - if (!dipTimeAttribute.isNull() and !bunchConf2Attribute.isNull()) { - ret = true; - cond::Time_t dipTime = cond::time::from_boost(dipTimeAttribute.data().time()); - // assuming only one sample has been selected... - unsigned short slot = (bunchConf2Attribute.data() - 1) / 10 + 1; - if (lumiSectionTime == 0 or lumiSectionTime == dipTime) { - bunchConfiguration2[slot] = true; - } else - break; - lumiSectionTime = dipTime; + auto query2 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam2"); + query2->filterGT("dip_time",beginFillTime).filterLT("dip_time",endFillTime); + if(query2->execute()){ + auto res = query2->result(); + if(!res.empty()){ + std::bitset bunchConfiguration2(0ULL); + auto row = *res.begin(); + //auto dipTime = row.get("dip_time"); + auto vbunchConf2 = row.getArray("value"); + for( auto vb: vbunchConf2 ){ + if( vb!=0){ + unsigned short slot = (vb - 1) / 10 + 1; + bunchConfiguration2[slot] = true; + } + } + m_fillPayload->setBunchBitsetForBeam2(bunchConfiguration2); } } - if (ret) { - m_fillPayload->setBunchBitsetForBeam2(bunchConfiguration2); - } - //execute query for lumiPerBX - std::unique_ptr lumiDataQuery(beamCondSchema.newQuery()); - lumiDataQuery->addToTableList(std::string("CMS_LHC_LUMIPERBUNCH"), - std::string("LUMIPERBUNCH\", TABLE( LUMIPERBUNCH.LUMI_BUNCHINST ) \"VALUE")); - lumiDataQuery->addToOutputList(std::string("LUMIPERBUNCH.DIPTIME"), std::string("DIPTIME")); - lumiDataQuery->addToOutputList(std::string("VALUE.COLUMN_VALUE"), std::string("LUMI_BUNCH")); - coral::AttributeList lumiDataBindVariables; - lumiDataBindVariables.extend(std::string("beginFillTime")); - lumiDataBindVariables.extend(std::string("endFillTime")); - lumiDataBindVariables[std::string("beginFillTime")].data() = coral::TimeStamp(beginFillTime); - lumiDataBindVariables[std::string("endFillTime")].data() = coral::TimeStamp(endFillTime); - conditionStr = std::string("DIPTIME BETWEEN :beginFillTime AND :endFillTime"); - lumiDataQuery->setCondition(conditionStr, lumiDataBindVariables); - lumiDataQuery->addToOrderList(std::string("DIPTIME")); - lumiDataQuery->limitReturnedRows(3564); //Maximum number of bunches. - //define query output - coral::AttributeList lumiDataOutput; - lumiDataOutput.extend(std::string("DIPTIME")); - lumiDataOutput.extend(std::string("LUMI_BUNCH")); - lumiDataQuery->defineOutput(lumiDataOutput); - //execute the query - coral::ICursor& lumiDataCursor = lumiDataQuery->execute(); - std::vector lumiPerBX; - ret = false; - lumiSectionTime = 0; - while (lumiDataCursor.next()) { - if (m_debug) { - std::ostringstream lpBX; - lumiDataCursor.currentRow().toOutputStream(lpBX); - } - coral::Attribute const& dipTimeAttribute = lumiDataCursor.currentRow()[std::string("DIPTIME")]; - coral::Attribute const& lumiBunchAttribute = lumiDataCursor.currentRow()[std::string("LUMI_BUNCH")]; - if (!dipTimeAttribute.isNull() and !lumiBunchAttribute.isNull()) { - ret = true; - cond::Time_t dipTime = cond::time::from_boost(dipTimeAttribute.data().time()); - // assuming only one sample has been selected... - float lumi_b = lumiBunchAttribute.data(); - if (lumiSectionTime == 0 or lumiSectionTime == dipTime) { - if (lumi_b != 0.00) - lumiPerBX.push_back(lumi_b); - } else - break; - lumiSectionTime = dipTime; + auto query3 = oms.query("diplogger/dip/CMS/LHC/LumiPerBunch"); + query3->filterGT("dip_time",beginFillTime).filterLT("dip_time",endFillTime); + if(query3->execute()){ + auto res = query3->result(); + if(!res.empty()){ + std::vector lumiPerBX; + auto row = *res.begin(); + //auto dipTime = row.get("dip_time"); + auto lumiBunchInst = row.getArray("lumi_bunch_inst"); + for( auto lb: lumiBunchInst ){ + if( lb!=0.){ + lumiPerBX.push_back(lb); + } + } + m_fillPayload->setLumiPerBX(lumiPerBX); } } - if (ret) { - m_fillPayload->setLumiPerBX(lumiPerBX); - } - return ret; } bool LHCInfoPopConSourceHandler::getCTTPSData(cond::persistency::Session& session, @@ -534,19 +296,21 @@ bool LHCInfoPopConSourceHandler::getCTTPSData(cond::persistency::Session& sessio const boost::posix_time::ptime& endFillTime) { //run the fifth query against the CTPPS schema //Initializing the CMS_CTP_CTPPS_COND schema. - coral::ISchema& CTPPS = session.coralSession().schema("CMS_CTP_CTPPS_COND"); + coral::ISchema& CTPPS = session.coralSession().schema("CMS_PPS_SPECT_COND"); //execute query for CTPPS Data std::unique_ptr CTPPSDataQuery(CTPPS.newQuery()); //FROM clause - CTPPSDataQuery->addToTableList(std::string("CTPPS_LHC_MACHINE_PARAMS")); + CTPPSDataQuery->addToTableList(std::string("PPS_LHC_MACHINE_PARAMS")); //SELECT clause CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME")); CTPPSDataQuery->addToOutputList(std::string("LHC_STATE")); CTPPSDataQuery->addToOutputList(std::string("LHC_COMMENT")); - CTPPSDataQuery->addToOutputList(std::string("CTPPS_STATUS")); + //CTPPSDataQuery->addToOutputList(std::string("CTPPS_STATUS")); CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION")); - CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_URAD")); - CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_CMS")); + CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_X_URAD")); + CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_Y_URAD")); + CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_X_M")); + CTPPSDataQuery->addToOutputList(std::string("BETA_STAR_P5_Y_M")); //WHERE CLAUSE coral::AttributeList CTPPSDataBindVariables; CTPPSDataBindVariables.extend(std::string("beginFillTime")); @@ -562,17 +326,19 @@ bool LHCInfoPopConSourceHandler::getCTTPSData(cond::persistency::Session& sessio CTPPSDataOutput.extend(std::string("DIP_UPDATE_TIME")); CTPPSDataOutput.extend(std::string("LHC_STATE")); CTPPSDataOutput.extend(std::string("LHC_COMMENT")); - CTPPSDataOutput.extend(std::string("CTPPS_STATUS")); + //CTPPSDataOutput.extend(std::string("CTPPS_STATUS")); CTPPSDataOutput.extend(std::string("LUMI_SECTION")); - CTPPSDataOutput.extend(std::string("XING_ANGLE_URAD")); - CTPPSDataOutput.extend(std::string("BETA_STAR_CMS")); + CTPPSDataOutput.extend(std::string("XING_ANGLE_P5_X_URAD")); + CTPPSDataOutput.extend(std::string("XING_ANGLE_P5_Y_URAD")); + CTPPSDataOutput.extend(std::string("BETA_STAR_P5_X_M")); + CTPPSDataOutput.extend(std::string("BETA_STAR_P5_Y_M")); CTPPSDataQuery->defineOutput(CTPPSDataOutput); //execute the query coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute(); cond::Time_t dipTime = 0; std::string lhcState = "", lhcComment = "", ctppsStatus = ""; unsigned int lumiSection = 0; - float crossingAngle = 0., betastar = 0.; + float crossingAngle_x = 0., crossingAngle_y = 0., betastar_x = 0., betastar_y = 0.; bool ret = false; LHCInfoImpl::LumiSectionFilter filter(m_tmpBuffer); @@ -594,27 +360,37 @@ bool LHCInfoPopConSourceHandler::getCTTPSData(cond::persistency::Session& sessio if (!lhcCommentAttribute.isNull()) { lhcComment = lhcCommentAttribute.data(); } - coral::Attribute const& ctppsStatusAttribute = CTPPSDataCursor.currentRow()[std::string("CTPPS_STATUS")]; - if (!ctppsStatusAttribute.isNull()) { - ctppsStatus = ctppsStatusAttribute.data(); - } + //coral::Attribute const& ctppsStatusAttribute = CTPPSDataCursor.currentRow()[std::string("CTPPS_STATUS")]; + //if (!ctppsStatusAttribute.isNull()) { + // ctppsStatus = ctppsStatusAttribute.data(); + //} coral::Attribute const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[std::string("LUMI_SECTION")]; if (!lumiSectionAttribute.isNull()) { lumiSection = lumiSectionAttribute.data(); } - coral::Attribute const& crossingAngleAttribute = CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_URAD")]; - if (!crossingAngleAttribute.isNull()) { - crossingAngle = crossingAngleAttribute.data(); + coral::Attribute const& crossingAngleXAttribute = CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_X_URAD")]; + if (!crossingAngleXAttribute.isNull()) { + crossingAngle_x = crossingAngleXAttribute.data(); + } + coral::Attribute const& crossingAngleYAttribute = CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_Y_URAD")]; + if (!crossingAngleYAttribute.isNull()) { + crossingAngle_y = crossingAngleYAttribute.data(); } - coral::Attribute const& betaStarAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_CMS")]; - if (!betaStarAttribute.isNull()) { - betastar = betaStarAttribute.data(); + coral::Attribute const& betaStarXAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_X_M")]; + if (!betaStarXAttribute.isNull()) { + betastar_x = betaStarXAttribute.data(); + } + coral::Attribute const& betaStarYAttribute = CTPPSDataCursor.currentRow()[std::string("BETA_STAR_P5_Y_M")]; + if (!betaStarYAttribute.isNull()) { + betastar_y = betaStarYAttribute.data(); } for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) { // set the current values to all of the payloads of the lumi section samples after the current since LHCInfo& payload = *(it->second); - payload.setCrossingAngle(crossingAngle); - payload.setBetaStar(betastar); + payload.setXingAngleP5X(crossingAngle_x); + payload.setXingAngleP5Y(crossingAngle_y); + payload.setBetaStarP5X(betastar_x); + payload.setBetaStarP5Y(betastar_y); payload.setLhcState(lhcState); payload.setLhcComment(lhcComment); payload.setCtppsStatus(ctppsStatus); @@ -845,7 +621,7 @@ void LHCInfoPopConSourceHandler::getNewObjects() { Ref previousFill; //if a new tag is created, transfer fake fill from 1 to the first fill for the first time - if (tagInfo().name.empty()) { + if (tagInfo().size==0) { edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects"; } else { //check what is already inside the database @@ -857,9 +633,10 @@ void LHCInfoPopConSourceHandler::getNewObjects() { } cond::Time_t lastSince = tagInfo().lastInterval.since; - if (lastSince == 0) { + if (tagInfo().isEmpty()) { // for a new or empty tag, an empty payload should be added on top with since=1 addEmptyPayload(1); + lastSince = 1; } else { edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from " << m_name << "::getNewObjects"; @@ -909,12 +686,17 @@ void LHCInfoPopConSourceHandler::getNewObjects() { boost::posix_time::ptime targetTime = cond::time::to_boost(targetSince); boost::posix_time::ptime startSampleTime; boost::posix_time::ptime endSampleTime; + + cond::OMSService oms; + oms.connect( m_omsBaseUrl ); + auto query = oms.query("fills"); + if (!m_endFill and m_prevPayload->fillNumber() and m_prevPayload->endTime() == 0ULL) { // execute the query for the current fill - session.transaction().start(true); edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber(); - bool foundFill = getFillData(session, m_prevPayload->fillNumber()); - session.transaction().commit(); + query->filterEQ("fill_number",m_prevPayload->fillNumber()); + bool foundFill = query->execute(); + if(foundFill) foundFill= LHCInfoImpl::makeFillPayload(m_fillPayload,query->result()); if (!foundFill) { edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber(); break; @@ -922,10 +704,12 @@ void LHCInfoPopConSourceHandler::getNewObjects() { updateEcal = true; startSampleTime = cond::time::to_boost(lastSince); } else { - session.transaction().start(true); edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime); - bool foundFill = getNextFillData(session, targetTime, m_endFill); - session.transaction().commit(); + boost::posix_time::ptime startTime = targetTime + boost::posix_time::seconds(1); + query->filterNotNull("start_stable_beam").filterGT("start_time",startTime).filterNotNull("fill_number"); + if(m_endFill) query->filterNotNull("end_time"); + bool foundFill = query->execute(); + if(foundFill) foundFill= LHCInfoImpl::makeFillPayload(m_fillPayload,query->result()); if (!foundFill) { edm::LogInfo(m_name) << "No fill found - END of job."; if (iovAdded) @@ -948,13 +732,13 @@ void LHCInfoPopConSourceHandler::getNewObjects() { targetSince = endFillTime; } - session.transaction().start(true); - getDipData(session, startSampleTime, endSampleTime); - size_t nlumi = getLumiData(session, startSampleTime, endSampleTime); + getDipData(oms, startSampleTime, endSampleTime); + size_t nlumi = getLumiData(oms, lhcFill, startSampleTime, endSampleTime); edm::LogInfo(m_name) << "Found " << nlumi << " lumisections during the fill " << lhcFill; boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first); boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first); edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop; + session.transaction().start(true); getCTTPSData(session, startSampleTime, endSampleTime); session.transaction().commit(); session2.transaction().start(true); From b6d2cf0a94476750bca7b944c59410dd2e5eb126 Mon Sep 17 00:00:00 2001 From: Giacomo Govi Date: Mon, 14 Feb 2022 14:13:25 +0100 Subject: [PATCH 5/6] code-checks/code-format --- CondCore/CondDB/src/WebUtils.cc | 18 +- CondFormats/RunInfo/src/LHCInfo.cc | 8 +- .../interface/LHCInfoPopConSourceHandler.h | 2 +- CondTools/RunInfo/interface/OMSAccess.h | 165 +++++++++-------- .../RunInfo/src/LHCInfoPopConSourceHandler.cc | 167 +++++++++--------- CondTools/RunInfo/src/OMSAccess.cc | 104 +++++------ 6 files changed, 228 insertions(+), 236 deletions(-) diff --git a/CondCore/CondDB/src/WebUtils.cc b/CondCore/CondDB/src/WebUtils.cc index 90c36f1ea75e5..aca271dc8ec50 100644 --- a/CondCore/CondDB/src/WebUtils.cc +++ b/CondCore/CondDB/src/WebUtils.cc @@ -30,20 +30,20 @@ namespace cond { curl_easy_setopt(curl, CURLOPT_WRITEDATA, &body); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); res = curl_easy_perform(curl); - curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &ret); + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &ret); if (CURLE_OK == res) { - info = body; + info = body; } else { - size_t len = strlen(errbuf); - fprintf(stderr, "\nlibcurl: (%d) ", res); - if (len) - fprintf(stderr, "%s%s", errbuf, ((errbuf[len - 1] != '\n') ? "\n" : "")); - else - fprintf(stderr, "%s\n", curl_easy_strerror(res)); + size_t len = strlen(errbuf); + fprintf(stderr, "\nlibcurl: (%d) ", res); + if (len) + fprintf(stderr, "%s%s", errbuf, ((errbuf[len - 1] != '\n') ? "\n" : "")); + else + fprintf(stderr, "%s\n", curl_easy_strerror(res)); } curl_easy_cleanup(curl); } return ret; } -} +} // namespace cond diff --git a/CondFormats/RunInfo/src/LHCInfo.cc b/CondFormats/RunInfo/src/LHCInfo.cc index ca3659dad3264..fe672d24ece8f 100644 --- a/CondFormats/RunInfo/src/LHCInfo.cc +++ b/CondFormats/RunInfo/src/LHCInfo.cc @@ -308,8 +308,12 @@ void LHCInfo::setBetaStar(float const& betaStar) { LHCInfoImpl::setOneParam(m_fl void LHCInfo::setXingAngleP5X(float const& angle) { LHCInfoImpl::setOneParam(m_floatParams, XING_ANGLE_P5_X, angle); } void LHCInfo::setXingAngleP5Y(float const& angle) { LHCInfoImpl::setOneParam(m_floatParams, XING_ANGLE_P5_Y, angle); } -void LHCInfo::setBetaStarP5X(float const& betaStar){ LHCInfoImpl::setOneParam(m_floatParams, BETA_STAR_P5_X, betaStar); } -void LHCInfo::setBetaStarP5Y(float const& betaStar){ LHCInfoImpl::setOneParam(m_floatParams, BETA_STAR_P5_Y, betaStar); } +void LHCInfo::setBetaStarP5X(float const& betaStar) { + LHCInfoImpl::setOneParam(m_floatParams, BETA_STAR_P5_X, betaStar); +} +void LHCInfo::setBetaStarP5Y(float const& betaStar) { + LHCInfoImpl::setOneParam(m_floatParams, BETA_STAR_P5_Y, betaStar); +} void LHCInfo::setIntensityForBeam1(float const& intensity) { LHCInfoImpl::setOneParam(m_floatParams, INTENSITY_1, intensity); diff --git a/CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h b/CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h index e7451b3a4a185..9c49bce6f6774 100644 --- a/CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h +++ b/CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h @@ -22,7 +22,7 @@ class LHCInfoPopConSourceHandler : public popcon::PopConSourceHandler { void addEmptyPayload(cond::Time_t iov); size_t getLumiData(const cond::OMSService& service, - unsigned short fillId, + unsigned short fillId, const boost::posix_time::ptime& beginFillTime, const boost::posix_time::ptime& endFillTime); void getDipData(const cond::OMSService& service, diff --git a/CondTools/RunInfo/interface/OMSAccess.h b/CondTools/RunInfo/interface/OMSAccess.h index 6032fcb796cb9..5bf98e89ae8da 100644 --- a/CondTools/RunInfo/interface/OMSAccess.h +++ b/CondTools/RunInfo/interface/OMSAccess.h @@ -15,51 +15,45 @@ namespace cond { static constexpr const char* const OMS_TIME_FMT = "%Y-%m-%dT%H:%M:%SZ"; - template - inline T from_string_impl(const std::string& attributeValue, T zero ){ + template + inline T from_string_impl(const std::string& attributeValue, T zero) { T ret = zero; - if(not attributeValue.empty() && attributeValue!="null"){ - ret = fun(attributeValue); + if (not attributeValue.empty() && attributeValue != "null") { + ret = fun(attributeValue); } return ret; } - template - inline T from_string(const std::string& attributeValue){ - throw std::invalid_argument( "" ); + template + inline T from_string(const std::string& attributeValue) { + throw std::invalid_argument(""); } - template <> - inline std::string from_string(const std::string& attributeValue){ + template <> + inline std::string from_string(const std::string& attributeValue) { return std::string(attributeValue); } - inline float s_to_f(const std::string& val){ - return std::stof(val); - } - template <> - inline float from_string(const std::string& attributeValue){ - return from_string_impl(attributeValue,0.); + inline float s_to_f(const std::string& val) { return std::stof(val); } + template <> + inline float from_string(const std::string& attributeValue) { + return from_string_impl(attributeValue, 0.); } - inline int s_to_i(const std::string& val){ - return std::stoi(val); - } - template <> - inline int from_string(const std::string& attributeValue){ - return from_string_impl(attributeValue,0); + inline int s_to_i(const std::string& val) { return std::stoi(val); } + template <> + inline int from_string(const std::string& attributeValue) { + return from_string_impl(attributeValue, 0); } - inline unsigned long s_to_ul(const std::string& val){ - return std::stoul(val); - } - template <> - inline unsigned short from_string(const std::string& attributeValue){ - unsigned long int_val = from_string_impl(attributeValue,0); + inline unsigned long s_to_ul(const std::string& val) { return std::stoul(val); } + template <> + inline unsigned short from_string(const std::string& attributeValue) { + unsigned long int_val = from_string_impl(attributeValue, 0); return (unsigned short)int_val; } - inline boost::posix_time::ptime s_to_time(const std::string& val){ + inline boost::posix_time::ptime s_to_time(const std::string& val) { boost::posix_time::time_input_facet* facet = new boost::posix_time::time_input_facet(OMS_TIME_FMT); std::stringstream ss; ss.imbue(std::locale(std::locale(), facet)); @@ -68,29 +62,29 @@ namespace cond { ss >> time; return time; } - template <> - inline boost::posix_time::ptime from_string(const std::string& attributeValue){ - return from_string_impl(attributeValue,boost::posix_time::ptime()); - } + template <> + inline boost::posix_time::ptime from_string(const std::string& attributeValue) { + return from_string_impl(attributeValue, boost::posix_time::ptime()); + } template - inline std::string to_string( const V& value ){ + inline std::string to_string(const V& value) { return std::to_string(value); - } + } template - inline std::string to_string( const V* value ){ + inline std::string to_string(const V* value) { return std::to_string(*value); - } + } template <> - inline std::string to_string( const std::string& value ){ + inline std::string to_string(const std::string& value) { return std::string(value); } template <> - inline std::string to_string( const char* value ){ + inline std::string to_string(const char* value) { return std::string(value); } template <> - inline std::string to_string( const boost::posix_time::ptime& value ){ + inline std::string to_string(const boost::posix_time::ptime& value) { boost::posix_time::time_facet* facet = new boost::posix_time::time_facet(); facet->format(OMS_TIME_FMT); std::stringstream stream; @@ -99,26 +93,27 @@ namespace cond { return stream.str(); } - } + } // namespace impl // reference of a result set row. it does not own/hold data. class OMSServiceResultRef { public: OMSServiceResultRef() = delete; - OMSServiceResultRef( const boost::property_tree::ptree* row ); + OMSServiceResultRef(const boost::property_tree::ptree* row); // return true if no attribute is available bool empty(); - // typed getter for single param - template - inline T get(const std::string& attributeName ){ + // typed getter for single param + template + inline T get(const std::string& attributeName) { return impl::from_string(getAttribute(attributeName)); } // getter for arrays - template std::vector getArray( const std::string& attributeName ){ + template + std::vector getArray(const std::string& attributeName) { std::vector ret; - for(auto& item: m_row->get_child(attributeName)){ - ret.push_back(item.second.get_value()); + for (auto& item : m_row->get_child(attributeName)) { + ret.push_back(item.second.get_value()); } return ret; } @@ -130,36 +125,37 @@ namespace cond { // iterator object for result class OMSServiceResultIterator { - public: + public: OMSServiceResultIterator() = delete; - OMSServiceResultIterator( boost::property_tree::ptree::const_iterator iter ); + OMSServiceResultIterator(boost::property_tree::ptree::const_iterator iter); OMSServiceResultRef operator*(); OMSServiceResultIterator& operator++(); - + bool operator==(const OMSServiceResultIterator& rhs); bool operator!=(const OMSServiceResultIterator& rhs); - + private: boost::property_tree::ptree::const_iterator m_iter; }; // container wrapping the query result, based on boost property tree class OMSServiceResult { - public: + public: OMSServiceResult(); // basic iterators, to enable the C++11 for loop semantics OMSServiceResultIterator begin() const; OMSServiceResultIterator end() const; // parse json returned from curl, filling the property tree - size_t parseData( const std::string& data); + size_t parseData(const std::string& data); // returns the number of top level elements of the tree ( result set "rows" ) size_t size() const; // returns size()==0 bool empty() const; + private: boost::property_tree::ptree m_root; boost::property_tree::ptree* m_data; @@ -170,50 +166,51 @@ namespace cond { public: // comparison operator label, used in query urls static constexpr const char* const NEQ = "NEQ"; - static constexpr const char* const EQ = "EQ"; - static constexpr const char* const LT = "LT"; - static constexpr const char* const GT = "GT"; - static constexpr const char* const SNULL = "null"; + static constexpr const char* const EQ = "EQ"; + static constexpr const char* const LT = "LT"; + static constexpr const char* const GT = "GT"; + static constexpr const char* const SNULL = "null"; + public: - OMSServiceQuery()= delete; + OMSServiceQuery() = delete; OMSServiceQuery(const std::string& baseUrl, const std::string& function); // functions to restring query output to specific variables OMSServiceQuery& addOutputVar(const std::string& varName); - OMSServiceQuery& addOutputVars( const std::initializer_list& varNames); + OMSServiceQuery& addOutputVars(const std::initializer_list& varNames); // generic query filter - template - inline OMSServiceQuery& filter( const char* cmp, const std::string& varName, const T& value ){ + template + inline OMSServiceQuery& filter(const char* cmp, const std::string& varName, const T& value) { std::stringstream filter; - if(m_filter.empty()) { - filter << "?"; + if (m_filter.empty()) { + filter << "?"; } else { - filter << m_filter << "&"; + filter << m_filter << "&"; } - filter << "filter[" << varName <<"]["<< cmp <<"]=" < s_particleTypeMap[] = {std::make_pair("PROTON", LHCInfo::PROTON), - std::make_pair("PB82", LHCInfo::PB82), - std::make_pair("AR18", LHCInfo::AR18), - std::make_pair("D", LHCInfo::D), - std::make_pair("XE54", LHCInfo::XE54)}; - - LHCInfo::FillType fillTypeFromString(const std::string& s_fill_type) { - for (auto const& i : s_fillTypeMap) - if (s_fill_type == i.first) - return i.second; - return LHCInfo::UNKNOWN; - } + std::make_pair("IONS", LHCInfo::IONS), + std::make_pair("COSMICS", LHCInfo::COSMICS), + std::make_pair("GAP", LHCInfo::GAP)}; + + static const std::pair s_particleTypeMap[] = { + std::make_pair("PROTON", LHCInfo::PROTON), + std::make_pair("PB82", LHCInfo::PB82), + std::make_pair("AR18", LHCInfo::AR18), + std::make_pair("D", LHCInfo::D), + std::make_pair("XE54", LHCInfo::XE54)}; + + LHCInfo::FillType fillTypeFromString(const std::string& s_fill_type) { + for (auto const& i : s_fillTypeMap) + if (s_fill_type == i.first) + return i.second; + return LHCInfo::UNKNOWN; + } - LHCInfo::ParticleType particleTypeFromString(const std::string& s_particle_type) { - for (auto const& i : s_particleTypeMap) - if (s_particle_type == i.first) - return i.second; - return LHCInfo::NONE; - } + LHCInfo::ParticleType particleTypeFromString(const std::string& s_particle_type) { + for (auto const& i : s_particleTypeMap) + if (s_particle_type == i.first) + return i.second; + return LHCInfo::NONE; + } namespace impl { - template <> LHCInfo::FillType from_string(const std::string& attributeValue){ - return from_string_impl(attributeValue,LHCInfo::UNKNOWN); + template <> + LHCInfo::FillType from_string(const std::string& attributeValue) { + return from_string_impl(attributeValue, LHCInfo::UNKNOWN); } - template <> LHCInfo::ParticleType from_string(const std::string& attributeValue){ - return from_string_impl(attributeValue,LHCInfo::NONE); + template <> + LHCInfo::ParticleType from_string(const std::string& attributeValue) { + return from_string_impl(attributeValue, LHCInfo::NONE); } - } -} + } // namespace impl +} // namespace cond LHCInfoPopConSourceHandler::LHCInfoPopConSourceHandler(edm::ParameterSet const& pset) : m_debug(pset.getUntrackedParameter("debug", false)), @@ -105,9 +108,9 @@ namespace LHCInfoImpl { return (p != container.begin()) ? p - 1 : container.end(); } - bool makeFillPayload( std::unique_ptr& targetPayload, const cond::OMSServiceResult& queryResult ){ + bool makeFillPayload(std::unique_ptr& targetPayload, const cond::OMSServiceResult& queryResult) { bool ret = false; - if(!queryResult.empty()){ + if (!queryResult.empty()) { auto row = *queryResult.begin(); auto currentFill = row.get("fill_number"); auto bunches1 = row.get("bunches_beam1"); @@ -148,27 +151,26 @@ namespace LHCInfoImpl { } // namespace LHCInfoImpl size_t LHCInfoPopConSourceHandler::getLumiData(const cond::OMSService& oms, - unsigned short fillId, + unsigned short fillId, const boost::posix_time::ptime& beginFillTime, const boost::posix_time::ptime& endFillTime) { - auto query = oms.query("lumisections"); - query->addOutputVars({"start_time","delivered_lumi","recorded_lumi"}); - query->filterEQ("fill_number",fillId).filterGT("start_time",beginFillTime).filterLT("start_time",endFillTime); + query->addOutputVars({"start_time", "delivered_lumi", "recorded_lumi"}); + query->filterEQ("fill_number", fillId).filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime); size_t nlumi = 0; - if(query->execute()){ - auto res = query->result(); - for( auto r: res ){ - nlumi++; - auto lumiTime = r.get("start_time"); - auto delivLumi = r.get("delivered_lumi"); - auto recLumi = r.get("recorded_lumi"); - LHCInfo* thisLumiSectionInfo = m_fillPayload->cloneFill(); - m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo)); - LHCInfo& payload = *thisLumiSectionInfo; - payload.setDelivLumi(delivLumi); - payload.setRecLumi(recLumi); - } + if (query->execute()) { + auto res = query->result(); + for (auto r : res) { + nlumi++; + auto lumiTime = r.get("start_time"); + auto delivLumi = r.get("delivered_lumi"); + auto recLumi = r.get("recorded_lumi"); + LHCInfo* thisLumiSectionInfo = m_fillPayload->cloneFill(); + m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(lumiTime), thisLumiSectionInfo)); + LHCInfo& payload = *thisLumiSectionInfo; + payload.setDelivLumi(delivLumi); + payload.setRecLumi(recLumi); + } } return nlumi; } @@ -233,58 +235,58 @@ namespace LHCInfoImpl { void LHCInfoPopConSourceHandler::getDipData(const cond::OMSService& oms, const boost::posix_time::ptime& beginFillTime, const boost::posix_time::ptime& endFillTime) { - // unsure how to handle this. + // unsure how to handle this. // the old implementation is not helping: apparently it is checking only the bunchconfiguration for the first diptime set of values... auto query1 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam1"); - query1->filterGT("dip_time",beginFillTime).filterLT("dip_time",endFillTime); - if(query1->execute()){ + query1->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime); + if (query1->execute()) { auto res = query1->result(); - if(!res.empty()){ + if (!res.empty()) { std::bitset bunchConfiguration1(0ULL); auto row = *res.begin(); //auto dipTime = row.get("dip_time"); auto vbunchConf1 = row.getArray("value"); - for( auto vb: vbunchConf1 ){ - if( vb!=0){ - unsigned short slot = (vb - 1) / 10 + 1; - bunchConfiguration1[slot] = true; - } + for (auto vb : vbunchConf1) { + if (vb != 0) { + unsigned short slot = (vb - 1) / 10 + 1; + bunchConfiguration1[slot] = true; + } } m_fillPayload->setBunchBitsetForBeam1(bunchConfiguration1); } } auto query2 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam2"); - query2->filterGT("dip_time",beginFillTime).filterLT("dip_time",endFillTime); - if(query2->execute()){ + query2->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime); + if (query2->execute()) { auto res = query2->result(); - if(!res.empty()){ + if (!res.empty()) { std::bitset bunchConfiguration2(0ULL); auto row = *res.begin(); //auto dipTime = row.get("dip_time"); auto vbunchConf2 = row.getArray("value"); - for( auto vb: vbunchConf2 ){ - if( vb!=0){ - unsigned short slot = (vb - 1) / 10 + 1; - bunchConfiguration2[slot] = true; - } + for (auto vb : vbunchConf2) { + if (vb != 0) { + unsigned short slot = (vb - 1) / 10 + 1; + bunchConfiguration2[slot] = true; + } } m_fillPayload->setBunchBitsetForBeam2(bunchConfiguration2); } } auto query3 = oms.query("diplogger/dip/CMS/LHC/LumiPerBunch"); - query3->filterGT("dip_time",beginFillTime).filterLT("dip_time",endFillTime); - if(query3->execute()){ + query3->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime); + if (query3->execute()) { auto res = query3->result(); - if(!res.empty()){ + if (!res.empty()) { std::vector lumiPerBX; auto row = *res.begin(); //auto dipTime = row.get("dip_time"); auto lumiBunchInst = row.getArray("lumi_bunch_inst"); - for( auto lb: lumiBunchInst ){ - if( lb!=0.){ + for (auto lb : lumiBunchInst) { + if (lb != 0.) { lumiPerBX.push_back(lb); - } + } } m_fillPayload->setLumiPerBX(lumiPerBX); } @@ -368,11 +370,13 @@ bool LHCInfoPopConSourceHandler::getCTTPSData(cond::persistency::Session& sessio if (!lumiSectionAttribute.isNull()) { lumiSection = lumiSectionAttribute.data(); } - coral::Attribute const& crossingAngleXAttribute = CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_X_URAD")]; + coral::Attribute const& crossingAngleXAttribute = + CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_X_URAD")]; if (!crossingAngleXAttribute.isNull()) { crossingAngle_x = crossingAngleXAttribute.data(); } - coral::Attribute const& crossingAngleYAttribute = CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_Y_URAD")]; + coral::Attribute const& crossingAngleYAttribute = + CTPPSDataCursor.currentRow()[std::string("XING_ANGLE_P5_Y_URAD")]; if (!crossingAngleYAttribute.isNull()) { crossingAngle_y = crossingAngleYAttribute.data(); } @@ -621,7 +625,7 @@ void LHCInfoPopConSourceHandler::getNewObjects() { Ref previousFill; //if a new tag is created, transfer fake fill from 1 to the first fill for the first time - if (tagInfo().size==0) { + if (tagInfo().size == 0) { edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects"; } else { //check what is already inside the database @@ -688,15 +692,16 @@ void LHCInfoPopConSourceHandler::getNewObjects() { boost::posix_time::ptime endSampleTime; cond::OMSService oms; - oms.connect( m_omsBaseUrl ); + oms.connect(m_omsBaseUrl); auto query = oms.query("fills"); - + if (!m_endFill and m_prevPayload->fillNumber() and m_prevPayload->endTime() == 0ULL) { // execute the query for the current fill edm::LogInfo(m_name) << "Searching started fill #" << m_prevPayload->fillNumber(); - query->filterEQ("fill_number",m_prevPayload->fillNumber()); + query->filterEQ("fill_number", m_prevPayload->fillNumber()); bool foundFill = query->execute(); - if(foundFill) foundFill= LHCInfoImpl::makeFillPayload(m_fillPayload,query->result()); + if (foundFill) + foundFill = LHCInfoImpl::makeFillPayload(m_fillPayload, query->result()); if (!foundFill) { edm::LogError(m_name) << "Could not find fill #" << m_prevPayload->fillNumber(); break; @@ -706,10 +711,12 @@ void LHCInfoPopConSourceHandler::getNewObjects() { } else { edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(targetTime); boost::posix_time::ptime startTime = targetTime + boost::posix_time::seconds(1); - query->filterNotNull("start_stable_beam").filterGT("start_time",startTime).filterNotNull("fill_number"); - if(m_endFill) query->filterNotNull("end_time"); + query->filterNotNull("start_stable_beam").filterGT("start_time", startTime).filterNotNull("fill_number"); + if (m_endFill) + query->filterNotNull("end_time"); bool foundFill = query->execute(); - if(foundFill) foundFill= LHCInfoImpl::makeFillPayload(m_fillPayload,query->result()); + if (foundFill) + foundFill = LHCInfoImpl::makeFillPayload(m_fillPayload, query->result()); if (!foundFill) { edm::LogInfo(m_name) << "No fill found - END of job."; if (iovAdded) diff --git a/CondTools/RunInfo/src/OMSAccess.cc b/CondTools/RunInfo/src/OMSAccess.cc index bd0c7ac1f4582..951fac68c5d17 100644 --- a/CondTools/RunInfo/src/OMSAccess.cc +++ b/CondTools/RunInfo/src/OMSAccess.cc @@ -4,53 +4,45 @@ namespace cond { - OMSServiceResultRef::OMSServiceResultRef( const boost::property_tree::ptree* row ): m_row(row){} - - bool OMSServiceResultRef::empty(){ return m_row == nullptr; } + OMSServiceResultRef::OMSServiceResultRef(const boost::property_tree::ptree* row) : m_row(row) {} - std::string OMSServiceResultRef::getAttribute(const std::string& attributeName){ + bool OMSServiceResultRef::empty() { return m_row == nullptr; } + + std::string OMSServiceResultRef::getAttribute(const std::string& attributeName) { return m_row->get(attributeName); } - OMSServiceResultIterator::OMSServiceResultIterator( boost::property_tree::ptree::const_iterator iter ): m_iter(iter){} + OMSServiceResultIterator::OMSServiceResultIterator(boost::property_tree::ptree::const_iterator iter) : m_iter(iter) {} - OMSServiceResultRef OMSServiceResultIterator::operator*(){ + OMSServiceResultRef OMSServiceResultIterator::operator*() { auto& attributeList = m_iter->second.get_child("attributes"); return OMSServiceResultRef(&attributeList); } - OMSServiceResultIterator& OMSServiceResultIterator::operator++(){ + OMSServiceResultIterator& OMSServiceResultIterator::operator++() { m_iter++; return *this; } - - bool OMSServiceResultIterator::operator==(const OMSServiceResultIterator& rhs){ - return m_iter==rhs.m_iter; - } - bool OMSServiceResultIterator::operator!=(const OMSServiceResultIterator& rhs){ - return m_iter!=rhs.m_iter; - } - OMSServiceResult::OMSServiceResult(){} - - OMSServiceResultIterator OMSServiceResult::begin() const { - return OMSServiceResultIterator(m_data->begin()); - } + bool OMSServiceResultIterator::operator==(const OMSServiceResultIterator& rhs) { return m_iter == rhs.m_iter; } + bool OMSServiceResultIterator::operator!=(const OMSServiceResultIterator& rhs) { return m_iter != rhs.m_iter; } - OMSServiceResultIterator OMSServiceResult::end() const { - return OMSServiceResultIterator(m_data->end()); - } + OMSServiceResult::OMSServiceResult() {} + + OMSServiceResultIterator OMSServiceResult::begin() const { return OMSServiceResultIterator(m_data->begin()); } - size_t OMSServiceResult::parseData( const std::string& data){ + OMSServiceResultIterator OMSServiceResult::end() const { return OMSServiceResultIterator(m_data->end()); } + + size_t OMSServiceResult::parseData(const std::string& data) { m_data = nullptr; std::stringstream sout; sout << data; try { boost::property_tree::read_json(sout, m_root); - } catch (boost::property_tree::json_parser_error const&ex) { - throw cond::Exception(ex.what(),"OMSServiceResult::parseData"); + } catch (boost::property_tree::json_parser_error const& ex) { + throw cond::Exception(ex.what(), "OMSServiceResult::parseData"); } - if(m_root.size()>0) { + if (!m_root.empty()) { m_data = &m_root.get_child("data"); } return m_root.size(); @@ -58,71 +50,61 @@ namespace cond { size_t OMSServiceResult::size() const { size_t ret = 0; - if(m_data){ + if (m_data) { ret = m_data->size(); } return ret; } - bool OMSServiceResult::empty() const { - return size()==0; - } + bool OMSServiceResult::empty() const { return size() == 0; } - void OMSServiceQuery::addVar(const std::string& varName){ + void OMSServiceQuery::addVar(const std::string& varName) { std::stringstream varList; - if(m_varList.empty()){ - varList <<"&fields="; + if (m_varList.empty()) { + varList << "&fields="; } else { - varList << m_varList <<","; + varList << m_varList << ","; } - varList <& varNames){ - for(auto v: varNames)addVar(v); + OMSServiceQuery& OMSServiceQuery::addOutputVars(const std::initializer_list& varNames) { + for (auto v : varNames) + addVar(v); return *this; } - bool OMSServiceQuery::execute(){ + bool OMSServiceQuery::execute() { bool ret = false; std::string out; m_status = cond::httpGet(url(), out); - if (m_status==200 || m_status==201) { + if (m_status == 200 || m_status == 201) { m_result = std::make_unique(); m_result->parseData(out); ret = true; } return ret; } - - unsigned long OMSServiceQuery::status(){ - return m_status; - } - OMSServiceResult& OMSServiceQuery::result(){ - return *m_result; - } + unsigned long OMSServiceQuery::status() { return m_status; } - std::string OMSServiceQuery::url(){ - return m_url+m_filter+m_varList; - } - - OMSService::OMSService():m_baseUrl(){} + OMSServiceResult& OMSServiceQuery::result() { return *m_result; } - void OMSService::connect(const std::string& baseUrl){ - m_baseUrl=baseUrl; - } - std::unique_ptr OMSService::query( const std::string& function ) const { - return std::make_unique(m_baseUrl,function); - } -} + std::string OMSServiceQuery::url() { return m_url + m_filter + m_varList; } + + OMSService::OMSService() : m_baseUrl() {} + void OMSService::connect(const std::string& baseUrl) { m_baseUrl = baseUrl; } + std::unique_ptr OMSService::query(const std::string& function) const { + return std::make_unique(m_baseUrl, function); + } +} // namespace cond From 539bd5fbfef82bedd61960e039c98e538df7fc38 Mon Sep 17 00:00:00 2001 From: Giacomo Govi Date: Thu, 17 Feb 2022 16:04:23 +0100 Subject: [PATCH 6/6] Cleaned up commented lines --- CondCore/CondDB/src/WebUtils.cc | 2 +- CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CondCore/CondDB/src/WebUtils.cc b/CondCore/CondDB/src/WebUtils.cc index aca271dc8ec50..2b21b2971c551 100644 --- a/CondCore/CondDB/src/WebUtils.cc +++ b/CondCore/CondDB/src/WebUtils.cc @@ -6,7 +6,7 @@ namespace cond { - // + // callback to obtain the Get result static size_t getBodyCallback(void* contents, size_t size, size_t nmemb, void* ptr) { // Cast ptr to std::string pointer and append contents to that string ((std::string*)ptr)->append((char*)contents, size * nmemb); diff --git a/CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc b/CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc index f5c715a6f3671..69039961c2266 100644 --- a/CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc +++ b/CondTools/RunInfo/src/LHCInfoPopConSourceHandler.cc @@ -244,7 +244,6 @@ void LHCInfoPopConSourceHandler::getDipData(const cond::OMSService& oms, if (!res.empty()) { std::bitset bunchConfiguration1(0ULL); auto row = *res.begin(); - //auto dipTime = row.get("dip_time"); auto vbunchConf1 = row.getArray("value"); for (auto vb : vbunchConf1) { if (vb != 0) { @@ -262,7 +261,6 @@ void LHCInfoPopConSourceHandler::getDipData(const cond::OMSService& oms, if (!res.empty()) { std::bitset bunchConfiguration2(0ULL); auto row = *res.begin(); - //auto dipTime = row.get("dip_time"); auto vbunchConf2 = row.getArray("value"); for (auto vb : vbunchConf2) { if (vb != 0) { @@ -281,7 +279,6 @@ void LHCInfoPopConSourceHandler::getDipData(const cond::OMSService& oms, if (!res.empty()) { std::vector lumiPerBX; auto row = *res.begin(); - //auto dipTime = row.get("dip_time"); auto lumiBunchInst = row.getArray("lumi_bunch_inst"); for (auto lb : lumiBunchInst) { if (lb != 0.) { @@ -307,6 +304,7 @@ bool LHCInfoPopConSourceHandler::getCTTPSData(cond::persistency::Session& sessio CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME")); CTPPSDataQuery->addToOutputList(std::string("LHC_STATE")); CTPPSDataQuery->addToOutputList(std::string("LHC_COMMENT")); + // this variable has not been found in the above schema. Need to check with PPS if a replacement is needed/available //CTPPSDataQuery->addToOutputList(std::string("CTPPS_STATUS")); CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION")); CTPPSDataQuery->addToOutputList(std::string("XING_ANGLE_P5_X_URAD")); @@ -328,6 +326,7 @@ bool LHCInfoPopConSourceHandler::getCTTPSData(cond::persistency::Session& sessio CTPPSDataOutput.extend(std::string("DIP_UPDATE_TIME")); CTPPSDataOutput.extend(std::string("LHC_STATE")); CTPPSDataOutput.extend(std::string("LHC_COMMENT")); + // see above comment... //CTPPSDataOutput.extend(std::string("CTPPS_STATUS")); CTPPSDataOutput.extend(std::string("LUMI_SECTION")); CTPPSDataOutput.extend(std::string("XING_ANGLE_P5_X_URAD")); @@ -362,6 +361,7 @@ bool LHCInfoPopConSourceHandler::getCTTPSData(cond::persistency::Session& sessio if (!lhcCommentAttribute.isNull()) { lhcComment = lhcCommentAttribute.data(); } + // missing variable in the new schema - see comments above //coral::Attribute const& ctppsStatusAttribute = CTPPSDataCursor.currentRow()[std::string("CTPPS_STATUS")]; //if (!ctppsStatusAttribute.isNull()) { // ctppsStatus = ctppsStatusAttribute.data();