CMS 3D CMS Logo

ProductResolver.h
Go to the documentation of this file.
1 #ifndef CondCore_ESSources_ProductResolver_H
2 #define CondCore_ESSources_ProductResolver_H
3 
4 #include <cassert>
5 //#include <iostream>
6 #include <memory>
7 #include <string>
8 #include <mutex>
9 
10 // user include files
13 
18 
19 // expose a cond::PayloadProxy as a eventsetup::ESProductResolver
20 namespace cond {
21  template <typename DataT>
23  void operator()(DataT&) {}
24  };
25 
26  template <class RecordT, class DataT, typename Initializer = cond::DefaultInitializer<DataT>>
28  public:
30  edm::SerialTaskQueue* iQueue,
31  std::mutex* iMutex)
32  : edm::eventsetup::ESSourceProductResolverTemplate<DataT>(iQueue, iMutex), m_data{pdata} {}
33  //ProductResolver(); // stop default
34  const ProductResolver& operator=(const ProductResolver&) = delete; // stop default
35 
36  // ---------- const member functions ---------------------
37 
38  // ---------- static member functions --------------------
39 
40  // ---------- member functions ---------------------------
41  protected:
43  m_data->make();
44  m_initializer(const_cast<DataT&>((*m_data)()));
45  }
46 
47  DataT const* fetch() const final { return &(*m_data)(); }
48 
49  private:
50  void initializeForNewIOV() override { m_data->initializeForNewIOV(); }
51 
52  // ---------- member data --------------------------------
53 
54  std::shared_ptr<cond::persistency::PayloadProxy<DataT>> m_data;
55  Initializer m_initializer;
56  };
57 
58  /* ABI bridging between the cond world and eventsetup world
59  * keep them separated!
60  */
62  public:
63  typedef std::shared_ptr<cond::persistency::BasePayloadProxy> ProxyP;
64  typedef std::shared_ptr<edm::eventsetup::ESProductResolver> esResolverP;
65 
66  // limitation of plugin manager...
67  typedef std::pair<std::string, std::string> Args;
68 
69  virtual edm::eventsetup::TypeTag type() const = 0;
70  virtual ProxyP proxy(unsigned int iovIndex) const = 0;
71  virtual esResolverP esResolver(unsigned int iovIndex) const = 0;
72 
74  // late initialize (to allow to load ALL library first)
76  const std::string& tag,
77  const boost::posix_time::ptime& snapshotTime,
78  std::string const& il,
79  std::string const& cs,
81  std::mutex* mutex) = 0;
82 
83  virtual void initConcurrentIOVs(unsigned int nConcurrentIOVs) = 0;
84 
85  void addInfo(std::string const& il, std::string const& cs, std::string const& tag);
86 
88 
89  std::string const& label() const { return m_label; }
90  std::string const& connString() const { return m_connString; }
91  std::string const& tag() const { return m_tag; }
93  persistency::IOVProxy const& iovProxy() const { return m_iovProxy; }
94  Iov_t const& currentIov() const { return m_currentIov; }
96  persistency::Session const& session() const { return m_session; }
97  std::shared_ptr<std::vector<Iov_t>> const& requests() const { return m_requests; }
98 
100 
101  void loadTag(std::string const& tag);
102  void loadTag(std::string const& tag, boost::posix_time::ptime const& snapshotTime);
103  void reload();
104 
107 
108  private:
115  std::shared_ptr<std::vector<Iov_t>> m_requests;
116  };
117 } // namespace cond
118 
119 /* bridge between the cond world and eventsetup world
120  * keep them separated!
121  */
122 template <class RecordT, class DataT, typename Initializer = cond::DefaultInitializer<DataT>>
124 public:
125  typedef ::cond::ProductResolver<RecordT, DataT, Initializer> ProductResolver;
126 
127  // constructor from plugin...
128  explicit ProductResolverWrapper(const char* source = nullptr) : m_source(source ? source : "") {
129  //NOTE: We do this so that the type 'DataT' will get registered
130  // when the plugin is dynamically loaded
131  m_type = edm::eventsetup::DataKey::makeTypeTag<DataT>();
132  }
133 
134  // late initialize (to allow to load ALL library first)
136  const std::string& tag,
137  const boost::posix_time::ptime& snapshotTime,
138  std::string const& il,
139  std::string const& cs,
141  std::mutex* mutex) override {
142  setSession(iSession);
143  // set the IOVProxy
145  // Only make the first PayloadProxy object now because we don't know yet
146  // how many we will need.
147  m_proxies.push_back(std::make_shared<cond::persistency::PayloadProxy<DataT>>(
148  &currentIov(), &session(), &requests(), m_source.empty() ? (const char*)nullptr : m_source.c_str()));
149  m_esResolvers.push_back(std::make_shared<ProductResolver>(m_proxies[0], queue, mutex));
150  addInfo(il, cs, tag);
151  }
152 
153  void initConcurrentIOVs(unsigned int nConcurrentIOVs) override {
154  // Create additional PayloadProxy objects if we are allowing
155  // multiple IOVs to run concurrently.
156  if (m_proxies.size() != nConcurrentIOVs) {
157  assert(m_proxies.size() == 1);
158  auto queue = m_esResolvers.front()->queue();
159  auto mutex = m_esResolvers.front()->mutex();
160  for (unsigned int i = 1; i < nConcurrentIOVs; ++i) {
161  m_proxies.push_back(std::make_shared<cond::persistency::PayloadProxy<DataT>>(
162  &currentIov(), &session(), &requests(), m_source.empty() ? (const char*)nullptr : m_source.c_str()));
163  m_esResolvers.push_back(std::make_shared<ProductResolver>(m_proxies[i], queue, mutex));
164  // This does nothing except in the special case of a KeyList PayloadProxy.
165  // They all need to have copies of the same IOVProxy object.
166  m_proxies[i]->initKeyList(*m_proxies[0]);
167  }
168  assert(m_proxies.size() == nConcurrentIOVs);
169  }
170  assert(m_proxies.size() == m_esResolvers.size());
171  }
172 
173  edm::eventsetup::TypeTag type() const override { return m_type; }
174  ProxyP proxy(unsigned int iovIndex) const override { return m_proxies.at(iovIndex); }
175  esResolverP esResolver(unsigned int iovIndex) const override { return m_esResolvers.at(iovIndex); }
176 
177 private:
180  std::vector<std::shared_ptr<cond::persistency::PayloadProxy<DataT>>> m_proxies;
181  std::vector<std::shared_ptr<ProductResolver>> m_esResolvers;
182 };
183 
184 #endif /* CondCore_ESSources_ProductResolver_H */
persistency::Session const & session() const
ALPAKA_FN_ACC ALPAKA_FN_INLINE void VtxSoAView & pdata
std::shared_ptr< std::vector< Iov_t > > m_requests
const ProductResolver & operator=(const ProductResolver &)=delete
void initializeForNewIOV() override
std::pair< std::string, std::string > Args
static std::mutex mutex
Definition: Proxy.cc:8
virtual void initConcurrentIOVs(unsigned int nConcurrentIOVs)=0
virtual edm::eventsetup::TypeTag type() const =0
void loadTag(std::string const &tag)
assert(be >=bs)
persistency::IOVProxy const & iovProxy() const
std::string const & label() const
edm::eventsetup::TypeTag m_type
void setSession(persistency::Session const &v)
std::string const & connString() const
DataT const * fetch() const final
TimeType
Definition: Time.h:19
virtual esResolverP esResolver(unsigned int iovIndex) const =0
virtual void lateInit(persistency::Session &session, const std::string &tag, const boost::posix_time::ptime &snapshotTime, std::string const &il, std::string const &cs, edm::SerialTaskQueue *queue, std::mutex *mutex)=0
unsigned long long Time_t
Definition: Time.h:14
void initConcurrentIOVs(unsigned int nConcurrentIOVs) override
persistency::IOVProxy & iovProxy()
void lateInit(cond::persistency::Session &iSession, const std::string &tag, const boost::posix_time::ptime &snapshotTime, std::string const &il, std::string const &cs, edm::SerialTaskQueue *queue, std::mutex *mutex) override
void prefetch(edm::eventsetup::DataKey const &iKey, edm::EventSetupRecordDetails) final
cond::Tag_t tagInfo() const
Definition: IOVProxy.cc:246
std::shared_ptr< cond::persistency::PayloadProxy< DataT > > m_data
std::shared_ptr< std::vector< Iov_t > > const & requests() const
esResolverP esResolver(unsigned int iovIndex) const override
ProxyP proxy(unsigned int iovIndex) const override
Iov_t const & currentIov() const
void addInfo(std::string const &il, std::string const &cs, std::string const &tag)
edm::eventsetup::TypeTag type() const override
std::shared_ptr< cond::persistency::BasePayloadProxy > ProxyP
ProductResolverWrapper(const char *source=nullptr)
TimeType timeType
Definition: Types.h:63
std::string const & tag() const
virtual ProxyP proxy(unsigned int iovIndex) const =0
std::vector< std::shared_ptr< ProductResolver > > m_esResolvers
std::shared_ptr< edm::eventsetup::ESProductResolver > esResolverP
persistency::IOVProxy m_iovProxy
HLT enums.
std::vector< std::shared_ptr< cond::persistency::PayloadProxy< DataT > > > m_proxies
persistency::Session & session()
::cond::ProductResolver< RecordT, DataT, Initializer > ProductResolver
ProductResolver(std::shared_ptr< cond::persistency::PayloadProxy< DataT >> pdata, edm::SerialTaskQueue *iQueue, std::mutex *iMutex)
ValidityInterval setIntervalFor(Time_t target)
static std::string const source
Definition: EdmProvDump.cc:49