CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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/shared_ptr.hpp"
16 #include <boost/algorithm/string.hpp>
21 
24 
28 #include <exception>
29 
30 #include <iomanip>
31 
32 namespace {
33  /* utility ot build the name of the plugin corresponding to a given record
34  se ESSources
35  */
37  buildName( std::string const & iRecordName ) {
38  return iRecordName + std::string( "@NewProxy" );
39  }
40 
41  std::string joinRecordAndLabel( std::string const & iRecordName, std::string const & iLabelName ) {
42  return iRecordName + std::string( "@" ) + iLabelName;
43  }
44 
45  /* utility class to return a IOVs associated to a given "name"
46  This implementation return the IOV associated to a record...
47  It is essentialy a workaround to get the full IOV out of the tag colector
48  that is not accessible as hidden in the ESSource
49  FIXME: need to support label??
50  */
51  class CondGetterFromESSource : public cond::persistency::CondGetter {
52  public:
53  CondGetterFromESSource(CondDBESSource::ProxyMap const & ip) : m_proxies(ip){}
54  virtual ~CondGetterFromESSource(){}
55 
56  cond::persistency::IOVProxy get(std::string name) const override {
57  CondDBESSource::ProxyMap::const_iterator p = m_proxies.find(name);
58  if ( p != m_proxies.end())
59  return (*p).second->proxy()->iov();
61  }
62 
63  CondDBESSource::ProxyMap const & m_proxies;
64  };
65 
66  // This needs to be re-design and implemented...
67  // dump the state of a DataProxy
68  void dumpInfo(std::ostream & out, std::string const & recName, cond::DataProxyWrapperBase const & proxy) {
69  //cond::SequenceState state(proxy.proxy()->iov().state());
70  out << recName << " / " << proxy.label() << ": "
71  << proxy.connString() << ", " << proxy.tag() << "\n "
72  // << state.size() << ", " << state.revision() << ", "
73  // << cond::time::to_boost(state.timestamp()) << "\n "
74  // << state.comment()
75  << "\n "
76  // << "refresh " << proxy.proxy()->stats.nRefresh
77  // << "/" << proxy.proxy()->stats.nArefresh
78  // << ", reconnect " << proxy.proxy()->stats.nReconnect
79  // << "/" << proxy.proxy()->stats.nAreconnect
80  // << ", make " << proxy.proxy()->stats.nMake
81  // << ", load " << proxy.proxy()->stats.nLoad
82  ;
83  //if ( proxy.proxy()->stats.nLoad>0) {
84  out << "Time look up, payloadIds:" <<std::endl;
85  const auto& pids = proxy.proxy()->requests();
86  for (auto id: pids )
87  out << " "<< id.since <<" - "<< id.till <<" : "<<id.payloadId<<std::endl;
88  }
89 
90 }
91 
92 
93 /*
94  * config Param
95  * RefreshEachRun: if true will refresh the IOV at each new run (or lumiSection)
96  * DumpStat: if true dump the statistics of all DataProxy (currently on cout)
97  * DBParameters: configuration set of the connection
98  * globaltag: The GlobalTag
99  * toGet: list of record label tag connection-string to add/overwrite the content of the global-tag
100  */
102  m_connection(),
103  m_connectionString(""),
104  m_lastRun(0), // for the stat
105  m_lastLumi(0), // for the stat
106  m_policy( NOREFRESH ),
107  m_doDump( iConfig.getUntrackedParameter<bool>( "DumpStat", false ) )
108 {
109  if( iConfig.getUntrackedParameter<bool>( "RefreshAlways", false ) ) {
111  }
112  if( iConfig.getUntrackedParameter<bool>( "RefreshOpenIOVs", false ) ) {
114  }
115  if( iConfig.getUntrackedParameter<bool>( "RefreshEachRun", false ) ) {
117  }
118  if( iConfig.getUntrackedParameter<bool>( "ReconnectEachRun", false ) ) {
120  }
121 
122  Stats s = {0,0,0,0,0,0,0,0};
123  m_stats = s;
124 
125  /*parameter set parsing
126  */
128  if( iConfig.exists( "globaltag" ) ) {
129  globaltag = iConfig.getParameter<std::string>( "globaltag" );
130  // the global tag _requires_ a connection string
131  m_connectionString= iConfig.getParameter<std::string>("connect");
132  } else if( iConfig.exists("connect") ) // default connection string
133  m_connectionString= iConfig.getParameter<std::string>("connect");
134 
135  // snapshot
136  boost::posix_time::ptime snapshotTime;
137  if( iConfig.exists( "snapshotTime" ) ){
138  std::string snapshotTimeString = iConfig.getParameter<std::string>("snapshotTime" );
139  if( !snapshotTimeString.empty() ) snapshotTime = boost::posix_time::time_from_string( snapshotTimeString );
140  }
141 
142  // connection configuration
143  if( iConfig.exists("DBParameters") ) {
144  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>( "DBParameters" );
145  m_connection.setParameters( connectionPset );
146  }
148 
149  // load specific record/tag info - it will overwrite the global tag ( if any )
150  std::map<std::string,cond::GTEntry_t> replacements;
151  std::map<std::string,boost::posix_time::ptime> specialSnapshots;
152  if( iConfig.exists( "toGet" ) ) {
153  typedef std::vector< edm::ParameterSet > Parameters;
154  Parameters toGet = iConfig.getParameter<Parameters>( "toGet" );
155  for( Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet ) {
156  std::string recordname = itToGet->getParameter<std::string>( "record" );
157  if( recordname.empty() ) throw cond::Exception( "ESSource: The record name has not been provided in a \"toGet\" entry." );
158  std::string labelname = itToGet->getUntrackedParameter<std::string>( "label", "" );
159  std::string pfn("");
160  if( m_connectionString.empty() || itToGet->exists("connect") ) pfn = itToGet->getParameter<std::string>( "connect" );
161  std::string tag("");
162  std::string fqTag("");
163  if( itToGet->exists("tag") ) {
164  tag = itToGet->getParameter<std::string>( "tag" );
165  fqTag = cond::persistency::fullyQualifiedTag(tag,pfn);
166  }
167  boost::posix_time::ptime tagSnapshotTime = boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP) );
168  if( itToGet->exists("snapshotTime") ) tagSnapshotTime = boost::posix_time::time_from_string( itToGet->getParameter<std::string>("snapshotTime" ) );
169  std::string recordLabelKey = joinRecordAndLabel( recordname, labelname );
170  replacements.insert( std::make_pair( recordLabelKey, cond::GTEntry_t( std::make_tuple(recordname, labelname, fqTag ) ) ) );
171  specialSnapshots.insert( std::make_pair( recordLabelKey, tagSnapshotTime ) );
172  }
173  }
174 
175  // get the global tag, merge with "replacement" store in "tagCollection"
176  std::vector<std::string> globaltagList;
177  std::vector<std::string> connectList;
178  std::vector<std::string> pfnPrefixList;
179  std::vector<std::string> pfnPostfixList;
180  if( !globaltag.empty() ) {
181  std::string pfnPrefix(iConfig.getUntrackedParameter<std::string>( "pfnPrefix", "" ));
182  std::string pfnPostfix(iConfig.getUntrackedParameter<std::string>( "pfnPostfix", "" ));
183  boost::split( globaltagList, globaltag, boost::is_any_of("|"), boost::token_compress_off );
184  fillList(m_connectionString, connectList, globaltagList.size(), "connection");
185  fillList(pfnPrefix, pfnPrefixList, globaltagList.size(), "pfnPrefix");
186  fillList(pfnPostfix, pfnPostfixList, globaltagList.size(), "pfnPostfix");
187  }
188 
189  cond::GTMetadata_t gtMetadata;
190  fillTagCollectionFromDB(connectList,
191  pfnPrefixList,
192  pfnPostfixList,
193  globaltagList,
194  replacements,
195  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<cond::DataProxyWrapperBase *> proxyWrappers(m_tagCollection.size());
215  size_t ipb=0;
216  for(it=itBeg;it!=itEnd;++it){
217  proxyWrappers[ipb++] =
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 = cond::persistency::parseConnectionString( oracleConnStr );
237  std::string dbService = std::get<1>( connPars );
238  std::string dbAccount = std::get<2>( connPars );
239  if( (dbService == "cms_orcon_prod" || dbService == "cms_orcon_adg") && dbAccount != "CMS_CONDITIONS" )
240  edm::LogWarning( "CondDBESSource" )<<"[WARNING] You are reading tag \""<<tag<<"\" from V1 account \""<<connStr<<"\". The concerned Conditions might be out of date."<<std::endl;
241  //open db get tag info (i.e. the IOV token...)
242  nsess = m_connection.createReadOnlySession( connStr, "" );
243  sessions.insert(std::make_pair( connStr, nsess));
244  } else nsess = (*p).second;
245 
246  // ownership...
247  ProxyP proxy(proxyWrappers[ipb++]);
248  // instert in the map
249  m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
250  // initialize
251  boost::posix_time::ptime tagSnapshotTime = snapshotTime;
252  auto tagSnapshotIter = specialSnapshots.find( it->first );
253  if( tagSnapshotIter != specialSnapshots.end() ) tagSnapshotTime = tagSnapshotIter->second;
254  // finally, if the snapshot is set to infinity, reset the snapshot to null, to take the full iov set...
255  if(tagSnapshotTime == boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP) ) )
256  tagSnapshotTime = boost::posix_time::ptime();
257 
258  proxy->lateInit(nsess, tag, tagSnapshotTime, it->second.recordLabel(), connStr);
259  }
260 
261  // one loaded expose all other tags to the Proxy!
262  CondGetterFromESSource visitor( m_proxies );
263  ProxyMap::iterator b = m_proxies.begin();
264  ProxyMap::iterator e = m_proxies.end();
265  for ( ;b != e; b++ ) {
266 
267  (*b).second->proxy()->loadMore( visitor );
268 
271  if( recordKey.type() != edm::eventsetup::EventSetupRecordKey::TypeTag() ) {
272  findingRecordWithKey( recordKey );
273  usingRecordWithKey( recordKey );
274  }
275  }
276 
277  m_stats.nData=m_proxies.size();
278 
279 }
280 
281 void CondDBESSource::fillList(const std::string & stringList, std::vector<std::string> & listToFill, const unsigned int listSize, const std::string & type)
282 {
283  boost::split( listToFill, stringList, boost::is_any_of("|"), boost::token_compress_off );
284  // If it is one clone it for each GT
285  if( listToFill.size() == 1 ) {
286  for( unsigned int i=1; i<listSize; ++i ) {
287  listToFill.push_back(stringList);
288  }
289  }
290  // else if they don't match the number of GTs throw an exception
291  else if( listSize != listToFill.size() ) {
292  throw cond::Exception( std::string( "ESSource: number of global tag components does not match number of "+type+" strings" ) );
293  }
294 }
295 
297  //dump info FIXME: find a more suitable place...
298  if (m_doDump) {
299  std::cout << "CondDBESSource Statistics" << std::endl
300  << "DataProxy " << m_stats.nData
301  << " setInterval " << m_stats.nSet
302  << " Runs " << m_stats.nRun
303  << " Lumis " << m_stats.nLumi
304  << " Refresh " << m_stats.nRefresh
305  << " Actual Refresh " << m_stats.nActualRefresh
306  << " Reconnect " << m_stats.nReconnect
307  << " Actual Reconnect " << m_stats.nActualReconnect;
308  std::cout << std::endl;
309 
310 
311  ProxyMap::iterator b= m_proxies.begin();
312  ProxyMap::iterator e= m_proxies.end();
313  for ( ;b != e; b++ ) {
314  dumpInfo( std::cout, (*b).first, *(*b).second );
315  std::cout << "\n" << std::endl;
316  }
317 
318  // FIXME
319  // We shall eventually close transaction and session...
320  }
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 //
328 void
330 
331  std::string recordname=iKey.name();
332 
333  edm::LogInfo( "CondDBESSource" ) << "Getting data for record \""<< recordname
334  << "\" to be consumed by "<< 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 
350  bool doRefresh = false;
352  // find out the last run number for the proxy of the specified record
353  std::map<std::string,unsigned int>::iterator iRec = m_lastRecordRuns.find( recordname );
354  if( iRec != m_lastRecordRuns.end() ){
355  unsigned int lastRecordRun = iRec->second;
356  if( lastRecordRun != m_lastRun ){
357  // a refresh is required!
358  doRefresh = true;
359  iRec->second = m_lastRun;
360  edm::LogInfo( "CondDBESSource" ) << "Preparing refresh for record \"" << recordname
361  << "\" since there has been a transition from run "
362  << lastRecordRun << " to run " << m_lastRun
363  << "; from CondDBESSource::setIntervalFor";
364  }
365  } else {
366  doRefresh = true;
367  m_lastRecordRuns.insert( std::make_pair( recordname, m_lastRun ) );
368  edm::LogInfo( "CondDBESSource" ) << "Preparing refresh for record \"" << recordname
369  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
370  << "; from CondDBESSource::setIntervalFor";
371  }
372  if ( !doRefresh )
373  edm::LogInfo( "CondDBESSource" ) << "Though enabled, refresh not needed for record \"" << recordname
374  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
375  << "; from CondDBESSource::setIntervalFor";
376  } else if( m_policy == REFRESH_ALWAYS || m_policy == REFRESH_OPEN_IOVS ) {
377  doRefresh = true;
378  edm::LogInfo( "CondDBESSource" ) << "Forcing refresh for record \"" << recordname
379  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
380  << "; from CondDBESSource::setIntervalFor";
381  }
382 
384 
385  // compute the smallest interval (assume all objects have the same timetype....)
386  cond::ValidityInterval recordValidity(1,cond::TIMELIMIT);
388  bool userTime=true;
389 
390  //FIXME use equal_range
391  ProxyMap::const_iterator pmBegin = m_proxies.lower_bound(recordname);
392  ProxyMap::const_iterator pmEnd = m_proxies.upper_bound(recordname);
393  if ( pmBegin == pmEnd ) {
394  edm::LogInfo( "CondDBESSource" ) << "No DataProxy (Pluging) found for record \""<< recordname
395  << "\"; from CondDBESSource::setIntervalFor";
396  return;
397  }
398 
399  for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
400 
401  edm::LogInfo( "CondDBESSource" ) << "Processing record \"" << recordname
402  << "\" and label \""<< pmIter->second->label()
403  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
404  << "; from CondDBESSource::setIntervalFor";
405 
406  timetype = (*pmIter).second->proxy()->timeType();
407 
408  cond::Time_t abtime = cond::time::fromIOVSyncValue( iTime, timetype );
409  userTime = ( 0 == abtime );
410 
411  if (userTime) return; // oInterval invalid to avoid that make is called...
412 
413  if( doRefresh ) {
414 
415  std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
416  TagCollection::const_iterator tcIter = m_tagCollection.find( recKey );
417  if ( tcIter == m_tagCollection.end() ) {
418  edm::LogInfo( "CondDBESSource" ) << "No Tag found for record \""<< recordname
419  << "\" and label \""<< pmIter->second->label()
420  << "\"; from CondDBESSource::setIntervalFor";
421  return;
422  }
423 
424  // first reconnect if required
425  if( m_policy == RECONNECT_EACH_RUN ) {
426  edm::LogInfo( "CondDBESSource" ) << "Checking if the session must be closed and re-opened for getting correct conditions"
427  << "; from CondDBESSource::setIntervalFor";
428  std::stringstream transId;
429  //transId << "long" << m_lastRun;
430  transId << m_lastRun;
432  std::pair<std::string,std::string> tagParams = cond::persistency::parseTag( tcIter->second.tagName() );
433  if( !tagParams.second.empty() ) connStr = tagParams.second;
434  std::map<std::string,std::pair<cond::persistency::Session,std::string> >::iterator iSess = m_sessionPool.find( connStr );
435  bool reopen = false;
436  if( iSess != m_sessionPool.end() ){
437  if( iSess->second.second != transId.str() ) {
438  // the available session is open for a different run: reopen
439  reopen = true;
440  iSess->second.second = transId.str();
441  }
442  } else {
443  // no available session: probably first run analysed...
444  iSess = m_sessionPool.insert(std::make_pair( connStr, std::make_pair( cond::persistency::Session(),transId.str()) )).first;
445  reopen = true;
446  }
447  if( reopen ){
448  iSess->second.first = m_connection.createReadOnlySession( connStr, transId.str() );
449  edm::LogInfo( "CondDBESSource" ) << "Re-opening the session with connection string " << connStr
450  << " and new transaction Id " << transId.str()
451  << "; from CondDBESSource::setIntervalFor";
452  }
453 
454  edm::LogInfo( "CondDBESSource" ) << "Reconnecting to \"" << connStr
455  << "\" for getting new payload for record \"" << recordname
456  << "\" and label \""<< pmIter->second->label()
457  << "\" from IOV tag \"" << tcIter->second.tagName()
458  << "\" to be consumed by " << iTime.eventID() << ", timestamp: " << iTime.time().value()
459  << "; from CondDBESSource::setIntervalFor";
460  pmIter->second->proxy()->setUp( iSess->second.first );
461  pmIter->second->proxy()->reload();
462  //if( isSizeIncreased )
463  //edm::LogInfo( "CondDBESSource" ) << "After reconnecting, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
464  // << "\" was found; from CondDBESSource::setIntervalFor";
465  //m_stats.nActualReconnect += isSizeIncreased;
467  } else {
468  edm::LogInfo( "CondDBESSource" ) << "Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
469  << "\" for getting new payload for record \"" << recordname
470  << "\" and label \""<< pmIter->second->label()
471  << "\" to be consumed by " << iTime.eventID() << ", timestamp: " << iTime.time().value()
472  << "; from CondDBESSource::setIntervalFor";
473  pmIter->second->proxy()->reload();
474  //if( isSizeIncreased )
475  // edm::LogInfo( "CondDBESSource" ) << "After refreshing, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
476  // << "\" was found; from CondDBESSource::setIntervalFor";
477  //m_stats.nActualRefresh += isSizeIncreased;
478  m_stats.nRefresh++;
479  }
480 
481  }
482 
483  /*
484  // make oInterval valid For Ever
485  {
486  oInterval = edm::ValidityInterval(cond::toIOVSyncValue(recordValidity.first, cond::runnumber, true),
487  cond::toIOVSyncValue(recordValidity.second, cond::runnumber, false));
488  return;
489  }
490  */
491 
492  //query the IOVSequence
493  cond::ValidityInterval validity = (*pmIter).second->proxy()->setIntervalFor( abtime );
494 
495  edm::LogInfo( "CondDBESSource" ) << "Validity coming from IOV sequence for record \"" << recordname
496  << "\" and label \""<< pmIter->second->label()
497  << "\": (" << validity.first << ", " << validity.second
498  << ") for time (type: "<< cond::timeTypeNames( timetype ) << ") " << abtime
499  << "; from CondDBESSource::setIntervalFor";
500 
501  recordValidity.first = std::max(recordValidity.first,validity.first);
502  recordValidity.second = std::min(recordValidity.second,validity.second);
503  }
504 
505  if( m_policy == REFRESH_OPEN_IOVS ) {
506  doRefresh = ( recordValidity.second == cond::timeTypeSpecs[timetype].endValue );
507  edm::LogInfo( "CondDBESSource" ) << "Validity for record \"" << recordname
508  << "\" and the corresponding label(s) coming from Condition DB: (" << recordValidity.first
509  << ", "<< recordValidity.first
510  << ") as the last IOV element in the IOV sequence is infinity"
511  << "; from CondDBESSource::setIntervalFor";
512  }
513 
514  // to force refresh we set end-value to the minimum such an IOV can extend to: current run or lumiblock
515 
516  if ( (!userTime) && recordValidity.second !=0 ) {
517  edm::IOVSyncValue start = cond::time::toIOVSyncValue(recordValidity.first, timetype, true);
518  edm::IOVSyncValue stop = doRefresh ? cond::time::limitedIOVSyncValue (iTime, timetype)
519  : cond::time::toIOVSyncValue(recordValidity.second, timetype, false);
520 
521  oInterval = edm::ValidityInterval( start, stop );
522  }
523 
524  edm::LogInfo( "CondDBESSource" ) << "Setting validity for record \"" << recordname
525  << "\" and corresponding label(s): starting at " << oInterval.first().eventID() << ", timestamp: " << oInterval.first().time().value()
526  << ", ending at "<< oInterval.last().eventID() << ", timestamp: " << oInterval.last().time().value()
527  << ", for "<< iTime.eventID() << ", timestamp: " << iTime.time().value()
528  << "; from CondDBESSource::setIntervalFor";
529 }
530 
531 
532 //required by EventSetup System
533 void
535  std::string recordname=iRecordKey.name();
536 
537  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
538  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
539  if ( b == e) {
540  edm::LogInfo( "CondDBESSource" ) << "No DataProxy (Pluging) found for record \""<< recordname
541  << "\"; from CondDBESSource::registerProxies";
542  return;
543  }
544 
545  for (ProxyMap::const_iterator p=b;p!=e;++p) {
546  if(0 != (*p).second.get()) {
547  edm::eventsetup::TypeTag type = (*p).second->type();
548  edm::eventsetup::DataKey key( type, edm::eventsetup::IdTags((*p).second->label().c_str()) );
549  aProxyList.push_back(KeyedProxies::value_type(key,(*p).second->edmProxy()));
550  }
551  }
552 }
553 
554 // required by the EventSetup System
555 void
557  const edm::ValidityInterval&)
558 {
559  //LogDebug ("CondDBESSource")<<"newInterval";
560  invalidateProxies(iRecordType);
561 }
562 
563 
564 // Fills tag collection from the given globaltag
566  const std::string & prefix,
567  const std::string & postfix,
568  const std::string & roottag,
569  std::set< cond::GTEntry_t > & tagcoll,
570  cond::GTMetadata_t& gtMetadata )
571 {
572  if ( !roottag.empty() ) {
573  if ( connectionString.empty() )
574  throw cond::Exception( std::string( "ESSource: requested global tag ") + roottag + std::string( " but not connection string given" ) );
575  std::tuple<std::string,std::string,std::string> connPars = cond::persistency::parseConnectionString( connectionString );
576  if( std::get<2>( connPars ) == "CMS_COND_31X_GLOBALTAG" ){
577  edm::LogWarning( "CondDBESSource" )<<"[WARNING] You are reading Global Tag \""<<roottag<<"\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date."<<std::endl;
578  } else if( roottag.rfind("::All")!=std::string::npos && std::get<2>( connPars ) == "CMS_CONDITIONS" ){
579  edm::LogWarning( "CondDBESSource" )<<"[WARNING] You are trying to read Global Tag \""<<roottag<<"\" - postfix \"::All\" should not be used for V2."<<std::endl;
580  }
582  session.transaction().start( true );
583  cond::persistency::GTProxy gtp = session.readGlobalTag( roottag, prefix, postfix );
584  gtMetadata.snapshotTime = gtp.snapshotTime();
585  for( const auto& gte : gtp ){
586  tagcoll.insert( gte );
587  }
588  session.transaction().commit();
589  }
590 }
591 
592 // fills tagcollection merging with replacement
593 // 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.
594 void CondDBESSource::fillTagCollectionFromDB( const std::vector<std::string> & connectionStringList,
595  const std::vector<std::string> & prefixList,
596  const std::vector<std::string> & postfixList,
597  const std::vector<std::string> & roottagList,
598  std::map<std::string,cond::GTEntry_t>& replacement,
599  cond::GTMetadata_t& gtMetadata )
600 {
601  std::set< cond::GTEntry_t > tagcoll;
602 
603  auto connectionString = connectionStringList.begin();
604  auto prefix = prefixList.begin();
605  auto postfix = postfixList.begin();
606  for( auto roottag = roottagList.begin(); roottag != roottagList.end(); ++roottag, ++connectionString, ++prefix, ++postfix) {
607  fillTagCollectionFromGT(*connectionString, *prefix, *postfix, *roottag, tagcoll, gtMetadata);
608  }
609 
610  std::set<cond::GTEntry_t>::iterator tagCollIter;
611  std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
612  std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
613 
614  // FIXME the logic is a bit perverse: can be surely linearized (at least simplified!) ....
615  for( tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter ) {
616  std::string recordLabelKey = joinRecordAndLabel( tagCollIter->recordName(), tagCollIter->recordLabel() );
617  std::map<std::string,cond::GTEntry_t>::iterator fid = replacement.find( recordLabelKey );
618  if( fid != replacement.end() ) {
619  if( !fid->second.tagName().empty() ){
620  cond::GTEntry_t tagMetadata( std::make_tuple( tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName() ) );
621  m_tagCollection.insert( std::make_pair( recordLabelKey, tagMetadata ) );
622  edm::LogInfo( "CondDBESSource" ) << "Replacing tag \"" << tagCollIter->tagName()
623  << "\" for record \"" << tagMetadata.recordName()
624  << "\" and label \"" << tagMetadata.recordLabel()
625  << "\" with tag " << tagMetadata.tagName()
626  << "\"; from CondDBESSource::fillTagCollectionFromDB";
627  } else {
628  m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
629  }
630  replacement.erase( fid );
631  } else {
632  m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
633  }
634  }
635  std::map<std::string,cond::GTEntry_t>::iterator replacementIter;
636  std::map<std::string,cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
637  std::map<std::string,cond::GTEntry_t>::iterator replacementEnd = replacement.end();
638  for( replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter ){
639  if( replacementIter->second.tagName().empty() ){
640  std::stringstream msg;
641  msg << "ESSource: no tag provided for record " << replacementIter->second.recordName();
642  if( !replacementIter->second.recordLabel().empty() ) msg << " and label "<<replacementIter->second.recordLabel();
643  throw cond::Exception( msg.str() );
644  }
645  m_tagCollection.insert( *replacementIter );
646  }
647 }
648 
649 
650 // backward compatibility for configuration files
652 public:
653  explicit PoolDBESSource( const edm::ParameterSet& ps) :
654  CondDBESSource(ps){}
655 };
656 
658 //define this as a plug-in
660 
RunNumber_t run() const
Definition: EventID.h:39
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
list pfn
Definition: dbtoconf.py:76
list globaltag
Definition: align_cfg.py:7
const EventID & eventID() const
Definition: IOVSyncValue.h:42
virtual void registerProxies(const edm::eventsetup::EventSetupRecordKey &iRecordKey, KeyedProxies &aProxyList)
void start(bool readOnly=true)
Definition: Session.cc:22
bool exists(std::string const &parameterName) const
checks if a parameter exists
boost::posix_time::ptime snapshotTime
Definition: Types.h:111
static constexpr const char *const MAX_TIMESTAMP
Definition: Time.h:23
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
void usingRecordWithKey(const EventSetupRecordKey &)
virtual ProxyP proxy() const =0
RefreshPolicy m_policy
Transaction & transaction()
Definition: Session.cc:66
TimeType
Definition: Time.h:21
void setParameters(const edm::ParameterSet &connectionPset)
const IOVSyncValue & last() const
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)
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
Definition: Time.cc:74
std::string const & timeTypeNames(int)
Definition: Time.cc:15
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
Definition: Utils.h:61
std::string const & label() const
Definition: DataProxy.h:86
unsigned long long Time_t
Definition: Time.h:16
void invalidateProxies(const EventSetupRecordKey &iRecordKey)
vector< ParameterSet > Parameters
std::string convertoToOracleConnection(const std::string &input)
Definition: Utils.h:84
std::pair< std::string, std::string > parseTag(const std::string &tag)
Definition: GTProxy.cc:13
std::map< std::string, unsigned int > m_lastRecordRuns
Session createSession(const std::string &connectionString, bool writeCapable=false, BackendType backType=DEFAULT_DB)
std::vector< std::pair< DataKey, boost::shared_ptr< DataProxy > > > KeyedProxies
cond::persistency::ConnectionPool m_connection
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, TimeType timetype, bool startOrStop)
Definition: Time.cc:52
LuminosityBlockNumber_t luminosityBlockNumber() const
Definition: IOVSyncValue.h:43
boost::posix_time::ptime snapshotTime() const
Definition: GTProxy.cc:166
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
std::string fullyQualifiedTag(const std::string &tag, const std::string &connectionString)
Definition: GTProxy.cc:8
void fillList(const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
T min(T a, T b)
Definition: MathUtil.h:58
Container::value_type value_type
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
const std::string & recordLabel() const
Definition: Types.h:134
tuple out
Definition: dbtoconf.py:99
std::multimap< std::string, ProxyP > ProxyMap
std::string const & connString() const
Definition: DataProxy.h:88
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
string connectionString
Definition: autoCondHLT.py:4
PoolDBESSource(const edm::ParameterSet &ps)
TagCollection m_tagCollection
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
double b
Definition: hdecay.h:120
std::string const & tag() const
Definition: DataProxy.h:89
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)
heterocontainer::HCTypeTag TypeTag
std::string m_connectionString
ProxyMap m_proxies
unsigned int m_lastRun
const std::string & recordName() const
Definition: Types.h:131
static const ValidityInterval & invalidInterval()
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
const std::string & tagName() const
Definition: Types.h:137
const Timestamp & time() const
Definition: IOVSyncValue.h:44
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
Definition: Time.cc:91
tuple cout
Definition: gather_cfg.py:121
virtual void newInterval(const edm::eventsetup::EventSetupRecordKey &iRecordType, const edm::ValidityInterval &iInterval)
called when a new interval of validity occurs for iRecordType
volatile std::atomic< bool > shutdown_flag false
const IOVSyncValue & first() const
Time_t endValue
Definition: Time.h:46
CondDBESSource(const edm::ParameterSet &)
GTProxy readGlobalTag(const std::string &name)
Definition: Session.cc:173
list fid
Definition: NewTree.py:51
unsigned int m_lastLumi
double split
Definition: MVATrainer.cc:139
TimeValue_t value() const
Definition: Timestamp.h:56
boost::shared_ptr< cond::DataProxyWrapperBase > ProxyP
T get(const Candidate &c)
Definition: component.h:55
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
Definition: HCTypeTag.cc:125