CMS 3D CMS Logo

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

using DataKey = edm::eventsetup::DataKey
 
using EventSetupRecordKey = edm::eventsetup::EventSetupRecordKey
 
typedef std::multimap< std::string, ProxyPProxyMap
 
typedef std::shared_ptr< cond::DataProxyWrapperBaseProxyP
 
enum  RefreshPolicy {
  NOREFRESH, REFRESH_ALWAYS, REFRESH_OPEN_IOVS, REFRESH_EACH_RUN,
  RECONNECT_EACH_RUN
}
 

Public Member Functions

 CondDBESSource (const edm::ParameterSet &)
 
 ~CondDBESSource () override
 
- Public Member Functions inherited from edm::eventsetup::DataProxyProvider
void createKeyedProxies (EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
 
 DataProxyProvider ()
 
 DataProxyProvider (const DataProxyProvider &)=delete
 
const ComponentDescriptiondescription () const
 
void fillRecordsNotAllowingConcurrentIOVs (std::set< EventSetupRecordKey > &recordsNotAllowingConcurrentIOVs) const
 
virtual void initConcurrentIOVs (EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
 
bool isUsingRecord (const EventSetupRecordKey &key) const
 
KeyedProxieskeyedProxies (const EventSetupRecordKey &iRecordKey, unsigned int iovIndex=0)
 
const DataProxyProvideroperator= (const DataProxyProvider &)=delete
 
void setAppendToDataLabel (const edm::ParameterSet &)
 
void setDescription (const ComponentDescription &iDescription)
 
virtual void updateLookup (ESRecordsToProxyIndices const &)
 
std::set< EventSetupRecordKeyusingRecords () const
 
virtual ~DataProxyProvider () noexcept(false)
 
- Public Member Functions inherited from edm::EventSetupRecordIntervalFinder
bool concurrentFinder () const
 
const eventsetup::ComponentDescriptiondescriptionForFinder () const
 
 EventSetupRecordIntervalFinder ()
 
 EventSetupRecordIntervalFinder (const EventSetupRecordIntervalFinder &)=delete
 
std::set< eventsetup::EventSetupRecordKeyfindingForRecords () const
 
const ValidityIntervalfindIntervalFor (const eventsetup::EventSetupRecordKey &, const IOVSyncValue &)
 
bool nonconcurrentAndIOVNeedsUpdate (const eventsetup::EventSetupRecordKey &key, const IOVSyncValue &syncValue) const
 
const EventSetupRecordIntervalFinderoperator= (const EventSetupRecordIntervalFinder &)=delete
 
void resetInterval (const eventsetup::EventSetupRecordKey &)
 
void setDescriptionForFinder (const eventsetup::ComponentDescription &iDescription)
 
virtual ~EventSetupRecordIntervalFinder () noexcept(false)
 

Protected Member Functions

void initConcurrentIOVs (const EventSetupRecordKey &key, unsigned int nConcurrentIOVs) override
 
bool isConcurrentFinder () const override
 
KeyedProxiesVector registerProxies (const EventSetupRecordKey &, unsigned int iovIndex) override
 
void setIntervalFor (const EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
 
- Protected Member Functions inherited from edm::eventsetup::DataProxyProvider
template<class T >
void usingRecord ()
 
void usingRecordWithKey (const EventSetupRecordKey &key)
 
- 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_tTagCollection
 

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, cond::GTMetadata_t &gtMetadata)
 
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)
 

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 &)
 
- Protected Types inherited from edm::eventsetup::DataProxyProvider
using KeyedProxiesVector = std::vector< std::pair< DataKey, std::shared_ptr< DataProxy >>>
 

Detailed Description

Definition at line 60 of file CondDBESSource.h.

Member Typedef Documentation

Definition at line 62 of file CondDBESSource.h.

Definition at line 63 of file CondDBESSource.h.

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

Definition at line 65 of file CondDBESSource.h.

Definition at line 64 of file CondDBESSource.h.

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

Definition at line 90 of file CondDBESSource.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

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

required by eventsetup

Definition at line 96 of file CondDBESSource.cc.

