CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
l1t::DataWriterExt Class Reference

#include <DataWriterExt.h>

Public Member Functions

 DataWriterExt ()
 
 DataWriterExt (const std::string &)
 
bool fillLastTriggerKeyList (L1TriggerKeyListExt &output)
 
WriterProxygetWriter ()
 
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 (L1TriggerKeyListExt *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
 
std::string writePayload (const edm::EventSetup &setup)
 
std::string writePayload (const edm::EventSetup &setup, const std::string &recordType)
 
 ~DataWriterExt ()
 

Private Attributes

WriterProxyPtr writer_
 

Detailed Description

Definition at line 37 of file DataWriterExt.h.

Constructor & Destructor Documentation

◆ DataWriterExt() [1/2]

l1t::DataWriterExt::DataWriterExt ( )

Definition at line 15 of file DataWriterExt.cc.

15 {}

◆ DataWriterExt() [2/2]

l1t::DataWriterExt::DataWriterExt ( const std::string &  recordType)

Definition at line 19 of file DataWriterExt.cc.

References get, Skims_PA_cff::name, and writer_.

19  {
20  WriterFactory* factory = WriterFactory::get();
21  writer_ = factory->create(recordType + "@Writer");
22  if (writer_.get() == nullptr) {
23  throw cond::Exception("DataWriter: could not create WriterProxy with name " + recordType + "@Writer");
24  }
25  edm::LogVerbatim("L1-O2O DataWriterExt::DataWriterExt")
26  << "Created new " << typeid(writer_).name() << " | address " << writer_.get() << " | rcd " << recordType;
27  }
persistency::Exception Exception
Definition: Exception.h:25
Log< level::Info, true > LogVerbatim
edmplugin::PluginFactory< l1t::WriterProxy *()> WriterFactory
Definition: WriterProxy.h:85
WriterProxyPtr writer_
Definition: DataWriterExt.h:75
#define get

◆ ~DataWriterExt()

l1t::DataWriterExt::~DataWriterExt ( )

Definition at line 29 of file DataWriterExt.cc.

29 {}

Member Function Documentation

◆ fillLastTriggerKeyList()

bool l1t::DataWriterExt::fillLastTriggerKeyList ( L1TriggerKeyListExt output)

Definition at line 182 of file DataWriterExt.cc.

References lastPayloadToken(), readObject(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by L1CondDBIOVWriterExt::analyze(), L1CondDBPayloadWriterExt::analyze(), L1O2OTestAnalyzerExt::analyze(), L1ConfigOnlineProdBaseExt< L1TCaloParamsO2ORcd, l1t::CaloParams >::getObjectKey(), and L1SubsystemKeysOnlineProdExt::produce().

182  {
183  std::string keyListToken = lastPayloadToken("L1TriggerKeyListExtRcd");
184  if (keyListToken.empty()) {
185  return false;
186  } else {
187  readObject(keyListToken, output);
188  return true;
189  }
190  }
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriterExt.h:81
std::string lastPayloadToken(const std::string &recordName)
Definition: output.py:1

◆ getWriter()

WriterProxy* l1t::DataWriterExt::getWriter ( )
inline

Definition at line 72 of file DataWriterExt.h.

References writer_.

72 { return writer_.get(); }
WriterProxyPtr writer_
Definition: DataWriterExt.h:75

◆ lastPayloadToken()

std::string l1t::DataWriterExt::lastPayloadToken ( const std::string &  recordName)

Definition at line 171 of file DataWriterExt.cc.

References edm::Service< T >::isAvailable(), align_cfg::recordName, dumpRecoGeometry_cfg::tagInfo, and cond::service::PoolDBOutputService::tagInfo().

Referenced by fillLastTriggerKeyList().

171  {
173  if (!poolDb.isAvailable()) {
174  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
175  }
176 
178  poolDb->tagInfo(recordName, tagInfo);
179  return tagInfo.lastInterval.payloadId;
180  }
persistency::Exception Exception
Definition: Exception.h:25
bool isAvailable() const
Definition: Service.h:40
bool tagInfo(const std::string &recordName, cond::TagInfo_t &result)

◆ payloadToken()

std::string l1t::DataWriterExt::payloadToken ( const std::string &  recordName,
edm::RunNumber_t  runNumber 
)

Definition at line 148 of file DataWriterExt.cc.

References cond::persistency::Transaction::commit(), edm::Service< T >::isAvailable(), cond::persistency::Session::readIov(), align_cfg::recordName, convertSQLiteXML::runNumber, cond::persistency::IOVProxy::selectAll(), cond::service::PoolDBOutputService::session(), cond::persistency::Transaction::start(), AlCaHLTBitMon_QueryRunRegistry::string, cond::service::PoolDBOutputService::tag(), and cond::persistency::Session::transaction().

Referenced by readObject(), updateIOV(), writeKeyList(), and writePayload().

148  {
150  if (!poolDb.isAvailable()) {
151  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
152  }
153 
154  // Get tag corresponding to EventSetup record name.
155  std::string iovTag = poolDb->tag(recordName);
156 
157  // Get IOV token for tag.
158  cond::persistency::Session session = poolDb->session();
159  cond::persistency::IOVProxy iov = session.readIov(iovTag);
160  session.transaction().start();
161  auto iovs = iov.selectAll();
163  auto iP = iovs.find(runNumber);
164  if (iP != iovs.end()) {
165  payloadToken = (*iP).payloadId;
166  }
167  session.transaction().commit();
168  return payloadToken;
169  }
persistency::Exception Exception
Definition: Exception.h:25
void start(bool readOnly=true)
Definition: Session.cc:18
Transaction & transaction()
Definition: Session.cc:52
std::string tag(const std::string &recordName)
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
bool isAvailable() const
Definition: Service.h:40
cond::persistency::Session session() const

◆ readObject()

template<class T >
void l1t::DataWriterExt::readObject ( const std::string &  payloadToken,
T outputObject 
)

Definition at line 81 of file DataWriterExt.h.

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

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

81  {
83  if (!poolDb.isAvailable()) {
84  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
85  }
86 
87  poolDb->forceInit();
88  cond::persistency::Session session = poolDb->session();
89  session.transaction().start(true);
90 
91  // Get object from CondDB
92  std::shared_ptr<T> ref = session.fetchPayload<T>(payloadToken);
93  outputObject = *ref;
94  session.transaction().commit();
95  }
persistency::Exception Exception
Definition: Exception.h:25
void start(bool readOnly=true)
Definition: Session.cc:18
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
Transaction & transaction()
Definition: Session.cc:52
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
bool isAvailable() const
Definition: Service.h:40
long double T
cond::persistency::Session session() const

◆ updateIOV()

bool l1t::DataWriterExt::updateIOV ( const std::string &  esRecordName,
const std::string &  payloadToken,
edm::RunNumber_t  sinceRun,
bool  logTransactions = false 
)

Definition at line 107 of file DataWriterExt.cc.

References cond::service::PoolDBOutputService::appendSinceTime(), cond::service::PoolDBOutputService::beginOfTime(), cond::service::PoolDBOutputService::createNewIOV(), edm::Service< T >::isAvailable(), cond::service::PoolDBOutputService::isNewTagRequest(), payloadToken(), cond::service::PoolDBOutputService::tag(), dumpRecoGeometry_cfg::tagInfo, and cond::service::PoolDBOutputService::tagInfo().

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

110  {
111  edm::LogVerbatim("L1-O2O") << esRecordName << " PAYLOAD TOKEN " << payloadToken;
112 
114  if (!poolDb.isAvailable()) {
115  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
116  }
117 
118  bool iovUpdated = true;
119 
120  if (poolDb->isNewTagRequest(esRecordName)) {
121  sinceRun = poolDb->beginOfTime();
122  poolDb->createNewIOV(payloadToken, sinceRun, esRecordName);
123  } else {
125  poolDb->tagInfo(esRecordName, tagInfo);
126 
127  if (sinceRun == 0) // find last since and add 1
128  {
129  sinceRun = tagInfo.lastInterval.since;
130  ++sinceRun;
131  }
132 
133  if (tagInfo.lastInterval.payloadId != payloadToken) {
134  poolDb->appendSinceTime(payloadToken, sinceRun, esRecordName);
135  } else {
136  iovUpdated = false;
137  edm::LogVerbatim("L1-O2O") << "IOV already up to date.";
138  }
139  }
140 
141  if (iovUpdated) {
142  edm::LogVerbatim("L1-O2O") << esRecordName << " " << poolDb->tag(esRecordName) << " SINCE " << sinceRun;
143  }
144 
145  return iovUpdated;
146  }
persistency::Exception Exception
Definition: Exception.h:25
Log< level::Info, true > LogVerbatim
std::string tag(const std::string &recordName)
bool isNewTagRequest(const std::string &recordName)
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
bool appendSinceTime(const std::string &payloadId, cond::Time_t sinceTime, const std::string &recordName)
void createNewIOV(const std::string &firstPayloadId, cond::Time_t firstSinceTime, const std::string &recordName)
bool isAvailable() const
Definition: Service.h:40
bool tagInfo(const std::string &recordName, cond::TagInfo_t &result)

◆ writeKeyList()

void l1t::DataWriterExt::writeKeyList ( L1TriggerKeyListExt keyList,
edm::RunNumber_t  sinceRun = 0,
bool  logTransactions = false 
)

Definition at line 84 of file DataWriterExt.cc.

References cond::persistency::Transaction::commit(), cond::service::PoolDBOutputService::forceInit(), cond::persistency::Transaction::isActive(), edm::Service< T >::isAvailable(), payloadToken(), cond::service::PoolDBOutputService::session(), cond::persistency::Transaction::start(), cond::persistency::Session::storePayload(), AlCaHLTBitMon_QueryRunRegistry::string, cond::persistency::Session::transaction(), and updateIOV().

Referenced by L1CondDBPayloadWriterExt::analyze().

84  {
86  if (!poolDb.isAvailable()) {
87  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
88  }
89 
90  poolDb->forceInit();
91  cond::persistency::Session session = poolDb->session();
92  if (not session.transaction().isActive())
93  session.transaction().start(false);
94 
95  // Write L1TriggerKeyListExt payload and save payload token before committing
96  std::shared_ptr<L1TriggerKeyListExt> pointer(keyList);
97  std::string payloadToken = session.storePayload(*pointer);
98 
99  // Commit before calling updateIOV(), otherwise PoolDBOutputService gets
100  // confused. ??? why?
101 
102  // Set L1TriggerKeyListExt IOV
103  session.transaction().commit();
104  updateIOV("L1TriggerKeyListExtRcd", payloadToken, sinceRun, logTransactions);
105  }
persistency::Exception Exception
Definition: Exception.h:25
void start(bool readOnly=true)
Definition: Session.cc:18
Transaction & transaction()
Definition: Session.cc:52
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:186
bool isAvailable() const
Definition: Service.h:40
cond::persistency::Session session() const

◆ writePayload() [1/2]

std::string l1t::DataWriterExt::writePayload ( const edm::EventSetup setup)

Definition at line 31 of file DataWriterExt.cc.

References edm::Service< T >::isAvailable(), Skims_PA_cff::name, payloadToken(), singleTopDQM_cfi::setup, AlCaHLTBitMon_QueryRunRegistry::string, and writer_.

Referenced by L1CondDBPayloadWriterExt::analyze().

31  {
32  edm::LogVerbatim("L1-O2O DataWriterExt::writePayload") << "Will use stored writer at " << writer_.get();
33 
35  if (!poolDb.isAvailable()) {
36  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
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.
43  auto& writerRef = *writer_.get();
44  edm::LogVerbatim("L1-O2O") << typeid(writerRef).name() << " PAYLOAD TOKEN " << payloadToken;
45 
46  return payloadToken;
47  }
persistency::Exception Exception
Definition: Exception.h:25
Log< level::Info, true > LogVerbatim
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
WriterProxyPtr writer_
Definition: DataWriterExt.h:75
bool isAvailable() const
Definition: Service.h:40

◆ writePayload() [2/2]

std::string l1t::DataWriterExt::writePayload ( const edm::EventSetup setup,
const std::string &  recordType 
)

cond::persistency::TransactionScope tr(poolDb->session().transaction());

Definition at line 49 of file DataWriterExt.cc.

References get, edm::Service< T >::isAvailable(), eostools::move(), Skims_PA_cff::name, payloadToken(), singleTopDQM_cfi::setup, AlCaHLTBitMon_QueryRunRegistry::string, convertToRaw::writer, and writer_.

49  {
50  WriterFactory* factory = WriterFactory::get();
51  WriterProxyPtr writer(factory->create(recordType + "@Writer"));
52  if (writer.get() == nullptr) {
53  throw cond::Exception("DataWriter: could not create WriterProxy with name " + recordType + "@Writer");
54  }
56 
58  if (!poolDb.isAvailable()) {
59  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
60  }
61 
62  // 2010-02-16: Move session and transaction to WriterProxy::save(). Otherwise, if another transaction is
63  // started while WriterProxy::save() is called (e.g. in a ESProducer like L1ConfigOnlineProdBase), the
64  // transaction here will become read-only.
65  // cond::DbSession session = poolDb->session();
66  // cond::DbScopedTransaction tr(session);
67 
69  // // if throw transaction will unroll
70  // tr.start(false);
71 
72  // update key to have new payload registered for record-type pair.
73  // std::string payloadToken = writer->save( setup, session ) ;
75  auto& writerRef = *writer_.get();
76  edm::LogVerbatim("L1-O2O") << typeid(writerRef).name() << " PAYLOAD TOKEN " << payloadToken;
77 
79  // tr.commit ();
80 
81  return payloadToken;
82  }
persistency::Exception Exception
Definition: Exception.h:25
Log< level::Info, true > LogVerbatim
edmplugin::PluginFactory< l1t::WriterProxy *()> WriterFactory
Definition: WriterProxy.h:85
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
std::unique_ptr< WriterProxy > WriterProxyPtr
Definition: DataWriterExt.h:35
WriterProxyPtr writer_
Definition: DataWriterExt.h:75
bool isAvailable() const
Definition: Service.h:40
#define get
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ writer_

WriterProxyPtr l1t::DataWriterExt::writer_
private

Definition at line 75 of file DataWriterExt.h.

Referenced by DataWriterExt(), getWriter(), and writePayload().