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 
8 
9 #include <utility>
10 
11 namespace l1t
12 {
15 
16 
17 
18 std::string
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 
69  cond::DbSession session = poolDb->session();
70  cond::DbScopedTransaction tr(session);
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.storeObject(pointer.get(),
77  );
78 
79  // Commit before calling updateIOV(), otherwise PoolDBOutputService gets
80  // confused.
81  tr.commit ();
82 
83  // Set L1TriggerKeyList IOV
84  updateIOV( "L1TriggerKeyListRcd",
85  payloadToken,
86  sinceRun,
87  logTransactions ) ;
88 }
89 
90 bool
91 DataWriter::updateIOV( const std::string& esRecordName,
92  const std::string& payloadToken,
93  edm::RunNumber_t sinceRun,
94  bool logTransactions )
95 {
96  edm::LogVerbatim( "L1-O2O" ) << esRecordName
97  << " PAYLOAD TOKEN " << payloadToken ;
98 
100  if (!poolDb.isAvailable())
101  {
102  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
103  ) ;
104  }
105 
106  bool iovUpdated = true ;
107 
108  if( poolDb->isNewTagRequest( esRecordName ) )
109  {
110  sinceRun = poolDb->beginOfTime() ;
111  poolDb->createNewIOV( payloadToken,
112  sinceRun,
113  poolDb->endOfTime(),
114  esRecordName,
115  logTransactions ) ;
116  }
117  else
118  {
119  cond::TagInfo tagInfo ;
120  poolDb->tagInfo( esRecordName, tagInfo ) ;
121 
122  if( sinceRun == 0 ) // find last since and add 1
123  {
124  sinceRun = tagInfo.lastInterval.first ;
125  ++sinceRun ;
126  }
127 
128  if( tagInfo.lastPayloadToken != payloadToken )
129  {
130  poolDb->appendSinceTime( payloadToken,
131  sinceRun,
132  esRecordName,
133  logTransactions ) ;
134  }
135  else
136  {
137  iovUpdated = false ;
138  edm::LogVerbatim( "L1-O2O" ) << "IOV already up to date." ;
139  }
140  }
141 
142  if( iovUpdated )
143  {
144  edm::LogVerbatim( "L1-O2O" ) << esRecordName << " "
145  << poolDb->tag( esRecordName )
146  << " SINCE " << sinceRun ;
147  }
148 
149  return iovUpdated ;
150 }
151 
152 std::string
155 {
157  if( !poolDb.isAvailable() )
158  {
159  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
160  ) ;
161  }
162 
163  // Get tag corresponding to EventSetup record name.
164  std::string iovTag = poolDb->tag( recordName ) ;
165 
166  // Get IOV token for tag.
167  cond::DbSession session = poolDb->session();
168  cond::DbScopedTransaction tr(session);
169  tr.start(true);
170  cond::MetaData metadata(session ) ;
171  std::string iovToken ;
172  if( metadata.hasTag( iovTag ) )
173  {
174  iovToken = metadata.getToken( iovTag ) ;
175  }
176  if( iovToken.empty() )
177  {
178  return std::string() ;
179  }
180 
181  // Get payload token for run number.
182 
183  cond::IOVProxy iov( session );
184  iov.load(iovToken ) ;
185  std::string payloadToken("");
186  cond::IOVProxy::const_iterator iP = iov.find( runNumber );
187  if( iP != iov.end() ){
188  payloadToken = iP->token();
189  }
190  tr.commit() ;
191  return payloadToken ;
192 }
193 
194 std::string
196 {
198  if( !poolDb.isAvailable() )
199  {
200  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
201  ) ;
202  }
203 
204  cond::TagInfo tagInfo ;
205  poolDb->tagInfo( recordName, tagInfo ) ;
206  return tagInfo.lastPayloadToken ;
207 }
208 
209 bool
211 {
212  std::string keyListToken =
213  lastPayloadToken( "L1TriggerKeyListRcd" ) ;
214  if( keyListToken.empty() )
215  {
216  return false ;
217  }
218  else
219  {
220  readObject( keyListToken, output ) ;
221  return true ;
222  }
223 }
224 
225 } // ns
const std::string getToken(const std::string &tagname) const
Definition: MetaData.cc:53
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriter.cc:195
const_iterator end() const
Definition: IOVProxy.h:193
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:153
std::string lastPayloadToken
Definition: TagInfo.h:12
std::string tag(const std::string &recordName)
std::string classNameForTypeId(const std::type_info &typeInfo)
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
const_iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:264
tuple iov
Definition: o2o.py:307
bool isNewTagRequest(const std::string &recordName)
bool hasTag(const std::string &name) const
Definition: MetaData.cc:70
bool isAvailable() const
Definition: Service.h:47
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
Definition: DataWriter.cc:19
void writeKeyList(L1TriggerKeyList *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Definition: DataWriter.cc:58
int start(bool readOnly=false)
start transaction
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:210
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:131
void tagInfo(const std::string &recordName, cond::TagInfo &result)
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriter.h:82
cond::ValidityInterval lastInterval
Definition: TagInfo.h:11
unsigned int RunNumber_t
Definition: EventRange.h:32
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:91
int commit()
commit transaction. Will disconnect from database if connection timeout==0 or connectted time close t...
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
iov_range_iterator const_iterator
Definition: IOVProxy.h:160
T get(const Candidate &c)
Definition: component.h:56
void load(const std::string &token)
Definition: IOVProxy.cc:197