CMS 3D CMS Logo

L1ConfigOnlineProdBaseExt.h
Go to the documentation of this file.
1 #ifndef CondTools_L1TriggerExt_L1ConfigOnlineProdBaseExt_h
2 #define CondTools_L1TriggerExt_L1ConfigOnlineProdBaseExt_h
3 
4 // system include files
5 #include <memory>
6 
7 // user include files
9 
12 
15 
18 
22 
25 
28 
29 // forward declarations
30 
31 template <class TRcd, class TData>
33 public:
35  ~L1ConfigOnlineProdBaseExt() override;
36 
37  std::unique_ptr<const TData> produce(const TRcd& iRecord);
38 
39  virtual std::unique_ptr<const TData> newObject(const std::string& objectKey, const TRcd& iRecord) = 0;
40 
41 private:
42  // ----------member data ---------------------------
45 
46 protected:
50 
51  // Called from produce methods.
52  // bool is true if the object data should be made.
53  // If bool is false, produce method should throw
54  // DataAlreadyPresentException.
55  bool getObjectKey(const TRcd& record, std::string& objectKey);
56 
57  // For reading object directly from a CondDB w/o PoolDBOutputService
60 };
61 
62 template <class TRcd, class TData>
64  : m_omdsReader(),
65  m_forceGeneration(iConfig.getParameter<bool>("forceGeneration")),
66  m_dbSession(),
67  m_copyFromCondDB(false) {
68  //the following line is needed to tell the framework what
69  // data is being produced
70  // setWhatProduced(this)
71  // .setConsumes(keyList_token)
72  // .setConsumes(key_token);
73 
74  //now do what ever other initialization is needed
75 
76  if (iConfig.exists("copyFromCondDB")) {
77  m_copyFromCondDB = iConfig.getParameter<bool>("copyFromCondDB");
78 
79  if (m_copyFromCondDB) {
80  cond::persistency::ConnectionPool connectionPool;
81  // Connect DB Session
82  connectionPool.setAuthenticationPath(iConfig.getParameter<std::string>("onlineAuthentication"));
83  connectionPool.configure();
84  m_dbSession = connectionPool.createSession(iConfig.getParameter<std::string>("onlineDB"));
85  }
86  } else {
87  m_omdsReader.connect(iConfig.getParameter<std::string>("onlineDB"),
88  iConfig.getParameter<std::string>("onlineAuthentication"));
89  }
90 }
91 
92 template <class TRcd, class TData>
94  const edm::ParameterSet& iConfig) {
95  auto collector = setWhatProduced(this);
96  keyList_token = collector.consumes();
97  key_token = collector.consumes();
98  return collector;
99 }
100 
101 template <class TRcd, class TData>
103  // do anything here that needs to be done at desctruction time
104  // (e.g. close files, deallocate resources etc.)
105 }
106 
107 template <class TRcd, class TData>
108 std::unique_ptr<const TData> L1ConfigOnlineProdBaseExt<TRcd, TData>::produce(const TRcd& iRecord) {
109  std::unique_ptr<const TData> pData;
110 
111  // Get object key and check if already in ORCON
113  if (getObjectKey(iRecord, key) || m_forceGeneration) {
114  if (m_copyFromCondDB) {
115  // Get L1TriggerKeyListExt from EventSetup
116  const L1TriggerKeyListExtRcd& keyListRcd =
119  iRecord.template getRecord<L1TriggerKeyListExtRcd>();
122 
123  auto const& keyList = keyListRcd.get(keyList_token);
124 
125  // Find payload token
126  std::string recordName = edm::typelookup::className<TRcd>();
127  std::string dataType = edm::typelookup::className<TData>();
128  std::string payloadToken = keyList.token(recordName, dataType, key);
129 
130  edm::LogVerbatim("L1-O2O") << "Copying payload for " << recordName << "@" << dataType << " obj key " << key
131  << " from CondDB.";
132  edm::LogVerbatim("L1-O2O") << "TOKEN " << payloadToken;
133 
134  // Get object from POOL
135  // Copied from l1t::DataWriter::readObject()
136  if (!payloadToken.empty()) {
137  m_dbSession.transaction().start();
138  pData = m_dbSession.fetchPayload<TData>(payloadToken);
139  m_dbSession.transaction().commit();
140  }
141  } else {
142  pData = newObject(key, iRecord);
143  }
144 
145  // if( pData.get() == 0 )
146  if (pData == std::unique_ptr<const TData>()) {
147  std::string dataType = edm::typelookup::className<TData>();
148 
149  throw l1t::DataInvalidException("Unable to generate " + dataType + " for key " + key + ".");
150  }
151  } else {
152  std::string dataType = edm::typelookup::className<TData>();
153 
154  throw l1t::DataAlreadyPresentException(dataType + " for key " + key + " already in CondDB.");
155  }
156 
157  return pData;
158 }
159 
160 template <class TRcd, class TData>
162  // Get L1TriggerKeyExt
163  const L1TriggerKeyExtRcd& keyRcd = record.template getRecord<L1TriggerKeyExtRcd>();
164 
165  // Explanation of funny syntax: since record is dependent, we are not
166  // expecting getRecord to be a template so the compiler parses it
167  // as a non-template. http://gcc.gnu.org/ml/gcc-bugs/2005-11/msg03685.html
168 
169  // If L1TriggerKeyExt is invalid, then all configuration objects are
170  // already in ORCON.
171  // edm::ESHandle<L1TriggerKeyExt> key_token;
172  try {
173  keyRcd.get(key_token);
174  } catch (l1t::DataAlreadyPresentException& ex) {
175  objectKey = std::string();
176  return false;
177  }
178 
179  // Get object key from L1TriggerKeyExt
180  std::string recordName = edm::typelookup::className<TRcd>();
181  std::string dataType = edm::typelookup::className<TData>();
182 
183  objectKey = keyRcd.get(key_token).get(recordName, dataType);
184 
185  /* edm::LogVerbatim( "L1-O2O" ) */
186  /* << "L1ConfigOnlineProdBase record " << recordName */
187  /* << " type " << dataType << " obj key " << objectKey ; */
188 
189  // Get L1TriggerKeyListExt
190  L1TriggerKeyListExt keyList;
193  l1t::DataWriterExt dataWriter;
195  if (!dataWriter.fillLastTriggerKeyList(keyList)) {
196  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyListExt";
198  }
199 
200  // If L1TriggerKeyList does not contain object key, token is empty
201 
202  return keyList.token(recordName, dataType, objectKey).empty();
203 }
204 
205 #endif
Log< level::Info, true > LogVerbatim
edm::ESGetToken< L1TriggerKeyExt, L1TriggerKeyExtRcd > key_token
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESGetToken< L1TriggerKeyListExt, L1TriggerKeyListExtRcd > keyList_token
cond::persistency::Session m_dbSession
bool exists(std::string const &parameterName) const
checks if a parameter exists
Log< level::Error, false > LogError
virtual std::unique_ptr< const TData > newObject(const std::string &objectKey, const TRcd &iRecord)=0
L1ConfigOnlineProdBaseExt(const edm::ParameterSet &)
bool getObjectKey(const TRcd &record, std::string &objectKey)
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
Session createSession(const std::string &connectionString, bool writeCapable=false)
void connect(const std::string &connectString, const std::string &authenticationPath)
Definition: OMDSReader.cc:43
edm::ESConsumesCollectorT< TRcd > wrappedSetWhatProduced(const edm::ParameterSet &)
std::unique_ptr< const TData > produce(const TRcd &iRecord)
std::string token(const std::string &tscKey) const
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
void setAuthenticationPath(const std::string &p)