CMS 3D CMS Logo

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

Constructor & Destructor Documentation

◆ DataWriter()

l1t::DataWriter::DataWriter ( )

Definition at line 12 of file DataWriter.cc.

12 {}

◆ ~DataWriter()

l1t::DataWriter::~DataWriter ( )

Definition at line 13 of file DataWriter.cc.

13 {}

Member Function Documentation

◆ fillLastTriggerKeyList()

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

Definition at line 147 of file DataWriter.cc.

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

Referenced by L1CondDBIOVWriter::analyze(), L1CondDBPayloadWriter::analyze(), L1O2OTestAnalyzer::analyze(), L1GtRunSettingsViewer::analyze(), L1ConfigOnlineProdBase< L1HtMissScaleRcd, L1CaloEtScale >::getObjectKey(), and L1SubsystemKeysOnlineProd::produce().

147  {
148  std::string keyListToken = lastPayloadToken("L1TriggerKeyListRcd");
149  if (keyListToken.empty()) {
150  return false;
151  } else {
152  readObject(keyListToken, output);
153  return true;
154  }
155  }
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriter.cc:136
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriter.h:72

◆ lastPayloadToken()

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

Definition at line 136 of file DataWriter.cc.

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

Referenced by fillLastTriggerKeyList().

136  {
138  if (!poolDb.isAvailable()) {
139  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
140  }
141 
143  poolDb->tagInfo(recordName, tagInfo);
144  return tagInfo.lastInterval.payloadId;
145  }
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::DataWriter::payloadToken ( const std::string &  recordName,
edm::RunNumber_t  runNumber 
)

Definition at line 113 of file DataWriter.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().

113  {
115  if (!poolDb.isAvailable()) {
116  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
117  }
118 
119  // Get tag corresponding to EventSetup record name.
120  std::string iovTag = poolDb->tag(recordName);
121 
122  // Get IOV token for tag.
123  cond::persistency::Session session = poolDb->session();
124  cond::persistency::IOVProxy iov = session.readIov(iovTag);
125  session.transaction().start();
126  auto iovs = iov.selectAll();
128  auto iP = iovs.find(runNumber);
129  if (iP != iovs.end()) {
130  payloadToken = (*iP).payloadId;
131  }
132  session.transaction().commit();
133  return payloadToken;
134  }
persistency::Exception Exception
Definition: Exception.h:25
void start(bool readOnly=true)
Definition: Session.cc:18
Transaction & transaction()
Definition: Session.cc:52
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:113
std::string tag(const std::string &recordName)
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::DataWriter::readObject ( const std::string &  payloadToken,
T outputObject 
)

Definition at line 72 of file DataWriter.h.

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

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

72  {
74  if (!poolDb.isAvailable()) {
75  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
76  }
77 
78  cond::persistency::Session session = poolDb->session();
79  session.transaction().start(true);
80 
81  // Get object from CondDB
82  std::shared_ptr<T> ref = session.fetchPayload<T>(payloadToken);
83  outputObject = *ref;
84  session.transaction().commit();
85  }
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)
Definition: DataWriter.cc:113
bool isAvailable() const
Definition: Service.h:40
long double T
cond::persistency::Session session() const

◆ updateIOV()

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

Definition at line 72 of file DataWriter.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 L1TCaloParamsWriter::analyze(), CaloParamsWriter::analyze(), CaloConfigWriter::analyze(), L1CondDBIOVWriter::analyze(), and writeKeyList().