References b, cond::persistency::ConnectionPool::configure(), cond::persistency::convertoToOracleConnection(), cond::persistency::ConnectionPool::createReadOnlySession(), MillePedeFileConverter_cfg::e, edm::ParameterSet::exists(), fillList(), fillTagCollectionFromDB(), edm::EventSetupRecordIntervalFinder::findingRecordWithKey(), edm::eventsetup::heterocontainer::HCTypeTag::findType(), cond::persistency::fullyQualifiedTag(), timingPdfMaker::get, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), download_sqlite_cfg::globaltag, m_connection, m_connectionString, m_policy, m_proxies, m_stats, m_tagCollection, cond::time::MAX_TIMESTAMP, eostools::move(), CondDBESSource::Stats::nData, cond::persistency::parseConnectionString(), cond::persistency::parseTag(), loadRecoTauTagMVAsFromPrepDB_cfi::pfnPostfix, loadRecoTauTagMVAsFromPrepDB_cfi::pfnPrefix, RECONNECT_EACH_RUN, REFRESH_ALWAYS, REFRESH_EACH_RUN, REFRESH_OPEN_IOVS, alignCSCRings::s, cond::persistency::ConnectionPool::setParameters(), loadRecoTauTagMVAsFromPrepDB_cfi::snapshotTime, cms::dd::split(), AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, DBConfiguration_cff::toGet, edm::eventsetup::EventSetupRecordKey::type(), and edm::eventsetup::DataProxyProvider::usingRecordWithKey().

