CMS 3D CMS Logo

DataWriterExt.cc
Go to the documentation of this file.
2 
6 
8 
9 #include <utility>
10 
11 namespace l1t
12 {
15 
16 
17 
20  const std::string& recordType )
21 {
22  WriterFactory* factory = WriterFactory::get();
23  std::unique_ptr<WriterProxy> writer(factory->create( recordType + "@Writer" )) ;
24  if( writer.get() == nullptr )
25  {
26  throw cond::Exception( "DataWriter: could not create WriterProxy with name "
27  + recordType + "@Writer" ) ;
28  }
29 
31  if (!poolDb.isAvailable())
32  {
33  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
34  ) ;
35  }
36 
37  // 2010-02-16: Move session and transaction to WriterProxy::save(). Otherwise, if another transaction is
38  // started while WriterProxy::save() is called (e.g. in a ESProducer like L1ConfigOnlineProdBase), the
39  // transaction here will become read-only.
40 // cond::DbSession session = poolDb->session();
41 // cond::DbScopedTransaction tr(session);
42 
44 // // if throw transaction will unroll
45 // tr.start(false);
46 
47  // update key to have new payload registered for record-type pair.
48  // std::string payloadToken = writer->save( setup, session ) ;
49  std::string payloadToken = writer->save( setup ) ;
50 
51  edm::LogVerbatim( "L1-O2O" ) << recordType << " PAYLOAD TOKEN "
52  << payloadToken ;
53 
55 // tr.commit ();
56 
57  return payloadToken ;
58 }
59 
60 void
62  edm::RunNumber_t sinceRun,
63  bool logTransactions )
64 {
66  if( !poolDb.isAvailable() )
67  {
68  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
69  ) ;
70  }
71 
72  poolDb->forceInit();
76 
77  // Write L1TriggerKeyListExt payload and save payload token before committing
78  std::shared_ptr<L1TriggerKeyListExt> pointer(keyList);
79  std::string payloadToken = session.storePayload(*pointer );
80 
81  // Commit before calling updateIOV(), otherwise PoolDBOutputService gets
82  // confused.
84  tr.close ();
85 
86  // Set L1TriggerKeyListExt IOV
87  updateIOV( "L1TriggerKeyListExtRcd",
88  payloadToken,
89  sinceRun,
90  logTransactions ) ;
91 }
92 
93 bool
96  edm::RunNumber_t sinceRun,
97  bool logTransactions )
98 {
99  edm::LogVerbatim( "L1-O2O" ) << esRecordName
100  << " PAYLOAD TOKEN " << payloadToken ;
101 
103  if (!poolDb.isAvailable())
104  {
105  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
106  ) ;
107  }
108 
109  bool iovUpdated = true ;
110 
111  if( poolDb->isNewTagRequest( esRecordName ) )
112  {
113  sinceRun = poolDb->beginOfTime() ;
114  poolDb->createNewIOV( payloadToken,
115  sinceRun,
116  poolDb->endOfTime(),
117  esRecordName,
118  logTransactions ) ;
119  }
120  else
121  {
122  cond::TagInfo tagInfo ;
123  poolDb->tagInfo( esRecordName, tagInfo ) ;
124 
125  if( sinceRun == 0 ) // find last since and add 1
126  {
127  sinceRun = tagInfo.lastInterval.first ;
128  ++sinceRun ;
129  }
130 
131  if( tagInfo.lastPayloadToken != payloadToken )
132  {
133  poolDb->appendSinceTime( payloadToken,
134  sinceRun,
135  esRecordName,
136  logTransactions ) ;
137  }
138  else
139  {
140  iovUpdated = false ;
141  edm::LogVerbatim( "L1-O2O" ) << "IOV already up to date." ;
142  }
143  }
144 
145  if( iovUpdated )
146  {
147  edm::LogVerbatim( "L1-O2O" ) << esRecordName << " "
148  << poolDb->tag( esRecordName )
149  << " SINCE " << sinceRun ;
150  }
151 
152  return iovUpdated ;
153 }
154 
158 {
160  if( !poolDb.isAvailable() )
161  {
162  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
163  ) ;
164  }
165 
166  // Get tag corresponding to EventSetup record name.
167  std::string iovTag = poolDb->tag( recordName ) ;
168 
169  // Get IOV token for tag.
171  cond::persistency::IOVProxy iov = session.readIov( iovTag );
172  session.transaction().start();
173 
175  auto iP = iov.find( runNumber );
176  if( iP != iov.end() ){
177  payloadToken = (*iP).payloadId;
178  }
179  session.transaction().commit() ;
180  return payloadToken ;
181 }
182 
185 {
187  if( !poolDb.isAvailable() )
188  {
189  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
190  ) ;
191  }
192 
193  cond::TagInfo tagInfo ;
194  poolDb->tagInfo( recordName, tagInfo ) ;
195  return tagInfo.lastPayloadToken ;
196 }
197 
198 bool
200 {
201  std::string keyListToken =
202  lastPayloadToken( "L1TriggerKeyListExtRcd" ) ;
203  if( keyListToken.empty() )
204  {
205  return false ;
206  }
207  else
208  {
209  readObject( keyListToken, output ) ;
210  return true ;
211  }
212 }
213 
214 } // ns
persistency::Exception Exception
Definition: Exception.h:25
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriterExt.h:79
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
void start(bool readOnly=true)
Definition: Session.cc:22
cond::persistency::Session session() const
std::string lastPayloadToken(const std::string &recordName)
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
delete x;
Definition: CaloConfig.h:22
#define nullptr
void writeKeyList(L1TriggerKeyListExt *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Transaction & transaction()
Definition: Session.cc:66
std::string tag(const std::string &recordName)
cond::ValidityInterval lastInterval
Definition: Types.h:75
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:81
bool isNewTagRequest(const std::string &recordName)
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
bool isAvailable() const
Definition: Service.h:46
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:320
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:76
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:189
unsigned int RunNumber_t
T get(const Candidate &c)
Definition: component.h:55
Iterator end() const
Definition: IOVProxy.cc:297