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 ) ;
39  std::string payloadToken = writer->save(setup);
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,
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, poolDb->endOfTime(), esRecordName, logTransactions);
89  } else {
91  poolDb->tagInfo(esRecordName, tagInfo);
92 
93  if (sinceRun == 0) // find last since and add 1
94  {
95  sinceRun = tagInfo.lastInterval.first;
96  ++sinceRun;
97  }
98 
99  if (tagInfo.lastPayloadToken != payloadToken) {
100  poolDb->appendSinceTime(payloadToken, sinceRun, esRecordName, logTransactions);
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 
129  auto iP = iov.find(runNumber);
130  if (iP != iov.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.lastPayloadToken;
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
persistency::Exception Exception
Definition: Exception.h:25
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriterExt.h:72
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
void start(bool readOnly=true)
Definition: Session.cc:18
cond::persistency::Session session() const
std::string lastPayloadToken(const std::string &recordName)
delete x;
Definition: CaloConfig.h:22
void writeKeyList(L1TriggerKeyListExt *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Transaction & transaction()
Definition: Session.cc:43
std::string tag(const std::string &recordName)
cond::ValidityInterval lastInterval
Definition: Types.h:74
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:54
bool isNewTagRequest(const std::string &recordName)
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
bool isAvailable() const
Definition: Service.h:40
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:322
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
void tagInfo(const std::string &recordName, cond::TagInfo_t &result)
std::string lastPayloadToken
Definition: Types.h:75
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:197
unsigned int RunNumber_t
Iterator end() const
Definition: IOVProxy.cc:293