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& ){
89  if(!m_cache.load( name )) return false;
90  description = m_cache.iovSequence().comment();
91  // TO DO: get insertion / modification time from the Logger?
92  return true;
93  }
94 
97  cond::Time_t, const boost::posix_time::ptime& ){
98  std::string tok = m_cache.editor().create( timeType, endOfValidity );
99  if( !m_cache.validationMode() ){
100  m_cache.editor().stamp( description );
101  }
102  m_cache.addTag( name, tok );
103  }
104 
106  cond::Time_t, const boost::posix_time::ptime& ){
107 
108  std::string tok = m_cache.getToken( name );
109  if( tok.empty() ) throwException( "Tag \""+name+"\" has not been found in the database.","OraTagTable::update");
110  m_cache.editor().load( tok );
111  m_cache.editor().updateClosure( endOfValidity );
112  if( !m_cache.validationMode() ) m_cache.editor().stamp( description );
113  }
114 
116  const boost::posix_time::ptime& ){
117  // can't be done in this case...
118  }
119 
122  }
123 
125  m_session( session ){
126  }
127 
128  bool OraPayloadTable::select( const cond::Hash& payloadHash,
129  std::string& objectType,
130  cond::Binary& payloadData,
131  cond::Binary& //streamerInfoData
132  ){
133  ora::Object obj = m_session.getObject( payloadHash );
134  objectType = obj.typeName();
135  payloadData.fromOraObject(obj );
136  return true;
137  }
138 
139  bool OraPayloadTable::getType( const cond::Hash& payloadHash, std::string& objectType ){
140  objectType = m_session.classNameForItem( payloadHash );
141  return true;
142  }
143 
145  const cond::Binary& payloadData,
146  const cond::Binary&, //streamerInfoData
147  const boost::posix_time::ptime& ){
148  ora::Object obj = payloadData.oraObject();
149  std::string tok = m_session.storeObject( obj, objectType );
150  m_session.flush();
151  return tok;
152  }
153 
155  m_cache( iovCache ){
156  }
157 
158  size_t OraIOVTable::selectGroups( const std::string& tag, std::vector<cond::Time_t>& groups ){
159  if(!m_cache.load( tag )) return 0;
160  if( m_cache.iovSequence().size()>0 ){
161  groups.push_back( m_cache.iovSequence().firstSince() );
162  groups.push_back( m_cache.iovSequence().lastTill() );
163  return true;
164  }
165  return false;
166  }
167 
168  size_t OraIOVTable::selectSnapshotGroups( const std::string& tag, const boost::posix_time::ptime&,
169  std::vector<cond::Time_t>& groups ){
170  // no (easy) way to do it...
171  return selectGroups( tag, groups );
172  }
173 
175  std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs){
176  if(!m_cache.load( tag )) return 0;
177  cond::IOVRange range = m_cache.iovSequence().range( lowerGroup, upperGroup );
178  size_t ret = 0;
179  for( auto iov : range ){
180  iovs.push_back( std::make_tuple( iov.since(), iov.token() ) );
181  ret++;
182  }
183  return ret;
184  }
185 
187  const boost::posix_time::ptime&,
188  std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs){
189  // no (easy) way to do it...
190  return selectLatestByGroup( tag, lowerGroup, upperGroup, iovs );
191  }
192 
193  size_t OraIOVTable::selectLatest( const std::string& tag, std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs){
194  // avoid this! copying the entire iov sequence...
195  if(!m_cache.load( tag )) return 0;
196  size_t ret = 0;
197  for( auto iov : m_cache.iovSequence() ){
198  iovs.push_back( std::make_tuple( iov.since(), iov.token() ) );
199  ret++;
200  }
201  return ret;
202  }
203 
205  if(!m_cache.load( tag ) || m_cache.iovSequence().size()==0 ) return false;
207  since = last.since();
208  hash = last.token();
209  return true;
210  }
211 
212  bool OraIOVTable::getSize( const std::string& tag, size_t& size ){
213  if(!m_cache.load( tag )) return false;
214  size = m_cache.iovSequence().size();
215  return true;
216  }
217 
218  bool OraIOVTable::getSnapshotSize( const std::string& tag, const boost::posix_time::ptime&, size_t& size ){
219  // no (easy) way to do it...
220  return getSize( tag,size );
221  }
222 
223  void OraIOVTable::insertOne( const std::string& tag, cond::Time_t since, cond::Hash payloadHash,
224  const boost::posix_time::ptime& ){
225  if(!m_cache.load(tag)) throwException("Tag "+tag+" has not been found in the database.",
226  "OraIOVTable::insertOne");
227  m_cache.editor().append( since, payloadHash );
228  }
229 
231  const std::vector<std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime> >& iovs ){
232  if(!m_cache.load(tag)) throwException("Tag "+tag+" has not been found in the database.",
233  "OraIOVTable::insertOne");
234  std::vector<std::pair<cond::Time_t, std::string > > data;
235  data.reserve( iovs.size() );
236  for( auto v : iovs ){
237  data.push_back( std::make_pair( std::get<0>(v), std::get<1>(v) ) );
238  }
239  m_cache.editor().bulkAppend( data );
240  }
241 
243  throwException( "Erase iovs from ORA database is not supported.",
244  "OraIOVTable::erase" );
245  }
246 
248  m_cache( session ),
249  m_tagTable( m_cache ),
250  m_iovTable( m_cache ),
251  m_payloadTable( session ){
252  };
253 
255  return m_cache.session().storage().exists();
256  }
257 
259  return m_cache.session().createDatabase();
260  }
261 
263  return m_tagTable;
264  }
265 
267  return m_iovTable;
268  }
269 
271  return m_payloadTable;
272  }
273 
275  throwException("Tag Migration interface is not available in this implementation.",
276  "OraIOVSchema::tagMigrationTabl");
277  }
278 
280  m_session( session ){
281  }
282 
284  cond::TagCollectionRetriever gtRetriever( m_session, "", "" );
285  return gtRetriever.existsTagCollection( name+"::All" );
286  }
287 
288  bool OraGTTable::select( const std::string& name, cond::Time_t& validity, boost::posix_time::ptime& snapshotTime){
289  bool ret = false;
290  if( select( name ) ){
291  ret = true;
292  validity = cond::time::MAX_VAL;
293  snapshotTime = boost::posix_time::ptime();
294  }
295  return ret;
296  }
297 
299  std::string&, boost::posix_time::ptime& snapshotTime){
300  return select( name, validity, snapshotTime );
301  }
302 
304  const boost::posix_time::ptime&, const boost::posix_time::ptime& ){
305  // not supported...
306  }
307 
309  const boost::posix_time::ptime&, const boost::posix_time::ptime& ){
310  // not supported...
311  }
312 
314  m_session( session ){
315  }
316 
317  bool OraGTMapTable::select( const std::string& gtName, std::vector<std::tuple<std::string,std::string,std::string> >& tags ){
318  return select( gtName, "", "", tags );
319  }
320 
321  bool OraGTMapTable::select( const std::string& gtName, const std::string& preFix, const std::string& postFix,
322  std::vector<std::tuple<std::string,std::string,std::string> >& tags ){
323  std::set<cond::TagMetadata> tmp;
324  cond::TagCollectionRetriever gtRetriever( m_session, preFix, postFix );
325  if(!gtRetriever.selectTagCollection( gtName, tmp ) ) return false;
326  if( tmp.size() ) tags.resize( tmp.size() );
327  size_t i = 0;
328  for( const auto& m : tmp ){
329  std::string tagFullName = m.tag+"@["+m.pfn+"]";
330  tags[ i ] = std::make_tuple( m.recordname, m.labelname, tagFullName );
331  i++;
332  }
333  return true;
334  }
335 
336  void OraGTMapTable::insert( const std::string& gtName, const std::vector<std::tuple<std::string,std::string,std::string> >& tags ){
337  // not supported...
338  }
339 
341  m_session( session ),
342  m_gtTable( session ),
343  m_gtMapTable( session ){
344  }
345 
347  cond::TagCollectionRetriever gtRetriever( m_session, "", "" );
348  return gtRetriever.existsTagDatabase();
349  }
350 
352  return m_gtTable;
353  }
354 
356  return m_gtMapTable;
357  }
358 
359  }
360 }
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:308
bool getSnapshotSize(const std::string &tag, const boost::posix_time::ptime &snapshotTime, size_t &size)
Definition: OraDbSchema.cc:218
size_t selectGroups(const std::string &tag, std::vector< cond::Time_t > &groups)
Definition: OraDbSchema.cc:158
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:270
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
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:317
bool select(const std::string &name)
Definition: OraDbSchema.cc:283
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:105
void addTag(const std::string &tag, const std::string token)
Definition: OraDbSchema.cc:47
const_iterator end() const
Definition: IOVProxy.h:193
bool getLastIov(const std::string &tag, cond::Time_t &since, cond::Hash &hash)
Definition: OraDbSchema.cc:204
TimeType
Definition: Time.h:21
bool select(const cond::Hash &payloadHash, std::string &objectType, cond::Binary &payloadData, cond::Binary &streamerInfoData)
Definition: OraDbSchema.cc:128
IOVElementProxy front() const
Definition: IOVProxy.cc:155
OraGTTable(DbSession &session)
Definition: OraDbSchema.cc:279
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:336
unsigned long long Time_t
Definition: Time.h:16
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:247
void erase(const std::string &tag)
Definition: OraDbSchema.cc:242
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:212
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:230
void insertOne(const std::string &tag, cond::Time_t since, cond::Hash payloadHash, const boost::posix_time::ptime &insertTime)
Definition: OraDbSchema.cc:223
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:174
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:303
tuple description
Definition: idDealer.py:66
cond::IOVProxy proxy() const
Definition: IOVEditor.cc:546
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:124
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:340
bool getType(const cond::Hash &payloadHash, std::string &objectType)
Definition: OraDbSchema.cc:139
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
ITagMigrationTable & tagMigrationTable()
Definition: OraDbSchema.cc:274
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:313
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:186
cond::Hash insertIfNew(const std::string &objectType, const cond::Binary &payloadData, const cond::Binary &streamerInfoData, const boost::posix_time::ptime &insertionTime)
Definition: OraDbSchema.cc:144
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:168
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:193
void updateValidity(const std::string &name, cond::Time_t lastValidatedTime, const boost::posix_time::ptime &updateTime)
Definition: OraDbSchema.cc:115
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
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
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:95
IOVElementProxy back() const
Definition: IOVProxy.cc:160
IOVCache(cond::DbSession &s)
Definition: OraDbSchema.cc:17
DbSession & db()
Definition: IOVProxy.cc:312