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