CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes
CondDBESSource Class Reference

#include <CondDBESSource.h>

Inheritance diagram for CondDBESSource:
edm::eventsetup::DataProxyProvider edm::EventSetupRecordIntervalFinder PoolDBESSource

Classes

struct  Stats
 

Public Types

typedef std::multimap
< std::string, ProxyP
ProxyMap
 
typedef boost::shared_ptr
< cond::DataProxyWrapperBase
ProxyP
 
enum  RefreshPolicy {
  NOREFRESH, REFRESH_ALWAYS, REFRESH_OPEN_IOVS, REFRESH_EACH_RUN,
  RECONNECT_EACH_RUN
}
 
- Public Types inherited from edm::eventsetup::DataProxyProvider
typedef std::vector< std::pair
< DataKey, boost::shared_ptr
< DataProxy > > > 
KeyedProxies
 
typedef std::vector
< EventSetupRecordKey
Keys
 
typedef std::map
< EventSetupRecordKey,
KeyedProxies
RecordProxies
 

Public Member Functions

 CondDBESSource (const edm::ParameterSet &)
 
 ~CondDBESSource ()
 
- Public Member Functions inherited from edm::eventsetup::DataProxyProvider
 DataProxyProvider ()
 
const ComponentDescriptiondescription () const
 
bool isUsingRecord (const EventSetupRecordKey &) const
 
const KeyedProxieskeyedProxies (const EventSetupRecordKey &iRecordKey) const
 
void resetProxies (const EventSetupRecordKey &iRecordType)
 
void resetProxiesIfTransient (const EventSetupRecordKey &iRecordType)
 
void setAppendToDataLabel (const edm::ParameterSet &)
 
void setDescription (const ComponentDescription &iDescription)
 
std::set< EventSetupRecordKeyusingRecords () const
 
virtual ~DataProxyProvider ()
 
- Public Member Functions inherited from edm::EventSetupRecordIntervalFinder
const
eventsetup::ComponentDescription
descriptionForFinder () const
 
 EventSetupRecordIntervalFinder ()
 
std::set
< eventsetup::EventSetupRecordKey
findingForRecords () const
 
const ValidityIntervalfindIntervalFor (const eventsetup::EventSetupRecordKey &, const IOVSyncValue &)
 
void setDescriptionForFinder (const eventsetup::ComponentDescription &iDescription)
 
virtual ~EventSetupRecordIntervalFinder ()
 

Protected Member Functions

virtual void newInterval (const edm::eventsetup::EventSetupRecordKey &iRecordType, const edm::ValidityInterval &iInterval)
 called when a new interval of validity occurs for iRecordType More...
 
virtual void registerProxies (const edm::eventsetup::EventSetupRecordKey &iRecordKey, KeyedProxies &aProxyList)
 
