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::unique_ptr< TData > produce(const TRcd& iRecord);
58 
59  virtual std::unique_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::string& objectKey ) ;
75 
76  // For reading object directly from a CondDB w/o PoolDBOutputService
79 };
80 
81 
82 template< class TRcd, class TData >
84  : m_omdsReader(),
85  m_forceGeneration( iConfig.getParameter< bool >( "forceGeneration" ) ),
86  m_dbSession(),
88 {
89  //the following line is needed to tell the framework what
90  // data is being produced
91  setWhatProduced(this);
92 
93  //now do what ever other initialization is needed
94 
95  if( iConfig.exists( "copyFromCondDB" ) )
96  {
97  m_copyFromCondDB = iConfig.getParameter< bool >( "copyFromCondDB" ) ;
98 
99  if( m_copyFromCondDB )
100  {
101  cond::persistency::ConnectionPool connectionPool;
102  // Connect DB Session
103  connectionPool.setAuthenticationPath(
104  iConfig.getParameter< std::string >( "onlineAuthentication" ) ) ;
105  connectionPool.configure() ;
106  m_dbSession = connectionPool.createSession( iConfig.getParameter< std::string >( "onlineDB" ) ) ;
107  }
108  }
109  else
110  {
112  iConfig.getParameter< std::string >( "onlineDB" ),
113  iConfig.getParameter< std::string >( "onlineAuthentication" ) ) ;
114  }
115 }
116 
117 template< class TRcd, class TData >
119 {
120 
121  // do anything here that needs to be done at desctruction time
122  // (e.g. close files, deallocate resources etc.)
123 
124 }
125 
126 template< class TRcd, class TData >
127 std::unique_ptr< TData >
129 {
130  std::unique_ptr< TData > pData ;
131 
132  // Get object key and check if already in ORCON
133  std::string key ;
134  if( getObjectKey( iRecord, key ) || m_forceGeneration )
135  {
136  if( m_copyFromCondDB )
137  {
138  // Get L1TriggerKeyList from EventSetup
139  const L1TriggerKeyListRcd& keyListRcd =
140  iRecord.template getRecord< L1TriggerKeyListRcd >() ;
142  keyListRcd.get( keyList ) ;
143 
144  // Find payload token
145  std::string recordName = edm::typelookup::className<TRcd>();
146  std::string dataType = edm::typelookup::className<TData>();
147  std::string payloadToken =
148  keyList->token( recordName, dataType, key ) ;
149 
150  edm::LogVerbatim( "L1-O2O" )
151  << "Copying payload for " << recordName
152  << "@" << dataType << " obj key " << key
153  << " from CondDB." ;
154  edm::LogVerbatim( "L1-O2O" )
155  << "TOKEN " << payloadToken ;
156 
157  // Get object from POOL
158  // Copied from l1t::DataWriter::readObject()
159  if( !payloadToken.empty() )
160  {
162  pData = m_dbSession.fetchPayload<TData>( payloadToken ) ;
164  }
165  }
166  else
167  {
168  pData = newObject( key ) ;
169  }
170 
171  // if( pData.get() == 0 )
172  if( pData == std::unique_ptr< TData >() )
173  {
174  std::string dataType = edm::typelookup::className<TData>();
175 
176  throw l1t::DataInvalidException( "Unable to generate " +
177  dataType + " for key " + key +
178  "." ) ;
179  }
180  }
181  else
182  {
183  std::string dataType = edm::typelookup::className<TData>();
184 
185  throw l1t::DataAlreadyPresentException( dataType +
186  " for key " + key + " already in CondDB." ) ;
187  }
188 
189  return pData ;
190 }
191 
192 
193 template< class TRcd, class TData >
194 bool
196  const TRcd& record,
197  std::string& objectKey )
198 {
199  // Get L1TriggerKey
200  const L1TriggerKeyRcd& keyRcd =
201  record.template getRecord< L1TriggerKeyRcd >() ;
202 
203  // Explanation of funny syntax: since record is dependent, we are not
204  // expecting getRecord to be a template so the compiler parses it
205  // as a non-template. http://gcc.gnu.org/ml/gcc-bugs/2005-11/msg03685.html
206 
207  // If L1TriggerKey is invalid, then all configuration objects are
208  // already in ORCON.
210  try
211  {
212  keyRcd.get( key ) ;
213  }
215  {
216  objectKey = std::string() ;
217  return false ;
218  }
219 
220  // Get object key from L1TriggerKey
221  std::string recordName = edm::typelookup::className<TRcd>();
222  std::string dataType = edm::typelookup::className<TData>();
223 
224  objectKey = key->get( recordName, dataType ) ;
225 
226 /* edm::LogVerbatim( "L1-O2O" ) */
227 /* << "L1ConfigOnlineProdBase record " << recordName */
228 /* << " type " << dataType << " obj key " << objectKey ; */
229 
230  // Get L1TriggerKeyList
231  L1TriggerKeyList keyList ;
232  l1t::DataWriter dataWriter ;
233  if( !dataWriter.fillLastTriggerKeyList( keyList ) )
234  {
235  edm::LogError( "L1-O2O" )
236  << "Problem getting last L1TriggerKeyList" ;
237  }
238 
239  // If L1TriggerKeyList does not contain object key, token is empty
240  return
241  keyList.token( recordName, dataType, objectKey ).empty() ;
242 }
243 
244 #endif
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:116
bool getObjectKey(const TRcd &record, std::string &objectKey)
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:215
Transaction & transaction()
Definition: Session.cc:66
virtual std::unique_ptr< TData > newObject(const std::string &objectKey)=0
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::unique_ptr< TData > produce(const TRcd &iRecord)
void setAuthenticationPath(const std::string &p)
bool get(HolderT &iHolder) const