97  : m_connection(),
99  m_lastRun(0), // for the stat
100  m_lastLumi(0), // for the stat
102  m_doDump(iConfig.getUntrackedParameter<bool>("DumpStat", false)) {
103  if (iConfig.getUntrackedParameter<bool>("RefreshAlways", false)) {
105  }
106  if (iConfig.getUntrackedParameter<bool>("RefreshOpenIOVs", false)) {
108  }
109  if (iConfig.getUntrackedParameter<bool>("RefreshEachRun", false)) {
111  }
112  if (iConfig.getUntrackedParameter<bool>("ReconnectEachRun", false)) {
114  }
115 
116  Stats s = {0, 0, 0, 0, 0, 0, 0, 0};
117  m_stats = s;
118 
119  /*parameter set parsing
120  */
122  if (iConfig.exists("globaltag")) {
123  globaltag = iConfig.getParameter<std::string>("globaltag");
124  // the global tag _requires_ a connection string
125  m_connectionString = iConfig.getParameter<std::string>("connect");
126  } else if (iConfig.exists("connect")) // default connection string
127  m_connectionString = iConfig.getParameter<std::string>("connect");
128 
129  // snapshot
130  boost::posix_time::ptime snapshotTime;
131  if (iConfig.exists("snapshotTime")) {
132  std::string snapshotTimeString = iConfig.getParameter<std::string>("snapshotTime");
133  if (!snapshotTimeString.empty())
134  snapshotTime = boost::posix_time::time_from_string(snapshotTimeString);
135  }
136 
137  // connection configuration
138  if (iConfig.exists("DBParameters")) {
139  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>("DBParameters");
140  m_connection.setParameters(connectionPset);
141  }
143 
144  // load specific record/tag info - it will overwrite the global tag ( if any )
145  std::map<std::string, cond::GTEntry_t> replacements;
146  std::map<std::string, boost::posix_time::ptime> specialSnapshots;
147  if (iConfig.exists("toGet")) {
148  typedef std::vector<edm::ParameterSet> Parameters;
149  Parameters toGet = iConfig.getParameter<Parameters>("toGet");
150  for (Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet) {
151  std::string recordname = itToGet->getParameter<std::string>("record");
152  if (recordname.empty())
153  throw cond::Exception("ESSource: The record name has not been provided in a \"toGet\" entry.");
154  std::string labelname = itToGet->getUntrackedParameter<std::string>("label", "");
155  std::string pfn("");
156  if (m_connectionString.empty() || itToGet->exists("connect"))
157  pfn = itToGet->getParameter<std::string>("connect");
158  std::string tag("");
159  std::string fqTag("");
160  if (itToGet->exists("tag")) {
161  tag = itToGet->getParameter<std::string>("tag");
163  }
164  boost::posix_time::ptime tagSnapshotTime =
165  boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP));
166  if (itToGet->exists("snapshotTime"))
167  tagSnapshotTime = boost::posix_time::time_from_string(itToGet->getParameter<std::string>("snapshotTime"));
168  std::string recordLabelKey = joinRecordAndLabel(recordname, labelname);
169  replacements.insert(
170  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, pfnPrefixList, pfnPostfixList, globaltagList, replacements, gtMetadata);
191  // if no job specific setting has been found, use the GT timestamp
192  if (snapshotTime.is_not_a_date_time())
193  snapshotTime = gtMetadata.snapshotTime;
194 
195  TagCollection::iterator it;
196  TagCollection::iterator itBeg = m_tagCollection.begin();
197  TagCollection::iterator itEnd = m_tagCollection.end();
198 
199  std::map<std::string, cond::persistency::Session> sessions;
200 
201  /* load DataProxy Plugin (it is strongly typed due to EventSetup ideosyncrasis)
202  * construct proxy
203  * contrary to EventSetup the "object-name" is not used as identifier: multiple entries in a record are
204  * dinstinguished only by their label...
205  * done in two step: first create ProxyWrapper loading ALL required dictionaries
206  * this will allow to initialize POOL in one go for each "database"
207  * The real initialization of the Data-Proxies is done in the second loop
208  */
209  std::vector<std::unique_ptr<cond::DataProxyWrapperBase>> proxyWrappers(m_tagCollection.size());
210  size_t ipb = 0;
211  for (it = itBeg; it != itEnd; ++it) {
212  proxyWrappers[ipb++] = std::unique_ptr<cond::DataProxyWrapperBase>{
213  cond::ProxyFactory::get()->create(buildName(it->second.recordName()))};
214  }
215 
216  // now all required libraries have been loaded
217  // init sessions and DataProxies
218  ipb = 0;
219  for (it = itBeg; it != itEnd; ++it) {
221  std::string tag = it->second.tagName();
222  std::pair<std::string, std::string> tagParams = cond::persistency::parseTag(it->second.tagName());
223  if (!tagParams.second.empty()) {
224  connStr = tagParams.second;
225  tag = tagParams.first;
226  }
227  std::map<std::string, cond::persistency::Session>::iterator p = sessions.find(connStr);
229  if (p == sessions.end()) {
231  std::tuple<std::string, std::string, std::string> connPars =
233  std::string dbService = std::get<1>(connPars);
234  std::string dbAccount = std::get<2>(connPars);
235  if ((dbService == "cms_orcon_prod" || dbService == "cms_orcon_adg") && dbAccount != "CMS_CONDITIONS")
236  edm::LogWarning("CondDBESSource")
237  << "[WARNING] You are reading tag \"" << tag << "\" from V1 account \"" << connStr
238  << "\". The concerned Conditions might be out of date." << std::endl;
239  //open db get tag info (i.e. the IOV token...)
240  nsess = m_connection.createReadOnlySession(connStr, "");
241  sessions.insert(std::make_pair(connStr, nsess));
242  } else
243  nsess = (*p).second;
244 
245  // ownership...
246  ProxyP proxy(std::move(proxyWrappers[ipb++]));
247  // instert in the map
248  m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
249  // initialize
250  boost::posix_time::ptime tagSnapshotTime = snapshotTime;
251  auto tagSnapshotIter = specialSnapshots.find(it->first);
252  if (tagSnapshotIter != specialSnapshots.end())
253  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  (*b).second->proxy(0)->loadMore(visitor);
267 
270  if (recordKey.type() != EventSetupRecordKey::TypeTag()) {
271  findingRecordWithKey(recordKey);
272  usingRecordWithKey(recordKey);
273  }
274  }
275 
276  m_stats.nData = m_proxies.size();
277 }
std::vector< std::string_view > split(std::string_view, const char *)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
Definition: Utils.h:96
Base exception class for the object to relational access.
Definition: Exception.h:11
void usingRecordWithKey(const EventSetupRecordKey &key)
bool exists(std::string const &parameterName) const
checks if a parameter exists
static constexpr const char *const MAX_TIMESTAMP
Definition: Time.h:26
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
RefreshPolicy m_policy
void setParameters(const edm::ParameterSet &connectionPset)
vector< ParameterSet > Parameters
std::string convertoToOracleConnection(const std::string &input)
Definition: Utils.h:121
std::pair< std::string, std::string > parseTag(const std::string &tag)
Definition: GTProxy.cc:14
cond::persistency::ConnectionPool m_connection
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)
std::shared_ptr< cond::DataProxyWrapperBase > ProxyP
TagCollection m_tagCollection
double b
Definition: hdecay.h:118
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
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
unsigned int m_lastLumi
def move(src, dest)
Definition: eostools.py:511
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
CondDBESSource::~CondDBESSource ( )
override

Definition at line 297 of file CondDBESSource.cc.

References b, gather_cfg::cout, MillePedeFileConverter_cfg::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.

