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
DataWriterExt.h
electrons_cff.bool
bool
Definition: electrons_cff.py:393
L1TriggerKeyListExt
Definition: L1TriggerKeyListExt.h:10
L1ConfigOnlineProdBaseExt::newObject
virtual std::unique_ptr< const TData > newObject(const std::string &objectKey, const TRcd &iRecord)=0
ConnectionPool.h
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
Exception.h
l1t::OMDSReader
Definition: OMDSReader.h:42
OMDSReader.h
L1ConfigOnlineProdBaseExt::m_omdsReader
l1t::OMDSReader m_omdsReader
Definition: L1ConfigOnlineProdBaseExt.h:47
align_cfg.recordName
recordName
Definition: align_cfg.py:66
L1TriggerKeyExtRcd
Definition: L1TriggerKeyExtRcd.h:8
ESProducer.h
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
typelookup.h
l1t::DataAlreadyPresentException
Definition: Exception.h:32
L1ConfigOnlineProdBaseExt::m_forceGeneration
bool m_forceGeneration
Definition: L1ConfigOnlineProdBaseExt.h:48
cond::persistency::ConnectionPool::createSession
Session createSession(const std::string &connectionString, bool writeCapable=false)
Definition: ConnectionPool.cc:158
DTskim_cfg.dataType
dataType
Definition: DTskim_cfg.py:56
l1t::DataInvalidException
Definition: Exception.h:51
L1ConfigOnlineProdBaseExt::keyList_token
edm::ESGetToken< L1TriggerKeyListExt, L1TriggerKeyListExtRcd > keyList_token
Definition: L1ConfigOnlineProdBaseExt.h:43
L1TriggerKeyExtRcd.h
L1TriggerKeyExt.h
edm::ESConsumesCollectorT
Definition: ESConsumesCollector.h:125
L1TriggerKeyListExtRcd.h
L1ConfigOnlineProdBaseExt::L1ConfigOnlineProdBaseExt
L1ConfigOnlineProdBaseExt(const edm::ParameterSet &)
Definition: L1ConfigOnlineProdBaseExt.h:63
L1ConfigOnlineProdBaseExt::key_token
edm::ESGetToken< L1TriggerKeyExt, L1TriggerKeyExtRcd > key_token
Definition: L1ConfigOnlineProdBaseExt.h:44
L1ConfigOnlineProdBaseExt
Definition: L1ConfigOnlineProdBaseExt.h:32
cond::persistency::ConnectionPool
Definition: ConnectionPool.h:35
L1ConfigOnlineProdBaseExt::getObjectKey
bool getObjectKey(const TRcd &record, std::string &objectKey)
Definition: L1ConfigOnlineProdBaseExt.h:161
l1t::OMDSReader::connect
void connect(const std::string &connectString, const std::string &authenticationPath)
Definition: OMDSReader.cc:43
edm::eventsetup::DependentRecordImplementation::get
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:103
l1t::DataWriterExt::fillLastTriggerKeyList
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
Definition: DataWriterExt.cc:148
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
edm::ParameterSet
Definition: ParameterSet.h:47
L1TriggerKeyListExtRcd
Definition: L1TriggerKeyListExtRcd.h:6
cond::persistency::Session
Definition: Session.h:63
cond::persistency::ConnectionPool::setAuthenticationPath
void setAuthenticationPath(const std::string &p)
Definition: ConnectionPool.cc:33
cond::persistency::ConnectionPool::configure
void configure()
Definition: ConnectionPool.cc:125
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
edm::ESGetToken< L1TriggerKeyListExt, L1TriggerKeyListExtRcd >
L1ConfigOnlineProdBaseExt::~L1ConfigOnlineProdBaseExt
~L1ConfigOnlineProdBaseExt() override
Definition: L1ConfigOnlineProdBaseExt.h:102
L1ConfigOnlineProdBaseExt::produce
std::unique_ptr< const TData > produce(const TRcd &iRecord)
Definition: L1ConfigOnlineProdBaseExt.h:108
ModuleFactory.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
L1TriggerKeyListExt.h
L1ConfigOnlineProdBaseExt::m_copyFromCondDB
bool m_copyFromCondDB
Definition: L1ConfigOnlineProdBaseExt.h:59
edm::ESProducer
Definition: ESProducer.h:104
edm::eventsetup::EventSetupRecordImplementation::get
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
Definition: EventSetupRecordImplementation.h:74
Session.h
crabWrapper.key
key
Definition: crabWrapper.py:19
L1ConfigOnlineProdBaseExt::wrappedSetWhatProduced
edm::ESConsumesCollectorT< TRcd > wrappedSetWhatProduced(const edm::ParameterSet &)
Definition: L1ConfigOnlineProdBaseExt.h:93
L1ConfigOnlineProdBaseExt::m_dbSession
cond::persistency::Session m_dbSession
Definition: L1ConfigOnlineProdBaseExt.h:58
L1TriggerKeyListExt::token
std::string token(const std::string &tscKey) const
Definition: L1TriggerKeyListExt.cc:69
l1t::DataWriterExt
Definition: DataWriterExt.h:35