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.fromOraObject(obj );
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  ora::Object obj = payloadData.oraObject();
133  std::string tok = m_session.storeObject( obj, objectType );
134  m_session.flush();
135  return tok;
136  }
137 
139  m_cache( iovCache ){
140  }
141 
142  size_t OraIOVTable::selectGroups( const std::string& tag, std::vector<cond::Time_t>& groups ){
143  if(!m_cache.load( tag )) return 0;
144  if( m_cache.iovSequence().size()>0 ){
145  groups.push_back( m_cache.iovSequence().firstSince() );
146  groups.push_back( m_cache.iovSequence().lastTill() );
147  return true;
148  }
149  return false;
150  }
151 
152  size_t OraIOVTable::selectSnapshotGroups( const std::string& tag, const boost::posix_time::ptime&,
153  std::vector<cond::Time_t>& groups ){
154  // no (easy) way to do it...
155  return selectGroups( tag, groups );
156  }
157 
159  std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs){
160  if(!m_cache.load( tag )) return 0;
161  cond::IOVRange range = m_cache.iovSequence().range( lowerGroup, upperGroup );
162  size_t ret = 0;
163  for( auto iov : range ){
164  iovs.push_back( std::make_tuple( iov.since(), iov.token() ) );
165  ret++;
166  }
167  return ret;
168  }
169 
171  const boost::posix_time::ptime&,
172  std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs){
173  // no (easy) way to do it...
174  return selectLatestByGroup( tag, lowerGroup, upperGroup, iovs );
175  }
176 
177  size_t OraIOVTable::selectLatest( const std::string& tag, std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs){
178  // avoid this! copying the entire iov sequence...
179  if(!m_cache.load( tag )) return 0;
180  size_t ret = 0;
181  for( auto iov : m_cache.iovSequence() ){
182  iovs.push_back( std::make_tuple( iov.since(), iov.token() ) );
183  ret++;
184  }
185  return ret;
186  }
187 
189  if(!m_cache.load( tag ) || m_cache.iovSequence().size()==0 ) return false;
191  since = last.since();
192  hash = last.token();
193  return true;
194  }
195 
196  bool OraIOVTable::getSize( const std::string& tag, size_t& size ){
197  if(!m_cache.load( tag )) return false;
198  size = m_cache.iovSequence().size();
199  return true;
200  }
201 
202  bool OraIOVTable::getSnapshotSize( const std::string& tag, const boost::posix_time::ptime&, size_t& size ){
203  // no (easy) way to do it...
204  return getSize( tag,size );
205  }
206 
207  void OraIOVTable::insertOne( const std::string& tag, cond::Time_t since, cond::Hash payloadHash,
208  const boost::posix_time::ptime& ){
209  if(!m_cache.load(tag)) throwException("Tag "+tag+" has not been found in the database.",
210  "OraIOVTable::insertOne");
211  m_cache.editor().append( since, payloadHash );
212  }
213 
215  const std::vector<std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime> >& iovs ){
216  if(!m_cache.load(tag)) throwException("Tag "+tag+" has not been found in the database.",
217  "OraIOVTable::insertOne");
218  std::vector<std::pair<cond::Time_t, std::string > > data;
219  data.reserve( iovs.size() );
220  for( auto v : iovs ){
221  data.push_back( std::make_pair( std::get<0>(v), std::get<1>(v) ) );
222  }
223  m_cache.editor().bulkAppend( data );
224  }
225 
227  m_cache( session ),
228  m_tagTable( m_cache ),
229  m_iovTable( m_cache ),
230  m_payloadTable( session ){
231  };
232 
234  return m_cache.session().storage().exists();
235  }
236 
238  return m_cache.session().createDatabase();
239  }
240 
242  return m_tagTable;
243  }
244 
246  return m_iovTable;
247  }
248 
250  return m_payloadTable;
251  }
252 
254  throwException("Tag Migration interface is not available in this implementation.",
255  "OraIOVSchema::tagMigrationTabl");
256  }
257 
259  m_session( session ){
260  }
261 
263  cond::TagCollectionRetriever gtRetriever( m_session, "", "" );
264  return gtRetriever.existsTagCollection( name+"::All" );
265  }
266 
267  bool OraGTTable::select( const std::string& name, cond::Time_t& validity, boost::posix_time::ptime& snapshotTime){
268  bool ret = false;
269  if( select( name ) ){
270  ret = true;
271  validity = cond::time::MAX_VAL;
272  snapshotTime = boost::posix_time::ptime();
273  }
274  return ret;
275  }
276 
278  std::string&, boost::posix_time::ptime& snapshotTime){
279  return select( name, validity, snapshotTime );
280  }
281 
283  const boost::posix_time::ptime&, const boost::posix_time::ptime& ){
284  // not supported...
285  }
286 
288  const boost::posix_time::ptime&, const boost::posix_time::ptime& ){
289  // not supported...
290  }
291 
293  m_session( session ){
294  }
295 
296  bool OraGTMapTable::select( const std::string& gtName, std::vector<std::tuple<std::string,std::string,std::string> >& tags ){
297  return select( gtName, "", "", tags );
298  }
299 
300  bool OraGTMapTable::select( const std::string& gtName, const std::string& preFix, const std::string& postFix,
301  std::vector<std::tuple<std::string,std::string,std::string> >& tags ){
302  std::set<cond::TagMetadata> tmp;
303  cond::TagCollectionRetriever gtRetriever( m_session, preFix, postFix );
304  if(!gtRetriever.selectTagCollection( gtName, tmp ) ) return false;
305  if( tmp.size() ) tags.resize( tmp.size() );
306  size_t i = 0;
307  for( const auto& m : tmp ){
308  std::string tagFullName = m.tag+"@["+m.pfn+"]";
309  tags[ i ] = std::make_tuple( m.recordname, m.labelname, tagFullName );
310  i++;
311  }
312  return true;
313  }
314 
315  void OraGTMapTable::insert( const std::string& gtName, const std::vector<std::tuple<std::string,std::string,std::string> >& tags ){
316  // not supported...
317  }
318 
320  m_session( session ),
321  m_gtTable( session ),
322  m_gtMapTable( session ){
323  }
324 
326  cond::TagCollectionRetriever gtRetriever( m_session, "", "" );
327  return gtRetriever.existsTagDatabase();
328  }
329 
331  return m_gtTable;
332  }
333 
335  return m_gtMapTable;
336  }
337 
338  }
339 }
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:287
bool getSnapshotSize(const std::string &tag, const boost::posix_time::ptime &snapshotTime, size_t &size)
Definition: OraDbSchema.cc:202
size_t selectGroups(const std::string &tag, std::vector< cond::Time_t > &groups)
Definition: OraDbSchema.cc:142
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:249
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: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:296
bool select(const std::string &name)
Definition: OraDbSchema.cc:262
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:188
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:258
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:315
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:226
std::string Hash
Definition: Types.h:38
bool load(const std::string &tag)
Definition: OraDbSchema.cc:56
bool getSize(const std::string &tag, size_t &size)
Definition: OraDbSchema.cc:196
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:214
void insertOne(const std::string &tag, cond::Time_t since, cond::Hash payloadHash, const boost::posix_time::ptime &insertTime)
Definition: OraDbSchema.cc:207
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:158
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:282
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: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:319
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:253
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:26
TimeType timetype() const
Definition: IOVProxy.cc:281
OraGTMapTable(DbSession &session)
Definition: OraDbSchema.cc:292
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:170
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:152
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:215
size_t selectLatest(const std::string &tag, std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)
Definition: OraDbSchema.cc:177
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
IOVCache(cond::DbSession &s)
Definition: OraDbSchema.cc:17