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 //
12 #include "CondDBESSource.h"
13 
14 #include "boost/shared_ptr.hpp"
15 #include <boost/algorithm/string.hpp>
21 
24 
29 #include <exception>
30 //#include <cstdlib>
31 //#include <iostream>
32 
33 
35 #include <iomanip>
36 
37 namespace {
38  /* utility ot build the name of the plugin corresponding to a given record
39  se ESSources
40  */
42  buildName( std::string const & iRecordName ) {
43  return iRecordName + std::string( "@NewProxy" );
44  }
45 
46  std::string joinRecordAndLabel( std::string const & iRecordName, std::string const & iLabelName ) {
47  return iRecordName + std::string( "@" ) + iLabelName;
48  }
49 
50  /* utility class to return a IOVs associated to a given "name"
51  This implementation return the IOV associated to a record...
52  It is essentialy a workaround to get the full IOV out of the tag colector
53  that is not accessible as hidden in the ESSource
54  FIXME: need to support label??
55  */
56  class CondGetterFromESSource : public cond::CondGetter {
57  public:
58  CondGetterFromESSource(CondDBESSource::ProxyMap const & ip) : m_proxies(ip){}
59  virtual ~CondGetterFromESSource(){}
60 
61  cond::IOVProxy get(std::string name) const {
62  CondDBESSource::ProxyMap::const_iterator p = m_proxies.find(name);
63  if ( p != m_proxies.end())
64  return (*p).second->proxy()->iov();
65  return cond::IOVProxy();
66  }
67 
68  CondDBESSource::ProxyMap const & m_proxies;
69  };
70 
71  // dump the state of a DataProxy
72  void dumpInfo(std::ostream & out, std::string const & recName, cond::DataProxyWrapperBase const & proxy) {
73  cond::SequenceState state(proxy.proxy()->iov().state());
74  out << recName << " / " << proxy.label() << ": "
75  << proxy.connString() << ", " << proxy.tag() << "\n "
76  << state.size() << ", " << state.revision() << ", "
77  << cond::time::to_boost(state.timestamp()) << "\n "
78  << state.comment()
79  << "\n "
80  << "refresh " << proxy.proxy()->stats.nRefresh
81  << "/" << proxy.proxy()->stats.nArefresh
82  << ", reconnect " << proxy.proxy()->stats.nReconnect
83  << "/" << proxy.proxy()->stats.nAreconnect
84  << ", make " << proxy.proxy()->stats.nMake
85  << ", load " << proxy.proxy()->stats.nLoad
86  ;
87  if ( proxy.proxy()->stats.nLoad>0) {
88  out << "\n oids,sinces:";
89  cond::BasePayloadProxy::ObjIds const & ids = proxy.proxy()->stats.ids;
90  for (cond::BasePayloadProxy::ObjIds::const_iterator id=ids.begin(); id!=ids.end(); ++id)
91  out << " "
92  // << std::ios::hex
93  << (*id).oid1 <<"-"<< (*id).oid2 <<","
94  // << std::ios::dec
95  << (*id).since;
96  }
97  }
98 
99 }
100 
101 
102 /*
103  * config Param
104  * RefreshEachRun: if true will refresh the IOV at each new run (or lumiSection)
105  * DumpStat: if true dump the statistics of all DataProxy (currently on cout)
106  * DBParameters: configuration set of the connection
107  * globaltag: The GlobalTag
108  * toGet: list of record label tag connection-string to add/overwrite the content of the global-tag
109  */
111  m_connection(),
112  m_lastRun(0), // for the stat
113  m_lastLumi(0), // for the stat
114  m_policy( NOREFRESH ),
115  m_doDump( iConfig.getUntrackedParameter<bool>( "DumpStat", false ) )
116 {
117  if( iConfig.getUntrackedParameter<bool>( "RefreshAlways", false ) ) {
119  }
120  if( iConfig.getUntrackedParameter<bool>( "RefreshOpenIOVs", false ) ) {
122  }
123  if( iConfig.getUntrackedParameter<bool>( "RefreshEachRun", false ) ) {
125  }
126  if( iConfig.getUntrackedParameter<bool>( "ReconnectEachRun", false ) ) {
128  }
129 
130  Stats s = {0,0,0,0,0,0,0,0};
131  m_stats = s;
132  //std::cout<<"CondDBESSource::CondDBESSource"<<std::endl;
133  /*parameter set parsing and pool environment setting
134  */
135 
136  // default connection string
137  // inproduction used for the global tag
138  std::string userconnect= iConfig.getParameter<std::string>("connect");
139 
140 
141  // connection configuration
142  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>( "DBParameters" );
143  m_connection.configuration().setParameters( connectionPset );
145 
146 
147  // load additional record/tag info it will overwrite the global tag
148  std::map<std::string,cond::TagMetadata> replacement;
149  if( iConfig.exists( "toGet" ) ) {
150  typedef std::vector< edm::ParameterSet > Parameters;
151  Parameters toGet = iConfig.getParameter<Parameters>( "toGet" );
152  for( Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet ) {
154  nm.recordname = itToGet->getParameter<std::string>( "record" );
155  nm.labelname = itToGet->getUntrackedParameter<std::string>( "label", "" );
156  nm.tag = itToGet->getParameter<std::string>( "tag" );
157  nm.pfn = itToGet->getUntrackedParameter<std::string>( "connect", userconnect );
158  // nm.objectname=itFound->second;
159  std::string recordLabelKey = joinRecordAndLabel( nm.recordname, nm.labelname );
160  replacement.insert( std::pair<std::string,cond::TagMetadata>( recordLabelKey, nm ) );
161  }
162  }
163 
164  // get the global tag, merge with "replacement" store in "tagCollection"
165  std::vector<std::string> globaltagList;
166  std::vector<std::string> connectList;
167  std::vector<std::string> pfnPrefixList;
168  std::vector<std::string> pfnPostfixList;
169  if( iConfig.exists( "globaltag" ) ) {
170  std::string pfnPrefix(iConfig.getUntrackedParameter<std::string>( "pfnPrefix", "" ));
171  std::string pfnPostfix(iConfig.getUntrackedParameter<std::string>( "pfnPostfix", "" ));
172  std::string globaltag(iConfig.getParameter<std::string>( "globaltag" ));
173  boost::split( globaltagList, globaltag, boost::is_any_of("|"), boost::token_compress_off );
174  fillList(userconnect, connectList, globaltagList.size(), "connection");
175  fillList(pfnPrefix, pfnPrefixList, globaltagList.size(), "pfnPrefix");
176  fillList(pfnPostfix, pfnPostfixList, globaltagList.size(), "pfnPostfix");
177  }
178 
179  fillTagCollectionFromDB(connectList,
180  pfnPrefixList,
181  pfnPostfixList,
182  globaltagList,
183  replacement);
184 
185  TagCollection::iterator it;
186  TagCollection::iterator itBeg = m_tagCollection.begin();
187  TagCollection::iterator itEnd = m_tagCollection.end();
188 
189  std::map<std::string, cond::DbSession> sessions;
190 
191  /* load DataProxy Plugin (it is strongly typed due to EventSetup ideosyncrasis)
192  * construct proxy
193  * contrary to EventSetup the "object-name" is not used as identifier: multiple entries in a record are
194  * dinstinguished only by their label...
195  * done in two step: first create ProxyWrapper loading ALL required dictionaries
196  * this will allow to initialize POOL in one go for each "database"
197  * The real initialization of the Data-Proxies is done in the second loop
198  */
199  std::vector<cond::DataProxyWrapperBase *> proxyWrappers(m_tagCollection.size());
200  size_t ipb=0;
201  for(it=itBeg;it!=itEnd;++it){
202  proxyWrappers[ipb++] =
203  cond::ProxyFactory::get()->create(buildName(it->second.recordname));
204  }
205  // now all required libraries have been loaded
206  // init sessions and DataProxies
207  ipb=0;
208  for(it=itBeg;it!=itEnd;++it){
209  std::map<std::string, cond::DbSession>::iterator p = sessions.find( it->second.pfn );
210  cond::DbSession nsess;
211  if (p==sessions.end()) {
212  //open db get tag info (i.e. the IOV token...)
213  nsess = m_connection.createSession();
214  nsess.openReadOnly( it->second.pfn, "" );
215  sessions.insert(std::make_pair(it->second.pfn,nsess));
216  } else nsess = (*p).second;
217  //cond::MetaData metadata(nsess);
218  //nsess.transaction().start(true);
219  //std::string iovtoken = metadata.getToken(it->tag);
220  // owenship...
221  ProxyP proxy(proxyWrappers[ipb++]);
222  // instert in the map
223  m_proxies.insert(std::make_pair(it->second.recordname, proxy));
224  // initialize
225  //proxy->lateInit(nsess,iovtoken,
226  // it->labelname, it->pfn, it->tag
227  // );
228  proxy->lateInit(nsess,it->second.tag,
229  it->second.labelname, it->second.pfn);
230  //nsess.transaction().commit();
231  }
232 
233  // one loaded expose all other tags to the Proxy!
234  CondGetterFromESSource visitor( m_proxies );
235  ProxyMap::iterator b = m_proxies.begin();
236  ProxyMap::iterator e = m_proxies.end();
237  for ( ;b != e; b++ ) {
238 
239  (*b).second->proxy()->loadMore( visitor );
240 
243  if( recordKey.type() != edm::eventsetup::EventSetupRecordKey::TypeTag() ) {
244  findingRecordWithKey( recordKey );
245  usingRecordWithKey( recordKey );
246  }
247  }
248 
249  m_stats.nData=m_proxies.size();
250 
251 }
252 
253 void CondDBESSource::fillList(const std::string & stringList, std::vector<std::string> & listToFill, const unsigned int listSize, const std::string & type)
254 {
255  boost::split( listToFill, stringList, boost::is_any_of("|"), boost::token_compress_off );
256  // If it is one clone it for each GT
257  if( listToFill.size() == 1 ) {
258  for( unsigned int i=1; i<listSize; ++i ) {
259  listToFill.push_back(stringList);
260  }
261  }
262  // else if they don't match the number of GTs throw an exception
263  else if( listSize != listToFill.size() ) {
264  throw cond::Exception( std::string( "ESSource: number of global tag components does not match number of "+type+" strings" ) );
265  }
266 }
267 
269  //dump info FIXME: find a more suitable place...
270  if (m_doDump) {
271  std::cout << "CondDBESSource Statistics" << std::endl
272  << "DataProxy " << m_stats.nData
273  << " setInterval " << m_stats.nSet
274  << " Runs " << m_stats.nRun
275  << " Lumis " << m_stats.nLumi
276  << " Refresh " << m_stats.nRefresh
277  << " Actual Refresh " << m_stats.nActualRefresh
278  << " Reconnect " << m_stats.nReconnect
279  << " Actual Reconnect " << m_stats.nActualReconnect;
280  std::cout << std::endl;
281  std::cout << "Global Proxy Statistics" << std::endl
282  << "proxy " << cond::BasePayloadProxy::gstats.nProxy
283  << " make " << cond::BasePayloadProxy::gstats.nMake
284  << " load " << cond::BasePayloadProxy::gstats.nLoad;
285  std::cout << std::endl;
286 
287 
288  ProxyMap::iterator b= m_proxies.begin();
289  ProxyMap::iterator e= m_proxies.end();
290  for ( ;b != e; b++ ) {
291  dumpInfo( std::cout, (*b).first, *(*b).second );
292  std::cout << "\n" << std::endl;
293  }
294 
295  // FIXME
296  // We shall eventually close transaction and session...
297  }
298 }
299 
300 
301 //
302 // invoked by EventSetUp: for a given record return the smallest IOV for which iTime is valid
303 // limit to next run/lumisection of Refresh is required
304 //
305 void
307 
308  std::string recordname=iKey.name();
309 
310  edm::LogInfo( "CondDBESSource" ) << "Getting data for record \""<< recordname
311  << "\" to be consumed by "<< iTime.eventID() << ", timestamp: " << iTime.time().value()
312  << "; from CondDBESSource::setIntervalFor";
313 
314  m_stats.nSet++;
315  //{
316  // not really required, keep here for the time being
317  if(iTime.eventID().run()!=m_lastRun) {
318  m_lastRun=iTime.eventID().run();
319  m_stats.nRun++;
320  }
321  if(iTime.luminosityBlockNumber()!=m_lastLumi) {
323  m_stats.nLumi++;
324  }
325  //}
326 
327  bool doRefresh = false;
329  // find out the last run number for the proxy of the specified record
330  std::map<std::string,unsigned int>::iterator iRec = m_lastRecordRuns.find( recordname );
331  if( iRec != m_lastRecordRuns.end() ){
332  unsigned int lastRecordRun = iRec->second;
333  if( lastRecordRun != m_lastRun ){
334  // a refresh is required!
335  doRefresh = true;
336  iRec->second = m_lastRun;
337  edm::LogInfo( "CondDBESSource" ) << "Preparing refresh for record \"" << recordname
338  << "\" since there has been a transition from run "
339  << lastRecordRun << " to run " << m_lastRun
340  << "; from CondDBESSource::setIntervalFor";
341  }
342  } else {
343  doRefresh = true;
344  m_lastRecordRuns.insert( std::make_pair( recordname, m_lastRun ) );
345  edm::LogInfo( "CondDBESSource" ) << "Preparing refresh for record \"" << recordname
346  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
347  << "; from CondDBESSource::setIntervalFor";
348  }
349  if ( !doRefresh )
350  edm::LogInfo( "CondDBESSource" ) << "Though enabled, refresh not needed for record \"" << recordname
351  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
352  << "; from CondDBESSource::setIntervalFor";
353  } else if( m_policy == REFRESH_ALWAYS || m_policy == REFRESH_OPEN_IOVS ) {
354  doRefresh = true;
355  edm::LogInfo( "CondDBESSource" ) << "Forcing refresh for record \"" << recordname
356  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
357  << "; from CondDBESSource::setIntervalFor";
358  }
359 
361 
362  // compute the smallest interval (assume all objects have the same timetype....)
363  cond::ValidityInterval recordValidity(1,cond::TIMELIMIT);
365  bool userTime=true;
366 
367  //FIXME use equal_range
368  ProxyMap::const_iterator pmBegin = m_proxies.lower_bound(recordname);
369  ProxyMap::const_iterator pmEnd = m_proxies.upper_bound(recordname);
370  if ( pmBegin == pmEnd ) {
371  edm::LogInfo( "CondDBESSource" ) << "No DataProxy (Pluging) found for record \""<< recordname
372  << "\"; from CondDBESSource::setIntervalFor";
373  return;
374  }
375 
376  for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
377 
378  edm::LogInfo( "CondDBESSource" ) << "Processing record \"" << recordname
379  << "\" and label \""<< pmIter->second->label()
380  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
381  << "; from CondDBESSource::setIntervalFor";
382 
383  timetype = (*pmIter).second->proxy()->timetype();
384 
385  cond::Time_t abtime = cond::fromIOVSyncValue( iTime, timetype );
386  userTime = ( 0 == abtime );
387 
388  //std::cout<<"abtime "<<abtime<<std::endl;
389 
390  if (userTime) return; // oInterval invalid to avoid that make is called...
391 
392 
393 
394  if( doRefresh ) {
395 
396  std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
397  TagCollection::const_iterator tcIter = m_tagCollection.find( recKey );
398  if ( tcIter == m_tagCollection.end() ) {
399  edm::LogInfo( "CondDBESSource" ) << "No Tag found for record \""<< recordname
400  << "\" and label \""<< pmIter->second->label()
401  << "\"; from CondDBESSource::setIntervalFor";
402  return;
403  }
404 
405  // first reconnect if required
406  if( m_policy == RECONNECT_EACH_RUN ) {
407  edm::LogInfo( "CondDBESSource" ) << "Checking if the session must be closed and re-opened for getting correct conditions"
408  << "; from CondDBESSource::setIntervalFor";
409  std::stringstream transId;
410  //transId << "long" << m_lastRun;
411  transId << m_lastRun;
412  std::map<std::string,std::pair<cond::DbSession,std::string> >::iterator iSess = m_sessionPool.find( tcIter->second.pfn );
413  cond::DbSession theSession;
414  bool reopen = false;
415  if( iSess != m_sessionPool.end() ){
416  if( iSess->second.second != transId.str() ) {
417  // the available session is open for a different run: reopen
418  reopen = true;
419  iSess->second.second = transId.str();
420  }
421  theSession = iSess->second.first;
422  } else {
423  // no available session: probably first run analysed...
424  theSession = m_connection.createSession();
425  m_sessionPool.insert(std::make_pair( tcIter->second.pfn,std::make_pair(theSession,transId.str()) ));
426  reopen = true;
427  }
428  if( reopen ){
429  theSession.openReadOnly( tcIter->second.pfn, transId.str() );
430  edm::LogInfo( "CondDBESSource" ) << "Re-opening the session with connection string " << tcIter->second.pfn
431  << " and new transaction Id " << transId.str()
432  << "; from CondDBESSource::setIntervalFor";
433  }
434 
435  edm::LogInfo( "CondDBESSource" ) << "Reconnecting to \"" << tcIter->second.pfn
436  << "\" for getting new payload for record \"" << recordname
437  << "\" and label \""<< pmIter->second->label()
438  << "\" from IOV tag \"" << tcIter->second.tag
439  << "\" to be consumed by " << iTime.eventID() << ", timestamp: " << iTime.time().value()
440  << "; from CondDBESSource::setIntervalFor";
441  bool isSizeIncreased = pmIter->second->proxy()->refresh( theSession );
442  if( isSizeIncreased )
443  edm::LogInfo( "CondDBESSource" ) << "After reconnecting, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
444  << "\" was found; from CondDBESSource::setIntervalFor";
445  m_stats.nActualReconnect += isSizeIncreased;
447  } else {
448  edm::LogInfo( "CondDBESSource" ) << "Refreshing IOV sequence labeled by tag \"" << tcIter->second.tag
449  << "\" for getting new payload for record \"" << recordname
450  << "\" and label \""<< pmIter->second->label()
451  << "\" to be consumed by " << iTime.eventID() << ", timestamp: " << iTime.time().value()
452  << "; from CondDBESSource::setIntervalFor";
453  bool isSizeIncreased = pmIter->second->proxy()->refresh();
454  if( isSizeIncreased )
455  edm::LogInfo( "CondDBESSource" ) << "After refreshing, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
456  << "\" was found; from CondDBESSource::setIntervalFor";
457  m_stats.nActualRefresh += isSizeIncreased;
458  m_stats.nRefresh++;
459  }
460 
461  }
462 
463  /*
464  // make oInterval valid For Ever
465  {
466  oInterval = edm::ValidityInterval(cond::toIOVSyncValue(recordValidity.first, cond::runnumber, true),
467  cond::toIOVSyncValue(recordValidity.second, cond::runnumber, false));
468  return;
469  }
470  */
471 
472  //query the IOVSequence
473  cond::ValidityInterval validity = (*pmIter).second->proxy()->setIntervalFor( abtime );
474 
475  edm::LogInfo( "CondDBESSource" ) << "Validity coming from IOV sequence for record \"" << recordname
476  << "\" and label \""<< pmIter->second->label()
477  << "\": (" << validity.first << ", " << validity.second
478  << ") for time (type: "<< cond::timeTypeNames( timetype ) << ") " << abtime
479  << "; from CondDBESSource::setIntervalFor";
480 
481  recordValidity.first = std::max(recordValidity.first,validity.first);
482  recordValidity.second = std::min(recordValidity.second,validity.second);
483  }
484 
485  if( m_policy == REFRESH_OPEN_IOVS ) {
486  doRefresh = ( recordValidity.second == cond::timeTypeSpecs[timetype].endValue );
487  edm::LogInfo( "CondDBESSource" ) << "Validity for record \"" << recordname
488  << "\" and the corresponding label(s) coming from Condition DB: (" << recordValidity.first
489  << ", "<< recordValidity.first
490  << ") as the last IOV element in the IOV sequence is infinity"
491  << "; from CondDBESSource::setIntervalFor";
492  }
493 
494  // to force refresh we set end-value to the minimum such an IOV can extend to: current run or lumiblock
495 
496  if ( (!userTime) && recordValidity.second !=0 ) {
497  edm::IOVSyncValue start = cond::toIOVSyncValue(recordValidity.first, timetype, true);
498  edm::IOVSyncValue stop = doRefresh ? cond::limitedIOVSyncValue (iTime, timetype)
499  : cond::toIOVSyncValue(recordValidity.second, timetype, false);
500 
501  oInterval = edm::ValidityInterval( start, stop );
502  }
503 
504  edm::LogInfo( "CondDBESSource" ) << "Setting validity for record \"" << recordname
505  << "\" and corresponding label(s): starting at " << oInterval.first().eventID() << ", timestamp: " << oInterval.first().time().value()
506  << ", ending at "<< oInterval.last().eventID() << ", timestamp: " << oInterval.last().time().value()
507  << ", for "<< iTime.eventID() << ", timestamp: " << iTime.time().value()
508  << "; from CondDBESSource::setIntervalFor";
509 }
510 
511 
512 //required by EventSetup System
513 void
515  std::string recordname=iRecordKey.name();
516 
517  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
518  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
519  if ( b == e) {
520  edm::LogInfo( "CondDBESSource" ) << "No DataProxy (Pluging) found for record \""<< recordname
521  << "\"; from CondDBESSource::registerProxies";
522  return;
523  }
524 
525  for (ProxyMap::const_iterator p=b;p!=e;++p) {
526  if(0 != (*p).second.get()) {
527  edm::eventsetup::TypeTag type = (*p).second->type();
528  edm::eventsetup::DataKey key( type, edm::eventsetup::IdTags((*p).second->label().c_str()) );
529  aProxyList.push_back(KeyedProxies::value_type(key,(*p).second->edmProxy()));
530  }
531  }
532 }
533 
534 // required by the EventSetup System
535 void
537  const edm::ValidityInterval&)
538 {
539  //LogDebug ("CondDBESSource")<<"newInterval";
540  invalidateProxies(iRecordType);
541 }
542 
543 
544 // Fills tag collection from the given globaltag
546  const std::string & prefix,
547  const std::string & postfix,
548  const std::string & roottag,
549  std::set< cond::TagMetadata > & tagcoll )
550 {
551  // std::cout << "coraldb = " << coraldb << std::endl;
552  // std::cout << "prefix = " << prefix << std::endl;
553  // std::cout << "postfix = " << postfix << std::endl;
554  // std::cout << "roottag = " << roottag << std::endl;
555  if ( !roottag.empty() ) {
556  if ( coraldb.empty() )
557  throw cond::Exception( std::string( "ESSource: requested global tag ") + roottag + std::string( " but not connection string given" ) );
559  session.open( coraldb, cond::Auth::COND_READER_ROLE, true );
560  session.transaction().start( true );
561  cond::TagCollectionRetriever tagRetriever( session, prefix, postfix );
562  tagRetriever.getTagCollection( roottag,tagcoll );
563  session.transaction().commit();
564  }
565 }
566 
567 // fills tagcollection merging with replacement
568 // 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.
569 void CondDBESSource::fillTagCollectionFromDB( const std::vector<std::string> & coraldbList,
570  const std::vector<std::string> & prefixList,
571  const std::vector<std::string> & postfixList,
572  const std::vector<std::string> & roottagList,
573  std::map<std::string,cond::TagMetadata>& replacement )
574 {
575  std::set< cond::TagMetadata > tagcoll;
576 
577  auto coraldb = coraldbList.begin();
578  auto prefix = prefixList.begin();
579  auto postfix = postfixList.begin();
580  for( auto roottag = roottagList.begin(); roottag != roottagList.end(); ++roottag, ++coraldb, ++prefix, ++postfix) {
581  fillTagCollectionFromGT(*coraldb, *prefix, *postfix, *roottag, tagcoll);
582  }
583 
584  std::set<cond::TagMetadata>::iterator tagCollIter;
585  std::set<cond::TagMetadata>::iterator tagCollBegin = tagcoll.begin();
586  std::set<cond::TagMetadata>::iterator tagCollEnd = tagcoll.end();
587 
588  // FIXME the logic is a bit perverse: can be surely linearized (at least simplified!) ....
589  for( tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter ) {
590  std::string recordLabelKey = joinRecordAndLabel( tagCollIter->recordname, tagCollIter->labelname );
591  std::map<std::string,cond::TagMetadata>::iterator fid = replacement.find( recordLabelKey );
592  if( fid != replacement.end() ) {
593  cond::TagMetadata tagMetadata;
594  tagMetadata.recordname = tagCollIter->recordname;
595  tagMetadata.labelname = tagCollIter->labelname;
596  tagMetadata.pfn = fid->second.pfn;
597  tagMetadata.tag = fid->second.tag;
598  tagMetadata.objectname = tagCollIter->objectname;
599  m_tagCollection.insert( std::make_pair( recordLabelKey, tagMetadata ) );
600  replacement.erase( fid );
601  edm::LogInfo( "CondDBESSource" ) << "Replacing connection string \"" << tagCollIter->pfn
602  << "\" and tag \"" << tagCollIter->tag
603  << "\" for record \"" << tagMetadata.recordname
604  << "\" and label \"" << tagMetadata.labelname
605  << "\" with connection string \"" << tagMetadata.pfn
606  << "\" and tag " << tagMetadata.tag
607  << "\"; from CondDBESSource::fillTagCollectionFromDB";
608  } else {
609  m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
610  }
611  }
612  std::map<std::string,cond::TagMetadata>::iterator replacementIter;
613  std::map<std::string,cond::TagMetadata>::iterator replacementBegin = replacement.begin();
614  std::map<std::string,cond::TagMetadata>::iterator replacementEnd = replacement.end();
615  for( replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter ){
616  // std::cout<<"appending"<<std::endl;
617  // std::cout<<"pfn "<<replacementIter->second.pfn<<std::endl;
618  // std::cout<<"objectname "<<replacementIter->second.objectname<<std::endl;
619  // std::cout<<"tag "<<replacementIter->second.tag<<std::endl;
620  // std::cout<<"recordname "<<replacementIter->second.recordname<<std::endl;
621  m_tagCollection.insert( *replacementIter );
622  }
623 }
624 
625 
626 // backward compatibility for configuration files
628 public:
629  explicit PoolDBESSource( const edm::ParameterSet& ps) :
630  CondDBESSource(ps){}
631 };
632 
634 //define this as a plug-in
636 
RunNumber_t run() const
Definition: EventID.h:42
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
edm::IOVSyncValue limitedIOVSyncValue(cond::Time_t time, cond::TimeType timetype)
list globaltag
Definition: align_cfg.py:7
void fillTagCollectionFromGT(const std::string &coraldb, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::set< cond::TagMetadata > &tagcoll)
const EventID & eventID() const
Definition: IOVSyncValue.h:42
DbTransaction & transaction()
Definition: DbSession.cc:189
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:144
void fillTagCollectionFromDB(const std::vector< std::string > &coraldbList, const std::vector< std::string > &prefix, const std::vector< std::string > &postfix, const std::vector< std::string > &roottagList, std::map< std::string, cond::TagMetadata > &replacement)
std::map< std::string, std::pair< cond::DbSession, std::string > > m_sessionPool
virtual void registerProxies(const edm::eventsetup::EventSetupRecordKey &iRecordKey, KeyedProxies &aProxyList)
void getTagCollection(const std::string &globaltag, std::set< cond::TagMetadata > &result)
int commit()
commit transaction.
void openReadOnly(const std::string &connectionString, const std::string &id)
Definition: DbSession.cc:155
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:89
std::string objectname
Definition: TagMetadata.h:12
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
#define min(a, b)
Definition: mlp_lapack.h:161
void usingRecordWithKey(const EventSetupRecordKey &)
virtual ProxyP proxy() const =0
cond::DbConnection m_connection
RefreshPolicy m_policy
void setParameters(const edm::ParameterSet &connectionPset)
TimeType
Definition: Time.h:21
const IOVSyncValue & last() const
std::string labelname
Definition: TagMetadata.h:11
std::string const & timeTypeNames(int)
Definition: Time.cc:15
int start(bool readOnly=false)
start transaction
std::string const & label() const
Definition: DataProxy.h:81
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, cond::TimeType timetype, bool startOrStop)
unsigned long long Time_t
Definition: Time.h:16
std::string tag
Definition: TagMetadata.h:8
void invalidateProxies(const EventSetupRecordKey &iRecordKey)
vector< ParameterSet > Parameters
const T & max(const T &a, const T &b)
std::map< std::string, unsigned int > m_lastRecordRuns
std::vector< std::pair< DataKey, boost::shared_ptr< DataProxy > > > KeyedProxies
LuminosityBlockNumber_t luminosityBlockNumber() const
Definition: IOVSyncValue.h:43
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
void fillList(const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
Container::value_type value_type
static const std::string COND_READER_ROLE
Definition: Auth.h:19
tuple out
Definition: dbtoconf.py:99
std::vector< ObjId > ObjIds
Definition: PayloadProxy.h:31
std::multimap< std::string, ProxyP > ProxyMap
std::string const & connString() const
Definition: DataProxy.h:83
TimeValue_t value() const
Definition: Timestamp.cc:72
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
PoolDBESSource(const edm::ParameterSet &ps)
TagCollection m_tagCollection
DbSession createSession() const
Definition: DbConnection.cc:72
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
double b
Definition: hdecay.h:120
std::string const & tag() const
Definition: DataProxy.h:84
std::string pfn
Definition: TagMetadata.h:9
char state
Definition: procUtils.cc:75
heterocontainer::HCTypeTag TypeTag
ProxyMap m_proxies
unsigned int m_lastRun
list key
Definition: combine.py:13
static const ValidityInterval & invalidInterval()
const Timestamp & time() const
Definition: IOVSyncValue.h:44
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
cond::Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, cond::TimeType timetype)
const IOVSyncValue & first() const
Time_t endValue
Definition: Time.h:46
CondDBESSource(const edm::ParameterSet &)
std::string recordname
Definition: TagMetadata.h:10
list fid
Definition: NewTree.py:51
unsigned int m_lastLumi
double split
Definition: MVATrainer.cc:139
boost::shared_ptr< cond::DataProxyWrapperBase > ProxyP
boost::posix_time::ptime to_boost(Time_t iValue)
T get(const Candidate &c)
Definition: component.h:56
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:129