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 
13 
16 
19 
23 
26 
29 
30 // forward declarations
31 
32 template <class TRcd, class TData>
34 public:
36  ~L1ConfigOnlineProdBaseExt() override;
37 
38  std::unique_ptr<const TData> produce(const TRcd& iRecord);
39 
40  virtual std::unique_ptr<const TData> newObject(const std::string& objectKey, const TRcd& iRecord) = 0;
41 
42 private:
43  // ----------member data ---------------------------
44 
45 protected:
48 
49  // Called from produce methods.
50  // bool is true if the object data should be made.
51  // If bool is false, produce method should throw
52  // DataAlreadyPresentException.
53  bool getObjectKey(const TRcd& record, std::string& objectKey);
54 
55  // For reading object directly from a CondDB w/o PoolDBOutputService
58 };
59 
60 template <class TRcd, class TData>
62  : m_omdsReader(),
63  m_forceGeneration(iConfig.getParameter<bool>("forceGeneration")),
64  m_dbSession(),
66  //the following line is needed to tell the framework what
67  // data is being produced
68  setWhatProduced(this);
69 
70  //now do what ever other initialization is needed
71 
72  if (iConfig.exists("copyFromCondDB")) {
73  m_copyFromCondDB = iConfig.getParameter<bool>("copyFromCondDB");
74 
75  if (m_copyFromCondDB) {
76  cond::persistency::ConnectionPool connectionPool;
77  // Connect DB Session
78  connectionPool.setAuthenticationPath(iConfig.getParameter<std::string>("onlineAuthentication"));
79  connectionPool.configure();
80  m_dbSession = connectionPool.createSession(iConfig.getParameter<std::string>("onlineDB"));
81  }
82  } else {
83  m_omdsReader.connect(iConfig.getParameter<std::string>("onlineDB"),
84  iConfig.getParameter<std::string>("onlineAuthentication"));
85  }
86 }
87 
88 template <class TRcd, class TData>
90  // do anything here that needs to be done at desctruction time
91  // (e.g. close files, deallocate resources etc.)
92 }
93 
94 template <class TRcd, class TData>
95 std::unique_ptr<const TData> L1ConfigOnlineProdBaseExt<TRcd, TData>::produce(const TRcd& iRecord) {
96  std::unique_ptr<const TData> pData;
97 
98  // Get object key and check if already in ORCON
100  if (getObjectKey(iRecord, key) || m_forceGeneration) {
101  if (m_copyFromCondDB) {
102  // Get L1TriggerKeyListExt from EventSetup
103  const L1TriggerKeyListExtRcd& keyListRcd =
106  iRecord.template getRecord<L1TriggerKeyListExtRcd>();
110 
111  keyListRcd.get(keyList);
112 
113  // Find payload token
114  std::string recordName = edm::typelookup::className<TRcd>();
115  std::string dataType = edm::typelookup::className<TData>();
116  std::string payloadToken = keyList->token(recordName, dataType, key);
117 
118  edm::LogVerbatim("L1-O2O") << "Copying payload for " << recordName << "@" << dataType << " obj key " << key
119  << " from CondDB.";
120  edm::LogVerbatim("L1-O2O") << "TOKEN " << payloadToken;
121 
122  // Get object from POOL
123  // Copied from l1t::DataWriter::readObject()
124  if (!payloadToken.empty()) {
126  pData = m_dbSession.fetchPayload<TData>(payloadToken);
128  }
129  } else {
130  pData = newObject(key, iRecord);
131  }
132 
133  // if( pData.get() == 0 )
134  if (pData == std::unique_ptr<const TData>()) {
135  std::string dataType = edm::typelookup::className<TData>();
136 
137  throw l1t::DataInvalidException("Unable to generate " + dataType + " for key " + key + ".");
138  }
139  } else {
140  std::string dataType = edm::typelookup::className<TData>();
141 
142  throw l1t::DataAlreadyPresentException(dataType + " for key " + key + " already in CondDB.");
143  }
144 
145  return pData;
146 }
147 
148 template <class TRcd, class TData>
150  // Get L1TriggerKeyExt
151  const L1TriggerKeyExtRcd& keyRcd = record.template getRecord<L1TriggerKeyExtRcd>();
152 
153  // Explanation of funny syntax: since record is dependent, we are not
154  // expecting getRecord to be a template so the compiler parses it
155  // as a non-template. http://gcc.gnu.org/ml/gcc-bugs/2005-11/msg03685.html
156 
157  // If L1TriggerKeyExt is invalid, then all configuration objects are
158  // already in ORCON.
160  try {
161  keyRcd.get(key);
162  } catch (l1t::DataAlreadyPresentException& ex) {
163  objectKey = std::string();
164  return false;
165  }
166 
167  // Get object key from L1TriggerKeyExt
168  std::string recordName = edm::typelookup::className<TRcd>();
169  std::string dataType = edm::typelookup::className<TData>();
170 
171  objectKey = key->get(recordName, dataType);
172 
173  /* edm::LogVerbatim( "L1-O2O" ) */
174  /* << "L1ConfigOnlineProdBase record " << recordName */
175  /* << " type " << dataType << " obj key " << objectKey ; */
176 
177  // Get L1TriggerKeyListExt
178  L1TriggerKeyListExt keyList;
181  l1t::DataWriterExt dataWriter;
183  if (!dataWriter.fillLastTriggerKeyList(keyList)) {
184  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyListExt";
186  }
187 
188  // If L1TriggerKeyList does not contain object key, token is empty
189 
190  return keyList.token(recordName, dataType, objectKey).empty();
191 }
192 
193 #endif
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
cond::persistency::Session m_dbSession
JetCorrectorParameters::Record record
Definition: classes.h:7
void start(bool readOnly=true)
Definition: Session.cc:18
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:224
Transaction & transaction()
Definition: Session.cc:43
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
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)
ProductT const & get(ESGetToken< ProductT, DepRecordT > 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
std::unique_ptr< const TData > produce(const TRcd &iRecord)
void setAuthenticationPath(const std::string &p)
std::string token(const std::string &tscKey) const