test
CMS 3D CMS Logo

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