75  {
76  edm::LogVerbatim("L1-O2O") << esRecordName << " PAYLOAD TOKEN " << payloadToken;
77 
79  if (!poolDb.isAvailable()) {
80  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
81  }
82 
83  bool iovUpdated = true;
84 
85  if (poolDb->isNewTagRequest(esRecordName)) {
86  sinceRun = poolDb->beginOfTime();
87  poolDb->createNewIOV(payloadToken, sinceRun, esRecordName);
88  } else {
90  poolDb->tagInfo(esRecordName, tagInfo);
91 
92  if (sinceRun == 0) // find last since and add 1
93  {
94  sinceRun = tagInfo.lastInterval.since;
95  ++sinceRun;
96  }
97 
98  if (tagInfo.lastInterval.payloadId != payloadToken) {
99  poolDb->appendSinceTime(payloadToken, sinceRun, esRecordName);
100  } else {
101  iovUpdated = false;
102  edm::LogVerbatim("L1-O2O") << "IOV already up to date.";
103  }
104  }
105 
106  if (iovUpdated) {
107  edm::LogVerbatim("L1-O2O") << esRecordName << " " << poolDb->tag(esRecordName) << " SINCE " << sinceRun;
108  }
109 
110  return iovUpdated;
111  }
persistency::Exception Exception
Definition: Exception.h:25
Log< level::Info, true > LogVerbatim
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:113
std::string tag(const std::string &recordName)
bool isNewTagRequest(const std::string &recordName)
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::DataWriter::writeKeyList ( L1TriggerKeyList keyList,
edm::RunNumber_t  sinceRun = 0,
bool  logTransactions = false 
)

tr.start( false );

Definition at line 49 of file DataWriter.cc.

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

Referenced by L1CondDBPayloadWriter::analyze().

49  {
51  if (!poolDb.isAvailable()) {
52  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
53  }
54 
55  cond::persistency::Session session = poolDb->session();
58 
59  // Write L1TriggerKeyList payload and save payload token before committing
60  std::shared_ptr<L1TriggerKeyList> pointer(keyList);
61  std::string payloadToken = session.storePayload(*pointer);
62 
63  // Commit before calling updateIOV(), otherwise PoolDBOutputService gets
64  // confused.
65  //tr.commit ();
66  tr.close();
67 
68  // Set L1TriggerKeyList IOV
69  updateIOV("L1TriggerKeyListRcd", payloadToken, sinceRun, logTransactions);
70  }
persistency::Exception Exception
Definition: Exception.h:25
Transaction & transaction()
Definition: Session.cc:52
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:113
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
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:72
cond::persistency::Session session() const

◆ writePayload()

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

Definition at line 15 of file DataWriter.cc.

References get, edm::Service< T >::isAvailable(), payloadToken(), cond::service::PoolDBOutputService::session(), singleTopDQM_cfi::setup, AlCaHLTBitMon_QueryRunRegistry::string, cond::persistency::Session::transaction(), and convertToRaw::writer.

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

15  {
16  WriterFactory* factory = WriterFactory::get();
17  std::unique_ptr<WriterProxy> writer(factory->create(recordType + "@Writer"));
18  if (writer.get() == nullptr) {
19  throw cond::Exception("DataWriter: could not create WriterProxy with name " + recordType + "@Writer");
20  }
21 
23  if (!poolDb.isAvailable()) {
24  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
25  }
26 
27  // 2010-02-16: Move session and transaction to WriterProxy::save(). Otherwise, if another transaction is
28  // started while WriterProxy::save() is called (e.g. in a ESProducer like L1ConfigOnlineProdBase), the
29  // transaction here will become read-only.
30  // cond::DbSession session = poolDb->session();
31  // cond::DbScopedTransaction tr(session);
32 
34  // // if throw transaction will unroll
35  // tr.start(false);
36 
37  // update key to have new payload registered for record-type pair.
38  // std::string payloadToken = writer->save( setup, session ) ;
40 
41  edm::LogVerbatim("L1-O2O") << recordType << " PAYLOAD TOKEN " << payloadToken;
42 
43  tr.close();
44  // tr.commit ();
45 
46  return payloadToken;
47  }
persistency::Exception Exception
Definition: Exception.h:25
Log< level::Info, true > LogVerbatim
edmplugin::PluginFactory< l1t::WriterProxy *()> WriterFactory
Definition: WriterProxy.h:85
Transaction & transaction()
Definition: Session.cc:52
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:113
bool isAvailable() const
Definition: Service.h:40
#define get
cond::persistency::Session session() const