297  {
298  //dump info FIXME: find a more suitable place...
299  if (m_doDump) {
300  std::cout << "CondDBESSource Statistics" << std::endl
301  << "DataProxy " << m_stats.nData << " setInterval " << m_stats.nSet << " Runs " << m_stats.nRun
302  << " Lumis " << m_stats.nLumi << " Refresh " << m_stats.nRefresh << " Actual Refresh "
303  << m_stats.nActualRefresh << " Reconnect " << m_stats.nReconnect << " Actual Reconnect "
305  std::cout << std::endl;
306 
307  ProxyMap::iterator b = m_proxies.begin();
308  ProxyMap::iterator e = m_proxies.end();
309  for (; b != e; b++) {
310  dumpInfo(std::cout, (*b).first, *(*b).second);
311  std::cout << "\n" << std::endl;
312  }
313 
314  // FIXME
315  // We shall eventually close transaction and session...
316  }
317 }
double b
Definition: hdecay.h:118
ProxyMap m_proxies

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 279 of file CondDBESSource.cc.

References mps_fire::i, cms::dd::split(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by CondDBESSource().

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(
293  std::string("ESSource: number of global tag components does not match number of " + type + " strings"));
294  }
295 }
persistency::Exception Exception
Definition: Exception.h:25
std::vector< std::string_view > split(std::string_view, const char *)
type
Definition: HCALResponse.h:21
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,
cond::GTMetadata_t gtMetadata 
)
private

Definition at line 600 of file CondDBESSource.cc.

References l1RCTOmdsFedVectorProducer_cfi::connectionString, fillTagCollectionFromGT(), m_tagCollection, mps_check::msg, ZMuMuAnalysisNtupler_cff::prefix, cond::GTEntry_t::recordLabel(), cond::GTEntry_t::recordName(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::GTEntry_t::tagName().

Referenced by CondDBESSource().

605  {
606  std::set<cond::GTEntry_t> tagcoll;
607 
608  auto connectionString = connectionStringList.begin();
609  auto prefix = prefixList.begin();
610  auto postfix = postfixList.begin();
611  for (auto roottag = roottagList.begin(); roottag != roottagList.end();
612  ++roottag, ++connectionString, ++prefix, ++postfix) {
613  fillTagCollectionFromGT(*connectionString, *prefix, *postfix, *roottag, tagcoll, gtMetadata);
614  }
615 
616  std::set<cond::GTEntry_t>::iterator tagCollIter;
617  std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
618  std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
619 
620  // FIXME the logic is a bit perverse: can be surely linearized (at least simplified!) ....
621  for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
622  std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
623  std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
624  if (fid != replacement.end()) {
625  if (!fid->second.tagName().empty()) {
626  cond::GTEntry_t tagMetadata(
627  std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
628  m_tagCollection.insert(std::make_pair(recordLabelKey, tagMetadata));
629  edm::LogInfo("CondDBESSource") << "Replacing tag \"" << tagCollIter->tagName() << "\" for record \""
630  << tagMetadata.recordName() << "\" and label \"" << tagMetadata.recordLabel()
631  << "\" with tag " << tagMetadata.tagName()
632  << "\"; from CondDBESSource::fillTagCollectionFromDB";
633  } else {
634  m_tagCollection.insert(std::make_pair(recordLabelKey, *tagCollIter));
635  }
636  replacement.erase(fid);
637  } else {
638  m_tagCollection.insert(std::make_pair(recordLabelKey, *tagCollIter));
639  }
640  }
641  std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
642  std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
643  std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
644  for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
645  if (replacementIter->second.tagName().empty()) {
646  std::stringstream msg;
647  msg << "ESSource: no tag provided for record " << replacementIter->second.recordName();
648  if (!replacementIter->second.recordLabel().empty())
649  msg << " and label " << replacementIter->second.recordLabel();
650  throw cond::Exception(msg.str());
651  }
652  m_tagCollection.insert(*replacementIter);
653  }
654 }
persistency::Exception Exception
Definition: Exception.h:25
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)
TagCollection m_tagCollection
tuple msg
Definition: mps_check.py:285
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,
cond::GTMetadata_t gtMetadata 
)
private

Definition at line 566 of file CondDBESSource.cc.