virtual void setIntervalFor (const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
 
- Protected Member Functions inherited from edm::eventsetup::DataProxyProvider
void eraseAll (const EventSetupRecordKey &iRecordKey)
 deletes all the Proxies in aStream More...
 
void invalidateProxies (const EventSetupRecordKey &iRecordKey)
 
template<class T >
void usingRecord ()
 
void usingRecordWithKey (const EventSetupRecordKey &)
 
- Protected Member Functions inherited from edm::EventSetupRecordIntervalFinder
template<class T >
void findingRecord ()
 
void findingRecordWithKey (const eventsetup::EventSetupRecordKey &)
 

Private Types

typedef std::map< std::string,
cond::GTEntry_t
TagCollection
 

Private Member Functions

void fillList (const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
 
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)
 
void fillTagCollectionFromGT (const std::string &connectionString, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::set< cond::GTEntry_t > &tagcoll)
 

Private Attributes

cond::persistency::ConnectionPool m_connection
 
std::string m_connectionString
 
bool m_doDump
 
unsigned int m_lastLumi
 
std::map< std::string,
unsigned int > 
m_lastRecordRuns
 
unsigned int m_lastRun
 
RefreshPolicy m_policy
 
ProxyMap m_proxies
 
std::map< std::string,
std::pair
< cond::persistency::Session,
std::string > > 
m_sessionPool
 
Stats m_stats
 
TagCollection m_tagCollection
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::eventsetup::DataProxyProvider
static void prevalidate (ConfigurationDescriptions &)
 

Detailed Description

Definition at line 32 of file CondDBESSource.h.

Member Typedef Documentation

typedef std::multimap< std::string, ProxyP> CondDBESSource::ProxyMap

Definition at line 36 of file CondDBESSource.h.

Definition at line 35 of file CondDBESSource.h.

typedef std::map< std::string, cond::GTEntry_t > CondDBESSource::TagCollection
private

Definition at line 64 of file CondDBESSource.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

CondDBESSource::CondDBESSource ( const edm::ParameterSet iConfig)
explicit

required by eventsetup

Definition at line 100 of file CondDBESSource.cc.

References b, cond::persistency::ConnectionPool::configure(), cond::persistency::ConnectionPool::createReadOnlySession(), alignCSCRings::e, edm::ParameterSet::exists(), fillList(), fillTagCollectionFromDB(), edm::EventSetupRecordIntervalFinder::findingRecordWithKey(), edm::eventsetup::heterocontainer::HCTypeTag::findType(), reco::get(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), align_cfg::globaltag, m_connection, m_connectionString, m_policy, m_proxies, m_stats, m_tagCollection, CondDBESSource::Stats::nData, cond::persistency::parseTag(), dbtoconf::pfn, RECONNECT_EACH_RUN, REFRESH_ALWAYS, REFRESH_EACH_RUN, REFRESH_OPEN_IOVS, alignCSCRings::s, cond::persistency::ConnectionPool::setParameters(), split, AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, convertSQLitetoXML_cfg::toGet, edm::eventsetup::EventSetupRecordKey::type(), and edm::eventsetup::DataProxyProvider::usingRecordWithKey().

100  :
101  m_connection(),
102  m_connectionString(""),
103  m_lastRun(0), // for the stat
104  m_lastLumi(0), // for the stat
105  m_policy( NOREFRESH ),
106  m_doDump( iConfig.getUntrackedParameter<bool>( "DumpStat", false ) )
107 {
108  if( iConfig.getUntrackedParameter<bool>( "RefreshAlways", false ) ) {
110  }
111  if( iConfig.getUntrackedParameter<bool>( "RefreshOpenIOVs", false ) ) {
113  }
114  if( iConfig.getUntrackedParameter<bool>( "RefreshEachRun", false ) ) {
116  }
117  if( iConfig.getUntrackedParameter<bool>( "ReconnectEachRun", false ) ) {
119  }
120 
121  Stats s = {0,0,0,0,0,0,0,0};
122  m_stats = s;
123  /*parameter set parsing and pool environment setting
124  */
125 
126  // default connection string
127  // inproduction used for the global tag
128  m_connectionString= iConfig.getParameter<std::string>("connect");
129 
130 
131  // connection configuration
132  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>( "DBParameters" );
133  m_connection.setParameters( connectionPset );
135 
136  // load additional record/tag info it will overwrite the global tag
137  std::map<std::string,cond::GTEntry_t> replacements;
138  if( iConfig.exists( "toGet" ) ) {
139  typedef std::vector< edm::ParameterSet > Parameters;
140  Parameters toGet = iConfig.getParameter<Parameters>( "toGet" );
141  for( Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet ) {
142  std::string recordname = itToGet->getParameter<std::string>( "record" );
143  std::string labelname = itToGet->getUntrackedParameter<std::string>( "label", "" );
144  std::string tag = itToGet->getParameter<std::string>( "tag" );
145  std::string pfn = itToGet->getUntrackedParameter<std::string>( "connect", m_connectionString );
146  std::string recordLabelKey = joinRecordAndLabel( recordname, labelname );
147  std::string fullyQualifiedTag = tag+"@["+pfn+"]";
148  replacements.insert( std::make_pair( recordLabelKey, cond::GTEntry_t( std::make_tuple(recordname, labelname, fullyQualifiedTag ) ) ) );
149  }
150  }
151 
152  // get the global tag, merge with "replacement" store in "tagCollection"
153  std::vector<std::string> globaltagList;
154  std::vector<std::string> connectList;
155  std::vector<std::string> pfnPrefixList;
156  std::vector<std::string> pfnPostfixList;
157  if( iConfig.exists( "globaltag" ) ) {
158  std::string pfnPrefix(iConfig.getUntrackedParameter<std::string>( "pfnPrefix", "" ));
159  std::string pfnPostfix(iConfig.getUntrackedParameter<std::string>( "pfnPostfix", "" ));
160  std::string globaltag(iConfig.getParameter<std::string>( "globaltag" ));
161  boost::split( globaltagList, globaltag, boost::is_any_of("|"), boost::token_compress_off );
162  fillList(m_connectionString, connectList, globaltagList.size(), "connection");
163  fillList(pfnPrefix, pfnPrefixList, globaltagList.size(), "pfnPrefix");
164  fillList(pfnPostfix, pfnPostfixList, globaltagList.size(), "pfnPostfix");
165  }
166 
167  fillTagCollectionFromDB(connectList,
168  pfnPrefixList,
169  pfnPostfixList,
170  globaltagList,
171  replacements);
172 
173  TagCollection::iterator it;
174  TagCollection::iterator itBeg = m_tagCollection.begin();
175  TagCollection::iterator itEnd = m_tagCollection.end();
176 
177  std::map<std::string, cond::persistency::Session> sessions;
178 
179  /* load DataProxy Plugin (it is strongly typed due to EventSetup ideosyncrasis)
180  * construct proxy
181  * contrary to EventSetup the "object-name" is not used as identifier: multiple entries in a record are
182  * dinstinguished only by their label...
183  * done in two step: first create ProxyWrapper loading ALL required dictionaries
184  * this will allow to initialize POOL in one go for each "database"
185  * The real initialization of the Data-Proxies is done in the second loop
186  */
187  std::vector<cond::DataProxyWrapperBase *> proxyWrappers(m_tagCollection.size());
188  size_t ipb=0;
189  for(it=itBeg;it!=itEnd;++it){
190  proxyWrappers[ipb++] =
191  cond::ProxyFactory::get()->create(buildName(it->second.recordName()));
192  }
193 
194  // now all required libraries have been loaded
195  // init sessions and DataProxies
196  ipb=0;
197  for(it=itBeg;it!=itEnd;++it){
199  std::string tag = it->second.tagName();
200  std::pair<std::string,std::string> tagParams = cond::persistency::parseTag( it->second.tagName() );
201  if( !tagParams.second.empty() ) {
202  connStr = tagParams.second;
203  tag = tagParams.first;
204  }
205  std::map<std::string, cond::persistency::Session>::iterator p = sessions.find( connStr );
207  if (p == sessions.end()) {
208  //open db get tag info (i.e. the IOV token...)
209  nsess = m_connection.createReadOnlySession( connStr, "" );
210  sessions.insert(std::make_pair( connStr, nsess));
211  } else nsess = (*p).second;
212 
213  // ownership...
214  ProxyP proxy(proxyWrappers[ipb++]);
215  // instert in the map
216  m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
217  // initialize
218  proxy->lateInit(nsess, tag, it->second.recordLabel(), connStr);
219  }
220 
221  // one loaded expose all other tags to the Proxy!
222  CondGetterFromESSource visitor( m_proxies );
223  ProxyMap::iterator b = m_proxies.begin();
224  ProxyMap::iterator e = m_proxies.end();
225  for ( ;b != e; b++ ) {
226 
227  (*b).second->proxy()->loadMore( visitor );
228 
231  if( recordKey.type() != edm::eventsetup::EventSetupRecordKey::TypeTag() ) {
232  findingRecordWithKey( recordKey );
233  usingRecordWithKey( recordKey );
234  }
235  }
236 
237  m_stats.nData=m_proxies.size();
238 
239 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
list pfn
Definition: dbtoconf.py:76
list globaltag
Definition: align_cfg.py:7
bool exists(std::string const &parameterName) const
checks if a parameter exists
void usingRecordWithKey(const EventSetupRecordKey &)
RefreshPolicy m_policy
void setParameters(const edm::ParameterSet &connectionPset)
vector< ParameterSet > Parameters
std::pair< std::string, std::string > parseTag(const std::string &tag)
Definition: GTProxy.cc:8
cond::persistency::ConnectionPool m_connection
void fillList(const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
TagCollection m_tagCollection
double b
Definition: hdecay.h:120
heterocontainer::HCTypeTag TypeTag
std::string m_connectionString
ProxyMap m_proxies
unsigned int m_lastRun
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
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)
unsigned int m_lastLumi
double split
Definition: MVATrainer.cc:139
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
CondDBESSource::~CondDBESSource ( )

Definition at line 256 of file CondDBESSource.cc.

References b, gather_cfg::cout, alignCSCRings::e, m_doDump, m_proxies, m_stats, CondDBESSource::Stats::nActualReconnect, CondDBESSource::Stats::nActualRefresh, CondDBESSource::Stats::nData, CondDBESSource::Stats::nLumi, CondDBESSource::Stats::nReconnect, CondDBESSource::Stats::nRefresh, CondDBESSource::Stats::nRun, and CondDBESSource::Stats::nSet.

256  {
257  //dump info FIXME: find a more suitable place...
258  if (m_doDump) {
259  std::cout << "CondDBESSource Statistics" << std::endl
260  << "DataProxy " << m_stats.nData
261  << " setInterval " << m_stats.nSet
262  << " Runs " << m_stats.nRun
263  << " Lumis " << m_stats.nLumi
264  << " Refresh " << m_stats.nRefresh
265  << " Actual Refresh " << m_stats.nActualRefresh
266  << " Reconnect " << m_stats.nReconnect
267  << " Actual Reconnect " << m_stats.nActualReconnect;
268  std::cout << std::endl;
269 
270 
271  ProxyMap::iterator b= m_proxies.begin();
272  ProxyMap::iterator e= m_proxies.end();
273  for ( ;b != e; b++ ) {
274  dumpInfo( std::cout, (*b).first, *(*b).second );
275  std::cout << "\n" << std::endl;
276  }
277 
278  // FIXME
279  // We shall eventually close transaction and session...
280  }
281 }
double b
Definition: hdecay.h:120
ProxyMap m_proxies
tuple cout
Definition: gather_cfg.py:121

Member Function Documentation

void CondDBESSource::fillList ( const std::string &  pfn,
std::vector< std::string > &  pfnList,
const unsigned int  listSize,
const std::string &  type 
)
private

Definition at line 241 of file CondDBESSource.cc.

References edm::hlt::Exception, i, split, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by CondDBESSource().

242 {
243  boost::split( listToFill, stringList, boost::is_any_of("|"), boost::token_compress_off );
244  // If it is one clone it for each GT
245  if( listToFill.size() == 1 ) {
246  for( unsigned int i=1; i<listSize; ++i ) {
247  listToFill.push_back(stringList);
248  }
249  }
250  // else if they don't match the number of GTs throw an exception
251  else if( listSize != listToFill.size() ) {
252  throw cond::Exception( std::string( "ESSource: number of global tag components does not match number of "+type+" strings" ) );
253  }
254 }
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
double split
Definition: MVATrainer.cc:139
void CondDBESSource::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 
)
private

Definition at line 550 of file CondDBESSource.cc.

References NewTree::fid, fillTagCollectionFromGT(), m_tagCollection, prof2calltree::prefix, cond::GTEntry_t::recordLabel(), cond::GTEntry_t::recordName(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::GTEntry_t::tagName().

Referenced by CondDBESSource().

555 {
556  std::set< cond::GTEntry_t > tagcoll;
557 
558  auto connectionString = connectionStringList.begin();
559  auto prefix = prefixList.begin();
560  auto postfix = postfixList.begin();
561  for( auto roottag = roottagList.begin(); roottag != roottagList.end(); ++roottag, ++connectionString, ++prefix, ++postfix) {
562  fillTagCollectionFromGT(*connectionString, *prefix, *postfix, *roottag, tagcoll);
563  }
564 
565  std::set<cond::GTEntry_t>::iterator tagCollIter;
566  std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
567  std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
568 
569  // FIXME the logic is a bit perverse: can be surely linearized (at least simplified!) ....
570  for( tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter ) {
571  std::string recordLabelKey = joinRecordAndLabel( tagCollIter->recordName(), tagCollIter->recordLabel() );
572  std::map<std::string,cond::GTEntry_t>::iterator fid = replacement.find( recordLabelKey );
573  if( fid != replacement.end() ) {
574  cond::GTEntry_t tagMetadata( std::make_tuple( tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName() ) );
575  m_tagCollection.insert( std::make_pair( recordLabelKey, tagMetadata ) );
576  replacement.erase( fid );
577  edm::LogInfo( "CondDBESSource" ) << "Replacing tag \"" << tagCollIter->tagName()
578  << "\" for record \"" << tagMetadata.recordName()
579  << "\" and label \"" << tagMetadata.recordLabel()
580  << "\" with tag " << tagMetadata.tagName()
581  << "\"; from CondDBESSource::fillTagCollectionFromDB";
582  } else {
583  m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
584  }
585  }
586  std::map<std::string,cond::GTEntry_t>::iterator replacementIter;
587  std::map<std::string,cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
588  std::map<std::string,cond::GTEntry_t>::iterator replacementEnd = replacement.end();
589  for( replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter ){
590  // std::cout<<"appending"<<std::endl;
591  // std::cout<<"pfn "<<replacementIter->second.pfn<<std::endl;
592  // std::cout<<"objectname "<<replacementIter->second.objectname<<std::endl;
593  // std::cout<<"tag "<<replacementIter->second.tag<<std::endl;
594  // std::cout<<"recordname "<<replacementIter->second.recordname<<std::endl;
595  m_tagCollection.insert( *replacementIter );
596  }
597 }
void fillTagCollectionFromGT(const std::string &connectionString, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::set< cond::GTEntry_t > &tagcoll)
TagCollection m_tagCollection
list fid
Definition: NewTree.py:51
void CondDBESSource::fillTagCollectionFromGT ( const std::string &  connectionString,
const std::string &  prefix,
const std::string &  postfix,
const std::string &  roottag,
std::set< cond::GTEntry_t > &  tagcoll 
)
private

Definition at line 529 of file CondDBESSource.cc.

References cond::persistency::Transaction::commit(), cond::persistency::ConnectionPool::createSession(), m_connection, cond::persistency::Session::readGlobalTag(), python.CommonUtils::session, cond::persistency::Transaction::start(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::persistency::Session::transaction().

Referenced by fillTagCollectionFromDB().

534 {
535  if ( !roottag.empty() ) {
536  if ( connectionString.empty() )
537  throw cond::Exception( std::string( "ESSource: requested global tag ") + roottag + std::string( " but not connection string given" ) );
539  session.transaction().start( true );
540  cond::persistency::GTProxy gtp = session.readGlobalTag( roottag, prefix, postfix );
541  for( const auto& gte : gtp ){
542  tagcoll.insert( gte );
543  }
544  session.transaction().commit();
545  }
546 }
void start(bool readOnly=true)
Definition: Session.cc:22
Transaction & transaction()
Definition: Session.cc:66
Session createSession(const std::string &connectionString, bool writeCapable=false, BackendType backType=DEFAULT_DB)
cond::persistency::ConnectionPool m_connection
GTProxy readGlobalTag(const std::string &name)
Definition: Session.cc:164
void CondDBESSource::newInterval ( const edm::eventsetup::EventSetupRecordKey iRecordType,
const edm::ValidityInterval iInterval 
)
protectedvirtual

called when a new interval of validity occurs for iRecordType

Implements edm::eventsetup::DataProxyProvider.

Definition at line 520 of file CondDBESSource.cc.

References edm::eventsetup::DataProxyProvider::invalidateProxies().

522 {
523  //LogDebug ("CondDBESSource")<<"newInterval";
524  invalidateProxies(iRecordType);
525 }
void invalidateProxies(const EventSetupRecordKey &iRecordKey)
void CondDBESSource::registerProxies ( const edm::eventsetup::EventSetupRecordKey iRecordKey,
KeyedProxies aProxyList 
)
protectedvirtual

Implements edm::eventsetup::DataProxyProvider.

Definition at line 498 of file CondDBESSource.cc.

References b, alignCSCRings::e, relval_steps::key, m_proxies, edm::eventsetup::EventSetupRecordKey::name(), AlCaHLTBitMon_ParallelJobs::p, and AlCaHLTBitMon_QueryRunRegistry::string.

498  {
499  std::string recordname=iRecordKey.name();
500 
501  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
502  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
503  if ( b == e) {
504  edm::LogInfo( "CondDBESSource" ) << "No DataProxy (Pluging) found for record \""<< recordname
505  << "\"; from CondDBESSource::registerProxies";
506  return;
507  }
508 
509  for (ProxyMap::const_iterator p=b;p!=e;++p) {
510  if(0 != (*p).second.get()) {
511  edm::eventsetup::TypeTag type = (*p).second->type();
512  edm::eventsetup::DataKey key( type, edm::eventsetup::IdTags((*p).second->label().c_str()) );
513  aProxyList.push_back(KeyedProxies::value_type(key,(*p).second->edmProxy()));
514  }
515  }
516 }
type
Definition: HCALResponse.h:21
Container::value_type value_type
double b
Definition: hdecay.h:120
ProxyMap m_proxies
void CondDBESSource::setIntervalFor ( const edm::eventsetup::EventSetupRecordKey iKey,
const edm::IOVSyncValue iTime,
edm::ValidityInterval oInterval 
)
protectedvirtual

Implements edm::EventSetupRecordIntervalFinder.

Definition at line 289 of file CondDBESSource.cc.

References cond::persistency::ConnectionPool::createReadOnlySession(), cond::TimeTypeSpecs::endValue, edm::IOVSyncValue::eventID(), edm::ValidityInterval::first(), plotBeamSpotDB::first, cond::time::fromIOVSyncValue(), align::invalid, edm::ValidityInterval::invalidInterval(), edm::ValidityInterval::last(), cond::time::limitedIOVSyncValue(), edm::IOVSyncValue::luminosityBlockNumber(), m_connection, m_connectionString, m_lastLumi, m_lastRecordRuns, m_lastRun, m_policy, m_proxies, m_sessionPool, m_stats, m_tagCollection, python.multivaluedict::map(), bookConverter::max, min(), edm::eventsetup::EventSetupRecordKey::name(), CondDBESSource::Stats::nLumi, CondDBESSource::Stats::nReconnect, CondDBESSource::Stats::nRefresh, CondDBESSource::Stats::nRun, CondDBESSource::Stats::nSet, cond::persistency::parseTag(), RECONNECT_EACH_RUN, REFRESH_ALWAYS, REFRESH_EACH_RUN, REFRESH_OPEN_IOVS, edm::EventID::run(), dqm_diff::start, AlCaHLTBitMon_QueryRunRegistry::string, edm::IOVSyncValue::time(), cond::TIMELIMIT(), dtNoiseCalibration_cfg::timetype, cond::timeTypeNames(), cond::timeTypeSpecs, cond::time::toIOVSyncValue(), and edm::Timestamp::value().

289  {
290 
291  std::string recordname=iKey.name();
292 
293  edm::LogInfo( "CondDBESSource" ) << "Getting data for record \""<< recordname
294  << "\" to be consumed by "<< iTime.eventID() << ", timestamp: " << iTime.time().value()
295  << "; from CondDBESSource::setIntervalFor";
296 
297  m_stats.nSet++;
298  //{
299  // not really required, keep here for the time being
300  if(iTime.eventID().run()!=m_lastRun) {
301  m_lastRun=iTime.eventID().run();
302  m_stats.nRun++;
303  }
304  if(iTime.luminosityBlockNumber()!=m_lastLumi) {
306  m_stats.nLumi++;
307  }
308  //}
309 
310  bool doRefresh = false;
312  // find out the last run number for the proxy of the specified record
313  std::map<std::string,unsigned int>::iterator iRec = m_lastRecordRuns.find( recordname );
314  if( iRec != m_lastRecordRuns.end() ){
315  unsigned int lastRecordRun = iRec->second;
316  if( lastRecordRun != m_lastRun ){
317  // a refresh is required!
318  doRefresh = true;
319  iRec->second = m_lastRun;
320  edm::LogInfo( "CondDBESSource" ) << "Preparing refresh for record \"" << recordname
321  << "\" since there has been a transition from run "
322  << lastRecordRun << " to run " << m_lastRun
323  << "; from CondDBESSource::setIntervalFor";
324  }
325  } else {
326  doRefresh = true;
327  m_lastRecordRuns.insert( std::make_pair( recordname, m_lastRun ) );
328  edm::LogInfo( "CondDBESSource" ) << "Preparing refresh for record \"" << recordname
329  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
330  << "; from CondDBESSource::setIntervalFor";
331  }
332  if ( !doRefresh )
333  edm::LogInfo( "CondDBESSource" ) << "Though enabled, refresh not needed for record \"" << recordname
334  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
335  << "; from CondDBESSource::setIntervalFor";
336  } else if( m_policy == REFRESH_ALWAYS || m_policy == REFRESH_OPEN_IOVS ) {
337  doRefresh = true;
338  edm::LogInfo( "CondDBESSource" ) << "Forcing refresh for record \"" << recordname
339  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
340  << "; from CondDBESSource::setIntervalFor";
341  }
342 
344 
345  // compute the smallest interval (assume all objects have the same timetype....)
346  cond::ValidityInterval recordValidity(1,cond::TIMELIMIT);
348  bool userTime=true;
349 
350  //FIXME use equal_range
351  ProxyMap::const_iterator pmBegin = m_proxies.lower_bound(recordname);
352  ProxyMap::const_iterator pmEnd = m_proxies.upper_bound(recordname);
353  if ( pmBegin == pmEnd ) {
354  edm::LogInfo( "CondDBESSource" ) << "No DataProxy (Pluging) found for record \""<< recordname
355  << "\"; from CondDBESSource::setIntervalFor";
356  return;
357  }
358 
359  for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
360 
361  edm::LogInfo( "CondDBESSource" ) << "Processing record \"" << recordname
362  << "\" and label \""<< pmIter->second->label()
363  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
364  << "; from CondDBESSource::setIntervalFor";
365 
366  timetype = (*pmIter).second->proxy()->timeType();
367 
368  cond::Time_t abtime = cond::time::fromIOVSyncValue( iTime, timetype );
369  userTime = ( 0 == abtime );
370 
371  //std::cout<<"abtime "<<abtime<<std::endl;
372 
373  if (userTime) return; // oInterval invalid to avoid that make is called...
374 
375 
376 
377  if( doRefresh ) {
378 
379  std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
380  TagCollection::const_iterator tcIter = m_tagCollection.find( recKey );
381  if ( tcIter == m_tagCollection.end() ) {
382  edm::LogInfo( "CondDBESSource" ) << "No Tag found for record \""<< recordname
383  << "\" and label \""<< pmIter->second->label()
384  << "\"; from CondDBESSource::setIntervalFor";
385  return;
386  }
387 
388  // first reconnect if required
389  if( m_policy == RECONNECT_EACH_RUN ) {
390  edm::LogInfo( "CondDBESSource" ) << "Checking if the session must be closed and re-opened for getting correct conditions"
391  << "; from CondDBESSource::setIntervalFor";
392  std::stringstream transId;
393  //transId << "long" << m_lastRun;
394  transId << m_lastRun;
396  std::pair<std::string,std::string> tagParams = cond::persistency::parseTag( tcIter->second.tagName() );
397  if( !tagParams.second.empty() ) connStr = tagParams.second;
398  std::map<std::string,std::pair<cond::persistency::Session,std::string> >::iterator iSess = m_sessionPool.find( connStr );
399  bool reopen = false;
400  if( iSess != m_sessionPool.end() ){
401  if( iSess->second.second != transId.str() ) {
402  // the available session is open for a different run: reopen
403  reopen = true;
404  iSess->second.second = transId.str();
405  }
406  } else {
407  // no available session: probably first run analysed...
408  iSess = m_sessionPool.insert(std::make_pair( connStr, std::make_pair( cond::persistency::Session(),transId.str()) )).first;
409  reopen = true;
410  }
411  if( reopen ){
412  iSess->second.first = m_connection.createReadOnlySession( connStr, transId.str() );
413  edm::LogInfo( "CondDBESSource" ) << "Re-opening the session with connection string " << connStr
414  << " and new transaction Id " << transId.str()
415  << "; from CondDBESSource::setIntervalFor";
416  }
417 
418  edm::LogInfo( "CondDBESSource" ) << "Reconnecting to \"" << connStr
419  << "\" for getting new payload for record \"" << recordname
420  << "\" and label \""<< pmIter->second->label()
421  << "\" from IOV tag \"" << tcIter->second.tagName()
422  << "\" to be consumed by " << iTime.eventID() << ", timestamp: " << iTime.time().value()
423  << "; from CondDBESSource::setIntervalFor";
424  pmIter->second->proxy()->setUp( iSess->second.first );
425  pmIter->second->proxy()->reload();
426  //if( isSizeIncreased )
427  //edm::LogInfo( "CondDBESSource" ) << "After reconnecting, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
428  // << "\" was found; from CondDBESSource::setIntervalFor";
429  //m_stats.nActualReconnect += isSizeIncreased;
431  } else {
432  edm::LogInfo( "CondDBESSource" ) << "Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
433  << "\" for getting new payload for record \"" << recordname
434  << "\" and label \""<< pmIter->second->label()
435  << "\" to be consumed by " << iTime.eventID() << ", timestamp: " << iTime.time().value()
436  << "; from CondDBESSource::setIntervalFor";
437  pmIter->second->proxy()->reload();
438  //if( isSizeIncreased )
439  // edm::LogInfo( "CondDBESSource" ) << "After refreshing, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
440  // << "\" was found; from CondDBESSource::setIntervalFor";
441  //m_stats.nActualRefresh += isSizeIncreased;
442  m_stats.nRefresh++;
443  }
444 
445  }
446 
447  /*
448  // make oInterval valid For Ever
449  {
450  oInterval = edm::ValidityInterval(cond::toIOVSyncValue(recordValidity.first, cond::runnumber, true),
451  cond::toIOVSyncValue(recordValidity.second, cond::runnumber, false));
452  return;
453  }
454  */
455 
456  //query the IOVSequence
457  cond::ValidityInterval validity = (*pmIter).second->proxy()->setIntervalFor( abtime );
458 
459  edm::LogInfo( "CondDBESSource" ) << "Validity coming from IOV sequence for record \"" << recordname
460  << "\" and label \""<< pmIter->second->label()
461  << "\": (" << validity.first << ", " << validity.second
462  << ") for time (type: "<< cond::timeTypeNames( timetype ) << ") " << abtime
463  << "; from CondDBESSource::setIntervalFor";
464 
465  recordValidity.first = std::max(recordValidity.first,validity.first);
466  recordValidity.second = std::min(recordValidity.second,validity.second);
467  }
468 
469  if( m_policy == REFRESH_OPEN_IOVS ) {
470  doRefresh = ( recordValidity.second == cond::timeTypeSpecs[timetype].endValue );
471  edm::LogInfo( "CondDBESSource" ) << "Validity for record \"" << recordname
472  << "\" and the corresponding label(s) coming from Condition DB: (" << recordValidity.first
473  << ", "<< recordValidity.first
474  << ") as the last IOV element in the IOV sequence is infinity"
475  << "; from CondDBESSource::setIntervalFor";
476  }
477 
478  // to force refresh we set end-value to the minimum such an IOV can extend to: current run or lumiblock
479 
480  if ( (!userTime) && recordValidity.second !=0 ) {
481  edm::IOVSyncValue start = cond::time::toIOVSyncValue(recordValidity.first, timetype, true);
482  edm::IOVSyncValue stop = doRefresh ? cond::time::limitedIOVSyncValue (iTime, timetype)
483  : cond::time::toIOVSyncValue(recordValidity.second, timetype, false);
484 
485  oInterval = edm::ValidityInterval( start, stop );
486  }
487 
488  edm::LogInfo( "CondDBESSource" ) << "Setting validity for record \"" << recordname
489  << "\" and corresponding label(s): starting at " << oInterval.first().eventID() << ", timestamp: " << oInterval.first().time().value()
490  << ", ending at "<< oInterval.last().eventID() << ", timestamp: " << oInterval.last().time().value()
491  << ", for "<< iTime.eventID() << ", timestamp: " << iTime.time().value()
492  << "; from CondDBESSource::setIntervalFor";
493 }
RunNumber_t run() const
Definition: EventID.h:39
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
const EventID & eventID() const
Definition: IOVSyncValue.h:42
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
RefreshPolicy m_policy
TimeType
Definition: Time.h:21
const IOVSyncValue & last() const
U second(std::pair< T, U > const &p)
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
Definition: Time.cc:74
std::string const & timeTypeNames(int)
Definition: Time.cc:15
unsigned long long Time_t
Definition: Time.h:16
std::pair< std::string, std::string > parseTag(const std::string &tag)
Definition: GTProxy.cc:8
std::map< std::string, unsigned int > m_lastRecordRuns
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
T min(T a, T b)
Definition: MathUtil.h:58
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
TagCollection m_tagCollection
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
std::string m_connectionString
ProxyMap m_proxies
unsigned int m_lastRun
static const ValidityInterval & invalidInterval()
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
const Timestamp & time() const
Definition: IOVSyncValue.h:44
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
Definition: Time.cc:91
volatile std::atomic< bool > shutdown_flag false
const IOVSyncValue & first() const
Time_t endValue
Definition: Time.h:46
unsigned int m_lastLumi
TimeValue_t value() const
Definition: Timestamp.h:56

Member Data Documentation

cond::persistency::ConnectionPool CondDBESSource::m_connection
private

Definition at line 57 of file CondDBESSource.h.

Referenced by CondDBESSource(), fillTagCollectionFromGT(), and setIntervalFor().

std::string CondDBESSource::m_connectionString
private

Definition at line 58 of file CondDBESSource.h.

Referenced by CondDBESSource(), and setIntervalFor().

bool CondDBESSource::m_doDump
private

Definition at line 87 of file CondDBESSource.h.

Referenced by ~CondDBESSource().

unsigned int CondDBESSource::m_lastLumi
private

Definition at line 84 of file CondDBESSource.h.

Referenced by setIntervalFor().

std::map<std::string,unsigned int> CondDBESSource::m_lastRecordRuns
private

Definition at line 68 of file CondDBESSource.h.

Referenced by setIntervalFor().

unsigned int CondDBESSource::m_lastRun
private

Definition at line 83 of file CondDBESSource.h.

Referenced by setIntervalFor().

RefreshPolicy CondDBESSource::m_policy
private

Definition at line 85 of file CondDBESSource.h.

Referenced by CondDBESSource(), and setIntervalFor().

ProxyMap CondDBESSource::m_proxies
private

Definition at line 61 of file CondDBESSource.h.

Referenced by CondDBESSource(), registerProxies(), setIntervalFor(), and ~CondDBESSource().

std::map<std::string,std::pair<cond::persistency::Session,std::string> > CondDBESSource::m_sessionPool
private

Definition at line 67 of file CondDBESSource.h.

Referenced by setIntervalFor().

Stats CondDBESSource::m_stats
private

Definition at line 81 of file CondDBESSource.h.

Referenced by CondDBESSource(), setIntervalFor(), and ~CondDBESSource().

TagCollection CondDBESSource::m_tagCollection
private

Definition at line 66 of file CondDBESSource.h.

Referenced by CondDBESSource(), fillTagCollectionFromDB(), and setIntervalFor().