CMS 3D CMS Logo

L1ConfigOnlineProdBase.h
Go to the documentation of this file.
1 #ifndef CondTools_L1Trigger_L1ConfigOnlineProdBase_h
2 #define CondTools_L1Trigger_L1ConfigOnlineProdBase_h
3 // -*- C++ -*-
4 //
5 // Package: L1Trigger
6 // Class : L1ConfigOnlineProdBase
7 //
18 //
19 // Original Author: Werner Sun
20 // Created: Tue Sep 2 22:48:15 CEST 2008
21 // $Id: L1ConfigOnlineProdBase.h,v 1.9 2010/02/16 21:55:43 wsun Exp $
22 //
23 
24 // system include files
25 #include <memory>
26 
27 // user include files
29 
33 
38 
42 
45 
48 
49 // forward declarations
50 
51 template< class TRcd, class TData >
53  public:
55  ~L1ConfigOnlineProdBase() override;
56 
57  virtual std::shared_ptr< TData > produce(const TRcd& iRecord);
58 
59  virtual std::shared_ptr< TData > newObject(
60  const std::string& objectKey ) = 0 ;
61 
62  private:
63  // ----------member data ---------------------------
64 
65  protected:
68 
69  // Called from produce methods.
70  // bool is true if the object data should be made.
71  // If bool is false, produce method should throw
72  // DataAlreadyPresentException.
73  bool getObjectKey( const TRcd& record,
74  std::shared_ptr< TData > data,
75  std::string& objectKey ) ;
76 
77  // For reading object directly from a CondDB w/o PoolDBOutputService
80 };
81 
82 
83 template< class TRcd, class TData >
85  : m_omdsReader(),
86  m_forceGeneration( iConfig.getParameter< bool >( "forceGeneration" ) ),
87  m_dbSession(),
89 {
90  //the following line is needed to tell the framework what
91  // data is being produced
92  setWhatProduced(this);
93 
94  //now do what ever other initialization is needed
95 
96  if( iConfig.exists( "copyFromCondDB" ) )
97  {
98  m_copyFromCondDB = iConfig.getParameter< bool >( "copyFromCondDB" ) ;
99 
100  if( m_copyFromCondDB )
101  {
102  cond::persistency::ConnectionPool connectionPool;
103  // Connect DB Session
104  connectionPool.setAuthenticationPath(
105  iConfig.getParameter< std::string >( "onlineAuthentication" ) ) ;
106  connectionPool.configure() ;
107  m_dbSession = connectionPool.createSession( iConfig.getParameter< std::string >( "onlineDB" ) ) ;
108  }
109  }
110  else
111  {
113  iConfig.getParameter< std::string >( "onlineDB" ),
114  iConfig.getParameter< std::string >( "onlineAuthentication" ) ) ;
115  }
116 }
117 
118 template< class TRcd, class TData >
120 {
121 
122  // do anything here that needs to be done at desctruction time
123  // (e.g. close files, deallocate resources etc.)
124 
125 }
126 
127 template< class TRcd, class TData >
128 std::shared_ptr< TData >
130 {
131  using namespace edm::es;
132  std::shared_ptr< TData > pData ;
133 
134  // Get object key and check if already in ORCON
135  std::string key ;
136  if( getObjectKey( iRecord, pData, key ) || m_forceGeneration )
137  {
138  if( m_copyFromCondDB )
139  {
140  // Get L1TriggerKeyList from EventSetup
141  const L1TriggerKeyListRcd& keyListRcd =
142  iRecord.template getRecord< L1TriggerKeyListRcd >() ;
144  keyListRcd.get( keyList ) ;
145 
146  // Find payload token
147  std::string recordName = edm::typelookup::className<TRcd>();
148  std::string dataType = edm::typelookup::className<TData>();
149  std::string payloadToken =
150  keyList->token( recordName, dataType, key ) ;
151 
152  edm::LogVerbatim( "L1-O2O" )
153  << "Copying payload for " << recordName
154  << "@" << dataType << " obj key " << key
155  << " from CondDB." ;
156  edm::LogVerbatim( "L1-O2O" )
157  << "TOKEN " << payloadToken ;
158 
159  // Get object from POOL
160  // Copied from l1t::DataWriter::readObject()
161  if( !payloadToken.empty() )
162  {
164  pData = m_dbSession.fetchPayload<TData>( payloadToken ) ;
166  }
167  }
168  else
169  {
170  pData = newObject( key ) ;
171  }
172 
173  // if( pData.get() == 0 )
174  if( pData == std::shared_ptr< TData >() )
175  {
176  std::string dataType = edm::typelookup::className<TData>();
177 
178  throw l1t::DataInvalidException( "Unable to generate " +
179  dataType + " for key " + key +
180  "." ) ;
181  }
182  }
183  else
184  {
185  std::string dataType = edm::typelookup::className<TData>();
186 
187  throw l1t::DataAlreadyPresentException( dataType +
188  " for key " + key + " already in CondDB." ) ;
189  }
190 
191  return pData ;
192 }
193 
194 
195 template< class TRcd, class TData >
196 bool
198  const TRcd& record,
199  std::shared_ptr< TData > data,
200  std::string& objectKey )
201 {
202  // Get L1TriggerKey
203  const L1TriggerKeyRcd& keyRcd =
204  record.template getRecord< L1TriggerKeyRcd >() ;
205 
206  // Explanation of funny syntax: since record is dependent, we are not
207  // expecting getRecord to be a template so the compiler parses it
208  // as a non-template. http://gcc.gnu.org/ml/gcc-bugs/2005-11/msg03685.html
209 
210  // If L1TriggerKey is invalid, then all configuration objects are
211  // already in ORCON.
213  try
214  {
215  keyRcd.get( key ) ;
216  }
218  {
219  objectKey = std::string() ;
220  return false ;
221  }
222 
223  // Get object key from L1TriggerKey
224  std::string recordName = edm::typelookup::className<TRcd>();
225  std::string dataType = edm::typelookup::className<TData>();
226 
227  objectKey = key->get( recordName, dataType ) ;
228 
229 /* edm::LogVerbatim( "L1-O2O" ) */
230 /* << "L1ConfigOnlineProdBase record " << recordName */
231 /* << " type " << dataType << " obj key " << objectKey ; */
232 
233  // Get L1TriggerKeyList
234  L1TriggerKeyList keyList ;
235  l1t::DataWriter dataWriter ;
236  if( !dataWriter.fillLastTriggerKeyList( keyList ) )
237  {
238  edm::LogError( "L1-O2O" )
239  << "Problem getting last L1TriggerKeyList" ;
240  }
241 
242  // If L1TriggerKeyList does not contain object key, token is empty
243  return
244  keyList.token( recordName, dataType, objectKey ) == std::string() ;
245 }
246 
247 #endif
T getParameter(std::string const &) const
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
Transaction & transaction()
Definition: Session.cc:66
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
bool getObjectKey(const TRcd &record, std::shared_ptr< TData > data, std::string &objectKey)
void get(HolderT &iHolder) const
Session createSession(const std::string &connectionString, bool writeCapable=false)
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:198
void connect(const std::string &connectString, const std::string &authenticationPath)
Definition: OMDSReader.cc:49
L1ConfigOnlineProdBase(const edm::ParameterSet &)
std::string token(const std::string &tscKey) const
virtual std::shared_ptr< TData > produce(const TRcd &iRecord)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void setAuthenticationPath(const std::string &p)
std::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:215
virtual std::shared_ptr< TData > newObject(const std::string &objectKey)=0