CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions
l1t::DataWriter Class Reference

#include <DataWriter.h>

Public Member Functions

 DataWriter ()
 
bool fillLastTriggerKeyList (L1TriggerKeyList &output)
 
std::string lastPayloadToken (const std::string &recordName)
 
std::string payloadToken (const std::string &recordName, edm::RunNumber_t runNumber)
 
template<class T >
void readObject (const std::string &payloadToken, T &outputObject)
 
bool updateIOV (const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
 
void writeKeyList (L1TriggerKeyList *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
 
std::string writePayload (const edm::EventSetup &setup, const std::string &recordType)
 
 ~DataWriter ()
 

Detailed Description

Definition at line 39 of file DataWriter.h.

Constructor & Destructor Documentation

l1t::DataWriter::DataWriter ( )

Definition at line 13 of file DataWriter.cc.

13 {}
l1t::DataWriter::~DataWriter ( )

Definition at line 14 of file DataWriter.cc.

14 {}

Member Function Documentation

bool l1t::DataWriter::fillLastTriggerKeyList ( L1TriggerKeyList output)

Definition at line 210 of file DataWriter.cc.

References funct::false, lastPayloadToken(), readObject(), and funct::true.

Referenced by L1CondDBPayloadWriter::analyze(), L1O2OTestAnalyzer::analyze(), and L1ConfigOnlineProdBase< TRcd, TData >::getObjectKey().

211 {
212  std::string keyListToken =
213  lastPayloadToken( "L1TriggerKeyListRcd" ) ;
214  if( keyListToken.empty() )
215  {
216  return false ;
217  }
218  else
219  {
220  readObject( keyListToken, output ) ;
221  return true ;
222  }
223 }
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriter.cc:195
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriter.h:82
std::string l1t::DataWriter::lastPayloadToken ( const std::string &  recordName)

Definition at line 195 of file DataWriter.cc.

References edm::hlt::Exception, edm::Service< T >::isAvailable(), cond::TagInfo::lastPayloadToken, and cond::service::PoolDBOutputService::tagInfo().

Referenced by fillLastTriggerKeyList().

196 {
198  if( !poolDb.isAvailable() )
199  {
200  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
201  ) ;
202  }
203 
204  cond::TagInfo tagInfo ;
205  poolDb->tagInfo( recordName, tagInfo ) ;
206  return tagInfo.lastPayloadToken ;
207 }
std::string lastPayloadToken
Definition: TagInfo.h:12
bool isAvailable() const
Definition: Service.h:47
void tagInfo(const std::string &recordName, cond::TagInfo &result)
std::string l1t::DataWriter::payloadToken ( const std::string &  recordName,
edm::RunNumber_t  runNumber 
)

Definition at line 153 of file DataWriter.cc.

References cond::DbScopedTransaction::commit(), cond::IOVProxy::end(), edm::hlt::Exception, cond::IOVProxy::find(), cond::MetaData::getToken(), cond::MetaData::hasTag(), o2o::iov, edm::Service< T >::isAvailable(), cond::IOVProxy::load(), python.CommonUtils::session, cond::service::PoolDBOutputService::session(), cond::DbScopedTransaction::start(), and cond::service::PoolDBOutputService::tag().

Referenced by L1O2OTestAnalyzer::analyze(), readObject(), updateIOV(), writeKeyList(), and writePayload().

155 {
157  if( !poolDb.isAvailable() )
158  {
159  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
160  ) ;
161  }
162 
163  // Get tag corresponding to EventSetup record name.
164  std::string iovTag = poolDb->tag( recordName ) ;
165 
166  // Get IOV token for tag.
167  cond::DbSession session = poolDb->session();
168  cond::DbScopedTransaction tr(session);
169  tr.start(true);
170  cond::MetaData metadata(session ) ;
171  std::string iovToken ;
172  if( metadata.hasTag( iovTag ) )
173  {
174  iovToken = metadata.getToken( iovTag ) ;
175  }
176  if( iovToken.empty() )
177  {
178  return std::string() ;
179  }
180 
181  // Get payload token for run number.
182 
183  cond::IOVProxy iov( session );
184  iov.load(iovToken ) ;
185  std::string payloadToken("");
187  if( iP != iov.end() ){
188  payloadToken = iP->token();
189  }
190  tr.commit() ;
191  return payloadToken ;
192 }
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:153
std::string tag(const std::string &recordName)
tuple iov
Definition: o2o.py:307
bool isAvailable() const
Definition: Service.h:47
iov_range_iterator const_iterator
Definition: IOVProxy.h:160
template<class T >
void l1t::DataWriter::readObject ( const std::string &  payloadToken,
T outputObject 
)

