CMS 3D CMS Logo

OnlineDBOutputService.cc
Go to the documentation of this file.
3 #include <curl/curl.h>
4 //
5 
8  : PoolDBOutputService(iConfig, iAR),
9  m_latencyInLumisections(iConfig.getUntrackedParameter<unsigned int>("latency", 1)),
10  m_lastLumiUrl(iConfig.getUntrackedParameter<std::string>("lastLumiUrl", "")),
11  m_preLoadConnectionString(iConfig.getUntrackedParameter<std::string>("preLoadConnectionString", "")),
12  m_debug(iConfig.getUntrackedParameter<bool>("debugLogging", false)) {
13  if (!m_lastLumiUrl.empty()) {
16  } else {
17  m_lastLumiFile = iConfig.getUntrackedParameter<std::string>("lastLumiFile", "");
18  //if( m_lastLumiFile.size() == 0 ){
19  // m_runNumber = iConfig.getUntrackedParameter<unsigned long long>("runNumber",100000);
20  // m_startRunTime = std::chrono::steady_clock::now();
21  //}
22  }
23 }
24 
26 
27 static size_t getHtmlCallback(void* contents, size_t size, size_t nmemb, void* ptr) {
28  // Cast ptr to std::string pointer and append contents to that string
29  ((std::string*)ptr)->append((char*)contents, size * nmemb);
30  return size * nmemb;
31 }
32 
34  CURL* curl;
35  CURLcode res;
36  std::string htmlBuffer;
37  char errbuf[CURL_ERROR_SIZE];
38 
39  curl = curl_easy_init();
40  bool ret = false;
41  if (curl) {
42  struct curl_slist* chunk = nullptr;
43  chunk = curl_slist_append(chunk, "content-type:document/plain");
44  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
45  curl_easy_setopt(curl, CURLOPT_URL, urlString.c_str());
46  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, getHtmlCallback);
47  curl_easy_setopt(curl, CURLOPT_WRITEDATA, &htmlBuffer);
48  curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
49  res = curl_easy_perform(curl);
50  if (CURLE_OK == res) {
51  info = htmlBuffer;
52  ret = true;
53  } else {
54  size_t len = strlen(errbuf);
55  fprintf(stderr, "\nlibcurl: (%d) ", res);
56  if (len)
57  fprintf(stderr, "%s%s", errbuf, ((errbuf[len - 1] != '\n') ? "\n" : ""));
58  else
59  fprintf(stderr, "%s\n", curl_easy_strerror(res));
60  }
61  curl_easy_cleanup(curl);
62  }
63  return ret;
64 }
65 
67  cond::Time_t lastLumiProcessed = cond::time::MIN_VAL;
68  unsigned int lastL = 0;
69  if (!m_lastLumiUrl.empty()) {
70  std::string info("");
71  if (!getLatestLumiFromDAQ(m_lastLumiUrl, info))
72  throw Exception("Can't get last Lumisection from DAQ.");
73  lastL = boost::lexical_cast<unsigned int>(info);
74  lastLumiProcessed = cond::time::lumiTime(m_runNumber, lastL);
75  edm::LogInfo(MSGSOURCE) << "Last lumi: " << lastLumiProcessed << " Current run: " << m_runNumber
76  << " lumi id:" << lastL;
77  } else {
78  if (m_lastLumiFile.empty()) {
79  //auto t1 = std::chrono::steady_clock::now();
80  //auto deltat = std::chrono::duration_cast<std::chrono::seconds>( t1 - m_startRunTime ).count();
81  //lastL = (unsigned int)(deltat/23);
82  //lastLumiProcessed = cond::time::lumiTime( m_runNumber, lastL );
83  //edm::LogInfo( MSGSOURCE ) << "Last lumi: "<<lastLumiProcessed<<" Current run: "<<m_runNumber<<" lumi id:"<<lastL;
84  throw Exception("File name for last lumi has not been provided.");
85  } else {
86  lastLumiProcessed = cond::getLatestLumiFromFile(m_lastLumiFile);
87  auto upkTime = cond::time::unpack(lastLumiProcessed);
88  edm::LogInfo(MSGSOURCE) << "Last lumi: " << lastLumiProcessed << " Current run: " << upkTime.first
89  << " lumi id:" << upkTime.second;
90  }
91  }
92  return lastLumiProcessed;
93 }
94 
96  cond::persistency::Session session = getReadOnlyCache(targetTime);
97  cond::persistency::TransactionScope transaction(session.transaction());
98  transaction.start(true);
100  auto iov = proxy.getInterval(targetTime);
101  transaction.commit();
102  return iov;
103 }
104 
106  return PoolDBOutputService::newReadOnlySession(m_preLoadConnectionString, std::to_string(targetTime));
107 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
cond::persistency::TransactionScope
Definition: Session.h:231
cond::persistency::Session::getCurrentRun
cond::RunInfo_t getCurrentRun()
Definition: Session.cc:201
cond::time::MIN_VAL
const Time_t MIN_VAL(0)
cond::service::PoolDBOutputService::tag
std::string tag(const std::string &recordName)
Definition: PoolDBOutputService.cc:86
parallelization.stderr
stderr
Definition: parallelization.py:172
electrons_cff.bool
bool
Definition: electrons_cff.py:372
funct::false
false
Definition: Factorize.h:34
cond::persistency::IOVProxy::getInterval
cond::Iov_t getInterval(cond::Time_t time)
Definition: IOVProxy.cc:317
align_cfg.recordName
recordName
Definition: align_cfg.py:66
cond::RunInfo_t::run
Time_t run
Definition: Types.h:142
cond::getLatestLumiFromFile
cond::Time_t getLatestLumiFromFile(const std::string &fileName)
Definition: OnlineDBOutputService.h:24
edm::LogInfo
Definition: MessageLogger.h:254
cond::persistency::TransactionScope::start
void start(bool readOnly=true)
Definition: Session.cc:236
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
cond::service::PoolDBOutputService
Definition: PoolDBOutputService.h:32
cond::service::OnlineDBOutputService::m_lastLumiUrl
std::string m_lastLumiUrl
Definition: OnlineDBOutputService.h:90
relmon_rootfiles_spy.contents
contents
Definition: relmon_rootfiles_spy.py:129
cond::service::PoolDBOutputService::session
cond::persistency::Session session() const
Definition: PoolDBOutputService.cc:84
cond::service::OnlineDBOutputService::getReadOnlyCache
cond::persistency::Session getReadOnlyCache(cond::Time_t targetTime)
Definition: OnlineDBOutputService.cc:105
edm::ActivityRegistry
Definition: ActivityRegistry.h:132
getHtmlCallback
static size_t getHtmlCallback(void *contents, size_t size, size_t nmemb, void *ptr)
Definition: OnlineDBOutputService.cc:27
getLatestLumiFromDAQ
bool getLatestLumiFromDAQ(const std::string &urlString, std::string &info)
Definition: OnlineDBOutputService.cc:33
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
edm::ParameterSet
Definition: ParameterSet.h:36
cond::service::OnlineDBOutputService::getLastLumiProcessed
cond::Time_t getLastLumiProcessed()
Definition: OnlineDBOutputService.cc:66
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:25
res
Definition: Electron.h:6
cond::persistency::Session::transaction
Transaction & transaction()
Definition: Session.cc:52
std
Definition: JetResolutionObject.h:76
OnlineDBOutputService.h
cond::service::PoolDBOutputService::newReadOnlySession
cond::persistency::Session newReadOnlySession(const std::string &connectionString, const std::string &transactionId)
Definition: PoolDBOutputService.cc:77
cond::service::OnlineDBOutputService::OnlineDBOutputService
OnlineDBOutputService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &iAR)
Definition: OnlineDBOutputService.cc:6
cond::time::unpack
cond::UnpackedTime unpack(cond::Time_t iValue)
Definition: TimeConversions.h:22
cond::Iov_t
Definition: Types.h:47
ParameterSet.h
cond::service::OnlineDBOutputService::preLoadIov
cond::Iov_t preLoadIov(const std::string &recordName, cond::Time_t targetTime)
Definition: OnlineDBOutputService.cc:95
cond::service::PoolDBOutputService::startTransaction
void startTransaction()
Definition: PoolDBOutputService.cc:109
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
cond::service::OnlineDBOutputService::m_lastLumiFile
std::string m_lastLumiFile
Definition: OnlineDBOutputService.h:91
cond::service::OnlineDBOutputService::m_runNumber
cond::Time_t m_runNumber
Definition: OnlineDBOutputService.h:88