CMS 3D CMS Logo

OnlineDBOutputService.cc
Go to the documentation of this file.
3 #include <curl/curl.h>
4 //
5 
6 static size_t getHtmlCallback(void* contents, size_t size, size_t nmemb, void* ptr) {
7  // Cast ptr to std::string pointer and append contents to that string
8  ((std::string*)ptr)->append((char*)contents, size * nmemb);
9  return size * nmemb;
10 }
11 
12 bool getInfoFromService(const std::string& urlString, std::string& info) {
13  CURL* curl;
14  CURLcode res;
15  std::string htmlBuffer;
16  char errbuf[CURL_ERROR_SIZE];
17 
18  curl = curl_easy_init();
19  bool ret = false;
20  if (curl) {
21  struct curl_slist* chunk = nullptr;
22  chunk = curl_slist_append(chunk, "content-type:document/plain");
23  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
24  curl_easy_setopt(curl, CURLOPT_URL, urlString.c_str());
25  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, getHtmlCallback);
26  curl_easy_setopt(curl, CURLOPT_WRITEDATA, &htmlBuffer);
27  curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
28  res = curl_easy_perform(curl);
29  if (CURLE_OK == res) {
30  info = htmlBuffer;
31  ret = true;
32  } else {
33  size_t len = strlen(errbuf);
34  fprintf(stderr, "\nlibcurl: (%d) ", res);
35  if (len)
36  fprintf(stderr, "%s%s", errbuf, ((errbuf[len - 1] != '\n') ? "\n" : ""));
37  else
38  fprintf(stderr, "%s\n", curl_easy_strerror(res));
39  }
40  curl_easy_cleanup(curl);
41  }
42  return ret;
43 }
44 
45 namespace cond {
46 
48  cond::Time_t lastLumiProcessed = cond::time::MIN_VAL;
49  std::ifstream lastLumiFile(fileName);
50  if (lastLumiFile) {
51  lastLumiFile >> lastLumiProcessed;
52  } else {
53  throw Exception(std::string("Can't access lastLumi file ") + fileName);
54  }
55  return lastLumiProcessed;
56  }
57 
59  cond::Time_t lastLumiProcessed = cond::time::MIN_VAL;
60  std::string info("");
62  throw Exception("Can't get data from OMS Service.");
63  std::istringstream sinfo(info);
64  std::string srun;
65  if (!std::getline(sinfo, srun, ',')) {
66  throw Exception("Can't get run runmber info from OMS Service.");
67  }
68  std::string slumi;
69  if (!std::getline(sinfo, slumi, ',')) {
70  throw Exception("Can't get lumi id from OMS Service.");
71  }
72  unsigned int run = boost::lexical_cast<unsigned int>(srun);
73  unsigned int lumi = boost::lexical_cast<unsigned int>(slumi);
74  lastLumiProcessed = cond::time::lumiTime(run, lumi);
75  return lastLumiProcessed;
76  }
77 
78 } // namespace cond
79 
82  : PoolDBOutputService(iConfig, iAR),
83  m_runNumber(iConfig.getUntrackedParameter<unsigned long long>("runNumber", 1)),
84  m_latencyInLumisections(iConfig.getUntrackedParameter<unsigned int>("latency", 1)),
85  m_omsServiceUrl(iConfig.getUntrackedParameter<std::string>("omsServiceUrl", "")),
86  m_preLoadConnectionString(iConfig.getUntrackedParameter<std::string>("preLoadConnectionString", "")),
87  m_debug(iConfig.getUntrackedParameter<bool>("debugLogging", false)) {
88  if (m_omsServiceUrl.empty()) {
89  m_lastLumiFile = iConfig.getUntrackedParameter<std::string>("lastLumiFile", "");
90  }
91 }
92 
94 
96  cond::Time_t lastLumiProcessed = cond::time::MIN_VAL;
97  std::string info("");
98  if (!m_omsServiceUrl.empty()) {
99  lastLumiProcessed = cond::getLastLumiFromOMS(m_omsServiceUrl);
100  logger().logInfo() << "Last lumi: " << lastLumiProcessed
101  << " Current run: " << cond::time::unpack(lastLumiProcessed).first
102  << " lumi id:" << cond::time::unpack(lastLumiProcessed).second;
103  } else {
104  if (!m_lastLumiFile.empty()) {
105  lastLumiProcessed = cond::getLatestLumiFromFile(m_lastLumiFile);
106  auto upkTime = cond::time::unpack(lastLumiProcessed);
107  logger().logInfo() << "Last lumi: " << lastLumiProcessed << " Current run: " << upkTime.first
108  << " lumi id:" << upkTime.second;
109  } else {
110  lastLumiProcessed = cond::time::lumiTime(m_runNumber, 1);
111  }
112  }
113  return lastLumiProcessed;
114 }
115 
117  cond::persistency::Session session = getReadOnlyCache(targetTime);
118  cond::persistency::TransactionScope transaction(session.transaction());
119  transaction.start(true);
121  auto iov = proxy.getInterval(targetTime);
122  transaction.commit();
123  return iov;
124 }
125 
127  return PoolDBOutputService::newReadOnlySession(m_preLoadConnectionString, std::to_string(targetTime));
128 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
getInfoFromService
bool getInfoFromService(const std::string &urlString, std::string &info)
Definition: OnlineDBOutputService.cc:12
cond::persistency::TransactionScope
Definition: Session.h:231
cond::time::MIN_VAL
const Time_t MIN_VAL(0)
cond::service::PoolDBOutputService::tag
std::string tag(const std::string &recordName)
Definition: PoolDBOutputService.cc:124
electrons_cff.bool
bool
Definition: electrons_cff.py:393
funct::false
false
Definition: Factorize.h:29
cond::persistency::IOVProxy::getInterval
cond::Iov_t getInterval(cond::Time_t time)
Definition: IOVProxy.cc:321
cond::service::OnlineDBOutputService::m_omsServiceUrl
std::string m_omsServiceUrl
Definition: OnlineDBOutputService.h:84
align_cfg.recordName
recordName
Definition: align_cfg.py:66
cond::getLastLumiFromOMS
cond::Time_t getLastLumiFromOMS(const std::string &omsServiceUrl)
Definition: OnlineDBOutputService.cc:58
cond::getLatestLumiFromFile
cond::Time_t getLatestLumiFromFile(const std::string &fileName)
Definition: OnlineDBOutputService.cc:47
beam_dqm_sourceclient-live_cfg.lastLumiFile
lastLumiFile
Definition: beam_dqm_sourceclient-live_cfg.py:398
cond::persistency::TransactionScope::start
void start(bool readOnly=true)
Definition: Session.cc:236
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
cond::service::PoolDBOutputService
Definition: PoolDBOutputService.h:33
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
fwlog::logger
std::ostream & logger()
Definition: fwLog.cc:36
relmon_rootfiles_spy.contents
contents
Definition: relmon_rootfiles_spy.py:129
cond::service::OnlineDBOutputService::getReadOnlyCache
cond::persistency::Session getReadOnlyCache(cond::Time_t targetTime)
Definition: OnlineDBOutputService.cc:126
edm::ActivityRegistry
Definition: ActivityRegistry.h:133
getHtmlCallback
static size_t getHtmlCallback(void *contents, size_t size, size_t nmemb, void *ptr)
Definition: OnlineDBOutputService.cc:6
cond::persistency::Session::readIov
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::IOVProxy
Definition: IOVProxy.h:92
cond
Definition: plugin.cc:23
edm::ParameterSet
Definition: ParameterSet.h:47
submitPVResolutionJobs.stderr
stderr
Definition: submitPVResolutionJobs.py:45
cond::service::OnlineDBOutputService::getLastLumiProcessed
cond::Time_t getLastLumiProcessed()
Definition: OnlineDBOutputService.cc:95
cond::persistency::Session
Definition: Session.h:63
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
createfilelist.int
int
Definition: createfilelist.py:10
cond::Exception
persistency::Exception Exception
Definition: Exception.h:25
cond::time::lumiTime
Time_t lumiTime(unsigned int run, unsigned int lumiId)
Definition: Time.cc:54
cond::service::OnlineDBOutputService::~OnlineDBOutputService
~OnlineDBOutputService() override
Definition: OnlineDBOutputService.cc:93
res
Definition: Electron.h:6
cond::persistency::Session::transaction
Transaction & transaction()
Definition: Session.cc:52
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
OnlineDBOutputService.h
beam_dqm_sourceclient-live_cfg.omsServiceUrl
omsServiceUrl
Definition: beam_dqm_sourceclient-live_cfg.py:373
cond::service::PoolDBOutputService::newReadOnlySession
cond::persistency::Session newReadOnlySession(const std::string &connectionString, const std::string &transactionId)
Definition: PoolDBOutputService.cc:85
cond::service::OnlineDBOutputService::OnlineDBOutputService
OnlineDBOutputService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &iAR)
Definition: OnlineDBOutputService.cc:80
cond::time::unpack
cond::UnpackedTime unpack(cond::Time_t iValue)
Definition: TimeConversions.h:22
cond::Iov_t
Definition: Types.h:47
ParameterSet.h
lumi
Definition: LumiSectionData.h:20
cond::service::OnlineDBOutputService::preLoadIov
cond::Iov_t preLoadIov(const std::string &recordName, cond::Time_t targetTime)
Definition: OnlineDBOutputService.cc:116
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
cond::service::OnlineDBOutputService::m_lastLumiFile
std::string m_lastLumiFile
Definition: OnlineDBOutputService.h:85