CMS 3D CMS Logo

CondDBESSource.h
Go to the documentation of this file.
1 #ifndef CondCore_ESSources_CondDBESSource_h
2 #define CondCore_ESSources_CondDBESSource_h
3 //
4 // Package: CondCore/ESSources
5 // Class: CondDBESSource
6 //
7 /*
8  Description: EventSetup source module for serving data from offline database
9 */
10 //
11 // Author: Zhen Xie
12 //
13 
14 // Some comments on concurrency. Several things are working together
15 // to prevent concurrency issues when this module is executing.
16 // Some of these things are in this module and some are in the Framework.
17 // Here is a list of these things:
18 //
19 // 1. There is a single mutex that is a data member of CondDBESSource.
20 // This is locked near the beginning of setIntervalFor and also
21 // near the beginning of ::ProductResolver::prefetch so that these functions
22 // will never run concurrently. All the ::ProductResolver objects have a
23 // pointer to this mutex stored in their ESSourceProductResolverTemplate
24 // base class.
25 //
26 // 2. CondDBESSource contains a single SerialTaskQueue. The tasks
27 // that run the prefetch function are placed in this SerialTaskQueue.
28 // This allows only one ::ProductResolver::prefetch function to run at a
29 // time. All the ::ProductResolver objects have a pointer to this SerialTaskQueue
30 // stored in their ESSourceProductResolverTemplate base class. Note that
31 // locking the mutex is inside the task that runs prefetch.
32 // Since these tasks are serialized by the SerialTaskQueue,
33 // the mutex will never be locked by another prefetch call
34 // when prefetch is called. The mutex is really only protecting
35 // setIntervalFor calls from each other and from prefetch calls.
36 //
37 // 3. An ESSource is not allowed to get data from the EventSetup
38 // while its ProductResolver prefetch function runs, preventing deadlocks
39 // and ensuring the mutex does not need to be recursive.
40 //
41 // 4. The WaitingTaskList in ESSourceProductResolverBase (a base class of
42 // ::ProductResolver) is used to notify other tasks waiting for prefetch
43 // to complete that the data is available (other tasks created and
44 // managed by the Framework).
45 //
46 // 5. There is an atomic<bool> in ESSourceProductResolverBase which
47 // prevents the prefetch function being run more than once for the
48 // same IOV and ProductResolver.
49 //
50 // 6. The Framework ensures calls are sequenced such that a call to
51 // setIntervalFor is made and completes, then all related calls to
52 // ProductResolver::initializeForNewIOV are made before another call to
53 // setIntervalFor is made. It is configurable how many
54 // IOVs can be running concurrently. The Framework will not call
55 // initializeForNewIOV or start running a new IOV unless the
56 // number of active IOVs is less than that configured number.
57 //
58 // 7. The Framework guarantees that after a call is made to
59 // ProductResolver::initializeForNewIOV for a particular
60 // EventSetupRecordKey and iovIndex, all calls to ProductResolver::make
61 // associated with that whose data is requested will be completed
62 // and processing of luminosity blocks associated with that will
63 // be completed before another call to ProductResolver::initializeForNewIOV
64 // is made for that EventSetupRecordKey and iovIndex.
65 
66 // system include files
67 #include <string>
68 #include <map>
69 #include <memory>
70 #include <set>
71 #include <mutex>
72 // user include files
74 
78 
79 namespace edm {
80  class ParameterSet;
81 }
82 
83 namespace cond {
84  class ProductResolverWrapperBase;
85 }
86 
88 public:
91  typedef std::shared_ptr<cond::ProductResolverWrapperBase> ResolverP;
92  typedef std::multimap<std::string, ResolverP> ResolverMap;
93 
95 
97 
98  explicit CondDBESSource(const edm::ParameterSet&);
99  ~CondDBESSource() override;
100 
101 protected:
103 
104  KeyedResolversVector registerResolvers(const EventSetupRecordKey&, unsigned int iovIndex) override;
105 
106  void initConcurrentIOVs(const EventSetupRecordKey& key, unsigned int nConcurrentIOVs) override;
107 
108  bool isConcurrentFinder() const override { return true; }
109 
110 private:
111  // ----------member data ---------------------------
112 
116 
117  // Container of ProductResolver, implemented as multi-map keyed by records
119 
120  typedef std::map<std::string, cond::GTEntry_t> TagCollection;
121  // the collections of tag, record/label used in this ESSource
123  std::map<std::string, std::pair<cond::Time_t, bool> > m_refreshTimeForRecord;
124  std::map<std::string, std::pair<cond::persistency::Session, std::string> > m_sessionPool;
125  std::map<std::string, std::pair<cond::persistency::Session, std::string> > m_sessionPoolForLumiConditions;
126  std::map<std::string, unsigned int> m_lastRecordRuns;
127 
130 
131  struct Stats {
132  int nData;
133  int nSet;
134  int nRun;
135  int nLumi;
136  int nRefresh;
140  };
141 
143 
144  unsigned int m_lastRun;
145  unsigned int m_lastLumi;
147 
148  bool m_doDump;
149 
150 private:
151  void fillList(const std::string& pfn,
152  std::vector<std::string>& pfnList,
153  const unsigned int listSize,
154  const std::string& type);
155 
157  const std::string& prefix,
158  const std::string& postfix,
159  const std::string& roottag,
160  std::set<cond::GTEntry_t>& tagcoll,
161  cond::GTMetadata_t& gtMetadata);
162 
163  void fillTagCollectionFromDB(const std::vector<std::string>& connectionStringList,
164  const std::vector<std::string>& prefixList,
165  const std::vector<std::string>& postfixList,
166  const std::vector<std::string>& roottagList,
167  std::map<std::string, cond::GTEntry_t>& replacement,
168  cond::GTMetadata_t& gtMetadata);
169 
170  void printStatistics(const Stats& stats) const;
171 };
172 #endif
std::map< std::string, std::pair< cond::Time_t, bool > > m_refreshTimeForRecord
ResolverMap m_resolvers
std::mutex m_mutex
std::multimap< std::string, ResolverP > ResolverMap
std::map< std::string, cond::GTEntry_t > TagCollection
std::shared_ptr< cond::ProductResolverWrapperBase > ResolverP
static std::mutex mutex
Definition: Proxy.cc:8
void setIntervalFor(const EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
void printStatistics(const Stats &stats) const
RefreshPolicy m_policy
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)
edm::SerialTaskQueue m_queue
cond::persistency::ConnectionPool m_connection
key
prepare the HTCondor submission files and eventually submit them
void initConcurrentIOVs(const EventSetupRecordKey &key, unsigned int nConcurrentIOVs) override
void fillList(const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPoolForLumiConditions
TagCollection m_tagCollection
~CondDBESSource() override
std::string m_jsonDumpFilename
std::vector< std::pair< DataKey, std::shared_ptr< ESProductResolver > >> KeyedResolversVector
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)
std::string m_connectionString
HLT enums.
unsigned int m_lastRun
std::string m_frontierKey
CondDBESSource(const edm::ParameterSet &)
bool isConcurrentFinder() const override
std::map< std::string, unsigned int > m_lastRecordRuns
KeyedResolversVector registerResolvers(const EventSetupRecordKey &, unsigned int iovIndex) override
unsigned int m_lastLumi