CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DataWriter.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::auto_ptr<WriterProxy> writer(factory->create( recordType + "@Writer" )) ;
24  if( writer.get() == 0 )
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 // // if throw transaction will unroll
43 // tr.start(false);
44 
45  // update key to have new payload registered for record-type pair.
46  // std::string payloadToken = writer->save( setup, session ) ;
47  std::string payloadToken = writer->save( setup ) ;
48 
49  edm::LogVerbatim( "L1-O2O" ) << recordType << " PAYLOAD TOKEN "
50  << payloadToken ;
51 
52 // tr.commit ();
53 
54  return payloadToken ;
55 }
56 
57 void
59  edm::RunNumber_t sinceRun,
60  bool logTransactions )
61 {
63  if( !poolDb.isAvailable() )
64  {
65  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
66  ) ;
67  }
68 
71  tr.start( false );
72 
73  // Write L1TriggerKeyList payload and save payload token before committing
74  boost::shared_ptr<L1TriggerKeyList> pointer(keyList);
75  std::string payloadToken = session.storePayload(*pointer );
76 
77  // Commit before calling updateIOV(), otherwise PoolDBOutputService gets
78  // confused.
79  tr.commit ();
80 
81  // Set L1TriggerKeyList IOV
82  updateIOV( "L1TriggerKeyListRcd",
83  payloadToken,
84  sinceRun,
85  logTransactions ) ;
86 }
87 
88 bool
89 DataWriter::updateIOV( const std::string& esRecordName,
90  const std::string& payloadToken,
91  edm::RunNumber_t sinceRun,
92  bool logTransactions )
93 {
94  edm::LogVerbatim( "L1-O2O" ) << esRecordName
95  << " PAYLOAD TOKEN " << payloadToken ;
96 
98  if (!poolDb.isAvailable())
99  {
100  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
101  ) ;
102  }
103 
104  bool iovUpdated = true ;
105 
106  if( poolDb->isNewTagRequest( esRecordName ) )
107  {
108  sinceRun = poolDb->beginOfTime() ;
109  poolDb->createNewIOV( payloadToken,
110  sinceRun,
111  poolDb->endOfTime(),
112  esRecordName,
113  logTransactions ) ;
114  }
115  else
116  {
118  poolDb->tagInfo( esRecordName, tagInfo ) ;
119 
120  if( sinceRun == 0 ) // find last since and add 1
121  {
122  sinceRun = tagInfo.lastInterval.first ;
123  ++sinceRun ;
124  }
125 
126  if( tagInfo.lastPayloadToken != payloadToken )
127  {
128  poolDb->appendSinceTime( payloadToken,
129  sinceRun,
130  esRecordName,
131  logTransactions ) ;
132  }
133  else
134  {
135  iovUpdated = false ;
136  edm::LogVerbatim( "L1-O2O" ) << "IOV already up to date." ;
137  }
138  }
139 
140  if( iovUpdated )
141  {
142  edm::LogVerbatim( "L1-O2O" ) << esRecordName << " "
143  << poolDb->tag( esRecordName )
144  << " SINCE " << sinceRun ;
145  }
146 
147  return iovUpdated ;
148 }
149 
153 {
155  if( !poolDb.isAvailable() )
156  {
157  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
158  ) ;
159  }
160 
161  // Get tag corresponding to EventSetup record name.
162  std::string iovTag = poolDb->tag( recordName ) ;
163 
164  // Get IOV token for tag.
166  cond::persistency::IOVProxy iov = session.readIov( iovTag );
167  session.transaction().start();
168 
170  auto iP = iov.find( runNumber );
171  if( iP != iov.end() ){
172  payloadToken = (*iP).payloadId;
173  }
174  session.transaction().commit() ;
175  return payloadToken ;
176 }
177 
180 {
182  if( !poolDb.isAvailable() )
183  {
184  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
185  ) ;
186  }
187 
189  poolDb->tagInfo( recordName, tagInfo ) ;
190  return tagInfo.lastPayloadToken ;
191 }
192 
193 bool
195 {
196  std::string keyListToken =
197  lastPayloadToken( "L1TriggerKeyListRcd" ) ;
198  if( keyListToken.empty() )
199  {
200  return false ;
201  }
202  else
203  {
204  readObject( keyListToken, output ) ;
205  return true ;
206  }
207 }
208 
209 } // ns
persistency::Exception Exception
Definition: Exception.h:25
void start(bool readOnly=true)
Definition: Session.cc:22
cond::persistency::Session session() const
tuple recordName
Definition: align_cfg.py:66
Transaction & transaction()
Definition: Session.cc:66
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriter.cc:179
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:151
std::string tag(const std::string &recordName)
cond::ValidityInterval lastInterval
Definition: Types.h:73
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
tuple iov
Definition: o2o.py:307
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:46
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:288
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
Definition: DataWriter.cc:19
void start(bool readOnly=true)
Definition: Session.cc:227
void writeKeyList(L1TriggerKeyList *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Definition: DataWriter.cc:58
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:194
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriter.h:79
void tagInfo(const std::string &recordName, cond::TagInfo_t &result)
std::string lastPayloadToken
Definition: Types.h:74
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:177
unsigned int RunNumber_t
volatile std::atomic< bool > shutdown_flag false
session
Definition: models.py:201
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:89
T get(const Candidate &c)
Definition: component.h:55
Iterator end() const
Definition: IOVProxy.cc:265