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