Skip to content

Commit

Permalink
Merge pull request #36956 from ggovi/lhcinfo-o2o-4-12_3_X
Browse files Browse the repository at this point in the history
Changing LHCInfo O2O Implementation to access source data from OMS
  • Loading branch information
cmsbuild authored Feb 18, 2022
2 parents 4619cdc + 539bd5f commit f4b2b85
Show file tree
Hide file tree
Showing 12 changed files with 661 additions and 408 deletions.
1 change: 1 addition & 0 deletions CondCore/CondDB/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<use name="FWCore/Framework"/>
<use name="boost"/>
<use name="openssl"/>
<use name="curl"/>
<use name="CoralCommon"/>
<use name="CoralKernel"/>
<use name="CoralBase"/>
Expand Down
2 changes: 1 addition & 1 deletion CondCore/CondDB/interface/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions CondCore/CondDB/interface/WebUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef CondCore_CondDB_WebUtils_h
#define CondCore_CondDB_WebUtils_h

#include <string>

namespace cond {

unsigned long httpGet(const std::string& urlString, std::string& info);

}

#endif
49 changes: 49 additions & 0 deletions CondCore/CondDB/src/WebUtils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "CondCore/CondDB/interface/WebUtils.h"
//
#include <curl/curl.h>
#include <cstdio>
#include <cstring>

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);
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;
}

} // namespace cond
18 changes: 17 additions & 1 deletion CondFormats/RunInfo/interface/LHCInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions CondFormats/RunInfo/src/LHCInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down Expand Up @@ -299,6 +305,16 @@ 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);
}
Expand Down
13 changes: 9 additions & 4 deletions CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<LHCInfo> {
public:
LHCInfoPopConSourceHandler(const edm::ParameterSet& pset);
Expand All @@ -16,12 +20,12 @@ class LHCInfoPopConSourceHandler : public popcon::PopConSourceHandler<LHCInfo> {

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,
Expand All @@ -44,6 +48,7 @@ class LHCInfoPopConSourceHandler : public popcon::PopConSourceHandler<LHCInfo> {
//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<LHCInfo> m_fillPayload;
std::shared_ptr<LHCInfo> m_prevPayload;
std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfo> > > m_tmpBuffer;
Expand Down
Loading

0 comments on commit f4b2b85

Please sign in to comment.