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