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