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 
10 
11 #include <utility>
12 
13 namespace l1t
14 {
17 
18 
19 
22  const std::string& recordType )
23 {
24  WriterFactory* factory = WriterFactory::get();
25  std::auto_ptr<WriterProxy> writer(factory->create( recordType + "@Writer" )) ;
26  if( writer.get() == 0 )
27  {
28  throw cond::Exception( "DataWriter: could not create WriterProxy with name "
29  + recordType + "@Writer" ) ;
30  }
31 
33  if (!poolDb.isAvailable())
34  {
35  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
36  ) ;
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.
42 // cond::DbSession session = poolDb->session();
43 // cond::DbScopedTransaction tr(session);
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 
54 // tr.commit ();
55 
56  return payloadToken ;
57 }
58 
59 void
61  edm::RunNumber_t sinceRun,
62  bool logTransactions )
63 {
65  if( !poolDb.isAvailable() )
66  {
67  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
68  ) ;
69  }
70 
73  tr.start( false );
74 
75  // Write L1TriggerKeyList payload and save payload token before committing
76  boost::shared_ptr<L1TriggerKeyList> pointer(keyList);
77  std::string payloadToken = session.storePayload(*pointer );
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  {
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 
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.
168  cond::persistency::IOVProxy iov = session.readIov( iovTag );
169  session.transaction().start();
170 
172  auto iP = iov.find( runNumber );
173  if( iP != iov.end() ){
174  payloadToken = (*iP).payloadId;
175  }
176  session.transaction().commit() ;
177  return payloadToken ;
178 }
179 
182 {
184  if( !poolDb.isAvailable() )
185  {
186  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
187  ) ;
188  }
189 
191  poolDb->tagInfo( recordName, tagInfo ) ;
192  return tagInfo.lastPayloadToken ;
193 }
194 
195 bool
197 {
198  std::string keyListToken =
199  lastPayloadToken( "L1TriggerKeyListRcd" ) ;
200  if( keyListToken.empty() )
201  {
202  return false ;
203  }
204  else
205  {
206  readObject( keyListToken, output ) ;
207  return true ;
208  }
209 }
210 
211 } // ns
void start(bool readOnly=true)
Definition: Session.cc:22
cond::persistency::Session session() const
Transaction & transaction()
Definition: Session.cc:66
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriter.cc:181
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:153
std::string tag(const std::string &recordName)
cond::ValidityInterval lastInterval
Definition: Types.h:75
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:21
void start(bool readOnly=true)
Definition: Session.cc:292
void writeKeyList(L1TriggerKeyList *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Definition: DataWriter.cc:60
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:196
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:76
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:202
unsigned int RunNumber_t
volatile std::atomic< bool > shutdown_flag false
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:91
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
T get(const Candidate &c)
Definition: component.h:55
Iterator end() const
Definition: IOVProxy.cc:265