Definition at line 82 of file DataWriter.h.

References cond::DbScopedTransaction::commit(), edm::hlt::Exception, cond::DbSession::getTypedObject(), edm::Service< T >::isAvailable(), payloadToken(), python.CommonUtils::session, cond::service::PoolDBOutputService::session(), and cond::DbScopedTransaction::start().

Referenced by L1CondDBIOVWriter::analyze(), and fillLastTriggerKeyList().

84 {
86  if( !poolDb.isAvailable() )
87  {
88  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
89  ) ;
90  }
91 
92  cond::DbSession session = poolDb->session();
93  cond::DbScopedTransaction tr(session);
94  tr.start(true);
95 
96  // Get object from POOL
97  boost::shared_ptr<T> ref = session.getTypedObject<T>(payloadToken) ;
98  outputObject = *ref ;
99  tr.commit ();
100 }
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:153
bool isAvailable() const
Definition: Service.h:47
long double T
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:125
bool l1t::DataWriter::updateIOV ( const std::string &  esRecordName,
const std::string &  payloadToken,
edm::RunNumber_t  sinceRun,
bool  logTransactions = false 
)

Definition at line 91 of file DataWriter.cc.

References cond::service::PoolDBOutputService::appendSinceTime(), cond::service::PoolDBOutputService::beginOfTime(), cond::service::PoolDBOutputService::createNewIOV(), cond::service::PoolDBOutputService::endOfTime(), edm::hlt::Exception, funct::false, edm::Service< T >::isAvailable(), cond::service::PoolDBOutputService::isNewTagRequest(), cond::TagInfo::lastInterval, cond::TagInfo::lastPayloadToken, payloadToken(), cond::service::PoolDBOutputService::tag(), cond::service::PoolDBOutputService::tagInfo(), and funct::true.

Referenced by L1CondDBIOVWriter::analyze(), and writeKeyList().

95 {
96  edm::LogVerbatim( "L1-O2O" ) << esRecordName
97  << " PAYLOAD TOKEN " << payloadToken ;
98 
100  if (!poolDb.isAvailable())
101  {
102  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
103  ) ;
104  }
105 
106  bool iovUpdated = true ;
107 
108  if( poolDb->isNewTagRequest( esRecordName ) )
109  {
110  sinceRun = poolDb->beginOfTime() ;
111  poolDb->createNewIOV( payloadToken,
112  sinceRun,
113  poolDb->endOfTime(),
114  esRecordName,
115  logTransactions ) ;
116  }
117  else
118  {
119  cond::TagInfo tagInfo ;
120  poolDb->tagInfo( esRecordName, tagInfo ) ;
121 
122  if( sinceRun == 0 ) // find last since and add 1
123  {
124  sinceRun = tagInfo.lastInterval.first ;
125  ++sinceRun ;
126  }
127 
128  if( tagInfo.lastPayloadToken != payloadToken )
129  {
130  poolDb->appendSinceTime( payloadToken,
131  sinceRun,
132  esRecordName,
133  logTransactions ) ;
134  }
135  else
136  {
137  iovUpdated = false ;
138  edm::LogVerbatim( "L1-O2O" ) << "IOV already up to date." ;
139  }
140  }
141 
142  if( iovUpdated )
143  {
144  edm::LogVerbatim( "L1-O2O" ) << esRecordName << " "
145  << poolDb->tag( esRecordName )
146  << " SINCE " << sinceRun ;
147  }
148 
149  return iovUpdated ;
150 }
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:153
std::string lastPayloadToken
Definition: TagInfo.h:12
std::string tag(const std::string &recordName)
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:47
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
void tagInfo(const std::string &recordName, cond::TagInfo &result)
cond::ValidityInterval lastInterval
Definition: TagInfo.h:11
void l1t::DataWriter::writeKeyList ( L1TriggerKeyList keyList,
edm::RunNumber_t  sinceRun = 0,
bool  logTransactions = false 
)

