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 
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,
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.
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
persistency::Exception Exception
Definition: Exception.h:25
Log< level::Info, true > LogVerbatim
delete x;
Definition: CaloConfig.h:22
Transaction & transaction()
Definition: Session.cc:52
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriter.cc:136
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)
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
Definition: DataWriter.cc:15
void writeKeyList(L1TriggerKeyList *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Definition: DataWriter.cc:49
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:147
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriter.h:72
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
Definition: output.py:1
unsigned int RunNumber_t
#define get
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:72
bool tagInfo(const std::string &recordName, cond::TagInfo_t &result)
cond::persistency::Session session() const