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 
213  size_t OraIOVTable::selectSnapshot( const std::string& tag, const boost::posix_time::ptime&,
214  std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs){
215  // no (easy) way to do it...
216  return selectLatest( tag, iovs );
217  }
218 
220  if(!m_cache.load( tag ) || m_cache.iovSequence().size()==0 ) return false;
222  since = last.since();
223  hash = last.token();
224  return true;
225  }
226 
227  bool OraIOVTable::getSnapshotLastIov( const std::string& tag, const boost::posix_time::ptime&,
228  cond::Time_t& since, cond::Hash& hash ){
229  // no (easy) way to do it...
230  return getLastIov( tag, since, hash );
231  }
232 
233  bool OraIOVTable::getSize( const std::string& tag, size_t& size ){
234  if(!m_cache.load( tag )) return false;
235  size = m_cache.iovSequence().size();
236  return true;
237  }
238 
239  bool OraIOVTable::getSnapshotSize( const std::string& tag, const boost::posix_time::ptime&, size_t& size ){
240  // no (easy) way to do it...
241  return getSize( tag,size );
242  }
243 
244  void OraIOVTable::insertOne( const std::string& tag, cond::Time_t since, cond::Hash payloadHash,
245  const boost::posix_time::ptime& ){
246  if(!m_cache.load(tag)) throwException("Tag "+tag+" has not been found in the database.",
247  "OraIOVTable::insertOne");
248  if( m_cache.editor().timetype() != cond::hash ){
249  m_cache.editor().append( since, payloadHash );
250  } else {
251  m_cache.editor().freeInsert( since, payloadHash );
252  }
253  }
254 
256  const std::vector<std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime> >& iovs ){
257  if(!m_cache.load(tag)) throwException("Tag "+tag+" has not been found in the database.",
258  "OraIOVTable::insertOne");
259  if( m_cache.editor().timetype() != cond::hash ){
260  std::vector<std::pair<cond::Time_t, std::string > > data;
261  data.reserve( iovs.size() );
262  for( auto v : iovs ){
263  data.push_back( std::make_pair( std::get<0>(v), std::get<1>(v) ) );
264  }
265  m_cache.editor().bulkAppend( data );
266  } else {
267  for( auto v: iovs ){
268  insertOne( tag, std::get<0>(v), std::get<1>(v), std::get<2>(v) );
269  }
270  }
271  }
272 
274  throwException( "Erase iovs from ORA database is not supported.",
275  "OraIOVTable::erase" );
276  }
277 
279  m_cache( session ),
280  m_tagTable( m_cache ),
281  m_iovTable( m_cache ),
282  m_payloadTable( session ){
283  };
284 
286  return m_cache.session().storage().exists();
287  }
288 
290  return m_cache.session().createDatabase();
291  }
292 
294  return m_tagTable;
295  }
296 
298  return m_iovTable;
299  }
300 
302  return m_payloadTable;
303  }
304 
306  throwException("Tag Migration interface is not available in this implementation.",
307  "OraIOVSchema::tagMigrationTable");
308  }
309 
311  throwException("Payload Migration interface is not available in this implementation.",
312  "OraIOVSchema::payloadMigrationTable");
313  }
314 
317  return parser.parse( poolToken ).toString();
318  }
319 
321  m_session( session ){
322  }
323 
325  cond::TagCollectionRetriever gtRetriever( m_session, "", "" );
326  return gtRetriever.existsTagCollection( name );
327  }
328 
329  bool OraGTTable::select( const std::string& name, cond::Time_t& validity, boost::posix_time::ptime& snapshotTime){
330  bool ret = false;
331  if( select( name ) ){
332  ret = true;
333  validity = cond::time::MAX_VAL;
334  snapshotTime = boost::posix_time::ptime();
335  }
336  return ret;
337  }
338 
340  std::string&, boost::posix_time::ptime& snapshotTime){
341  return select( name, validity, snapshotTime );
342  }
343 
345  const boost::posix_time::ptime&, const boost::posix_time::ptime& ){
346  // not supported...
347  }
348 
350  const boost::posix_time::ptime&, const boost::posix_time::ptime& ){
351  // not supported...
352  }
353 
355  m_session( session ){
356  }
357 
358  bool OraGTMapTable::select( const std::string& gtName, std::vector<std::tuple<std::string,std::string,std::string> >& tags ){
359  return select( gtName, "", "", tags );
360  }
361 
362  bool OraGTMapTable::select( const std::string& gtName, const std::string& preFix, const std::string& postFix,
363  std::vector<std::tuple<std::string,std::string,std::string> >& tags ){
364  std::set<cond::TagMetadata> tmp;
365  cond::TagCollectionRetriever gtRetriever( m_session, preFix, postFix );
366  if(!gtRetriever.selectTagCollection( gtName, tmp ) ) return false;
367  if( tmp.size() ) tags.resize( tmp.size() );
368  size_t i = 0;
369  for( const auto& m : tmp ){
370  std::string tagFullName = m.tag+"@["+m.pfn+"]";
371  tags[ i ] = std::make_tuple( m.recordname, m.labelname, tagFullName );
372  i++;
373  }
374  return true;
375  }
376 
377  void OraGTMapTable::insert( const std::string& gtName, const std::vector<std::tuple<std::string,std::string,std::string> >& tags ){
378  // not supported...
379  }
380 
382  m_session( session ),
383  m_gtTable( session ),
384  m_gtMapTable( session ){
385  }
386 
387 
389  throwException("GT Schema can't be create in ORA implementation.",
390  "OraGTSchema::create");
391  }
392 
394  cond::TagCollectionRetriever gtRetriever( m_session, "", "" );
395  return gtRetriever.existsTagDatabase();
396  }
397 
399  return m_gtTable;
400  }
401 
403  return m_gtMapTable;
404  }
405 
406  }
407 }
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:349
bool getSnapshotSize(const std::string &tag, const boost::posix_time::ptime &snapshotTime, size_t &size)
Definition: OraDbSchema.cc:239
tuple t
Definition: tree.py:139
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
bool getSnapshotLastIov(const std::string &tag, const boost::posix_time::ptime &snapshotTime, cond::Time_t &since, cond::Hash &hash)
Definition: OraDbSchema.cc:227
IPayloadTable & payloadTable()
Definition: OraDbSchema.cc:301
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:358
size_t selectSnapshot(const std::string &tag, const boost::posix_time::ptime &snapshotTime, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)
Definition: OraDbSchema.cc:213
bool select(const std::string &name)
Definition: OraDbSchema.cc:324
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:219
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:320
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:377
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:278
void erase(const std::string &tag)
Definition: OraDbSchema.cc:273
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:233
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:255
void insertOne(const std::string &tag, cond::Time_t since, cond::Hash payloadHash, const boost::posix_time::ptime &insertTime)
Definition: OraDbSchema.cc:244
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:344
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:381
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:305
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:354
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:310
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:315
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