CMS 3D CMS Logo

DataWriter.cc
Go to the documentation of this file.
2 
6 
8 
9 #include <utility>
10 
11 namespace l1t {
14 
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  }
48 
49  void DataWriter::writeKeyList(L1TriggerKeyList* keyList, edm::RunNumber_t sinceRun, bool logTransactions) {
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  }
71 
72  bool DataWriter::updateIOV(const std::string& esRecordName,
73  const std::string& payloadToken,
74  edm::RunNumber_t sinceRun,
75  bool logTransactions) {
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  }
112 
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  }
135 
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  }
146 
148  std::string keyListToken = lastPayloadToken("L1TriggerKeyListRcd");
149  if (keyListToken.empty()) {
150  return false;
151  } else {
152  readObject(keyListToken, output);
153  return true;
154  }
155  }
156 
157 } // namespace l1t
cond::persistency::TransactionScope
Definition: Session.h:231
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
cond::service::PoolDBOutputService::tag
std::string tag(const std::string &recordName)
Definition: PoolDBOutputService.cc:96
DataWriter.h
MessageLogger.h
l1t::DataWriter::updateIOV
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:72
Exception.h
cond::service::PoolDBOutputService::beginOfTime
cond::Time_t beginOfTime() const
Definition: PoolDBOutputService.cc:187
Exception.h
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
align_cfg.recordName
recordName
Definition: align_cfg.py:66
cond::service::PoolDBOutputService::tagInfo
bool tagInfo(const std::string &recordName, cond::TagInfo_t &result)
Definition: PoolDBOutputService.cc:369
cond::service::PoolDBOutputService::appendSinceTime
void appendSinceTime(const T *payloadObj, cond::Time_t sinceTime, const std::string &recordName)
Definition: PoolDBOutputService.h:135
cscNeutronWriter_cfi.writer
writer
Definition: cscNeutronWriter_cfi.py:6
l1t::DataWriter::lastPayloadToken
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriter.cc:136
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
cond::persistency::IOVProxy::selectAll
IOVArray selectAll()
Definition: IOVProxy.cc:171
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
cond::service::PoolDBOutputService::createNewIOV
void createNewIOV(const T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t, const std::string &recordName)
Definition: PoolDBOutputService.h:110
cond::service::PoolDBOutputService::session
cond::persistency::Session session() const
Definition: PoolDBOutputService.cc:94
l1t::DataWriter::writeKeyList
void writeKeyList(L1TriggerKeyList *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Definition: DataWriter.cc:49
l1t::DataWriter::DataWriter
DataWriter()
Definition: DataWriter.cc:12
l1t::DataWriter::payloadToken
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:113
cond::persistency::Session::readIov
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::IOVProxy
Definition: IOVProxy.h:92
L1TriggerKeyList
Definition: L1TriggerKeyList.h:32
Serialization.h
l1t
delete x;
Definition: CaloConfig.h:22
l1t::DataWriter::writePayload
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
Definition: DataWriter.cc:15
edmplugin::PluginFactory
Definition: PluginFactory.h:34
cond::persistency::Session
Definition: Session.h:63
edm::Service< cond::service::PoolDBOutputService >
cond::persistency::Transaction::commit
void commit()
Definition: Session.cc:23
cond::Exception
persistency::Exception Exception
Definition: Exception.h:25
edm::LogVerbatim
Definition: MessageLogger.h:297
l1t::DataWriter::~DataWriter
~DataWriter()
Definition: DataWriter.cc:13
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
cond::persistency::Session::storePayload
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:186
cond::persistency::Session::transaction
Transaction & transaction()
Definition: Session.cc:52
cond::persistency::Transaction::start
void start(bool readOnly=true)
Definition: Session.cc:18
l1t::DataWriter::readObject
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriter.h:72
l1t::DataWriter::fillLastTriggerKeyList
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:147
cond::service::PoolDBOutputService::isNewTagRequest
bool isNewTagRequest(const std::string &recordName)
Definition: PoolDBOutputService.cc:100
dumpRecoGeometry_cfg.tagInfo
tagInfo
Definition: dumpRecoGeometry_cfg.py:194
cond::TagInfo_t
Definition: Types.h:69