CMS 3D CMS Logo

CondDBESSource.cc
Go to the documentation of this file.
1 //
2 // Package: CondCore/ESSources
3 // Module: CondDBESSource
4 //
5 // Description: <one line class summary>
6 //
7 // Implementation:
8 // <Notes on implementation>
9 //
10 // Author: Zhen Xie
11 // Fixes and other changes: Giacomo Govi
12 //
13 #include "CondDBESSource.h"
14 
15 #include <boost/algorithm/string.hpp>
20 
23 
29 #include <exception>
30 
31 #include <iomanip>
32 
33 namespace {
34  /* utility ot build the name of the plugin corresponding to a given record
35  se ESSources
36  */
37  std::string buildName(std::string const& iRecordName) { return iRecordName + std::string("@NewProxy"); }
38 
39  std::string joinRecordAndLabel(std::string const& iRecordName, std::string const& iLabelName) {
40  return iRecordName + std::string("@") + iLabelName;
41  }
42 
43  /* utility class to return a IOVs associated to a given "name"
44  This implementation return the IOV associated to a record...
45  It is essentialy a workaround to get the full IOV out of the tag colector
46  that is not accessible as hidden in the ESSource
47  FIXME: need to support label??
48  */
49  class CondGetterFromESSource : public cond::persistency::CondGetter {
50  public:
51  CondGetterFromESSource(CondDBESSource::ProxyMap const& ip) : m_proxies(ip) {}
52  ~CondGetterFromESSource() override {}
53 
55  CondDBESSource::ProxyMap::const_iterator p = m_proxies.find(name);
56  if (p != m_proxies.end())
57  return (*p).second->iovProxy();
59  }
60 
61  CondDBESSource::ProxyMap const& m_proxies;
62  };
63 
64  // This needs to be re-design and implemented...
65  // dump the state of a DataProxy
66  void dumpInfo(std::ostream& out, std::string const& recName, cond::DataProxyWrapperBase const& proxy) {
67  //cond::SequenceState state(proxy.proxy()->iov().state());
68  out << recName << " / " << proxy.label() << ": " << proxy.connString() << ", " << proxy.tag()
69  << "\n "
70  // << state.size() << ", " << state.revision() << ", "
71  // << cond::time::to_boost(state.timestamp()) << "\n "
72  // << state.comment()
73  << "\n "
74  // << "refresh " << proxy.proxy()->stats.nRefresh
75  // << "/" << proxy.proxy()->stats.nArefresh
76  // << ", reconnect " << proxy.proxy()->stats.nReconnect
77  // << "/" << proxy.proxy()->stats.nAreconnect
78  // << ", make " << proxy.proxy()->stats.nMake
79  // << ", load " << proxy.proxy()->stats.nLoad
80  ;
81  //if ( proxy.proxy()->stats.nLoad>0) {
82  out << "Time look up, payloadIds:" << std::endl;
83  const auto& pids = *proxy.requests();
84  for (const auto& id : pids)
85  out << " " << id.since << " - " << id.till << " : " << id.payloadId << std::endl;
86  }
87 
88 } // namespace
89 
90 /*
91  * config Param
92  * RefreshEachRun: if true will refresh the IOV at each new run (or lumiSection)
93  * DumpStat: if true dump the statistics of all DataProxy (currently on cout)
94  * DBParameters: configuration set of the connection
95  * globaltag: The GlobalTag
96  * toGet: list of record label tag connection-string to add/overwrite the content of the global-tag
97  */
99  : m_connection(),
100  m_connectionString(""),
101  m_frontierKey(""),
102  m_lastRun(0), // for the stat
103  m_lastLumi(0), // for the stat
104  m_policy(NOREFRESH),
105  m_doDump(iConfig.getUntrackedParameter<bool>("DumpStat", false)) {
106  if (iConfig.getUntrackedParameter<bool>("RefreshAlways", false)) {
108  }
109  if (iConfig.getUntrackedParameter<bool>("RefreshOpenIOVs", false)) {
111  }
112  if (iConfig.getUntrackedParameter<bool>("RefreshEachRun", false)) {
114  }
115  if (iConfig.getUntrackedParameter<bool>("ReconnectEachRun", false)) {
117  }
118 
119  Stats s = {0, 0, 0, 0, 0, 0, 0, 0};
120  m_stats = s;
121 
122  /*parameter set parsing
123  */
125  if (iConfig.exists("globaltag")) {
126  globaltag = iConfig.getParameter<std::string>("globaltag");
127  // the global tag _requires_ a connection string
128  m_connectionString = iConfig.getParameter<std::string>("connect");
129 
130  if (!globaltag.empty()) {
132  if (siteLocalConfig.isAvailable()) {
133  if (siteLocalConfig->useLocalConnectString()) {
134  std::string const& localConnectPrefix = siteLocalConfig->localConnectPrefix();
135  std::string const& localConnectSuffix = siteLocalConfig->localConnectSuffix();
136  m_connectionString = localConnectPrefix + globaltag + localConnectSuffix;
137  }
138  }
139  }
140  } else if (iConfig.exists("connect")) // default connection string
141  m_connectionString = iConfig.getParameter<std::string>("connect");
142 
143  // frontier key
144  m_frontierKey = iConfig.getUntrackedParameter<std::string>("frontierKey", "");
145 
146  // snapshot
147  boost::posix_time::ptime snapshotTime;
148  if (iConfig.exists("snapshotTime")) {
149  std::string snapshotTimeString = iConfig.getParameter<std::string>("snapshotTime");
150  if (!snapshotTimeString.empty())
151  snapshotTime = boost::posix_time::time_from_string(snapshotTimeString);
152  }
153 
154  // connection configuration
155  if (iConfig.exists("DBParameters")) {
156  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>("DBParameters");
157  m_connection.setParameters(connectionPset);
158  }
160 
161  // load specific record/tag info - it will overwrite the global tag ( if any )
162  std::map<std::string, cond::GTEntry_t> replacements;
163  std::map<std::string, boost::posix_time::ptime> specialSnapshots;
164  if (iConfig.exists("toGet")) {
165  typedef std::vector<edm::ParameterSet> Parameters;
166  Parameters toGet = iConfig.getParameter<Parameters>("toGet");
167  for (Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet) {
168  std::string recordname = itToGet->getParameter<std::string>("record");
169  if (recordname.empty())
170  throw cond::Exception("ESSource: The record name has not been provided in a \"toGet\" entry.");
171  std::string labelname = itToGet->getUntrackedParameter<std::string>("label", "");
172  std::string pfn("");
173  if (m_connectionString.empty() || itToGet->exists("connect"))
174  pfn = itToGet->getParameter<std::string>("connect");
175  std::string tag("");
176  std::string fqTag("");
177  if (itToGet->exists("tag")) {
178  tag = itToGet->getParameter<std::string>("tag");
180  }
181  boost::posix_time::ptime tagSnapshotTime =
182  boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP));
183  if (itToGet->exists("snapshotTime"))
184  tagSnapshotTime = boost::posix_time::time_from_string(itToGet->getParameter<std::string>("snapshotTime"));
185  if (itToGet->exists("refreshTime")) {
186  cond::Time_t refreshTime = itToGet->getParameter<unsigned long long>("refreshTime");
187  m_refreshTimeForRecord.insert(std::make_pair(recordname, refreshTime));
188  }
189 
190  std::string recordLabelKey = joinRecordAndLabel(recordname, labelname);
191  replacements.insert(
192  std::make_pair(recordLabelKey, cond::GTEntry_t(std::make_tuple(recordname, labelname, fqTag))));
193  specialSnapshots.insert(std::make_pair(recordLabelKey, tagSnapshotTime));
194  }
195  }
196 
197  // get the global tag, merge with "replacement" store in "tagCollection"
198  std::vector<std::string> globaltagList;
199  std::vector<std::string> connectList;
200  std::vector<std::string> pfnPrefixList;
201  std::vector<std::string> pfnPostfixList;
202  if (!globaltag.empty()) {
203  std::string pfnPrefix(iConfig.getUntrackedParameter<std::string>("pfnPrefix", ""));
204  std::string pfnPostfix(iConfig.getUntrackedParameter<std::string>("pfnPostfix", ""));
205  boost::split(globaltagList, globaltag, boost::is_any_of("|"), boost::token_compress_off);
206  fillList(m_connectionString, connectList, globaltagList.size(), "connection");
207  fillList(pfnPrefix, pfnPrefixList, globaltagList.size(), "pfnPrefix");
208  fillList(pfnPostfix, pfnPostfixList, globaltagList.size(), "pfnPostfix");
209  }
210 
211  cond::GTMetadata_t gtMetadata;
212  fillTagCollectionFromDB(connectList, pfnPrefixList, pfnPostfixList, globaltagList, replacements, gtMetadata);
213  // if no job specific setting has been found, use the GT timestamp
214  if (snapshotTime.is_not_a_date_time())
215  snapshotTime = gtMetadata.snapshotTime;
216 
217  TagCollection::iterator it;
218  TagCollection::iterator itBeg = m_tagCollection.begin();
219  TagCollection::iterator itEnd = m_tagCollection.end();
220 
221  std::map<std::string, cond::persistency::Session> sessions;
222 
223  /* load DataProxy Plugin (it is strongly typed due to EventSetup ideosyncrasis)
224  * construct proxy
225  * contrary to EventSetup the "object-name" is not used as identifier: multiple entries in a record are
226  * dinstinguished only by their label...
227  * done in two step: first create ProxyWrapper loading ALL required dictionaries
228  * this will allow to initialize POOL in one go for each "database"
229  * The real initialization of the Data-Proxies is done in the second loop
230  */
231  std::vector<std::unique_ptr<cond::DataProxyWrapperBase>> proxyWrappers(m_tagCollection.size());
232  size_t ipb = 0;
233  for (it = itBeg; it != itEnd; ++it) {
234  proxyWrappers[ipb++] = std::unique_ptr<cond::DataProxyWrapperBase>{
235  cond::ProxyFactory::get()->create(buildName(it->second.recordName()))};
236  }
237 
238  // now all required libraries have been loaded
239  // init sessions and DataProxies
240  ipb = 0;
241  for (it = itBeg; it != itEnd; ++it) {
243  std::string tag = it->second.tagName();
244  std::pair<std::string, std::string> tagParams = cond::persistency::parseTag(it->second.tagName());
245  if (!tagParams.second.empty()) {
246  connStr = tagParams.second;
247  tag = tagParams.first;
248  }
249  std::map<std::string, cond::persistency::Session>::iterator p = sessions.find(connStr);
251  if (p == sessions.end()) {
253  std::tuple<std::string, std::string, std::string> connPars =
255  std::string dbService = std::get<1>(connPars);
256  std::string dbAccount = std::get<2>(connPars);
257  if ((dbService == "cms_orcon_prod" || dbService == "cms_orcon_adg") && dbAccount != "CMS_CONDITIONS")
258  edm::LogWarning("CondDBESSource")
259  << "[WARNING] You are reading tag \"" << tag << "\" from V1 account \"" << connStr
260  << "\". The concerned Conditions might be out of date." << std::endl;
261  //open db get tag info (i.e. the IOV token...)
262  nsess = m_connection.createReadOnlySession(connStr, "");
263  sessions.insert(std::make_pair(connStr, nsess));
264  } else
265  nsess = (*p).second;
266 
267  // ownership...
268  ProxyP proxy(std::move(proxyWrappers[ipb++]));
269  // instert in the map
270  m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
271  // initialize
272  boost::posix_time::ptime tagSnapshotTime = snapshotTime;
273  auto tagSnapshotIter = specialSnapshots.find(it->first);
274  if (tagSnapshotIter != specialSnapshots.end())
275  tagSnapshotTime = tagSnapshotIter->second;
276  // finally, if the snapshot is set to infinity, reset the snapshot to null, to take the full iov set...
277  if (tagSnapshotTime == boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP)))
278  tagSnapshotTime = boost::posix_time::ptime();
279 
280  proxy->lateInit(nsess, tag, tagSnapshotTime, it->second.recordLabel(), connStr, &m_queue, &m_mutex);
281  }
282 
283  // one loaded expose all other tags to the Proxy!
284  CondGetterFromESSource visitor(m_proxies);
285  ProxyMap::iterator b = m_proxies.begin();
286  ProxyMap::iterator e = m_proxies.end();
287  for (; b != e; b++) {
288  (*b).second->proxy(0)->loadMore(visitor);
289 
292  if (recordKey.type() != EventSetupRecordKey::TypeTag()) {
293  findingRecordWithKey(recordKey);
294  usingRecordWithKey(recordKey);
295  }
296  }
297 
298  m_stats.nData = m_proxies.size();
299 }
300 
301 void CondDBESSource::fillList(const std::string& stringList,
302  std::vector<std::string>& listToFill,
303  const unsigned int listSize,
304  const std::string& type) {
305  boost::split(listToFill, stringList, boost::is_any_of("|"), boost::token_compress_off);
306  // If it is one clone it for each GT
307  if (listToFill.size() == 1) {
308  for (unsigned int i = 1; i < listSize; ++i) {
309  listToFill.push_back(stringList);
310  }
311  }
312  // else if they don't match the number of GTs throw an exception
313  else if (listSize != listToFill.size()) {
314  throw cond::Exception(
315  std::string("ESSource: number of global tag components does not match number of " + type + " strings"));
316  }
317 }
318 
320  //dump info FIXME: find a more suitable place...
321  if (m_doDump) {
322  std::cout << "CondDBESSource Statistics" << std::endl
323  << "DataProxy " << m_stats.nData << " setInterval " << m_stats.nSet << " Runs " << m_stats.nRun
324  << " Lumis " << m_stats.nLumi << " Refresh " << m_stats.nRefresh << " Actual Refresh "
325  << m_stats.nActualRefresh << " Reconnect " << m_stats.nReconnect << " Actual Reconnect "
327  std::cout << std::endl;
328 
329  ProxyMap::iterator b = m_proxies.begin();
330  ProxyMap::iterator e = m_proxies.end();
331  for (; b != e; b++) {
332  dumpInfo(std::cout, (*b).first, *(*b).second);
333  std::cout << "\n" << std::endl;
334  }
335 
336  // FIXME
337  // We shall eventually close transaction and session...
338  }
339 }
340 
341 //
342 // invoked by EventSetUp: for a given record return the smallest IOV for which iTime is valid
343 // limit to next run/lumisection of Refresh is required
344 //
346  const edm::IOVSyncValue& iTime,
347  edm::ValidityInterval& oInterval) {
348  std::string recordname = iKey.name();
349 
350  edm::LogInfo("CondDBESSource") << "Getting data for record \"" << recordname << "\" to be consumed by "
351  << iTime.eventID() << ", timestamp: " << iTime.time().value()
352  << "; from CondDBESSource::setIntervalFor";
353 
354  std::lock_guard<std::mutex> guard(m_mutex);
355  m_stats.nSet++;
356  //{
357  // not really required, keep here for the time being
358  if (iTime.eventID().run() != m_lastRun) {
359  m_lastRun = iTime.eventID().run();
360  m_stats.nRun++;
361  }
362  if (iTime.luminosityBlockNumber() != m_lastLumi) {
364  m_stats.nLumi++;
365  }
366  //}
367  cond::Time_t lastTime = m_lastRun;
368  cond::Time_t defaultIovSize = cond::time::MAX_VAL;
369  cond::Time_t minDiffTime = 1;
370  bool refreshThisRecord = false;
371  if (m_policy != REFRESH_ALWAYS) {
372  auto iR = m_refreshTimeForRecord.find(recordname);
373  refreshThisRecord = (iR != m_refreshTimeForRecord.end());
374  if (refreshThisRecord) {
376  defaultIovSize = iR->second;
377  minDiffTime = defaultIovSize;
378  }
379  }
380  bool doRefresh = false;
381  if (m_policy == REFRESH_EACH_RUN || m_policy == RECONNECT_EACH_RUN || refreshThisRecord) {
382  // find out the last run number for the proxy of the specified record
383  std::map<std::string, cond::Time_t>::iterator iRec = m_lastRecordRuns.find(recordname);
384  if (iRec != m_lastRecordRuns.end()) {
385  cond::Time_t lastRecordRun = iRec->second;
386  cond::Time_t diffTime = lastTime - lastRecordRun;
387  if (lastRecordRun > lastTime)
388  diffTime = lastRecordRun - lastTime;
389  if (diffTime >= minDiffTime) {
390  // a refresh is required!
391  doRefresh = true;
392  iRec->second = lastTime;
393  edm::LogInfo("CondDBESSource") << "Preparing refresh for record \"" << recordname
394  << "\" since there has been a transition from run/lumi " << lastRecordRun
395  << " to run/lumi " << lastTime << "; from CondDBESSource::setIntervalFor";
396  }
397  } else {
398  doRefresh = true;
399  m_lastRecordRuns.insert(std::make_pair(recordname, lastTime));
400  edm::LogInfo("CondDBESSource") << "Preparing refresh for record \"" << recordname << "\" for " << iTime.eventID()
401  << ", timestamp: " << iTime.time().value()
402  << "; from CondDBESSource::setIntervalFor";
403  }
404  if (!doRefresh)
405  edm::LogInfo("CondDBESSource") << "Though enabled, refresh not needed for record \"" << recordname << "\" for "
406  << iTime.eventID() << ", timestamp: " << iTime.time().value()
407  << "; from CondDBESSource::setIntervalFor";
408  } else if (m_policy == REFRESH_ALWAYS || m_policy == REFRESH_OPEN_IOVS) {
409  doRefresh = true;
410  edm::LogInfo("CondDBESSource") << "Forcing refresh for record \"" << recordname << "\" for " << iTime.eventID()
411  << ", timestamp: " << iTime.time().value()
412  << "; from CondDBESSource::setIntervalFor";
413  }
414 
416 
417  // compute the smallest interval (assume all objects have the same timetype....)
418  cond::ValidityInterval recordValidity(1, cond::TIMELIMIT);
419  cond::TimeType timetype = cond::TimeType::invalid;
420  bool userTime = true;
421 
422  //FIXME use equal_range
423  ProxyMap::const_iterator pmBegin = m_proxies.lower_bound(recordname);
424  ProxyMap::const_iterator pmEnd = m_proxies.upper_bound(recordname);
425  if (pmBegin == pmEnd) {
426  edm::LogInfo("CondDBESSource") << "No DataProxy (Pluging) found for record \"" << recordname
427  << "\"; from CondDBESSource::setIntervalFor";
428  return;
429  }
430 
431  for (ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter) {
432  edm::LogInfo("CondDBESSource") << "Processing record \"" << recordname << "\" and label \""
433  << pmIter->second->label() << "\" for " << iTime.eventID()
434  << ", timestamp: " << iTime.time().value()
435  << "; from CondDBESSource::setIntervalFor";
436 
437  timetype = (*pmIter).second->timeType();
438 
440  userTime = (0 == abtime);
441 
442  if (userTime)
443  return; // oInterval invalid to avoid that make is called...
444 
445  if (doRefresh) {
446  std::string recKey = joinRecordAndLabel(recordname, pmIter->second->label());
447  TagCollection::const_iterator tcIter = m_tagCollection.find(recKey);
448  if (tcIter == m_tagCollection.end()) {
449  edm::LogInfo("CondDBESSource") << "No Tag found for record \"" << recordname << "\" and label \""
450  << pmIter->second->label() << "\"; from CondDBESSource::setIntervalFor";
451  return;
452  }
453 
454  // first reconnect if required
455  if (m_policy == RECONNECT_EACH_RUN || refreshThisRecord) {
456  edm::LogInfo("CondDBESSource")
457  << "Checking if the session must be closed and re-opened for getting correct conditions"
458  << "; from CondDBESSource::setIntervalFor";
459  std::stringstream transId;
460  transId << lastTime;
461  if (!m_frontierKey.empty()) {
462  transId << "_" << m_frontierKey;
463  }
465  std::pair<std::string, std::string> tagParams = cond::persistency::parseTag(tcIter->second.tagName());
466  if (!tagParams.second.empty())
467  connStr = tagParams.second;
468  std::map<std::string, std::pair<cond::persistency::Session, std::string>>* sessionPool = &m_sessionPool;
469  if (refreshThisRecord) {
470  sessionPool = &m_sessionPoolForLumiConditions;
471  }
472  auto iSess = sessionPool->find(connStr);
473  bool reopen = false;
474  if (iSess != sessionPool->end()) {
475  if (iSess->second.second != transId.str()) {
476  // the available session is open for a different run: reopen
477  reopen = true;
478  iSess->second.second = transId.str();
479  }
480  } else {
481  // no available session: probably first run analysed...
482  iSess =
483  sessionPool->insert(std::make_pair(connStr, std::make_pair(cond::persistency::Session(), transId.str())))
484  .first;
485  reopen = true;
486  }
487  if (reopen) {
488  iSess->second.first = m_connection.createReadOnlySession(connStr, transId.str());
489  edm::LogInfo("CondDBESSource") << "Re-opening the session with connection string " << connStr
490  << " and new transaction Id " << transId.str()
491  << "; from CondDBESSource::setIntervalFor";
492  }
493 
494  edm::LogInfo("CondDBESSource") << "Reconnecting to \"" << connStr << "\" for getting new payload for record \""
495  << recordname << "\" and label \"" << pmIter->second->label()
496  << "\" from IOV tag \"" << tcIter->second.tagName() << "\" to be consumed by "
497  << iTime.eventID() << ", timestamp: " << iTime.time().value()
498  << "; from CondDBESSource::setIntervalFor";
499  pmIter->second->session() = iSess->second.first;
500  pmIter->second->reload();
501  //if( isSizeIncreased )
502  //edm::LogInfo( "CondDBESSource" ) << "After reconnecting, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
503  // << "\" was found; from CondDBESSource::setIntervalFor";
504  //m_stats.nActualReconnect += isSizeIncreased;
506  } else {
507  edm::LogInfo("CondDBESSource") << "Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
508  << "\" for getting new payload for record \"" << recordname << "\" and label \""
509  << pmIter->second->label() << "\" to be consumed by " << iTime.eventID()
510  << ", timestamp: " << iTime.time().value()
511  << "; from CondDBESSource::setIntervalFor";
512  pmIter->second->reload();
513  //if( isSizeIncreased )
514  // edm::LogInfo( "CondDBESSource" ) << "After refreshing, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
515  // << "\" was found; from CondDBESSource::setIntervalFor";
516  //m_stats.nActualRefresh += isSizeIncreased;
517  m_stats.nRefresh++;
518  }
519  }
520 
521  /*
522  // make oInterval valid For Ever
523  {
524  oInterval = edm::ValidityInterval(cond::toIOVSyncValue(recordValidity.first, cond::runnumber, true),
525  cond::toIOVSyncValue(recordValidity.second, cond::runnumber, false));
526  return;
527  }
528  */
529 
530  //query the IOVSequence
531  cond::ValidityInterval validity = (*pmIter).second->setIntervalFor(abtime, defaultIovSize);
532 
533  edm::LogInfo("CondDBESSource") << "Validity coming from IOV sequence for record \"" << recordname
534  << "\" and label \"" << pmIter->second->label() << "\": (" << validity.first << ", "
535  << validity.second << ") for time (type: " << cond::timeTypeNames(timetype) << ") "
536  << abtime << "; from CondDBESSource::setIntervalFor";
537 
538  recordValidity.first = std::max(recordValidity.first, validity.first);
539  recordValidity.second = std::min(recordValidity.second, validity.second);
540  }
541 
542  if (m_policy == REFRESH_OPEN_IOVS) {
543  doRefresh = (recordValidity.second == cond::timeTypeSpecs[timetype].endValue);
544  edm::LogInfo("CondDBESSource") << "Validity for record \"" << recordname
545  << "\" and the corresponding label(s) coming from Condition DB: ("
546  << recordValidity.first << ", " << recordValidity.first
547  << ") as the last IOV element in the IOV sequence is infinity"
548  << "; from CondDBESSource::setIntervalFor";
549  }
550 
551  // to force refresh we set end-value to the minimum such an IOV can extend to: current run or lumiblock
552 
553  if ((!userTime) && recordValidity.second != 0) {
554  edm::IOVSyncValue start = cond::time::toIOVSyncValue(recordValidity.first, timetype, true);
556  : cond::time::toIOVSyncValue(recordValidity.second, timetype, false);
557 
560  }
561  oInterval = edm::ValidityInterval(start, stop);
562  }
563 
564  edm::LogInfo("CondDBESSource") << "Setting validity for record \"" << recordname
565  << "\" and corresponding label(s): starting at " << oInterval.first().eventID()
566  << ", timestamp: " << oInterval.first().time().value() << ", ending at "
567  << oInterval.last().eventID() << ", timestamp: " << oInterval.last().time().value()
568  << ", for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
569  << "; from CondDBESSource::setIntervalFor";
570 }
571 
572 //required by EventSetup System
574  const EventSetupRecordKey& iRecordKey, unsigned int iovIndex) {
575  KeyedProxiesVector keyedProxiesVector;
576 
577  std::string recordname = iRecordKey.name();
578 
579  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
580  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
581  if (b == e) {
582  edm::LogInfo("CondDBESSource") << "No DataProxy (Pluging) found for record \"" << recordname
583  << "\"; from CondDBESSource::registerProxies";
584  return keyedProxiesVector;
585  }
586 
587  for (ProxyMap::const_iterator p = b; p != e; ++p) {
588  if (nullptr != (*p).second.get()) {
589  edm::eventsetup::TypeTag type = (*p).second->type();
590  DataKey key(type, edm::eventsetup::IdTags((*p).second->label().c_str()));
591  keyedProxiesVector.emplace_back(key, (*p).second->edmProxy(iovIndex));
592  }
593  }
594  return keyedProxiesVector;
595 }
596 
597 void CondDBESSource::initConcurrentIOVs(const EventSetupRecordKey& key, unsigned int nConcurrentIOVs) {
598  std::string recordname = key.name();
599  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
600  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
601  for (ProxyMap::const_iterator p = b; p != e; ++p) {
602  if (p->second) {
603  p->second->initConcurrentIOVs(nConcurrentIOVs);
604  }
605  }
606 }
607 
608 // Fills tag collection from the given globaltag
610  const std::string& prefix,
611  const std::string& postfix,
612  const std::string& roottag,
613  std::set<cond::GTEntry_t>& tagcoll,
614  cond::GTMetadata_t& gtMetadata) {
615  if (!roottag.empty()) {
616  if (connectionString.empty())
617  throw cond::Exception(std::string("ESSource: requested global tag ") + roottag +
618  std::string(" but not connection string given"));
619  std::tuple<std::string, std::string, std::string> connPars =
621  if (std::get<2>(connPars) == "CMS_COND_31X_GLOBALTAG") {
622  edm::LogWarning("CondDBESSource")
623  << "[WARNING] You are reading Global Tag \"" << roottag
624  << "\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date."
625  << std::endl;
626  } else if (roottag.rfind("::All") != std::string::npos && std::get<2>(connPars) == "CMS_CONDITIONS") {
627  edm::LogWarning("CondDBESSource") << "[WARNING] You are trying to read Global Tag \"" << roottag
628  << "\" - postfix \"::All\" should not be used for V2." << std::endl;
629  }
631  session.transaction().start(true);
632  cond::persistency::GTProxy gtp = session.readGlobalTag(roottag, prefix, postfix);
633  gtMetadata.snapshotTime = gtp.snapshotTime();
634  for (const auto& gte : gtp) {
635  tagcoll.insert(gte);
636  }
637  session.transaction().commit();
638  }
639 }
640 
641 // fills tagcollection merging with replacement
642 // Note: it assumem the coraldbList and roottagList have the same length. This checked in the constructor that prepares the two lists before calling this method.
643 void CondDBESSource::fillTagCollectionFromDB(const std::vector<std::string>& connectionStringList,
644  const std::vector<std::string>& prefixList,
645  const std::vector<std::string>& postfixList,
646  const std::vector<std::string>& roottagList,
647  std::map<std::string, cond::GTEntry_t>& replacement,
648  cond::GTMetadata_t& gtMetadata) {
649  std::set<cond::GTEntry_t> tagcoll;
650 
651  auto connectionString = connectionStringList.begin();
652  auto prefix = prefixList.begin();
653  auto postfix = postfixList.begin();
654  for (auto roottag = roottagList.begin(); roottag != roottagList.end();
655  ++roottag, ++connectionString, ++prefix, ++postfix) {
656  fillTagCollectionFromGT(*connectionString, *prefix, *postfix, *roottag, tagcoll, gtMetadata);
657  }
658 
659  std::set<cond::GTEntry_t>::iterator tagCollIter;
660  std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
661  std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
662 
663  // FIXME the logic is a bit perverse: can be surely linearized (at least simplified!) ....
664  for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
665  std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
666  std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
667  if (fid != replacement.end()) {
668  if (!fid->second.tagName().empty()) {
669  cond::GTEntry_t tagMetadata(
670  std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
671  m_tagCollection.insert(std::make_pair(recordLabelKey, tagMetadata));
672  edm::LogInfo("CondDBESSource") << "Replacing tag \"" << tagCollIter->tagName() << "\" for record \""
673  << tagMetadata.recordName() << "\" and label \"" << tagMetadata.recordLabel()
674  << "\" with tag " << tagMetadata.tagName()
675  << "\"; from CondDBESSource::fillTagCollectionFromDB";
676  } else {
677  m_tagCollection.insert(std::make_pair(recordLabelKey, *tagCollIter));
678  }
679  replacement.erase(fid);
680  } else {
681  m_tagCollection.insert(std::make_pair(recordLabelKey, *tagCollIter));
682  }
683  }
684  std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
685  std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
686  std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
687  for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
688  if (replacementIter->second.tagName().empty()) {
689  std::stringstream msg;
690  msg << "ESSource: no tag provided for record " << replacementIter->second.recordName();
691  if (!replacementIter->second.recordLabel().empty())
692  msg << " and label " << replacementIter->second.recordLabel();
693  throw cond::Exception(msg.str());
694  }
695  m_tagCollection.insert(*replacementIter);
696  }
697 }
698 
699 // backward compatibility for configuration files
701 public:
702  explicit PoolDBESSource(const edm::ParameterSet& ps) : CondDBESSource(ps) {}
703 };
704 
706 //define this as a plug-in
DBConfiguration_cff.toGet
toGet
Definition: DBConfiguration_cff.py:10
edm::eventsetup::heterocontainer::HCTypeTag::findType
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
Definition: HCTypeTag.cc:121
CondDBESSource::REFRESH_EACH_RUN
Definition: CondDBESSource.h:94
CondDBESSource::fillList
void fillList(const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
Definition: CondDBESSource.cc:301
PayloadProxy.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
CondDBESSource::m_connection
cond::persistency::ConnectionPool m_connection
Definition: CondDBESSource.h:111
start
Definition: start.py:1
CondDBESSource::Stats::nActualReconnect
int nActualReconnect
Definition: CondDBESSource.h:137
cond::TimeType
TimeType
Definition: Time.h:19
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
CondDBESSource::Stats::nRun
int nRun
Definition: CondDBESSource.h:132
cond::GTMetadata_t
Definition: Types.h:101
Exception.h
cond::persistency::GTProxy
Definition: GTProxy.h:32
CondDBESSource::initConcurrentIOVs
void initConcurrentIOVs(const EventSetupRecordKey &key, unsigned int nConcurrentIOVs) override
Definition: CondDBESSource.cc:597
cond::DataProxyWrapperBase
Definition: DataProxy.h:65
CondDBESSource.h
DataProxy.h
min
T min(T a, T b)
Definition: MathUtil.h:58
edm::IOVSyncValue::invalidIOVSyncValue
static const IOVSyncValue & invalidIOVSyncValue()
Definition: IOVSyncValue.cc:78
cond::persistency::parseConnectionString
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
Definition: Utils.h:96
cond::time::toIOVSyncValue
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, TimeType timetype, bool startOrStop)
Definition: Time.cc:67
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
CondDBESSource::m_lastRun
unsigned int m_lastRun
Definition: CondDBESSource.h:142
edm::ValidityInterval::last
const IOVSyncValue & last() const
Definition: ValidityInterval.h:38
edm::ValidityInterval
Definition: ValidityInterval.h:28
if
if(0==first)
Definition: CAHitNtupletGeneratorKernelsImpl.h:48
loadRecoTauTagMVAsFromPrepDB_cfi.snapshotTime
snapshotTime
Definition: loadRecoTauTagMVAsFromPrepDB_cfi.py:10
CondDBESSource::m_connectionString
std::string m_connectionString
Definition: CondDBESSource.h:112
edm::ValidityInterval::first
const IOVSyncValue & first() const
Definition: ValidityInterval.h:37
CondDBESSource::m_proxies
ProxyMap m_proxies
Definition: CondDBESSource.h:116
CondDBESSource::REFRESH_ALWAYS
Definition: CondDBESSource.h:94
edm::eventsetup::DataKey
Definition: DataKey.h:29
cond::persistency::fullyQualifiedTag
std::string fullyQualifiedTag(const std::string &tag, const std::string &connectionString)
Definition: GTProxy.cc:8
mps_check.msg
tuple msg
Definition: mps_check.py:285
CondDBESSource::CondDBESSource
CondDBESSource(const edm::ParameterSet &)
Definition: CondDBESSource.cc:98
ProxyFactory.h
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::Timestamp::value
TimeValue_t value() const
Definition: Timestamp.h:45
cond::persistency::Session::readGlobalTag
GTProxy readGlobalTag(const std::string &name)
Definition: Session.cc:163
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::IOVSyncValue::luminosityBlockNumber
LuminosityBlockNumber_t luminosityBlockNumber() const
Definition: IOVSyncValue.h:41
cond::time::MAX_TIMESTAMP
static constexpr const char *const MAX_TIMESTAMP
Definition: Time.h:26
cond::persistency::ConnectionPool::createSession
Session createSession(const std::string &connectionString, bool writeCapable=false)
Definition: ConnectionPool.cc:172
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
CondDBESSource::m_doDump
bool m_doDump
Definition: CondDBESSource.h:146
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
CondDBESSource::m_sessionPoolForLumiConditions
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPoolForLumiConditions
Definition: CondDBESSource.h:123
cond::DataProxyWrapperBase::label
std::string const & label() const
Definition: DataProxy.h:93
CondDBESSource::REFRESH_OPEN_IOVS
Definition: CondDBESSource.h:94
CondDBESSource::m_lastLumi
unsigned int m_lastLumi
Definition: CondDBESSource.h:143
cond::persistency::convertoToOracleConnection
std::string convertoToOracleConnection(const std::string &input)
Definition: Utils.h:121
CondDBESSource::fillTagCollectionFromDB
void fillTagCollectionFromDB(const std::vector< std::string > &connectionStringList, const std::vector< std::string > &prefixList, const std::vector< std::string > &postfixList, const std::vector< std::string > &roottagList, std::map< std::string, cond::GTEntry_t > &replacement, cond::GTMetadata_t &gtMetadata)
Definition: CondDBESSource.cc:643
alignCSCRings.s
s
Definition: alignCSCRings.py:92
CondDBESSource::m_tagCollection
TagCollection m_tagCollection
Definition: CondDBESSource.h:120
CondDBESSource
Definition: CondDBESSource.h:87
cond::timeTypeSpecs
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
CondDBESSource::Stats::nActualRefresh
int nActualRefresh
Definition: CondDBESSource.h:135
cond::time::fromIOVSyncValue
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
Definition: Time.cc:85
Utils.h
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
CondDBESSource::m_stats
Stats m_stats
Definition: CondDBESSource.h:140
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
cond::GTEntry_t
Definition: Types.h:109
Service.h
edm::EventSetupRecordIntervalFinder::findingRecordWithKey
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
Definition: EventSetupRecordIntervalFinder.cc:44
edm::eventsetup::EventSetupRecordKey::TypeTag
heterocontainer::HCTypeTag TypeTag
Definition: EventSetupRecordKey.h:32
edm::eventsetup::EventSetupRecordKey::name
const char * name() const
Definition: EventSetupRecordKey.h:46
cond::DataProxyWrapperBase::connString
std::string const & connString() const
Definition: DataProxy.h:94
b
double b
Definition: hdecay.h:118
cond::persistency::CondGetter
Definition: PayloadProxy.h:20
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
CondDBESSource::m_policy
RefreshPolicy m_policy
Definition: CondDBESSource.h:144
edm::EventID::run
RunNumber_t run() const
Definition: EventID.h:38
DEFINE_FWK_EVENTSETUP_SOURCE
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::IOVProxy
Definition: IOVProxy.h:92
CondDBESSource::Stats::nRefresh
int nRefresh
Definition: CondDBESSource.h:134
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
SourceFactory.h
edm::IOVSyncValue::eventID
const EventID & eventID() const
Definition: IOVSyncValue.h:40
Time.h
edm::ParameterSet
Definition: ParameterSet.h:47
cond::TIMELIMIT
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
cond::persistency::Session
Definition: Session.h:63
edm::eventsetup::heterocontainer::HCTypeTag
Definition: HCTypeTag.h:38
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
CondDBESSource::RECONNECT_EACH_RUN
Definition: CondDBESSource.h:94
edm::eventsetup::EventSetupRecordKey::type
const TypeTag & type() const
Definition: EventSetupRecordKey.h:40
download_sqlite_cfg.globaltag
globaltag
Definition: download_sqlite_cfg.py:14
loadRecoTauTagMVAsFromPrepDB_cfi.pfnPrefix
pfnPrefix
Definition: loadRecoTauTagMVAsFromPrepDB_cfi.py:18
edm::Service
Definition: Service.h:30
cond::persistency::Transaction::commit
void commit()
Definition: Session.cc:23
CondDBESSource::setIntervalFor
void setIntervalFor(const EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
Definition: CondDBESSource.cc:345
cond::time::MAX_VAL
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
cond::persistency::Exception
Base exception class for the object to relational access.
Definition: Exception.h:11
cond::TimeTypeSpecs::endValue
Time_t endValue
Definition: Time.h:42
cond::Exception
persistency::Exception Exception
Definition: Exception.h:25
cond::persistency::parseTag
std::pair< std::string, std::string > parseTag(const std::string &tag)
Definition: GTProxy.cc:14
cond::persistency::ConnectionPool::setParameters
void setParameters(const edm::ParameterSet &connectionPset)
Definition: ConnectionPool.cc:43
CondDBESSource::m_frontierKey
std::string m_frontierKey
Definition: CondDBESSource.h:113
CondDBESSource::Stats::nSet
int nSet
Definition: CondDBESSource.h:131
edm::eventsetup::DataProxyProvider::KeyedProxiesVector
std::vector< std::pair< DataKey, std::shared_ptr< DataProxy > >> KeyedProxiesVector
Definition: DataProxyProvider.h:196
cond::time::lumiTime
Time_t lumiTime(unsigned int run, unsigned int lumiId)
Definition: Time.cc:54
PoolDBESSource::PoolDBESSource
PoolDBESSource(const edm::ParameterSet &ps)
Definition: CondDBESSource.cc:702
cond::persistency::ConnectionPool::configure
void configure()
Definition: ConnectionPool.cc:127
cond::GTEntry_t::tagName
const std::string & tagName() const
Definition: Types.h:122
cond::GTEntry_t::recordLabel
const std::string & recordLabel() const
Definition: Types.h:121
CondDBESSource::registerProxies
KeyedProxiesVector registerProxies(const EventSetupRecordKey &, unsigned int iovIndex) override
Definition: CondDBESSource.cc:573
get
#define get
edm::eventsetup::DataProxyProvider::usingRecordWithKey
void usingRecordWithKey(const EventSetupRecordKey &key)
Definition: DataProxyProvider.h:194
onlinebeammonitor_dqm_sourceclient-live_cfg.refreshTime
refreshTime
Definition: onlinebeammonitor_dqm_sourceclient-live_cfg.py:126
CondDBESSource::fillTagCollectionFromGT
void fillTagCollectionFromGT(const std::string &connectionString, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::set< cond::GTEntry_t > &tagcoll, cond::GTMetadata_t &gtMetadata)
Definition: CondDBESSource.cc:609
cond::persistency::Session::transaction
Transaction & transaction()
Definition: Session.cc:52
CondDBESSource::m_mutex
std::mutex m_mutex
Definition: CondDBESSource.h:127
cond::persistency::Transaction::start
void start(bool readOnly=true)
Definition: Session.cc:18
PoolDBESSource
Definition: CondDBESSource.cc:700
edm::IOVSyncValue::time
const Timestamp & time() const
Definition: IOVSyncValue.h:42
cond::ValidityInterval
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
cond::timeTypeNames
std::string const & timeTypeNames(int)
Definition: Time.cc:11
CondDBESSource::ProxyMap
std::multimap< std::string, ProxyP > ProxyMap
Definition: CondDBESSource.h:92
eostools.move
def move(src, dest)
Definition: eostools.py:511
CondDBESSource::Stats::nReconnect
int nReconnect
Definition: CondDBESSource.h:136
CondDBESSource::Stats::nData
int nData
Definition: CondDBESSource.h:130
edm::eventsetup::NameTag
Definition: DataKeyTags.h:45
CondDBESSource::m_refreshTimeForRecord
std::map< std::string, cond::Time_t > m_refreshTimeForRecord
Definition: CondDBESSource.h:121
loadRecoTauTagMVAsFromPrepDB_cfi.pfnPostfix
pfnPostfix
Definition: loadRecoTauTagMVAsFromPrepDB_cfi.py:17
edm::IOVSyncValue::beginOfTime
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
CondDBESSource::~CondDBESSource
~CondDBESSource() override
Definition: CondDBESSource.cc:319
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
cond::DataProxyWrapperBase::requests
std::shared_ptr< std::vector< Iov_t > > const & requests() const
Definition: DataProxy.h:101
CondDBESSource::ProxyP
std::shared_ptr< cond::DataProxyWrapperBase > ProxyP
Definition: CondDBESSource.h:91
cond::persistency::GTProxy::snapshotTime
boost::posix_time::ptime snapshotTime() const
Definition: GTProxy.cc:135
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
genParticles_cff.map
map
Definition: genParticles_cff.py:11
cond::persistency::ConnectionPool::createReadOnlySession
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
Definition: ConnectionPool.cc:176
ParameterSet.h
Types.h
CondDBESSource::m_lastRecordRuns
std::map< std::string, cond::Time_t > m_lastRecordRuns
Definition: CondDBESSource.h:124
L1TCSCTPG_cff.siteLocalConfig
siteLocalConfig
Definition: L1TCSCTPG_cff.py:8
l1RCTOmdsFedVectorProducer_cfi.connectionString
connectionString
Definition: l1RCTOmdsFedVectorProducer_cfi.py:4
Parameters
vector< ParameterSet > Parameters
Definition: HLTMuonPlotter.cc:25
CondDBESSource::Stats::nLumi
int nLumi
Definition: CondDBESSource.h:133
crabWrapper.key
key
Definition: crabWrapper.py:19
CondDBESSource::Stats
Definition: CondDBESSource.h:129
cond::GTMetadata_t::snapshotTime
boost::posix_time::ptime snapshotTime
Definition: Types.h:106
cond::DataProxyWrapperBase::tag
std::string const & tag() const
Definition: DataProxy.h:95
CondDBESSource::m_sessionPool
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
Definition: CondDBESSource.h:122
edm::ValidityInterval::invalidInterval
static const ValidityInterval & invalidInterval()
Definition: ValidityInterval.cc:71
hcallasereventfilter2012_cfi.prefix
prefix
Definition: hcallasereventfilter2012_cfi.py:10
CondDBESSource::m_queue
edm::SerialTaskQueue m_queue
Definition: CondDBESSource.h:126
SiteLocalConfig.h
cond::GTEntry_t::recordName
const std::string & recordName() const
Definition: Types.h:120
DBConfiguration_cff.timetype
timetype
Definition: DBConfiguration_cff.py:23
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
cond::time::limitedIOVSyncValue
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
Definition: Time.cc:101