CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 #include "boost/shared_ptr.hpp"
27 
28 // user include files
30 
34 
39 
43 
46 
50 
51 // forward declarations
52 
53 template< class TRcd, class TData >
55  public:
58 
59  boost::shared_ptr< TData > produce(const TRcd& iRecord);
60 
61  virtual boost::shared_ptr< TData > newObject(
62  const std::string& objectKey ) = 0 ;
63 
64  private:
65  // ----------member data ---------------------------
66 
67  protected:
70 
71  // Called from produce methods.
72  // bool is true if the object data should be made.
73  // If bool is false, produce method should throw
74  // DataAlreadyPresentException.
75  bool getObjectKey( const TRcd& record,
76  boost::shared_ptr< TData > data,
77  std::string& objectKey ) ;
78 
79  // For reading object directly from a CondDB w/o PoolDBOutputService
83 };
84 
85 
86 template< class TRcd, class TData >
88  : m_omdsReader(),
89  m_forceGeneration( iConfig.getParameter< bool >( "forceGeneration" ) ),
90  m_dbConnection(),
91  m_dbSession(),
92  m_copyFromCondDB( false )
93 {
94  //the following line is needed to tell the framework what
95  // data is being produced
96  setWhatProduced(this);
97 
98  //now do what ever other initialization is needed
99 
100  if( iConfig.exists( "copyFromCondDB" ) )
101  {
102  m_copyFromCondDB = iConfig.getParameter< bool >( "copyFromCondDB" ) ;
103 
104  if( m_copyFromCondDB )
105  {
106  // Connect DbSession
108  iConfig.getParameter< std::string >( "onlineAuthentication" ) ) ;
112  iConfig.getParameter< std::string >( "onlineDB" ),
113  true ); // read-only
114  }
115  }
116  else
117  {
119  iConfig.getParameter< std::string >( "onlineDB" ),
120  iConfig.getParameter< std::string >( "onlineAuthentication" ) ) ;
121  }
122 }
123 
124 template< class TRcd, class TData >
126 {
127 
128  // do anything here that needs to be done at desctruction time
129  // (e.g. close files, deallocate resources etc.)
130 
131 }
132 
133 template< class TRcd, class TData >
134 boost::shared_ptr< TData >
136 {
137  using namespace edm::es;
138  boost::shared_ptr< TData > pData ;
139 
140  // Get object key and check if already in ORCON
141  std::string key ;
142  if( getObjectKey( iRecord, pData, key ) || m_forceGeneration )
143  {
144  if( m_copyFromCondDB )
145  {
146  // Get L1TriggerKeyList from EventSetup
147  const L1TriggerKeyListRcd& keyListRcd =
148  iRecord.template getRecord< L1TriggerKeyListRcd >() ;
150  keyListRcd.get( keyList ) ;
151 
152  // Find payload token
153  std::string recordName = edm::typelookup::className<TRcd>();
154  std::string dataType = edm::typelookup::className<TData>();
155  std::string payloadToken =
156  keyList->token( recordName, dataType, key ) ;
157 
158  edm::LogVerbatim( "L1-O2O" )
159  << "Copying payload for " << recordName
160  << "@" << dataType << " obj key " << key
161  << " from CondDB." ;
162  edm::LogVerbatim( "L1-O2O" )
163  << "TOKEN " << payloadToken ;
164 
165  // Get object from POOL
166  // Copied from l1t::DataWriter::readObject()
167  if( !payloadToken.empty() )
168  {
169  cond::DbScopedTransaction tr( m_dbSession ) ;
170  tr.start( true ) ;
171  pData = m_dbSession.getTypedObject<TData>( payloadToken ) ;
172  tr.commit ();
173  }
174  }
175  else
176  {
177  pData = newObject( key ) ;
178  }
179 
180  // if( pData.get() == 0 )
181  if( pData == boost::shared_ptr< TData >() )
182  {
183  std::string dataType = edm::typelookup::className<TData>();
184 
185  throw l1t::DataInvalidException( "Unable to generate " +
186  dataType + " for key " + key +
187  "." ) ;
188  }
189  }
190  else
191  {
192  std::string dataType = edm::typelookup::className<TData>();
193 
194  throw l1t::DataAlreadyPresentException( dataType +
195  " for key " + key + " already in CondDB." ) ;
196  }
197 
198  return pData ;
199 }
200 
201 
202 template< class TRcd, class TData >
203 bool
205  const TRcd& record,
206  boost::shared_ptr< TData > data,
207  std::string& objectKey )
208 {
209  // Get L1TriggerKey
210  const L1TriggerKeyRcd& keyRcd =
211  record.template getRecord< L1TriggerKeyRcd >() ;
212 
213  // Explanation of funny syntax: since record is dependent, we are not
214  // expecting getRecord to be a template so the compiler parses it
215  // as a non-template. http://gcc.gnu.org/ml/gcc-bugs/2005-11/msg03685.html
216 
217  // If L1TriggerKey is invalid, then all configuration objects are
218  // already in ORCON.
220  try
221  {
222  keyRcd.get( key ) ;
223  }
225  {
226  objectKey = std::string() ;
227  return false ;
228  }
229 
230  // Get object key from L1TriggerKey
231  std::string recordName = edm::typelookup::className<TRcd>();
232  std::string dataType = edm::typelookup::className<TData>();
233 
234  objectKey = key->get( recordName, dataType ) ;
235 
236 /* edm::LogVerbatim( "L1-O2O" ) */
237 /* << "L1ConfigOnlineProdBase record " << recordName */
238 /* << " type " << dataType << " obj key " << objectKey ; */
239 
240  // Get L1TriggerKeyList
241  L1TriggerKeyList keyList ;
242  l1t::DataWriter dataWriter ;
243  if( !dataWriter.fillLastTriggerKeyList( keyList ) )
244  {
245  edm::LogError( "L1-O2O" )
246  << "Problem getting last L1TriggerKeyList" ;
247  }
248 
249  // If L1TriggerKeyList does not contain object key, token is empty
250  return
251  keyList.token( recordName, dataType, objectKey ) == std::string() ;
252 }
253 
254 #endif
T getParameter(std::string const &) const
bool getObjectKey(const TRcd &record, boost::shared_ptr< TData > data, std::string &objectKey)
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:119
JetCorrectorParameters::Record record
Definition: classes.h:11
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:89
bool exists(std::string const &parameterName) const
checks if a parameter exists
boost::shared_ptr< TData > produce(const TRcd &iRecord)
virtual boost::shared_ptr< TData > newObject(const std::string &objectKey)=0
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void get(HolderT &iHolder) const
int start(bool readOnly=false)
start transaction
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:206
void connect(const std::string &connectString, const std::string &authenticationPath)
Definition: OMDSReader.cc:50
DbSession createSession() const
Definition: DbConnection.cc:72
L1ConfigOnlineProdBase(const edm::ParameterSet &)
std::string token(const std::string &tscKey) const
cond::DbConnection m_dbConnection
void setAuthenticationPath(const std::string &p)
list key
Definition: combine.py:13
int commit()
commit transaction. Will disconnect from database if connection timeout==0 or connectted time close t...