CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OraDbSchema.cc
Go to the documentation of this file.
2 #include "OraDbSchema.h"
3 //
9 //
10 // externals
11 #include "RelationalAccess/ISchema.h"
12 
13 namespace cond {
14 
15  namespace persistency {
16 
18  m_iovAccess( s ){
19  }
20 
22  return m_iovAccess.proxy().db();
23  }
24 
26  return m_iovAccess.proxy();
27  }
28 
30  return m_iovAccess;
31  }
32 
34  cond::MetaData metadata( session() );
35  return metadata.hasTag( t );
36  }
37 
39  if( tag != m_tag ){
40  cond::MetaData metadata( session() );
41  m_tag = tag;
42  m_token = metadata.getToken( tag );
43  }
44  return m_token;
45  }
46 
47  void IOVCache::addTag( const std::string& tag, const std::string token ){
48  if( tag != m_tag ){
49  cond::MetaData metadata( session() );
50  metadata.addMapping( tag, token );
51  m_tag = tag;
52  m_token = token;
53  }
54  }
55 
56  bool IOVCache::load( const std::string& tag ){
57  std::string token = getToken( tag );
58  if( token.empty() ) return false;
59  if(m_iovAccess.token() != token) m_iovAccess.load( token );
60  return true;
61  }
62 
64  m_cache( cache ){
65  }
66 
68  return m_cache.existsTag( name );
69  }
70 
71  bool OraTagTable::select( const std::string& name, cond::TimeType& timeType, std::string& objectType,
72  cond::SynchronizationType&, cond::Time_t& endOfValidity,
73  std::string& description, cond::Time_t& lastValidatedTime ){
74  if(!m_cache.load( name )) return false;
75  if( m_cache.iovSequence().size()==0 ) return false;
76  timeType = m_cache.iovSequence().timetype();
78  objectType = m_cache.session().classNameForItem( ptok );
79  //if( m_cache.iovSequence().payloadClasses().size()==0 ) throwException( "No payload type information found.","OraTagTable::select");
80  //objectType = *m_cache.iovSequence().payloadClasses().begin();
81  endOfValidity = m_cache.iovSequence().lastTill();
82  description = m_cache.iovSequence().comment();
83  lastValidatedTime = m_cache.iovSequence().tail(1).back().since();
84  return true;
85  }
86 
88  boost::posix_time::ptime&, boost::posix_time::ptime& modificationTime){
89  if(!m_cache.load( name )) return false;
90  description = m_cache.iovSequence().comment();
91  modificationTime = cond::time::to_boost( m_cache.iovSequence().timestamp() );
92  // TO DO: get insertion time from the Logger?
93  return true;
94  }
95 
98  cond::Time_t, const boost::posix_time::ptime& ){
99  std::string tok = m_cache.editor().create( timeType, endOfValidity );
100  if( !m_cache.validationMode() ){
101  m_cache.editor().stamp( description );
102  }
103  m_cache.addTag( name, tok );
104  }
105 
107  cond::Time_t, const boost::posix_time::ptime& ){
108 
109  std::string tok = m_cache.getToken( name );
110  if( tok.empty() ) throwException( "Tag \""+name+"\" has not been found in the database.","OraTagTable::update");
111  m_cache.editor().load( tok );
112  m_cache.editor().updateClosure( endOfValidity );
113  if( !m_cache.validationMode() ) m_cache.editor().stamp( description );
114  }
115 
117  const boost::posix_time::ptime& ){
118  // can't be done in this case...
119  }
120 
123  }
124 
126  m_session( session ){
127  }
128 
129  bool OraPayloadTable::select( const cond::Hash& payloadHash,
130  std::string& objectType,
131  cond::Binary& payloadData,
132  cond::Binary& //streamerInfoData
133  ){
135  try {
136  obj = m_session.getObject( payloadHash );
137  } catch( const ora::Exception& e ){
138  // hack to trap the non-existance of the object
139  if( e.explainSelf().find("has not been found in the database. from ReadBuffer::read") != std::string::npos ) {
140  return false;
141  } else throw;
142  }
143  objectType = obj.typeName();
144  payloadData.fromOraObject(obj );
145  return true;
146  }
147 
148  bool OraPayloadTable::getType( const cond::Hash& payloadHash, std::string& objectType ){
149  objectType = m_session.classNameForItem( payloadHash );
150  return true;
151  }
152 
154  const cond::Binary& payloadData,
155  const cond::Binary&, //streamerInfoData
156  const boost::posix_time::ptime& ){
157  ora::Object obj = payloadData.oraObject();
158  std::string tok = m_session.storeObject( obj, objectType );
159  m_session.flush();
160  return tok;
161  }
162 
164  m_cache( iovCache ){
165  }
166 
167  size_t OraIOVTable::selectGroups( const std::string& tag, std::vector<cond::Time_t>& groups ){
168  if(!m_cache.load( tag )) return 0;
169  if( m_cache.iovSequence().size()>0 ){
170  groups.push_back( m_cache.iovSequence().firstSince() );
171  groups.push_back( m_cache.iovSequence().lastTill() );
172  return true;
173  }
174  return false;
175  }
176 
177  size_t OraIOVTable::selectSnapshotGroups( const std::string& tag, const boost::posix_time::ptime&,
178  std::vector<cond::Time_t>& groups ){
179  // no (easy) way to do it...
180  return selectGroups( tag, groups );
181  }
182 
184  std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs){
185  if(!m_cache.load( tag )) return 0;
186  cond::IOVRange range = m_cache.iovSequence().range( lowerGroup, upperGroup );
187  size_t ret = 0;
188  for( auto iov : range ){
189  iovs.push_back( std::make_tuple( iov.since(), iov.token() ) );
190  ret++;
191  }
192  return ret;
193  }
194 
196  const boost::posix_time::ptime&,
197  std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs){
198  // no (easy) way to do it...
199  return selectLatestByGroup( tag, lowerGroup, upperGroup, iovs );
200  }
201 
202  size_t OraIOVTable::selectLatest( const std::string& tag, std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs){
203  // avoid this! copying the entire iov sequence...
204  if(!m_cache.load( tag )) return 0;
205  size_t ret = 0;
206  for( auto iov : m_cache.iovSequence() ){
207  iovs.push_back( std::make_tuple( iov.since(), iov.token() ) );
208  ret++;
209  }
210  return ret;
211  }
212 
214  if(!m_cache.load( tag ) || m_cache.iovSequence().size()==0 ) return false;
216  since = last.since();
217  hash = last.token();
218  return true;
219  }
220 
221  bool OraIOVTable::getSize( const std::string& tag, size_t& size ){
222  if(!m_cache.load( tag )) return false;
223  size = m_cache.iovSequence().size();
224  return true;
225  }
226 
227  bool OraIOVTable::getSnapshotSize( const std::string& tag, const boost::posix_time::ptime&, size_t& size ){
228  // no (easy) way to do it...
229  return getSize( tag,size );
230  }
231 
232  void OraIOVTable::insertOne( const std::string& tag, cond::Time_t since, cond::Hash payloadHash,
233  const boost::posix_time::ptime& ){
234  if(!m_cache.load(tag)) throwException("Tag "+tag+" has not been found in the database.",
235  "OraIOVTable::insertOne");
236  if( m_cache.editor().timetype() != cond::hash ){
237  m_cache.editor().append( since, payloadHash );
238  } else {
239  m_cache.editor().freeInsert( since, payloadHash );
240  }
241  }
242 
244  const std::vector<std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime> >& iovs ){
245  if(!m_cache.load(tag)) throwException("Tag "+tag+" has not been found in the database.",
246  "OraIOVTable::insertOne");
247  if( m_cache.editor().timetype() != cond::hash ){
248  std::vector<std::pair<cond::Time_t, std::string > > data;
249  data.reserve( iovs.size() );
250  for( auto v : iovs ){
251  data.push_back( std::make_pair( std::get<0>(v), std::get<1>(v) ) );
252  }
253  m_cache.editor().bulkAppend( data );
254  } else {
255  for( auto v: iovs ){
256  insertOne( tag, std::get<0>(v), std::get<1>(v), std::get<2>(v) );
257  }
258  }
259  }
260 
262  throwException( "Erase iovs from ORA database is not supported.",
263  "OraIOVTable::erase" );
264  }
265 
267  m_cache( session ),
268  m_tagTable( m_cache ),
269  m_iovTable( m_cache ),
270  m_payloadTable( session ){
271  };
272 
274  return m_cache.session().storage().exists();
275  }
276 
278  return m_cache.session().createDatabase();
279  }
280 
282  return m_tagTable;
283  }
284 
286  return m_iovTable;
287  }
288 
290  return m_payloadTable;
291  }
292 
294  throwException("Tag Migration interface is not available in this implementation.",
295  "OraIOVSchema::tagMigrationTable");
296  }
297 
299  throwException("Payload Migration interface is not available in this implementation.",
300  "OraIOVSchema::payloadMigrationTable");
301  }
302 
305  return parser.parse( poolToken ).toString();
306  }
307 
309  m_session( session ){
310  }
311 
313  cond::TagCollectionRetriever gtRetriever( m_session, "", "" );
314  return gtRetriever.existsTagCollection( name+"::All" );
315  }
316 
317  bool OraGTTable::select( const std::string& name, cond::Time_t& validity, boost::posix_time::ptime& snapshotTime){
318  bool ret = false;
319  if( select( name ) ){
320  ret = true;
321  validity = cond::time::MAX_VAL;
322  snapshotTime = boost::posix_time::ptime();
323  }
324  return ret;
325  }
326 
328  std::string&, boost::posix_time::ptime& snapshotTime){
329  return select( name, validity, snapshotTime );
330  }
331 
333  const boost::posix_time::ptime&, const boost::posix_time::ptime& ){
334  // not supported...
335  }
336 
338  const boost::posix_time::ptime&, const boost::posix_time::ptime& ){
339  // not supported...
340  }
341 
343  m_session( session ){
344  }
345 
346  bool OraGTMapTable::select( const std::string& gtName, std::vector<std::tuple<std::string,std::string,std::string> >& tags ){
347  return select( gtName, "", "", tags );
348  }
349 
350  bool OraGTMapTable::select( const std::string& gtName, const std::string& preFix, const std::string& postFix,
351  std::vector<std::tuple<std::string,std::string,std::string> >& tags ){
352  std::set<cond::TagMetadata> tmp;
353  cond::TagCollectionRetriever gtRetriever( m_session, preFix, postFix );
354  if(!gtRetriever.selectTagCollection( gtName, tmp ) ) return false;
355  if( tmp.size() ) tags.resize( tmp.size() );
356  size_t i = 0;
357  for( const auto& m : tmp ){
358  std::string tagFullName = m.tag+"@["+m.pfn+"]";
359  tags[ i ] = std::make_tuple( m.recordname, m.labelname, tagFullName );
360  i++;
361  }
362  return true;
363  }
364 
365  void OraGTMapTable::insert( const std::string& gtName, const std::vector<std::tuple<std::string,std::string,std::string> >& tags ){
366  // not supported...
367  }
368 
370  m_session( session ),
371  m_gtTable( session ),
372  m_gtMapTable( session ){
373  }
374 
376  cond::TagCollectionRetriever gtRetriever( m_session, "", "" );
377  return gtRetriever.existsTagDatabase();
378  }
379 
381  return m_gtTable;
382  }
383 
385  return m_gtMapTable;
386  }
387 
388  }
389 }
bool select(const std::string &name)
Definition: OraDbSchema.cc:67
void update(const std::string &name, cond::Time_t validity, const std::string &description, const std::string &release, const boost::posix_time::ptime &snapshotTime, const boost::posix_time::ptime &insertionTime)
Definition: OraDbSchema.cc:337
bool getSnapshotSize(const std::string &tag, const boost::posix_time::ptime &snapshotTime, size_t &size)
Definition: OraDbSchema.cc:227
size_t selectGroups(const std::string &tag, std::vector< cond::Time_t > &groups)
Definition: OraDbSchema.cc:167
int i
Definition: DBlmapReader.cc:9
std::string create(cond::TimeType timetype)
Definition: IOVEditor.cc:260
std::string getToken(const std::string &tag)
Definition: OraDbSchema.cc:38
IPayloadTable & payloadTable()
Definition: OraDbSchema.cc:289
bool selectTagCollection(const std::string &globaltag, std::set< cond::TagMetadata > &result)
OraTagTable(IOVCache &cache)
Definition: OraDbSchema.cc:63
void load(const std::string &token)
Definition: IOVEditor.cc:202
std::string classNameForItem(const std::string &objectId)
Definition: DbSession.cc:292
IOVRange range(cond::Time_t since, cond::Time_t till) const
Definition: IOVProxy.cc:239
std::string typeName() const
Definition: Object.cc:59
bool existsTag(const std::string &tag)
Definition: OraDbSchema.cc:33
cond::IOVEditor editor()
Definition: OraDbSchema.cc:29
virtual std::string explainSelf() const
Definition: Exception.cc:146
cond::DbSession & session()
Definition: OraDbSchema.cc:21
void fromOraObject(const ora::Object &object)
Definition: Binary.cc:66
bool select(const std::string &gtName, std::vector< std::tuple< std::string, std::string, std::string > > &tags)
Definition: OraDbSchema.cc:346
bool select(const std::string &name)
Definition: OraDbSchema.cc:312
std::string const & token() const
Definition: IOVEditor.cc:542
const std::string getToken(const std::string &tagname) const
Definition: MetaData.cc:52
IOVRange head(int n) const
Definition: IOVProxy.cc:256
void update(const std::string &name, cond::Time_t &endOfValidity, const std::string &description, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &updateTime)
Definition: OraDbSchema.cc:106
void addTag(const std::string &tag, const std::string token)
Definition: OraDbSchema.cc:47
const_iterator end() const
Definition: IOVProxy.h:193
unsigned int freeInsert(cond::Time_t sinceTime, const std::string &payloadToken)
insert a payload with known since in any position
Definition: IOVEditor.cc:451
bool getLastIov(const std::string &tag, cond::Time_t &since, cond::Hash &hash)
Definition: OraDbSchema.cc:213
TimeType
Definition: Time.h:21
bool select(const cond::Hash &payloadHash, std::string &objectType, cond::Binary &payloadData, cond::Binary &streamerInfoData)
Definition: OraDbSchema.cc:129
IOVElementProxy front() const
Definition: IOVProxy.cc:155
Base exception class for the object to relational access.
Definition: Exception.h:10
OraGTTable(DbSession &session)
Definition: OraDbSchema.cc:308
IOVRange tail(int n) const
Definition: IOVProxy.cc:260
void insert(const std::string &gtName, const std::vector< std::tuple< std::string, std::string, std::string > > &tags)
Definition: OraDbSchema.cc:365
unsigned long long Time_t
Definition: Time.h:16
TimeType timetype() const
Definition: IOVEditor.cc:538
cond::IOVProxy iovSequence()
Definition: OraDbSchema.cc:25
cond::Time_t lastTill() const
Definition: IOVProxy.cc:289
bool addMapping(const std::string &name, const std::string &token, cond::TimeType timetype=cond::runnumber)
Definition: MetaData.cc:36
tuple iov
Definition: o2o.py:307
bool getMetadata(const std::string &name, std::string &description, boost::posix_time::ptime &insertionTime, boost::posix_time::ptime &modificationTime)
Definition: OraDbSchema.cc:87
std::string const & token() const
Definition: IOVProxy.h:75
bool hasTag(const std::string &name) const
Definition: MetaData.cc:68
bool exists()
Definition: Database.cc:133
int size() const
Definition: IOVProxy.cc:272
OraIOVSchema(DbSession &session)
Definition: OraDbSchema.cc:266
void erase(const std::string &tag)
Definition: OraDbSchema.cc:261
std::string Hash
Definition: Types.h:43
bool load(const std::string &tag)
Definition: OraDbSchema.cc:56
bool getSize(const std::string &tag, size_t &size)
Definition: OraDbSchema.cc:221
ora::Object oraObject() const
Definition: Binary.cc:62
void insertMany(const std::string &tag, const std::vector< std::tuple< cond::Time_t, cond::Hash, boost::posix_time::ptime > > &iovs)
Definition: OraDbSchema.cc:243
void insertOne(const std::string &tag, cond::Time_t since, cond::Hash payloadHash, const boost::posix_time::ptime &insertTime)
Definition: OraDbSchema.cc:232
size_t selectLatestByGroup(const std::string &tag, cond::Time_t lowerGroup, cond::Time_t upperGroup, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)
Definition: OraDbSchema.cc:183
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:132
tuple tags
Definition: o2o.py:248
bool existsTagCollection(const std::string &globaltag)
void insert(const std::string &name, cond::Time_t validity, const std::string &description, const std::string &release, const boost::posix_time::ptime &snapshotTime, const boost::posix_time::ptime &insertionTime)
Definition: OraDbSchema.cc:332
tuple description
Definition: idDealer.py:66
cond::IOVProxy proxy() const
Definition: IOVEditor.cc:546
cond::Time_t timestamp() const
Definition: IOVProxy.cc:308
bool createDatabase()
Definition: DbSession.cc:221
void updateClosure(cond::Time_t newtillTime)
Update the closure of the iov sequence.
Definition: IOVEditor.cc:405
unsigned int append(cond::Time_t sinceTime, const std::string &payloadToken)
Definition: IOVEditor.cc:416
OraPayloadTable(DbSession &session)
Definition: OraDbSchema.cc:125
cond::Time_t since() const
Definition: IOVProxy.h:67
cond::Time_t firstSince() const
Definition: IOVProxy.cc:285
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
OraGTSchema(DbSession &session)
Definition: OraDbSchema.cc:369
bool getType(const cond::Hash &payloadHash, std::string &objectType)
Definition: OraDbSchema.cc:148
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
ITagMigrationTable & tagMigrationTable()
Definition: OraDbSchema.cc:293
void bulkAppend(std::vector< std::pair< cond::Time_t, std::string > > &values)
Bulk append of iov chunck.
Definition: IOVEditor.cc:321
SynchronizationType
Definition: Types.h:31
TimeType timetype() const
Definition: IOVProxy.cc:281
OraGTMapTable(DbSession &session)
Definition: OraDbSchema.cc:342
void stamp(std::string const &icomment, bool append=false)
Definition: IOVEditor.cc:375
cond::IOVEditor m_iovAccess
Definition: OraDbSchema.h:35
size_t selectSnapshotByGroup(const std::string &tag, cond::Time_t lowerGroup, cond::Time_t upperGroup, const boost::posix_time::ptime &snapshotTime, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)
Definition: OraDbSchema.cc:195
IPayloadMigrationTable & payloadMigrationTable()
Definition: OraDbSchema.cc:298
cond::Hash insertIfNew(const std::string &objectType, const cond::Binary &payloadData, const cond::Binary &streamerInfoData, const boost::posix_time::ptime &insertionTime)
Definition: OraDbSchema.cc:153
ora::Object getObject(const std::string &objectId)
Definition: DbSession.cc:268
size_t selectSnapshotGroups(const std::string &tag, const boost::posix_time::ptime &snapshotTime, std::vector< cond::Time_t > &groups)
Definition: OraDbSchema.cc:177
ora::Database & storage()
Definition: DbSession.cc:215
size_t selectLatest(const std::string &tag, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)
Definition: OraDbSchema.cc:202
void updateValidity(const std::string &name, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &updateTime)
Definition: OraDbSchema.cc:116
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
std::string parsePoolToken(const std::string &poolToken)
Definition: OraDbSchema.cc:303
tuple size
Write out results.
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:11
std::string comment() const
Definition: IOVProxy.cc:299
boost::posix_time::ptime to_boost(Time_t iValue)
void insert(const std::string &name, cond::TimeType timeType, const std::string &objectType, cond::SynchronizationType synchronizationType, cond::Time_t endOfValidity, const std::string &description, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &insertionTime)
Definition: OraDbSchema.cc:96
IOVElementProxy back() const
Definition: IOVProxy.cc:160
IOVCache(cond::DbSession &s)
Definition: OraDbSchema.cc:17
DbSession & db()
Definition: IOVProxy.cc:312