CMS 3D CMS Logo

DataWriterExt.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 
44  // tr.commit ();
45 
46  return payloadToken;
47  }
48 
49  void DataWriterExt::writeKeyList(L1TriggerKeyListExt* keyList, edm::RunNumber_t sinceRun, bool logTransactions) {
51  if (!poolDb.isAvailable()) {
52  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
53  }
54 
55  poolDb->forceInit();
56  cond::persistency::Session session = poolDb->session();
59 
60  // Write L1TriggerKeyListExt payload and save payload token before committing
61  std::shared_ptr<L1TriggerKeyListExt> pointer(keyList);
62  std::string payloadToken = session.storePayload(*pointer);
63 
64  // Commit before calling updateIOV(), otherwise PoolDBOutputService gets
65  // confused.
67  tr.close();
68 
69  // Set L1TriggerKeyListExt IOV
70  updateIOV("L1TriggerKeyListExtRcd", payloadToken, sinceRun, logTransactions);
71  }
72 
73  bool DataWriterExt::updateIOV(const std::string& esRecordName,
74  const std::string& payloadToken,
75  edm::RunNumber_t sinceRun,
76  bool logTransactions) {
77  edm::LogVerbatim("L1-O2O") << esRecordName << " PAYLOAD TOKEN " << payloadToken;
78 
80  if (!poolDb.isAvailable()) {
81  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
82  }
83 
84  bool iovUpdated = true;
85 
86  if (poolDb->isNewTagRequest(esRecordName)) {
87  sinceRun = poolDb->beginOfTime();
88  poolDb->createNewIOV(payloadToken, sinceRun, esRecordName);
89  } else {
91  poolDb->tagInfo(esRecordName, tagInfo);
92 
93  if (sinceRun == 0) // find last since and add 1
94  {
95  sinceRun = tagInfo.lastInterval.since;
96  ++sinceRun;
97  }
98 
99  if (tagInfo.lastInterval.payloadId != payloadToken) {
100  poolDb->appendSinceTime(payloadToken, sinceRun, esRecordName);
101  } else {
102  iovUpdated = false;
103  edm::LogVerbatim("L1-O2O") << "IOV already up to date.";
104  }
105  }
106 
107  if (iovUpdated) {
108  edm::LogVerbatim("L1-O2O") << esRecordName << " " << poolDb->tag(esRecordName) << " SINCE " << sinceRun;
109  }
110 
111  return iovUpdated;
112  }
113 
116  if (!poolDb.isAvailable()) {
117  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
118  }
119 
120  // Get tag corresponding to EventSetup record name.
121  std::string iovTag = poolDb->tag(recordName);
122 
123  // Get IOV token for tag.
124  cond::persistency::Session session = poolDb->session();
125  cond::persistency::IOVProxy iov = session.readIov(iovTag);
126  session.transaction().start();
127  auto iovs = iov.selectAll();
129  auto iP = iovs.find(runNumber);
130  if (iP != iovs.end()) {
131  payloadToken = (*iP).payloadId;
132  }
133  session.transaction().commit();
134  return payloadToken;
135  }
136 
139  if (!poolDb.isAvailable()) {
140  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
141  }
142 
144  poolDb->tagInfo(recordName, tagInfo);
145  return tagInfo.lastInterval.payloadId;
146  }
147 
149  std::string keyListToken = lastPayloadToken("L1TriggerKeyListExtRcd");
150  if (keyListToken.empty()) {
151  return false;
152  } else {
153  readObject(keyListToken, output);
154  return true;
155  }
156  }
157 
158 } // namespace l1t
cond::persistency::TransactionScope
Definition: Session.h:231
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
DataWriterExt.h
cond::service::PoolDBOutputService::tag
std::string tag(const std::string &recordName)
Definition: PoolDBOutputService.cc:124
L1TriggerKeyListExt
Definition: L1TriggerKeyListExt.h:10
l1t::DataWriterExt::payloadToken
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriterExt.cc:114
MessageLogger.h
Exception.h
cond::service::PoolDBOutputService::beginOfTime
cond::Time_t beginOfTime() const
Definition: PoolDBOutputService.cc:215
Exception.h
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
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:397
cond::service::PoolDBOutputService::appendSinceTime
void appendSinceTime(const T *payloadObj, cond::Time_t sinceTime, const std::string &recordName)
Definition: PoolDBOutputService.h:141
cscNeutronWriter_cfi.writer
writer
Definition: cscNeutronWriter_cfi.py:6
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
cond::persistency::IOVProxy::selectAll
IOVArray selectAll()
Definition: IOVProxy.cc:175
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:116
cond::service::PoolDBOutputService::session
cond::persistency::Session session() const
Definition: PoolDBOutputService.cc:92
l1t::DataWriterExt::lastPayloadToken
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriterExt.cc:137
l1t::DataWriterExt::DataWriterExt
DataWriterExt()
Definition: DataWriterExt.cc:12
cond::persistency::Session::readIov
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
l1t::DataWriterExt::fillLastTriggerKeyList
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
Definition: DataWriterExt.cc:148
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::IOVProxy
Definition: IOVProxy.h:92
Serialization.h
l1t
delete x;
Definition: CaloConfig.h:22
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::EventSetup
Definition: EventSetup.h:58
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::DataWriterExt::~DataWriterExt
~DataWriterExt()
Definition: DataWriterExt.cc:13
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
l1t::DataWriterExt::writePayload
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
Definition: DataWriterExt.cc:15
cond::service::PoolDBOutputService::isNewTagRequest
bool isNewTagRequest(const std::string &recordName)
Definition: PoolDBOutputService.cc:128
dumpRecoGeometry_cfg.tagInfo
tagInfo
Definition: dumpRecoGeometry_cfg.py:194
cond::TagInfo_t
Definition: Types.h:69
l1t::DataWriterExt::updateIOV
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriterExt.cc:73
l1t::DataWriterExt::readObject
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriterExt.h:72
cond::service::PoolDBOutputService::forceInit
void forceInit()
Definition: PoolDBOutputService.cc:201
l1t::DataWriterExt::writeKeyList
void writeKeyList(L1TriggerKeyListExt *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Definition: DataWriterExt.cc:49