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 
9 
10 #include <utility>
11 
12 namespace l1t
13 {
16 
17 
18 
19 std::string
21  const std::string& recordType )
22 {
23  WriterFactory* factory = WriterFactory::get();
24  std::auto_ptr<WriterProxy> writer(factory->create( recordType + "@Writer" )) ;
25  if( writer.get() == 0 )
26  {
27  throw cond::Exception( "DataWriter: could not create WriterProxy with name "
28  + recordType + "@Writer" ) ;
29  }
30 
32  if (!poolDb.isAvailable())
33  {
34  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
35  ) ;
36  }
37 
38  // 2010-02-16: Move session and transaction to WriterProxy::save(). Otherwise, if another transaction is
39  // started while WriterProxy::save() is called (e.g. in a ESProducer like L1ConfigOnlineProdBase), the
40  // transaction here will become read-only.
41 // cond::DbSession session = poolDb->session();
42 // cond::DbScopedTransaction tr(session);
43 // // if throw transaction will unroll
44 // tr.start(false);
45 
46  // update key to have new payload registered for record-type pair.
47  // std::string payloadToken = writer->save( setup, session ) ;
48  std::string payloadToken = writer->save( setup ) ;
49 
50  edm::LogVerbatim( "L1-O2O" ) << recordType << " PAYLOAD TOKEN "
51  << payloadToken ;
52 
53 // tr.commit ();
54 
55  return payloadToken ;
56 }
57 
58 void
60  edm::RunNumber_t sinceRun,
61  bool logTransactions )
62 {
64  if( !poolDb.isAvailable() )
65  {
66  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
67  ) ;
68  }
69 
70  cond::DbSession session = poolDb->session();
71  cond::DbScopedTransaction tr(session);
72  tr.start(false);
73 
74  // Write L1TriggerKeyList payload and save payload token before committing
75  boost::shared_ptr<L1TriggerKeyList> pointer(keyList);
76  std::string payloadToken = session.storeObject(pointer.get(),
78  );
79 
80  // Commit before calling updateIOV(), otherwise PoolDBOutputService gets
81  // confused.
82  tr.commit ();
83 
84  // Set L1TriggerKeyList IOV
85  updateIOV( "L1TriggerKeyListRcd",
86  payloadToken,
87  sinceRun,
88  logTransactions ) ;
89 }
90 
91 bool
92 DataWriter::updateIOV( const std::string& esRecordName,
93  const std::string& payloadToken,
94  edm::RunNumber_t sinceRun,
95  bool logTransactions )
96 {
97  edm::LogVerbatim( "L1-O2O" ) << esRecordName
98  << " PAYLOAD TOKEN " << payloadToken ;
99 
101  if (!poolDb.isAvailable())
102  {
103  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
104  ) ;
105  }
106 
107  bool iovUpdated = true ;
108 
109  if( poolDb->isNewTagRequest( esRecordName ) )
110  {
111  sinceRun = poolDb->beginOfTime() ;
112  poolDb->createNewIOV( payloadToken,
113  sinceRun,
114  poolDb->endOfTime(),
115  esRecordName,
116  logTransactions ) ;
117  }
118  else
119  {
120  cond::TagInfo tagInfo ;
121  poolDb->tagInfo( esRecordName, tagInfo ) ;
122 
123  if( sinceRun == 0 ) // find last since and add 1
124  {
125  sinceRun = tagInfo.lastInterval.first ;
126  ++sinceRun ;
127  }
128 
129  if( tagInfo.lastPayloadToken != payloadToken )
130  {
131  poolDb->appendSinceTime( payloadToken,
132  sinceRun,
133  esRecordName,
134  logTransactions ) ;
135  }
136  else
137  {
138  iovUpdated = false ;
139  edm::LogVerbatim( "L1-O2O" ) << "IOV already up to date." ;
140  }
141  }
142 
143  if( iovUpdated )
144  {
145  edm::LogVerbatim( "L1-O2O" ) << 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::IOVService iovService( session ) ;
184  std::string payloadToken = iovService.payloadToken( iovToken, runNumber ) ;
185 
186  tr.commit() ;
187  return payloadToken ;
188 }
189 
190 std::string
192 {
194  if( !poolDb.isAvailable() )
195  {
196  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
197  ) ;
198  }
199 
200  cond::TagInfo tagInfo ;
201  poolDb->tagInfo( recordName, tagInfo ) ;
202  return tagInfo.lastPayloadToken ;
203 }
204 
205 bool
207 {
208  std::string keyListToken =
209  lastPayloadToken( "L1TriggerKeyListRcd" ) ;
210  if( keyListToken.empty() )
211  {
212  return false ;
213  }
214  else
215  {
216  readObject( keyListToken, output ) ;
217  return true ;
218  }
219 }
220 
221 } // ns
const std::string getToken(const std::string &tagname) const
Definition: MetaData.cc:53
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriter.cc:191
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:153
std::string lastPayloadToken
Definition: TagInfo.h:12
std::string payloadToken(const std::string &iovToken, cond::Time_t currenttime)
Definition: IOVService.cc:38
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)
bool isNewTagRequest(const std::string &recordName)
bool hasTag(const std::string &name) const
Definition: MetaData.cc:72
bool isAvailable() const
Definition: Service.h:47
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
Definition: DataWriter.cc:20
void writeKeyList(L1TriggerKeyList *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Definition: DataWriter.cc:59
int start(bool readOnly=false)
start transaction
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:206
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:104
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:92
int commit()
commit transaction. Will disconnect from database if connection timeout==0 or connectted time close t...
T get(const Candidate &c)
Definition: component.h:56