CMS 3D CMS Logo

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 
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.close();
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 
75 
76  // Write L1TriggerKeyList payload and save payload token before committing
77  std::shared_ptr<L1TriggerKeyList> pointer(keyList);
78  std::string payloadToken = session.storePayload(*pointer );
79 
80  // Commit before calling updateIOV(), otherwise PoolDBOutputService gets
81  // confused.
82  //tr.commit ();
83  tr.close ();
84 
85  // Set L1TriggerKeyList IOV
86  updateIOV( "L1TriggerKeyListRcd",
87  payloadToken,
88  sinceRun,
89  logTransactions ) ;
90 }
91 
92 bool
93 DataWriter::updateIOV( const std::string& esRecordName,
95  edm::RunNumber_t sinceRun,
96  bool logTransactions )
97 {
98  edm::LogVerbatim( "L1-O2O" ) << esRecordName
99  << " PAYLOAD TOKEN " << payloadToken ;
100 
102  if (!poolDb.isAvailable())
103  {
104  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
105  ) ;
106  }
107 
108  bool iovUpdated = true ;
109 
110  if( poolDb->isNewTagRequest( esRecordName ) )
111  {
112  sinceRun = poolDb->beginOfTime() ;
113  poolDb->createNewIOV( payloadToken,
114  sinceRun,
115  poolDb->endOfTime(),
116  esRecordName,
117  logTransactions ) ;
118  }
119  else
120  {
121  cond::TagInfo tagInfo ;
122  poolDb->tagInfo( esRecordName, tagInfo ) ;
123 
124  if( sinceRun == 0 ) // find last since and add 1
125  {
126  sinceRun = tagInfo.lastInterval.first ;
127  ++sinceRun ;
128  }
129 
130  if( tagInfo.lastPayloadToken != payloadToken )
131  {
132  poolDb->appendSinceTime( payloadToken,
133  sinceRun,
134  esRecordName,
135  logTransactions ) ;
136  }
137  else
138  {
139  iovUpdated = false ;
140  edm::LogVerbatim( "L1-O2O" ) << "IOV already up to date." ;
141  }
142  }
143 
144  if( iovUpdated )
145  {
146  edm::LogVerbatim( "L1-O2O" ) << esRecordName << " "
147  << poolDb->tag( esRecordName )
148  << " SINCE " << sinceRun ;
149  }
150 
151  return iovUpdated ;
152 }
153 
157 {
159  if( !poolDb.isAvailable() )
160  {
161  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
162  ) ;
163  }
164 
165  // Get tag corresponding to EventSetup record name.
166  std::string iovTag = poolDb->tag( recordName ) ;
167 
168  // Get IOV token for tag.
170  cond::persistency::IOVProxy iov = session.readIov( iovTag );
171  session.transaction().start();
172 
174  auto iP = iov.find( runNumber );
175  if( iP != iov.end() ){
176  payloadToken = (*iP).payloadId;
177  }
178  session.transaction().commit() ;
179  return payloadToken ;
180 }
181 
184 {
186  if( !poolDb.isAvailable() )
187  {
188  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
189  ) ;
190  }
191 
192  cond::TagInfo tagInfo ;
193  poolDb->tagInfo( recordName, tagInfo ) ;
194  return tagInfo.lastPayloadToken ;
195 }
196 
197 bool
199 {
200  std::string keyListToken =
201  lastPayloadToken( "L1TriggerKeyListRcd" ) ;
202  if( keyListToken.empty() )
203  {
204  return false ;
205  }
206  else
207  {
208  readObject( keyListToken, output ) ;
209  return true ;
210  }
211 }
212 
213 } // ns
persistency::Exception Exception
Definition: Exception.h:25
void start(bool readOnly=true)
Definition: Session.cc:22
cond::persistency::Session session() const
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
delete x;
Definition: CaloConfig.h:22
Transaction & transaction()
Definition: Session.cc:66
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriter.cc:183
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:155
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
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:46
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:320
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:61
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:198
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:189
unsigned int RunNumber_t
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:93
T get(const Candidate &c)
Definition: component.h:55
Iterator end() const
Definition: IOVProxy.cc:297