CMS 3D CMS Logo

DataWriterExt.cc
Go to the documentation of this file.
2 
6 
8 
9 #include <utility>
10 #include <typeinfo>
11 
12 namespace l1t {
13 
14  // Default Constructor
16 
17  // Constructor Needed for Writers with Rcds dependednt on Online Producers
18  // they need to be constructed at "construction time" to register what they produce
20  WriterFactory* factory = WriterFactory::get();
21  writer_ = factory->create(recordType + "@Writer");
22  if (writer_.get() == nullptr) {
23  throw cond::Exception("DataWriter: could not create WriterProxy with name " + recordType + "@Writer");
24  }
25  edm::LogVerbatim("L1-O2O DataWriterExt::DataWriterExt")
26  << "Created new " << typeid(writer_).name() << " | address " << writer_.get() << " | rcd " << recordType;
27  }
28 
30 
32  edm::LogVerbatim("L1-O2O DataWriterExt::writePayload") << "Will use stored writer at " << writer_.get();
33 
35  if (!poolDb.isAvailable()) {
36  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
37  }
38 
39  // 2010-02-16: Move session and transaction to WriterProxy::save(). Otherwise, if another transaction is
40  // started while WriterProxy::save() is called (e.g. in a ESProducer like L1ConfigOnlineProdBase), the
41  // transaction here will become read-only.
43  auto& writerRef = *writer_.get();
44  edm::LogVerbatim("L1-O2O") << typeid(writerRef).name() << " PAYLOAD TOKEN " << payloadToken;
45 
46  return payloadToken;
47  }
48 
50  WriterFactory* factory = WriterFactory::get();
51  WriterProxyPtr writer(factory->create(recordType + "@Writer"));
52  if (writer.get() == nullptr) {
53  throw cond::Exception("DataWriter: could not create WriterProxy with name " + recordType + "@Writer");
54  }
56 
58  if (!poolDb.isAvailable()) {
59  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
60  }
61 
62  // 2010-02-16: Move session and transaction to WriterProxy::save(). Otherwise, if another transaction is
63  // started while WriterProxy::save() is called (e.g. in a ESProducer like L1ConfigOnlineProdBase), the
64  // transaction here will become read-only.
65  // cond::DbSession session = poolDb->session();
66  // cond::DbScopedTransaction tr(session);
67 
69  // // if throw transaction will unroll
70  // tr.start(false);
71 
72  // update key to have new payload registered for record-type pair.
73  // std::string payloadToken = writer->save( setup, session ) ;
75  auto& writerRef = *writer_.get();
76  edm::LogVerbatim("L1-O2O") << typeid(writerRef).name() << " PAYLOAD TOKEN " << payloadToken;
77 
79  // tr.commit ();
80 
81  return payloadToken;
82  }
83 
86  if (!poolDb.isAvailable()) {
87  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
88  }
89 
90  poolDb->forceInit();
92  if (not session.transaction().isActive())
93  session.transaction().start(false);
94 
95  // Write L1TriggerKeyListExt payload and save payload token before committing
96  std::shared_ptr<L1TriggerKeyListExt> pointer(keyList);
97  std::string payloadToken = session.storePayload(*pointer);
98 
99  // Commit before calling updateIOV(), otherwise PoolDBOutputService gets
100  // confused. ??? why?
101 
102  // Set L1TriggerKeyListExt IOV
103  session.transaction().commit();
104  updateIOV("L1TriggerKeyListExtRcd", payloadToken, sinceRun, logTransactions);
105  }
106 
107  bool DataWriterExt::updateIOV(const std::string& esRecordName,
108  const std::string& payloadToken,
110  bool logTransactions) {
111  edm::LogVerbatim("L1-O2O") << esRecordName << " PAYLOAD TOKEN " << payloadToken;
112 
114  if (!poolDb.isAvailable()) {
115  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
116  }
117 
118  bool iovUpdated = true;
119 
120  if (poolDb->isNewTagRequest(esRecordName)) {
121  sinceRun = poolDb->beginOfTime();
122  poolDb->createNewIOV(payloadToken, sinceRun, esRecordName);
123  } else {
125  poolDb->tagInfo(esRecordName, tagInfo);
126 
127  if (sinceRun == 0) // find last since and add 1
128  {
129  sinceRun = tagInfo.lastInterval.since;
130  ++sinceRun;
131  }
132 
133  if (tagInfo.lastInterval.payloadId != payloadToken) {
134  poolDb->appendSinceTime(payloadToken, sinceRun, esRecordName);
135  } else {
136  iovUpdated = false;
137  edm::LogVerbatim("L1-O2O") << "IOV already up to date.";
138  }
139  }
140 
141  if (iovUpdated) {
142  edm::LogVerbatim("L1-O2O") << esRecordName << " " << poolDb->tag(esRecordName) << " SINCE " << sinceRun;
143  }
144 
145  return iovUpdated;
146  }
147 
150  if (!poolDb.isAvailable()) {
151  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
152  }
153 
154  // Get tag corresponding to EventSetup record name.
155  std::string iovTag = poolDb->tag(recordName);
156 
157  // Get IOV token for tag.
159  cond::persistency::IOVProxy iov = session.readIov(iovTag);
160  session.transaction().start();
161  auto iovs = iov.selectAll();
163  auto iP = iovs.find(runNumber);
164  if (iP != iovs.end()) {
165  payloadToken = (*iP).payloadId;
166  }
167  session.transaction().commit();
168  return payloadToken;
169  }
170 
173  if (!poolDb.isAvailable()) {
174  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
175  }
176 
178  poolDb->tagInfo(recordName, tagInfo);
179  return tagInfo.lastInterval.payloadId;
180  }
181 
183  std::string keyListToken = lastPayloadToken("L1TriggerKeyListExtRcd");
184  if (keyListToken.empty()) {
185  return false;
186  } else {
187  readObject(keyListToken, output);
188  return true;
189  }
190  }
191 
192 } // namespace l1t
persistency::Exception Exception
Definition: Exception.h:25
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriterExt.h:81
Log< level::Info, true > LogVerbatim
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
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)
std::string tag(const std::string &recordName)
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
bool isNewTagRequest(const std::string &recordName)
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
std::unique_ptr< WriterProxy > WriterProxyPtr
Definition: DataWriterExt.h:35
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)
WriterProxyPtr writer_
Definition: DataWriterExt.h:75
std::string writePayload(const edm::EventSetup &setup)
bool isAvailable() const
Definition: Service.h:40
Definition: output.py:1
unsigned int RunNumber_t
#define get
bool tagInfo(const std::string &recordName, cond::TagInfo_t &result)
def move(src, dest)
Definition: eostools.py:511
cond::persistency::Session session() const