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 40 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 194 of file DataWriter.cc.

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

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

195 {
196  std::string keyListToken =
197  lastPayloadToken( "L1TriggerKeyListRcd" ) ;
198  if( keyListToken.empty() )
199  {
200  return false ;
201  }
202  else
203  {
204  readObject( keyListToken, output ) ;
205  return true ;
206  }
207 }
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriter.cc:179
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriter.h:83
volatile std::atomic< bool > shutdown_flag false
std::string l1t::DataWriter::lastPayloadToken ( const std::string &  recordName)

Definition at line 179 of file DataWriter.cc.

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

Referenced by fillLastTriggerKeyList().

180 {
182  if( !poolDb.isAvailable() )
183  {
184  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
185  ) ;
186  }
187 
188  cond::TagInfo tagInfo ;
189  poolDb->tagInfo( recordName, tagInfo ) ;
190  return tagInfo.lastPayloadToken ;
191 }
bool isAvailable() const
Definition: Service.h:46
void tagInfo(const std::string &recordName, cond::TagInfo_t &result)
std::string lastPayloadToken
Definition: Types.h:62
std::string l1t::DataWriter::payloadToken ( const std::string &  recordName,
edm::RunNumber_t  runNumber 
)

Definition at line 151 of file DataWriter.cc.

References cond::persistency::Transaction::commit(), cond::persistency::IOVProxy::end(), edm::hlt::Exception, cond::persistency::IOVProxy::find(), o2o::iov, edm::Service< T >::isAvailable(), cond::persistency::Session::readIov(), cond::service::PoolDBOutputService::session(), python.CommonUtils::session, cond::persistency::Transaction::start(), AlCaHLTBitMon_QueryRunRegistry::string, cond::service::PoolDBOutputService::tag(), and cond::persistency::Session::transaction().

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

153 {
155  if( !poolDb.isAvailable() )
156  {
157  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
158  ) ;
159  }
160 
161  // Get tag corresponding to EventSetup record name.
162  std::string iovTag = poolDb->tag( recordName ) ;
163 
164  // Get IOV token for tag.
166  cond::persistency::IOVProxy iov = session.readIov( iovTag );
167  session.transaction().start();
168 
170  auto iP = iov.find( runNumber );
171  if( iP != iov.end() ){
172  payloadToken = (*iP).payloadId;
173  }
174  session.transaction().commit() ;
175  return payloadToken ;
176 }
void start(bool readOnly=true)
Definition: Session.cc:22
cond::persistency::Session session() const
Transaction & transaction()
Definition: Session.cc:71
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:151
std::string tag(const std::string &recordName)
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:86
tuple iov
Definition: o2o.py:307
bool isAvailable() const
Definition: Service.h:46
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:230
Iterator end() const
Definition: IOVProxy.cc:208
template<class T >
void l1t::DataWriter::readObject ( const std::string &  payloadToken,
T outputObject 
)

Definition at line 83 of file DataWriter.h.

References cond::persistency::Transaction::commit(), edm::hlt::Exception, cond::persistency::Session::fetchPayload(), edm::Service< T >::isAvailable(), payloadToken(), cond::service::PoolDBOutputService::session(), python.CommonUtils::session, cond::persistency::Transaction::start(), and cond::persistency::Session::transaction().

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

85 {
87  if( !poolDb.isAvailable() )
88  {
89  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
90  ) ;
91  }
92 
94  session.transaction().start(true);
95 
96  // Get object from CondDB
97  boost::shared_ptr<T> ref = session.fetchPayload<T>(payloadToken) ;
98  outputObject = *ref ;
99  session.transaction().commit ();
100 }
boost::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:163
void start(bool readOnly=true)
Definition: Session.cc:22
cond::persistency::Session session() const
Transaction & transaction()
Definition: Session.cc:71
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:151
bool isAvailable() const
Definition: Service.h:46
long double T
bool l1t::DataWriter::updateIOV ( const std::string &  esRecordName,
const std::string &  payloadToken,
edm::RunNumber_t  sinceRun,
bool  logTransactions = false 
)

Definition at line 89 of file DataWriter.cc.

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

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

93 {
94  edm::LogVerbatim( "L1-O2O" ) << esRecordName
95  << " PAYLOAD TOKEN " << payloadToken ;
96 
98  if (!poolDb.isAvailable())
99  {
100  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
101  ) ;
102  }
103 
104  bool iovUpdated = true ;
105 
106  if( poolDb->isNewTagRequest( esRecordName ) )
107  {
108  sinceRun = poolDb->beginOfTime() ;
109  poolDb->createNewIOV( payloadToken,
110  sinceRun,
111  poolDb->endOfTime(),
112  esRecordName,
113  logTransactions ) ;
114  }
115  else
116  {
117  cond::TagInfo tagInfo ;
118  poolDb->tagInfo( esRecordName, tagInfo ) ;
119 
120  if( sinceRun == 0 ) // find last since and add 1
121  {
122  sinceRun = tagInfo.lastInterval.first ;
123  ++sinceRun ;
124  }
125 
126  if( tagInfo.lastPayloadToken != payloadToken )
127  {
128  poolDb->appendSinceTime( payloadToken,
129  sinceRun,
130  esRecordName,
131  logTransactions ) ;
132  }
133  else
134  {
135  iovUpdated = false ;
136  edm::LogVerbatim( "L1-O2O" ) << "IOV already up to date." ;
137  }
138  }
139 
140  if( iovUpdated )
141  {
142  edm::LogVerbatim( "L1-O2O" ) << esRecordName << " "
143  << poolDb->tag( esRecordName )
144  << " SINCE " << sinceRun ;
145  }
146 
147  return iovUpdated ;
148 }
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:151
std::string tag(const std::string &recordName)
cond::ValidityInterval lastInterval
Definition: Types.h:61
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:46
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_t &result)
std::string lastPayloadToken
Definition: Types.h:62
volatile std::atomic< bool > shutdown_flag false
void l1t::DataWriter::writeKeyList ( L1TriggerKeyList keyList,
edm::RunNumber_t  sinceRun = 0,
bool  logTransactions = false 
)

Definition at line 58 of file DataWriter.cc.

References edm::hlt::Exception, edm::Service< T >::isAvailable(), payloadToken(), cond::service::PoolDBOutputService::session(), python.CommonUtils::session, cond::persistency::TransactionScope::start(), cond::persistency::Session::storePayload(), AlCaHLTBitMon_QueryRunRegistry::string, cond::persistency::Session::transaction(), and updateIOV().

Referenced by L1CondDBPayloadWriter::analyze().

61 {
63  if( !poolDb.isAvailable() )
64  {
65  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
66  ) ;
67  }
68 
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.storePayload(*pointer );
76 
77  // Commit before calling updateIOV(), otherwise PoolDBOutputService gets
78  // confused.
79  tr.commit ();
80 
81  // Set L1TriggerKeyList IOV
82  updateIOV( "L1TriggerKeyListRcd",
83  payloadToken,
84  sinceRun,
85  logTransactions ) ;
86 }
cond::persistency::Session session() const
Transaction & transaction()
Definition: Session.cc:71
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:151
bool isAvailable() const
Definition: Service.h:46
void start(bool readOnly=true)
Definition: Session.cc:215
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:157
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:89
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(), payloadToken(), and AlCaHLTBitMon_QueryRunRegistry::string.

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:151
bool isAvailable() const
Definition: Service.h:46
edmplugin::PluginFactory< l1t::WriterProxy *()> WriterFactory
Definition: WriterProxy.h:88
T get(const Candidate &c)
Definition: component.h:55