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_lastRun(0), // for the stat
102  m_lastLumi(0), // for the stat
103  m_policy(NOREFRESH),
104  m_doDump(iConfig.getUntrackedParameter<bool>("DumpStat", false)) {
105  if (iConfig.getUntrackedParameter<bool>("RefreshAlways", false)) {
107  }
108  if (iConfig.getUntrackedParameter<bool>("RefreshOpenIOVs", false)) {
110  }
111  if (iConfig.getUntrackedParameter<bool>("RefreshEachRun", false)) {
113  }
114  if (iConfig.getUntrackedParameter<bool>("ReconnectEachRun", false)) {
116  }
117 
118  Stats s = {0, 0, 0, 0, 0, 0, 0, 0};
119  m_stats = s;
120 
121  /*parameter set parsing
122  */
124  if (iConfig.exists("globaltag")) {
125  globaltag = iConfig.getParameter<std::string>("globaltag");
126  // the global tag _requires_ a connection string
127  m_connectionString = iConfig.getParameter<std::string>("connect");
128 
129  if (!globaltag.empty()) {
131  if (siteLocalConfig.isAvailable()) {
132  if (siteLocalConfig->useLocalConnectString()) {
133  std::string const& localConnectPrefix = siteLocalConfig->localConnectPrefix();
134  std::string const& localConnectSuffix = siteLocalConfig->localConnectSuffix();
135  m_connectionString = localConnectPrefix + globaltag + localConnectSuffix;
136  }
137  }
138  }
139  } else if (iConfig.exists("connect")) // default connection string
140  m_connectionString = iConfig.getParameter<std::string>("connect");
141 
142  // snapshot
143  boost::posix_time::ptime snapshotTime;
144  if (iConfig.exists("snapshotTime")) {
145  std::string snapshotTimeString = iConfig.getParameter<std::string>("snapshotTime");
146  if (!snapshotTimeString.empty())
147  snapshotTime = boost::posix_time::time_from_string(snapshotTimeString);
148  }
149 
150  // connection configuration
151  if (iConfig.exists("DBParameters")) {
152  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>("DBParameters");
153  m_connection.setParameters(connectionPset);
154  }
156 
157  // load specific record/tag info - it will overwrite the global tag ( if any )
158  std::map<std::string, cond::GTEntry_t> replacements;
159  std::map<std::string, boost::posix_time::ptime> specialSnapshots;
160  if (iConfig.exists("toGet")) {
161  typedef std::vector<edm::ParameterSet> Parameters;
162  Parameters toGet = iConfig.getParameter<Parameters>("toGet");
163  for (Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet) {
164  std::string recordname = itToGet->getParameter<std::string>("record");
165  if (recordname.empty())
166  throw cond::Exception("ESSource: The record name has not been provided in a \"toGet\" entry.");
167  std::string labelname = itToGet->getUntrackedParameter<std::string>("label", "");
168  std::string pfn("");
169  if (m_connectionString.empty() || itToGet->exists("connect"))
170  pfn = itToGet->getParameter<std::string>("connect");
171  std::string tag("");
172  std::string fqTag("");
173  if (itToGet->exists("tag")) {
174  tag = itToGet->getParameter<std::string>("tag");
176  }
177  boost::posix_time::ptime tagSnapshotTime =
178  boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP));
179  if (itToGet->exists("snapshotTime"))
180  tagSnapshotTime = boost::posix_time::time_from_string(itToGet->getParameter<std::string>("snapshotTime"));
181  if (itToGet->exists("refreshTime")) {
182  cond::Time_t refreshTime = itToGet->getParameter<unsigned long long>("refreshTime");
183  m_refreshTimeForRecord.insert(std::make_pair(recordname, refreshTime));
184  }
185 
186  std::string recordLabelKey = joinRecordAndLabel(recordname, labelname);
187  replacements.insert(
188  std::make_pair(recordLabelKey, cond::GTEntry_t(std::make_tuple(recordname, labelname, fqTag))));
189  specialSnapshots.insert(std::make_pair(recordLabelKey, tagSnapshotTime));
190  }
191  }
192 
193  // get the global tag, merge with "replacement" store in "tagCollection"
194  std::vector<std::string> globaltagList;
195  std::vector<std::string> connectList;
196  std::vector<std::string> pfnPrefixList;
197  std::vector<std::string> pfnPostfixList;
198  if (!globaltag.empty()) {
199  std::string pfnPrefix(iConfig.getUntrackedParameter<std::string>("pfnPrefix", ""));
200  std::string pfnPostfix(iConfig.getUntrackedParameter<std::string>("pfnPostfix", ""));
201  boost::split(globaltagList, globaltag, boost::is_any_of("|"), boost::token_compress_off);
202  fillList(m_connectionString, connectList, globaltagList.size(), "connection");
203  fillList(pfnPrefix, pfnPrefixList, globaltagList.size(), "pfnPrefix");
204  fillList(pfnPostfix, pfnPostfixList, globaltagList.size(), "pfnPostfix");
205  }
206 
207  cond::GTMetadata_t gtMetadata;
208  fillTagCollectionFromDB(connectList, pfnPrefixList, pfnPostfixList, globaltagList, replacements, gtMetadata);
209  // if no job specific setting has been found, use the GT timestamp
210  if (snapshotTime.is_not_a_date_time())
211  snapshotTime = gtMetadata.snapshotTime;
212 
213  TagCollection::iterator it;
214  TagCollection::iterator itBeg = m_tagCollection.begin();
215  TagCollection::iterator itEnd = m_tagCollection.end();
216 
217  std::map<std::string, cond::persistency::Session> sessions;
218 
219  /* load DataProxy Plugin (it is strongly typed due to EventSetup ideosyncrasis)
220  * construct proxy
221  * contrary to EventSetup the "object-name" is not used as identifier: multiple entries in a record are
222  * dinstinguished only by their label...
223  * done in two step: first create ProxyWrapper loading ALL required dictionaries
224  * this will allow to initialize POOL in one go for each "database"
225  * The real initialization of the Data-Proxies is done in the second loop
226  */
227  std::vector<std::unique_ptr<cond::DataProxyWrapperBase>> proxyWrappers(m_tagCollection.size());
228  size_t ipb = 0;
229  for (it = itBeg; it != itEnd; ++it) {
230  proxyWrappers[ipb++] = std::unique_ptr<cond::DataProxyWrapperBase>{
231  cond::ProxyFactory::get()->create(buildName(it->second.recordName()))};
232  }
233 
234  // now all required libraries have been loaded
235  // init sessions and DataProxies
236  ipb = 0;
237  for (it = itBeg; it != itEnd; ++it) {
239  std::string tag = it->second.tagName();
240  std::pair<std::string, std::string> tagParams = cond::persistency::parseTag(it->second.tagName());
241  if (!tagParams.second.empty()) {
242  connStr = tagParams.second;
243  tag = tagParams.first;
244  }
245  std::map<std::string, cond::persistency::Session>::iterator p = sessions.find(connStr);
247  if (p == sessions.end()) {
249  std::tuple<std::string, std::string, std::string> connPars =
251  std::string dbService = std::get<1>(connPars);
252  std::string dbAccount = std::get<2>(connPars);
253  if ((dbService == "cms_orcon_prod" || dbService == "cms_orcon_adg") && dbAccount != "CMS_CONDITIONS")
254  edm::LogWarning("CondDBESSource")
255  << "[WARNING] You are reading tag \"" << tag << "\" from V1 account \"" << connStr
256  << "\". The concerned Conditions might be out of date." << std::endl;
257  //open db get tag info (i.e. the IOV token...)
258  nsess = m_connection.createReadOnlySession(connStr, "");
259  sessions.insert(std::make_pair(connStr, nsess));
260  } else
261  nsess = (*p).second;
262 
263  // ownership...
264  ProxyP proxy(std::move(proxyWrappers[ipb++]));
265  // instert in the map
266  m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
267  // initialize
268  boost::posix_time::ptime tagSnapshotTime = snapshotTime;
269  auto tagSnapshotIter = specialSnapshots.find(it->first);
270  if (tagSnapshotIter != specialSnapshots.end())
271  tagSnapshotTime = tagSnapshotIter->second;
272  // finally, if the snapshot is set to infinity, reset the snapshot to null, to take the full iov set...
273  if (tagSnapshotTime == boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP)))
274  tagSnapshotTime = boost::posix_time::ptime();
275 
276  proxy->lateInit(nsess, tag, tagSnapshotTime, it->second.recordLabel(), connStr, &m_queue, &m_mutex);
277  }
278 
279  // one loaded expose all other tags to the Proxy!
280  CondGetterFromESSource visitor(m_proxies);
281  ProxyMap::iterator b = m_proxies.begin();
282  ProxyMap::iterator e = m_proxies.end();
283  for (; b != e; b++) {
284  (*b).second->proxy(0)->loadMore(visitor);
285 
288  if (recordKey.type() != EventSetupRecordKey::TypeTag()) {
289  findingRecordWithKey(recordKey);
290  usingRecordWithKey(recordKey);
291  }
292  }
293 
294  m_stats.nData = m_proxies.size();
295 }
296 
297 void CondDBESSource::fillList(const std::string& stringList,
298  std::vector<std::string>& listToFill,
299  const unsigned int listSize,
300  const std::string& type) {
301  boost::split(listToFill, stringList, boost::is_any_of("|"), boost::token_compress_off);
302  // If it is one clone it for each GT
303  if (listToFill.size() == 1) {
304  for (unsigned int i = 1; i < listSize; ++i) {
305  listToFill.push_back(stringList);
306  }
307  }
308  // else if they don't match the number of GTs throw an exception
309  else if (listSize != listToFill.size()) {
310  throw cond::Exception(
311  std::string("ESSource: number of global tag components does not match number of " + type + " strings"));
312  }
313 }
314 
316  //dump info FIXME: find a more suitable place...
317  if (m_doDump) {
318  std::cout << "CondDBESSource Statistics" << std::endl
319  << "DataProxy " << m_stats.nData << " setInterval " << m_stats.nSet << " Runs " << m_stats.nRun
320  << " Lumis " << m_stats.nLumi << " Refresh " << m_stats.nRefresh << " Actual Refresh "
321  << m_stats.nActualRefresh << " Reconnect " << m_stats.nReconnect << " Actual Reconnect "
323  std::cout << std::endl;
324 
325  ProxyMap::iterator b = m_proxies.begin();
326  ProxyMap::iterator e = m_proxies.end();
327  for (; b != e; b++) {
328  dumpInfo(std::cout, (*b).first, *(*b).second);
329  std::cout << "\n" << std::endl;
330  }
331 
332  // FIXME
333  // We shall eventually close transaction and session...
334  }
335 }
336 
337 //
338 // invoked by EventSetUp: for a given record return the smallest IOV for which iTime is valid
339 // limit to next run/lumisection of Refresh is required
340 //
342  const edm::IOVSyncValue& iTime,
343  edm::ValidityInterval& oInterval) {
344  std::string recordname = iKey.name();
345 
346  edm::LogInfo("CondDBESSource") << "Getting data for record \"" << recordname << "\" to be consumed by "
347  << iTime.eventID() << ", timestamp: " << iTime.time().value()
348  << "; from CondDBESSource::setIntervalFor";
349 
350  std::lock_guard<std::mutex> guard(m_mutex);
351  m_stats.nSet++;
352  //{
353  // not really required, keep here for the time being
354  if (iTime.eventID().run() != m_lastRun) {
355  m_lastRun = iTime.eventID().run();
356  m_stats.nRun++;
357  }
358  if (iTime.luminosityBlockNumber() != m_lastLumi) {
360  m_stats.nLumi++;
361  }
362  //}
363  cond::Time_t lastTime = m_lastRun;
364  cond::Time_t defaultIovSize = cond::time::MAX_VAL;
365  cond::Time_t minDiffTime = 1;
366  bool refreshThisRecord = false;
367  if (m_policy != REFRESH_ALWAYS) {
368  auto iR = m_refreshTimeForRecord.find(recordname);
369  refreshThisRecord = (iR != m_refreshTimeForRecord.end());
370  if (refreshThisRecord) {
372  defaultIovSize = iR->second;
373  minDiffTime = defaultIovSize;
374  }
375  }
376  bool doRefresh = false;
377  if (m_policy == REFRESH_EACH_RUN || m_policy == RECONNECT_EACH_RUN || refreshThisRecord) {
378  // find out the last run number for the proxy of the specified record
379  std::map<std::string, cond::Time_t>::iterator iRec = m_lastRecordRuns.find(recordname);
380  if (iRec != m_lastRecordRuns.end()) {
381  cond::Time_t lastRecordRun = iRec->second;
382  cond::Time_t diffTime = lastTime - lastRecordRun;
383  if (lastRecordRun > lastTime)
384  diffTime = lastRecordRun - lastTime;
385  if (diffTime >= minDiffTime) {
386  // a refresh is required!
387  doRefresh = true;
388  iRec->second = lastTime;
389  edm::LogInfo("CondDBESSource") << "Preparing refresh for record \"" << recordname
390  << "\" since there has been a transition from run/lumi " << lastRecordRun
391  << " to run/lumi " << lastTime << "; from CondDBESSource::setIntervalFor";
392  }
393  } else {
394  doRefresh = true;
395  m_lastRecordRuns.insert(std::make_pair(recordname, lastTime));
396  edm::LogInfo("CondDBESSource") << "Preparing refresh for record \"" << recordname << "\" for " << iTime.eventID()
397  << ", timestamp: " << iTime.time().value()
398  << "; from CondDBESSource::setIntervalFor";
399  }
400  if (!doRefresh)
401  edm::LogInfo("CondDBESSource") << "Though enabled, refresh not needed for record \"" << recordname << "\" for "
402  << iTime.eventID() << ", timestamp: " << iTime.time().value()
403  << "; from CondDBESSource::setIntervalFor";
404  } else if (m_policy == REFRESH_ALWAYS || m_policy == REFRESH_OPEN_IOVS) {
405  doRefresh = true;
406  edm::LogInfo("CondDBESSource") << "Forcing refresh for record \"" << recordname << "\" for " << iTime.eventID()
407  << ", timestamp: " << iTime.time().value()
408  << "; from CondDBESSource::setIntervalFor";
409  }
410 
412 
413  // compute the smallest interval (assume all objects have the same timetype....)
414  cond::ValidityInterval recordValidity(1, cond::TIMELIMIT);
415  cond::TimeType timetype = cond::TimeType::invalid;
416  bool userTime = true;
417 
418  //FIXME use equal_range
419  ProxyMap::const_iterator pmBegin = m_proxies.lower_bound(recordname);
420  ProxyMap::const_iterator pmEnd = m_proxies.upper_bound(recordname);
421  if (pmBegin == pmEnd) {
422  edm::LogInfo("CondDBESSource") << "No DataProxy (Pluging) found for record \"" << recordname
423  << "\"; from CondDBESSource::setIntervalFor";
424  return;
425  }
426 
427  for (ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter) {
428  edm::LogInfo("CondDBESSource") << "Processing record \"" << recordname << "\" and label \""
429  << pmIter->second->label() << "\" for " << iTime.eventID()
430  << ", timestamp: " << iTime.time().value()
431  << "; from CondDBESSource::setIntervalFor";
432 
433  timetype = (*pmIter).second->timeType();
434 
436  userTime = (0 == abtime);
437 
438  if (userTime)
439  return; // oInterval invalid to avoid that make is called...
440 
441  if (doRefresh) {
442  std::string recKey = joinRecordAndLabel(recordname, pmIter->second->label());
443  TagCollection::const_iterator tcIter = m_tagCollection.find(recKey);
444  if (tcIter == m_tagCollection.end()) {
445  edm::LogInfo("CondDBESSource") << "No Tag found for record \"" << recordname << "\" and label \""
446  << pmIter->second->label() << "\"; from CondDBESSource::setIntervalFor";
447  return;
448  }
449 
450  // first reconnect if required
451  if (m_policy == RECONNECT_EACH_RUN || refreshThisRecord) {
452  edm::LogInfo("CondDBESSource")
453  << "Checking if the session must be closed and re-opened for getting correct conditions"
454  << "; from CondDBESSource::setIntervalFor";
455  std::stringstream transId;
456  //transId << "long" << m_lastRun;
457  transId << lastTime;
459  std::pair<std::string, std::string> tagParams = cond::persistency::parseTag(tcIter->second.tagName());
460  if (!tagParams.second.empty())
461  connStr = tagParams.second;
462  std::map<std::string, std::pair<cond::persistency::Session, std::string>>* sessionPool = &m_sessionPool;
463  if (refreshThisRecord) {
464  sessionPool = &m_sessionPoolForLumiConditions;
465  }
466  auto iSess = sessionPool->find(connStr);
467  bool reopen = false;
468  if (iSess != sessionPool->end()) {
469  if (iSess->second.second != transId.str()) {
470  // the available session is open for a different run: reopen
471  reopen = true;
472  iSess->second.second = transId.str();
473  }
474  } else {
475  // no available session: probably first run analysed...
476  iSess =
477  sessionPool->insert(std::make_pair(connStr, std::make_pair(cond::persistency::Session(), transId.str())))
478  .first;
479  reopen = true;
480  }
481  if (reopen) {
482  iSess->second.first = m_connection.createReadOnlySession(connStr, transId.str());
483  edm::LogInfo("CondDBESSource") << "Re-opening the session with connection string " << connStr
484  << " and new transaction Id " << transId.str()
485  << "; from CondDBESSource::setIntervalFor";
486  }
487 
488  edm::LogInfo("CondDBESSource") << "Reconnecting to \"" << connStr << "\" for getting new payload for record \""
489  << recordname << "\" and label \"" << pmIter->second->label()
490  << "\" from IOV tag \"" << tcIter->second.tagName() << "\" to be consumed by "
491  << iTime.eventID() << ", timestamp: " << iTime.time().value()
492  << "; from CondDBESSource::setIntervalFor";
493  pmIter->second->session() = iSess->second.first;
494  pmIter->second->reload();
495  //if( isSizeIncreased )
496  //edm::LogInfo( "CondDBESSource" ) << "After reconnecting, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
497  // << "\" was found; from CondDBESSource::setIntervalFor";
498  //m_stats.nActualReconnect += isSizeIncreased;
500  } else {
501  edm::LogInfo("CondDBESSource") << "Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
502  << "\" for getting new payload for record \"" << recordname << "\" and label \""
503  << pmIter->second->label() << "\" to be consumed by " << iTime.eventID()
504  << ", timestamp: " << iTime.time().value()
505  << "; from CondDBESSource::setIntervalFor";
506  pmIter->second->reload();
507  //if( isSizeIncreased )
508  // edm::LogInfo( "CondDBESSource" ) << "After refreshing, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
509  // << "\" was found; from CondDBESSource::setIntervalFor";
510  //m_stats.nActualRefresh += isSizeIncreased;
511  m_stats.nRefresh++;
512  }
513  }
514 
515  /*
516  // make oInterval valid For Ever
517  {
518  oInterval = edm::ValidityInterval(cond::toIOVSyncValue(recordValidity.first, cond::runnumber, true),
519  cond::toIOVSyncValue(recordValidity.second, cond::runnumber, false));
520  return;
521  }
522  */
523 
524  //query the IOVSequence
525  cond::ValidityInterval validity = (*pmIter).second->setIntervalFor(abtime, defaultIovSize);
526 
527  edm::LogInfo("CondDBESSource") << "Validity coming from IOV sequence for record \"" << recordname
528  << "\" and label \"" << pmIter->second->label() << "\": (" << validity.first << ", "
529  << validity.second << ") for time (type: " << cond::timeTypeNames(timetype) << ") "
530  << abtime << "; from CondDBESSource::setIntervalFor";
531 
532  recordValidity.first = std::max(recordValidity.first, validity.first);
533  recordValidity.second = std::min(recordValidity.second, validity.second);
534  }
535 
536  if (m_policy == REFRESH_OPEN_IOVS) {
537  doRefresh = (recordValidity.second == cond::timeTypeSpecs[timetype].endValue);
538  edm::LogInfo("CondDBESSource") << "Validity for record \"" << recordname
539  << "\" and the corresponding label(s) coming from Condition DB: ("
540  << recordValidity.first << ", " << recordValidity.first
541  << ") as the last IOV element in the IOV sequence is infinity"
542  << "; from CondDBESSource::setIntervalFor";
543  }
544 
545  // to force refresh we set end-value to the minimum such an IOV can extend to: current run or lumiblock
546 
547  if ((!userTime) && recordValidity.second != 0) {
548  edm::IOVSyncValue start = cond::time::toIOVSyncValue(recordValidity.first, timetype, true);
550  : cond::time::toIOVSyncValue(recordValidity.second, timetype, false);
551 
554  }
555  oInterval = edm::ValidityInterval(start, stop);
556  }
557 
558  edm::LogInfo("CondDBESSource") << "Setting validity for record \"" << recordname
559  << "\" and corresponding label(s): starting at " << oInterval.first().eventID()
560  << ", timestamp: " << oInterval.first().time().value() << ", ending at "
561  << oInterval.last().eventID() << ", timestamp: " << oInterval.last().time().value()
562  << ", for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
563  << "; from CondDBESSource::setIntervalFor";
564 }
565 
566 //required by EventSetup System
568  const EventSetupRecordKey& iRecordKey, unsigned int iovIndex) {
569  KeyedProxiesVector keyedProxiesVector;
570 
571  std::string recordname = iRecordKey.name();
572 
573  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
574  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
575  if (b == e) {
576  edm::LogInfo("CondDBESSource") << "No DataProxy (Pluging) found for record \"" << recordname
577  << "\"; from CondDBESSource::registerProxies";
578  return keyedProxiesVector;
579  }
580 
581  for (ProxyMap::const_iterator p = b; p != e; ++p) {
582  if (nullptr != (*p).second.get()) {
583  edm::eventsetup::TypeTag type = (*p).second->type();
584  DataKey key(type, edm::eventsetup::IdTags((*p).second->label().c_str()));
585  keyedProxiesVector.emplace_back(key, (*p).second->edmProxy(iovIndex));
586  }
587  }
588  return keyedProxiesVector;
589 }
590 
591 void CondDBESSource::initConcurrentIOVs(const EventSetupRecordKey& key, unsigned int nConcurrentIOVs) {
592  std::string recordname = key.name();
593  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
594  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
595  for (ProxyMap::const_iterator p = b; p != e; ++p) {
596  if (p->second) {
597  p->second->initConcurrentIOVs(nConcurrentIOVs);
598  }
599  }
600 }
601 
602 // Fills tag collection from the given globaltag
604  const std::string& prefix,
605  const std::string& postfix,
606  const std::string& roottag,
607  std::set<cond::GTEntry_t>& tagcoll,
608  cond::GTMetadata_t& gtMetadata) {
609  if (!roottag.empty()) {
610  if (connectionString.empty())
611  throw cond::Exception(std::string("ESSource: requested global tag ") + roottag +
612  std::string(" but not connection string given"));
613  std::tuple<std::string, std::string, std::string> connPars =
615  if (std::get<2>(connPars) == "CMS_COND_31X_GLOBALTAG") {
616  edm::LogWarning("CondDBESSource")
617  << "[WARNING] You are reading Global Tag \"" << roottag
618  << "\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date."
619  << std::endl;
620  } else if (roottag.rfind("::All") != std::string::npos && std::get<2>(connPars) == "CMS_CONDITIONS") {
621  edm::LogWarning("CondDBESSource") << "[WARNING] You are trying to read Global Tag \"" << roottag
622  << "\" - postfix \"::All\" should not be used for V2." << std::endl;
623  }
625  session.transaction().start(true);
626  cond::persistency::GTProxy gtp = session.readGlobalTag(roottag, prefix, postfix);
627  gtMetadata.snapshotTime = gtp.snapshotTime();
628  for (const auto& gte : gtp) {
629  tagcoll.insert(gte);
630  }
631  session.transaction().commit();
632  }
633 }
634 
635 // fills tagcollection merging with replacement
636 // 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.
637 void CondDBESSource::fillTagCollectionFromDB(const std::vector<std::string>& connectionStringList,
638  const std::vector<std::string>& prefixList,
639  const std::vector<std::string>& postfixList,
640  const std::vector<std::string>& roottagList,
641  std::map<std::string, cond::GTEntry_t>& replacement,
642  cond::GTMetadata_t& gtMetadata) {
643  std::set<cond::GTEntry_t> tagcoll;
644 
645  auto connectionString = connectionStringList.begin();
646  auto prefix = prefixList.begin();
647  auto postfix = postfixList.begin();
648  for (auto roottag = roottagList.begin(); roottag != roottagList.end();
649  ++roottag, ++connectionString, ++prefix, ++postfix) {
650  fillTagCollectionFromGT(*connectionString, *prefix, *postfix, *roottag, tagcoll, gtMetadata);
651  }
652 
653  std::set<cond::GTEntry_t>::iterator tagCollIter;
654  std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
655  std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
656 
657  // FIXME the logic is a bit perverse: can be surely linearized (at least simplified!) ....
658  for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
659  std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
660  std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
661  if (fid != replacement.end()) {
662  if (!fid->second.tagName().empty()) {
663  cond::GTEntry_t tagMetadata(
664  std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
665  m_tagCollection.insert(std::make_pair(recordLabelKey, tagMetadata));
666  edm::LogInfo("CondDBESSource") << "Replacing tag \"" << tagCollIter->tagName() << "\" for record \""
667  << tagMetadata.recordName() << "\" and label \"" << tagMetadata.recordLabel()
668  << "\" with tag " << tagMetadata.tagName()
669  << "\"; from CondDBESSource::fillTagCollectionFromDB";
670  } else {
671  m_tagCollection.insert(std::make_pair(recordLabelKey, *tagCollIter));
672  }
673  replacement.erase(fid);
674  } else {
675  m_tagCollection.insert(std::make_pair(recordLabelKey, *tagCollIter));
676  }
677  }
678  std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
679  std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
680  std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
681  for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
682  if (replacementIter->second.tagName().empty()) {
683  std::stringstream msg;
684  msg << "ESSource: no tag provided for record " << replacementIter->second.recordName();
685  if (!replacementIter->second.recordLabel().empty())
686  msg << " and label " << replacementIter->second.recordLabel();
687  throw cond::Exception(msg.str());
688  }
689  m_tagCollection.insert(*replacementIter);
690  }
691 }
692 
693 // backward compatibility for configuration files
695 public:
696  explicit PoolDBESSource(const edm::ParameterSet& ps) : CondDBESSource(ps) {}
697 };
698 
700 //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:297
PayloadProxy.h
electrons_cff.bool
bool
Definition: electrons_cff.py:393
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:136
cond::TimeType
TimeType
Definition: Time.h:19
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
CondDBESSource::Stats::nRun
int nRun
Definition: CondDBESSource.h:131
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:591
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:141
edm::ValidityInterval::last
const IOVSyncValue & last() const
Definition: ValidityInterval.h:38
edm::ValidityInterval
Definition: ValidityInterval.h:28
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:115
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:158
dqmdumpme.first
first
Definition: dqmdumpme.py:55
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
CondDBESSource::m_doDump
bool m_doDump
Definition: CondDBESSource.h:145
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:122
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:142
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:637
alignCSCRings.s
s
Definition: alignCSCRings.py:92
CondDBESSource::m_tagCollection
TagCollection m_tagCollection
Definition: CondDBESSource.h:119
CondDBESSource
Definition: CondDBESSource.h:87
cond::timeTypeSpecs
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
CondDBESSource::Stats::nActualRefresh
int nActualRefresh
Definition: CondDBESSource.h:134
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:139
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
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
CondDBESSource::m_policy
RefreshPolicy m_policy
Definition: CondDBESSource.h:143
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:133
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:341
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:41
CondDBESSource::Stats::nSet
int nSet
Definition: CondDBESSource.h:130
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:696
cond::persistency::ConnectionPool::configure
void configure()
Definition: ConnectionPool.cc:125
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:567
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:603
cond::persistency::Session::transaction
Transaction & transaction()
Definition: Session.cc:52
CondDBESSource::m_mutex
std::mutex m_mutex
Definition: CondDBESSource.h:126
cond::persistency::Transaction::start
void start(bool readOnly=true)
Definition: Session.cc:18
PoolDBESSource
Definition: CondDBESSource.cc:694
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:135
CondDBESSource::Stats::nData
int nData
Definition: CondDBESSource.h:129
edm::eventsetup::NameTag
Definition: DataKeyTags.h:45
CondDBESSource::m_refreshTimeForRecord
std::map< std::string, cond::Time_t > m_refreshTimeForRecord
Definition: CondDBESSource.h:120
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:315
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:162
ParameterSet.h
Types.h
CondDBESSource::m_lastRecordRuns
std::map< std::string, cond::Time_t > m_lastRecordRuns
Definition: CondDBESSource.h:123
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:132
crabWrapper.key
key
Definition: crabWrapper.py:19
CondDBESSource::Stats
Definition: CondDBESSource.h:128
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:121
edm::ValidityInterval::invalidInterval
static const ValidityInterval & invalidInterval()
Definition: ValidityInterval.cc:71
CondDBESSource::m_queue
edm::SerialTaskQueue m_queue
Definition: CondDBESSource.h:125
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
ZMuMuAnalysisNtupler_cff.prefix
prefix
Definition: ZMuMuAnalysisNtupler_cff.py:14
cond::time::limitedIOVSyncValue
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
Definition: Time.cc:101