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 36 of file DataWriter.h.

Constructor & Destructor Documentation

l1t::DataWriter::DataWriter ( )

Definition at line 15 of file DataWriter.cc.

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

Definition at line 16 of file DataWriter.cc.

16 {}

Member Function Documentation

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

Definition at line 196 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().

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

Definition at line 181 of file DataWriter.cc.

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

Referenced by fillLastTriggerKeyList().

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

Definition at line 153 of file DataWriter.cc.

References cond::persistency::Transaction::commit(), cond::persistency::IOVProxy::end(), 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().

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.
168  cond::persistency::IOVProxy iov = session.readIov( iovTag );
169  session.transaction().start();
170 
172  auto iP = iov.find( runNumber );
173  if( iP != iov.end() ){
174  payloadToken = (*iP).payloadId;
175  }
176  session.transaction().commit() ;
177  return payloadToken ;
178 }
void start(bool readOnly=true)
Definition: Session.cc:22
cond::persistency::Session session() const
Transaction & transaction()
Definition: Session.cc:66
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:153
std::string tag(const std::string &recordName)
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:81
tuple iov
Definition: o2o.py:307
bool isAvailable() const
Definition: Service.h:46
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:288
Iterator end() const
Definition: IOVProxy.cc:265
template<class T >
void l1t::DataWriter::readObject ( const std::string &  payloadToken,
T outputObject 
)

Definition at line 79 of file DataWriter.h.

References cond::persistency::Transaction::commit(), 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().

81 {
83  if( !poolDb.isAvailable() )
84  {
85  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
86  ) ;
87  }
88 
90  session.transaction().start(true);
91 
92  // Get object from CondDB
93  boost::shared_ptr<T> ref = session.fetchPayload<T>(payloadToken) ;
94  outputObject = *ref ;
95  session.transaction().commit ();
96 }
boost::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:215
void start(bool readOnly=true)
Definition: Session.cc:22
cond::persistency::Session session() const
Transaction & transaction()
Definition: Session.cc:66
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:153
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 91 of file DataWriter.cc.

References cond::service::PoolDBOutputService::appendSinceTime(), cond::service::PoolDBOutputService::beginOfTime(), cond::service::PoolDBOutputService::createNewIOV(), cond::service::PoolDBOutputService::endOfTime(), 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(), dumpRecoGeometry_cfg::tagInfo, and funct::true.

Referenced by CaloConfigWriter::analyze(), L1TCaloParamsWriter::analyze(), CaloParamsWriter::analyze(), 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  {
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 tag(const std::string &recordName)
cond::ValidityInterval lastInterval
Definition: Types.h:70
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:71
volatile std::atomic< bool > shutdown_flag false
void l1t::DataWriter::writeKeyList ( L1TriggerKeyList keyList,
edm::RunNumber_t  sinceRun = 0,
bool  logTransactions = false 
)

Definition at line 60 of file DataWriter.cc.

References 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().

63 {
65  if( !poolDb.isAvailable() )
66  {
67  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
68  ) ;
69  }
70 
73  tr.start( false );
74 
75  // Write L1TriggerKeyList payload and save payload token before committing
76  boost::shared_ptr<L1TriggerKeyList> pointer(keyList);
77  std::string payloadToken = session.storePayload(*pointer );
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 }
cond::persistency::Session session() const
Transaction & transaction()
Definition: Session.cc:66
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:153
bool isAvailable() const
Definition: Service.h:46
void start(bool readOnly=true)
Definition: Session.cc:292
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:202
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 21 of file DataWriter.cc.

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

Referenced by CaloConfigWriter::analyze(), L1TCaloParamsWriter::analyze(), CaloParamsWriter::analyze(), and L1CondDBPayloadWriter::analyze().

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