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 
49 
50 // forward declarations
51 
52 template< class TRcd, class TData >
54  public:
57 
58  boost::shared_ptr< TData > produce(const TRcd& iRecord);
59 
60  virtual boost::shared_ptr< TData > newObject(
61  const std::string& objectKey ) = 0 ;
62 
63  private:
64  // ----------member data ---------------------------
65 
66  protected:
69 
70  // Called from produce methods.
71  // bool is true if the object data should be made.
72  // If bool is false, produce method should throw
73  // DataAlreadyPresentException.
74  bool getObjectKey( const TRcd& record,
75  boost::shared_ptr< TData > data,
76  std::string& objectKey ) ;
77 
78  // For reading object directly from a CondDB w/o PoolDBOutputService
81 };
82 
83 
84 template< class TRcd, class TData >
86  : m_omdsReader(),
87  m_forceGeneration( iConfig.getParameter< bool >( "forceGeneration" ) ),
88  m_dbSession(),
89  m_copyFromCondDB( false )
90 {
91  //the following line is needed to tell the framework what
92  // data is being produced
93  setWhatProduced(this);
94 
95  //now do what ever other initialization is needed
96 
97  if( iConfig.exists( "copyFromCondDB" ) )
98  {
99  m_copyFromCondDB = iConfig.getParameter< bool >( "copyFromCondDB" ) ;
100 
101  if( m_copyFromCondDB )
102  {
103  cond::persistency::ConnectionPool connectionPool;
104  // Connect DB Session
105  connectionPool.setAuthenticationPath(
106  iConfig.getParameter< std::string >( "onlineAuthentication" ) ) ;
107  connectionPool.configure() ;
108  m_dbSession = connectionPool.createSession( iConfig.getParameter< std::string >( "onlineDB" ) ) ;
109  }
110  }
111  else
112  {
114  iConfig.getParameter< std::string >( "onlineDB" ),
115  iConfig.getParameter< std::string >( "onlineAuthentication" ) ) ;
116  }
117 }
118 
119 template< class TRcd, class TData >
121 {
122 
123  // do anything here that needs to be done at desctruction time
124  // (e.g. close files, deallocate resources etc.)
125 
126 }
127 
128 template< class TRcd, class TData >
129 boost::shared_ptr< TData >
131 {
132  using namespace edm::es;
133  boost::shared_ptr< TData > pData ;
134 
135  // Get object key and check if already in ORCON
136  std::string key ;
137  if( getObjectKey( iRecord, pData, key ) || m_forceGeneration )
138  {
139  if( m_copyFromCondDB )
140  {
141  // Get L1TriggerKeyList from EventSetup
142  const L1TriggerKeyListRcd& keyListRcd =
143  iRecord.template getRecord< L1TriggerKeyListRcd >() ;
145  keyListRcd.get( keyList ) ;
146 
147  // Find payload token
148  std::string recordName = edm::typelookup::className<TRcd>();
149  std::string dataType = edm::typelookup::className<TData>();
150  std::string payloadToken =
151  keyList->token( recordName, dataType, key ) ;
152 
153  edm::LogVerbatim( "L1-O2O" )
154  << "Copying payload for " << recordName
155  << "@" << dataType << " obj key " << key
156  << " from CondDB." ;
157  edm::LogVerbatim( "L1-O2O" )
158  << "TOKEN " << payloadToken ;
159 
160  // Get object from POOL
161  // Copied from l1t::DataWriter::readObject()
162  if( !payloadToken.empty() )
163  {
164  m_dbSession.transaction().start() ;
165  pData = m_dbSession.fetchPayload<TData>( payloadToken ) ;
166  m_dbSession.transaction().commit ();
167  }
168  }
169  else
170  {
171  pData = newObject( key ) ;
172  }
173 
174  // if( pData.get() == 0 )
175  if( pData == boost::shared_ptr< TData >() )
176  {
177  std::string dataType = edm::typelookup::className<TData>();
178 
179  throw l1t::DataInvalidException( "Unable to generate " +
180  dataType + " for key " + key +
181  "." ) ;
182  }
183  }
184  else
185  {
186  std::string dataType = edm::typelookup::className<TData>();
187 
188  throw l1t::DataAlreadyPresentException( dataType +
189  " for key " + key + " already in CondDB." ) ;
190  }
191 
192  return pData ;
193 }
194 
195 
196 template< class TRcd, class TData >
197 bool
199  const TRcd& record,
200  boost::shared_ptr< TData > data,
201  std::string& objectKey )
202 {
203  // Get L1TriggerKey
204  const L1TriggerKeyRcd& keyRcd =
205  record.template getRecord< L1TriggerKeyRcd >() ;
206 
207  // Explanation of funny syntax: since record is dependent, we are not
208  // expecting getRecord to be a template so the compiler parses it
209  // as a non-template. http://gcc.gnu.org/ml/gcc-bugs/2005-11/msg03685.html
210 
211  // If L1TriggerKey is invalid, then all configuration objects are
212  // already in ORCON.
214  try
215  {
216  keyRcd.get( key ) ;
217  }
219  {
220  objectKey = std::string() ;
221  return false ;
222  }
223 
224  // Get object key from L1TriggerKey
225  std::string recordName = edm::typelookup::className<TRcd>();
226  std::string dataType = edm::typelookup::className<TData>();
227 
228  objectKey = key->get( recordName, dataType ) ;
229 
230 /* edm::LogVerbatim( "L1-O2O" ) */
231 /* << "L1ConfigOnlineProdBase record " << recordName */
232 /* << " type " << dataType << " obj key " << objectKey ; */
233 
234  // Get L1TriggerKeyList
235  L1TriggerKeyList keyList ;
236  l1t::DataWriter dataWriter ;
237  if( !dataWriter.fillLastTriggerKeyList( keyList ) )
238  {
239  edm::LogError( "L1-O2O" )
240  << "Problem getting last L1TriggerKeyList" ;
241  }
242 
243  // If L1TriggerKeyList does not contain object key, token is empty
244  return
245  keyList.token( recordName, dataType, objectKey ) == std::string() ;
246 }
247 
248 #endif
T getParameter(std::string const &) const
bool getObjectKey(const TRcd &record, boost::shared_ptr< TData > data, std::string &objectKey)
cond::persistency::Session m_dbSession
JetCorrectorParameters::Record record
Definition: classes.h:7
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
Session createSession(const std::string &connectionString, bool writeCapable=false, BackendType backType=DEFAULT_DB)
void get(HolderT &iHolder) const
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:196
void connect(const std::string &connectString, const std::string &authenticationPath)
Definition: OMDSReader.cc:50
L1ConfigOnlineProdBase(const edm::ParameterSet &)
std::string token(const std::string &tscKey) const
volatile std::atomic< bool > shutdown_flag false
void setAuthenticationPath(const std::string &p)