Definition at line 58 of file DataWriter.cc.

References cond::classNameForTypeId(), cond::DbScopedTransaction::commit(), edm::hlt::Exception, edm::Service< T >::isAvailable(), payloadToken(), python.CommonUtils::session, cond::service::PoolDBOutputService::session(), cond::DbScopedTransaction::start(), cond::DbSession::storeObject(), and updateIOV().

Referenced by L1CondDBPayloadWriter::analyze().

61 {
63  if( !poolDb.isAvailable() )
64  {
65  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
66  ) ;
67  }
68 
69  cond::DbSession session = poolDb->session();
70  cond::DbScopedTransaction tr(session);
71  tr.start(false);
72 
73  // Write L1TriggerKeyList payload and save payload token before committing
74  boost::shared_ptr<L1TriggerKeyList> pointer(keyList);
75  std::string payloadToken = session.storeObject(pointer.get(),
77  );
78 
79  // Commit before calling updateIOV(), otherwise PoolDBOutputService gets
80  // confused.
81  tr.commit ();
82 
83  // Set L1TriggerKeyList IOV
84  updateIOV( "L1TriggerKeyListRcd",
85  payloadToken,
86  sinceRun,
87  logTransactions ) ;
88 }
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:153
std::string classNameForTypeId(const std::type_info &typeInfo)
bool isAvailable() const
Definition: Service.h:47
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:131
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:91
std::string l1t::DataWriter::writePayload ( const edm::EventSetup setup,
const std::string &  recordType 
)

Definition at line 19 of file DataWriter.cc.

References edm::hlt::Exception, reco::get(), edm::Service< T >::isAvailable(), and payloadToken().

Referenced by L1CondDBPayloadWriter::analyze().

21 {
22  WriterFactory* factory = WriterFactory::get();
23  std::auto_ptr<WriterProxy> writer(factory->create( recordType + "@Writer" )) ;
24  if( writer.get() == 0 )
25  {
26  throw cond::Exception( "DataWriter: could not create WriterProxy with name "
27  + recordType + "@Writer" ) ;
28  }
29 
31  if (!poolDb.isAvailable())
32  {
33  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
34  ) ;
35  }
36 
37  // 2010-02-16: Move session and transaction to WriterProxy::save(). Otherwise, if another transaction is
38  // started while WriterProxy::save() is called (e.g. in a ESProducer like L1ConfigOnlineProdBase), the
39  // transaction here will become read-only.
40 // cond::DbSession session = poolDb->session();
41 // cond::DbScopedTransaction tr(session);
42 // // if throw transaction will unroll
43 // tr.start(false);
44 
45  // update key to have new payload registered for record-type pair.
46  // std::string payloadToken = writer->save( setup, session ) ;
47  std::string payloadToken = writer->save( setup ) ;
48 
49  edm::LogVerbatim( "L1-O2O" ) << recordType << " PAYLOAD TOKEN "
50  << payloadToken ;
51 
52 // tr.commit ();
53 
54  return payloadToken ;
55 }
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:153
bool isAvailable() const
Definition: Service.h:47
edmplugin::PluginFactory< l1t::WriterProxy *()> WriterFactory
Definition: WriterProxy.h:90
T get(const Candidate &c)
Definition: component.h:56