References cond::persistency::Transaction::commit(), cond::persistency::ConnectionPool::createSession(), m_connection, cond::persistency::parseConnectionString(), cond::persistency::Session::readGlobalTag(), cond::persistency::GTProxy::snapshotTime(), cond::GTMetadata_t::snapshotTime, cond::persistency::Transaction::start(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::persistency::Session::transaction().

Referenced by fillTagCollectionFromDB().

571  {
572  if (!roottag.empty()) {
573  if (connectionString.empty())
574  throw cond::Exception(std::string("ESSource: requested global tag ") + roottag +
575  std::string(" but not connection string given"));
576  std::tuple<std::string, std::string, std::string> connPars =
578  if (std::get<2>(connPars) == "CMS_COND_31X_GLOBALTAG") {
579  edm::LogWarning("CondDBESSource")
580  << "[WARNING] You are reading Global Tag \"" << roottag
581  << "\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date."
582  << std::endl;
583  } else if (roottag.rfind("::All") != std::string::npos && std::get<2>(connPars) == "CMS_CONDITIONS") {
584  edm::LogWarning("CondDBESSource") << "[WARNING] You are trying to read Global Tag \"" << roottag
585  << "\" - postfix \"::All\" should not be used for V2." << std::endl;
586  }
588  session.transaction().start(true);
589  cond::persistency::GTProxy gtp = session.readGlobalTag(roottag, prefix, postfix);
590  gtMetadata.snapshotTime = gtp.snapshotTime();
591  for (const auto& gte : gtp) {
592  tagcoll.insert(gte);
593  }
594  session.transaction().commit();
595  }
596 }
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
Definition: Utils.h:96
Base exception class for the object to relational access.
Definition: Exception.h:11
void start(bool readOnly=true)
Definition: Session.cc:18
boost::posix_time::ptime snapshotTime
Definition: Types.h:110
Transaction & transaction()
Definition: Session.cc:43
cond::persistency::ConnectionPool m_connection
boost::posix_time::ptime snapshotTime() const
Definition: GTProxy.cc:135
Session createSession(const std::string &connectionString, bool writeCapable=false)
GTProxy readGlobalTag(const std::string &name)
Definition: Session.cc:172
void CondDBESSource::initConcurrentIOVs ( const EventSetupRecordKey key,
unsigned int  nConcurrentIOVs 
)
overrideprotected

Definition at line 554 of file CondDBESSource.cc.

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

554  {
555  std::string recordname = key.name();
556  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
557  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
558  for (ProxyMap::const_iterator p = b; p != e; ++p) {
559  if (p->second) {
560  p->second->initConcurrentIOVs(nConcurrentIOVs);
561  }
562  }
563 }
double b
Definition: hdecay.h:118
ProxyMap m_proxies
bool CondDBESSource::isConcurrentFinder ( ) const
inlineoverrideprotectedvirtual

Reimplemented from edm::EventSetupRecordIntervalFinder.

Definition at line 79 of file CondDBESSource.h.

79 { return true; }
edm::eventsetup::DataProxyProvider::KeyedProxiesVector CondDBESSource::registerProxies ( const EventSetupRecordKey iRecordKey,
unsigned int  iovIndex 
)
overrideprotectedvirtual

Implements edm::eventsetup::DataProxyProvider.

Definition at line 530 of file CondDBESSource.cc.

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

531  {
532  KeyedProxiesVector keyedProxiesVector;
533 
534  std::string recordname = iRecordKey.name();
535 
536  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
537  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
538  if (b == e) {
539  edm::LogInfo("CondDBESSource") << "No DataProxy (Pluging) found for record \"" << recordname
540  << "\"; from CondDBESSource::registerProxies";
541  return keyedProxiesVector;
542  }
543 
544  for (ProxyMap::const_iterator p = b; p != e; ++p) {
545  if (nullptr != (*p).second.get()) {
546  edm::eventsetup::TypeTag type = (*p).second->type();
547  DataKey key(type, edm::eventsetup::IdTags((*p).second->label().c_str()));
548  keyedProxiesVector.emplace_back(key, (*p).second->edmProxy(iovIndex));
549  }
550  }
551  return keyedProxiesVector;
552 }
type
Definition: HCALResponse.h:21
std::vector< std::pair< DataKey, std::shared_ptr< DataProxy >>> KeyedProxiesVector
double b
Definition: hdecay.h:118
ProxyMap m_proxies
void CondDBESSource::setIntervalFor ( const EventSetupRecordKey iKey,
const edm::IOVSyncValue iTime,
edm::ValidityInterval oInterval 
)
overrideprotectedvirtual

Implements edm::EventSetupRecordIntervalFinder.

Definition at line 323 of file CondDBESSource.cc.

References edm::IOVSyncValue::beginOfTime(), cond::persistency::ConnectionPool::createReadOnlySession(), cond::TimeTypeSpecs::endValue, edm::IOVSyncValue::eventID(), edm::ValidityInterval::first(), dqmdumpme::first, cond::time::fromIOVSyncValue(), edm::ValidityInterval::invalidInterval(), edm::IOVSyncValue::invalidIOVSyncValue(), 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, genParticles_cff::map, SiStripPI::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(), AlCaHLTBitMon_QueryRunRegistry::string, edm::IOVSyncValue::time(), cond::TIMELIMIT(), DBConfiguration_cff::timetype, cond::timeTypeNames(), cond::timeTypeSpecs, cond::time::toIOVSyncValue(), and edm::Timestamp::value().

325  {
326  std::string recordname = iKey.name();
327 
328  edm::LogInfo("CondDBESSource") << "Getting data for record \"" << recordname << "\" to be consumed by "
329  << iTime.eventID() << ", timestamp: " << iTime.time().value()
330  << "; from CondDBESSource::setIntervalFor";
331 
332  m_stats.nSet++;
333  //{
334  // not really required, keep here for the time being
335  if (iTime.eventID().run() != m_lastRun) {
336  m_lastRun = iTime.eventID().run();
337  m_stats.nRun++;
338  }
339  if (iTime.luminosityBlockNumber() != m_lastLumi) {
341  m_stats.nLumi++;
342  }
343  //}
344 
345  bool doRefresh = false;
347  // find out the last run number for the proxy of the specified record
348  std::map<std::string, unsigned int>::iterator iRec = m_lastRecordRuns.find(recordname);
349  if (iRec != m_lastRecordRuns.end()) {
350  unsigned int lastRecordRun = iRec->second;
351  if (lastRecordRun != m_lastRun) {
352  // a refresh is required!
353  doRefresh = true;
354  iRec->second = m_lastRun;
355  edm::LogInfo("CondDBESSource") << "Preparing refresh for record \"" << recordname
356  << "\" since there has been a transition from run " << lastRecordRun
357  << " to run " << m_lastRun << "; from CondDBESSource::setIntervalFor";
358  }
359  } else {
360  doRefresh = true;
361  m_lastRecordRuns.insert(std::make_pair(recordname, m_lastRun));
362  edm::LogInfo("CondDBESSource") << "Preparing refresh for record \"" << recordname << "\" for " << iTime.eventID()
363  << ", timestamp: " << iTime.time().value()
364  << "; from CondDBESSource::setIntervalFor";
365  }
366  if (!doRefresh)
367  edm::LogInfo("CondDBESSource") << "Though enabled, refresh not needed for record \"" << recordname << "\" for "
368  << iTime.eventID() << ", timestamp: " << iTime.time().value()
369  << "; from CondDBESSource::setIntervalFor";
370  } else if (m_policy == REFRESH_ALWAYS || m_policy == REFRESH_OPEN_IOVS) {
371  doRefresh = true;
372  edm::LogInfo("CondDBESSource") << "Forcing refresh for record \"" << recordname << "\" for " << iTime.eventID()
373  << ", timestamp: " << iTime.time().value()
374  << "; from CondDBESSource::setIntervalFor";
375  }
376 
378 
379  // compute the smallest interval (assume all objects have the same timetype....)
380  cond::ValidityInterval recordValidity(1, cond::TIMELIMIT);
381  cond::TimeType timetype = cond::TimeType::invalid;
382  bool userTime = true;
383 
384  //FIXME use equal_range
385  ProxyMap::const_iterator pmBegin = m_proxies.lower_bound(recordname);
386  ProxyMap::const_iterator pmEnd = m_proxies.upper_bound(recordname);
387  if (pmBegin == pmEnd) {
388  edm::LogInfo("CondDBESSource") << "No DataProxy (Pluging) found for record \"" << recordname
389  << "\"; from CondDBESSource::setIntervalFor";
390  return;
391  }
392 
393  for (ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter) {
394  edm::LogInfo("CondDBESSource") << "Processing record \"" << recordname << "\" and label \""
395  << pmIter->second->label() << "\" for " << iTime.eventID()
396  << ", timestamp: " << iTime.time().value()
397  << "; from CondDBESSource::setIntervalFor";
398 
399  timetype = (*pmIter).second->timeType();
400 
401  cond::Time_t abtime = cond::time::fromIOVSyncValue(iTime, timetype);
402  userTime = (0 == abtime);
403 
404  if (userTime)
405  return; // oInterval invalid to avoid that make is called...
406 
407  if (doRefresh) {
408  std::string recKey = joinRecordAndLabel(recordname, pmIter->second->label());
409  TagCollection::const_iterator tcIter = m_tagCollection.find(recKey);
410  if (tcIter == m_tagCollection.end()) {
411  edm::LogInfo("CondDBESSource") << "No Tag found for record \"" << recordname << "\" and label \""
412  << pmIter->second->label() << "\"; from CondDBESSource::setIntervalFor";
413  return;
414  }
415 
416  // first reconnect if required
417  if (m_policy == RECONNECT_EACH_RUN) {
418  edm::LogInfo("CondDBESSource")
419  << "Checking if the session must be closed and re-opened for getting correct conditions"
420  << "; from CondDBESSource::setIntervalFor";
421  std::stringstream transId;
422  //transId << "long" << m_lastRun;
423  transId << m_lastRun;
425  std::pair<std::string, std::string> tagParams = cond::persistency::parseTag(tcIter->second.tagName());
426  if (!tagParams.second.empty())
427  connStr = tagParams.second;
428  std::map<std::string, std::pair<cond::persistency::Session, std::string>>::iterator iSess =
429  m_sessionPool.find(connStr);
430  bool reopen = false;
431  if (iSess != m_sessionPool.end()) {
432  if (iSess->second.second != transId.str()) {
433  // the available session is open for a different run: reopen
434  reopen = true;
435  iSess->second.second = transId.str();
436  }
437  } else {
438  // no available session: probably first run analysed...
439  iSess =
440  m_sessionPool.insert(std::make_pair(connStr, std::make_pair(cond::persistency::Session(), transId.str())))
441  .first;
442  reopen = true;
443  }
444  if (reopen) {
445  iSess->second.first = m_connection.createReadOnlySession(connStr, transId.str());
446  edm::LogInfo("CondDBESSource") << "Re-opening the session with connection string " << connStr
447  << " and new transaction Id " << transId.str()
448  << "; from CondDBESSource::setIntervalFor";
449  }
450 
451  edm::LogInfo("CondDBESSource") << "Reconnecting to \"" << connStr << "\" for getting new payload for record \""
452  << recordname << "\" and label \"" << pmIter->second->label()
453  << "\" from IOV tag \"" << tcIter->second.tagName() << "\" to be consumed by "
454  << iTime.eventID() << ", timestamp: " << iTime.time().value()
455  << "; from CondDBESSource::setIntervalFor";
456  pmIter->second->session() = iSess->second.first;
457  pmIter->second->reload();
458  //if( isSizeIncreased )
459  //edm::LogInfo( "CondDBESSource" ) << "After reconnecting, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
460  // << "\" was found; from CondDBESSource::setIntervalFor";
461  //m_stats.nActualReconnect += isSizeIncreased;
463  } else {
464  edm::LogInfo("CondDBESSource") << "Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
465  << "\" for getting new payload for record \"" << recordname << "\" and label \""
466  << pmIter->second->label() << "\" to be consumed by " << iTime.eventID()
467  << ", timestamp: " << iTime.time().value()
468  << "; from CondDBESSource::setIntervalFor";
469  pmIter->second->reload();
470  //if( isSizeIncreased )
471  // edm::LogInfo( "CondDBESSource" ) << "After refreshing, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
472  // << "\" was found; from CondDBESSource::setIntervalFor";
473  //m_stats.nActualRefresh += isSizeIncreased;
474  m_stats.nRefresh++;
475  }
476  }
477 
478  /*
479  // make oInterval valid For Ever
480  {
481  oInterval = edm::ValidityInterval(cond::toIOVSyncValue(recordValidity.first, cond::runnumber, true),
482  cond::toIOVSyncValue(recordValidity.second, cond::runnumber, false));
483  return;
484  }
485  */
486 
487  //query the IOVSequence
488  cond::ValidityInterval validity = (*pmIter).second->setIntervalFor(abtime);
489 
490  edm::LogInfo("CondDBESSource") << "Validity coming from IOV sequence for record \"" << recordname
491  << "\" and label \"" << pmIter->second->label() << "\": (" << validity.first << ", "
492  << validity.second << ") for time (type: " << cond::timeTypeNames(timetype) << ") "
493  << abtime << "; from CondDBESSource::setIntervalFor";
494 
495  recordValidity.first = std::max(recordValidity.first, validity.first);
496  recordValidity.second = std::min(recordValidity.second, validity.second);
497  }
498 
499  if (m_policy == REFRESH_OPEN_IOVS) {
500  doRefresh = (recordValidity.second == cond::timeTypeSpecs[timetype].endValue);
501  edm::LogInfo("CondDBESSource") << "Validity for record \"" << recordname
502  << "\" and the corresponding label(s) coming from Condition DB: ("
503  << recordValidity.first << ", " << recordValidity.first
504  << ") as the last IOV element in the IOV sequence is infinity"
505  << "; from CondDBESSource::setIntervalFor";
506  }
507 
508  // to force refresh we set end-value to the minimum such an IOV can extend to: current run or lumiblock
509 
510  if ((!userTime) && recordValidity.second != 0) {
511  edm::IOVSyncValue start = cond::time::toIOVSyncValue(recordValidity.first, timetype, true);
512  edm::IOVSyncValue stop = doRefresh ? cond::time::limitedIOVSyncValue(iTime, timetype)
513  : cond::time::toIOVSyncValue(recordValidity.second, timetype, false);
514 
517  }
518  oInterval = edm::ValidityInterval(start, stop);
519  }
520 
521  edm::LogInfo("CondDBESSource") << "Setting validity for record \"" << recordname
522  << "\" and corresponding label(s): starting at " << oInterval.first().eventID()
523  << ", timestamp: " << oInterval.first().time().value() << ", ending at "
524  << oInterval.last().eventID() << ", timestamp: " << oInterval.last().time().value()
525  << ", for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
526  << "; from CondDBESSource::setIntervalFor";
527 }
RunNumber_t run() const
Definition: EventID.h:38
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
Definition: start.py:1
const EventID & eventID() const
Definition: IOVSyncValue.h:40
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
RefreshPolicy m_policy
TimeType
Definition: Time.h:19
const IOVSyncValue & last() const
U second(std::pair< T, U > const &p)
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
Definition: Time.cc:81
std::string const & timeTypeNames(int)
Definition: Time.cc:11
unsigned long long Time_t
Definition: Time.h:14
std::pair< std::string, std::string > parseTag(const std::string &tag)
Definition: GTProxy.cc:14
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
cond::persistency::ConnectionPool m_connection
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, TimeType timetype, bool startOrStop)
Definition: Time.cc:63
LuminosityBlockNumber_t luminosityBlockNumber() const
Definition: IOVSyncValue.h:41
T min(T a, T b)
Definition: MathUtil.h:58
TagCollection m_tagCollection
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
std::string m_connectionString
ProxyMap m_proxies
Definition: plugin.cc:23
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:42
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
Definition: Time.cc:97
const IOVSyncValue & first() const
Time_t endValue
Definition: Time.h:42
std::map< std::string, unsigned int > m_lastRecordRuns
unsigned int m_lastLumi
TimeValue_t value() const
Definition: Timestamp.h:45
static const IOVSyncValue & invalidIOVSyncValue()
Definition: IOVSyncValue.cc:78

Member Data Documentation

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

Definition at line 84 of file CondDBESSource.h.

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

std::string CondDBESSource::m_connectionString
private

Definition at line 85 of file CondDBESSource.h.

Referenced by CondDBESSource(), and setIntervalFor().

bool CondDBESSource::m_doDump
private

Definition at line 113 of file CondDBESSource.h.

Referenced by ~CondDBESSource().

unsigned int CondDBESSource::m_lastLumi
private

Definition at line 110 of file CondDBESSource.h.

Referenced by setIntervalFor().

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

Definition at line 94 of file CondDBESSource.h.

Referenced by setIntervalFor().

unsigned int CondDBESSource::m_lastRun
private

Definition at line 109 of file CondDBESSource.h.

Referenced by setIntervalFor().

RefreshPolicy CondDBESSource::m_policy
private

Definition at line 111 of file CondDBESSource.h.

Referenced by CondDBESSource(), and setIntervalFor().

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

Definition at line 93 of file CondDBESSource.h.

Referenced by setIntervalFor().

Stats CondDBESSource::m_stats
private

Definition at line 107 of file CondDBESSource.h.

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

TagCollection CondDBESSource::m_tagCollection
private

Definition at line 92 of file CondDBESSource.h.

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