CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MetaData.cc
Go to the documentation of this file.
4 #include "RelationalAccess/SchemaException.h"
5 #include <memory>
6 //#include <iostream>
7 
8 
9 namespace {
10 
11  std::string mdErrorPrefix(const std::string& source, const std::string& name) {
12  return source+std::string(": metadata entry \"")+name+std::string("\" ");
13  }
14 
15 
16  void mdError(const std::string& source, const std::string& name, const std::string& mess) {
17  throw cond::Exception(mdErrorPrefix(source,name)+mess);
18  }
19 
20  void mdDuplicateEntryError(const std::string& source, const std::string& name) {
21  mdError(source, name, "Already exists");
22  }
23 
24  void mdNoEntry(const std::string& source, const std::string& name) {
25  mdError(source, name, "does not exists");
26  }
27 
28 }
29 
30 
31 cond::MetaData::MetaData(cond::DbSession& userSession):m_userSession( userSession ){
32 }
34 }
35 bool
37  const std::string& iovtoken,
39  try{
40  ora::OId oid;
41  oid.fromString( iovtoken );
42  m_userSession.storage().setObjectName( name, oid );
43  }catch( const coral::DuplicateEntryInUniqueKeyException& er ){
44  mdDuplicateEntryError("addMapping",name);
45  }catch(std::exception& er){
46  mdError("MetaData::addMapping",name,er.what());
47  }
48  return true;
49 }
50 
51 const std::string
53  bool ok=false;
54  std::string iovtoken("");
55  try{
56  ora::OId oid;
57  ok = m_userSession.storage().getItemId( name, oid );
58  if(ok) {
59  iovtoken = oid.toString();
60  }
61  }catch(const std::exception& er){
62  mdError("MetaData::getToken", name,er.what() );
63  }
64  if (!ok) mdNoEntry("MetaData::getToken", name);
65  return iovtoken;
66 }
67 
69  bool result=false;
70  try{
71  ora::OId oid;
72  result = m_userSession.storage().getItemId( name, oid );
73  }catch(const std::exception& er){
74  mdError("MetaData::hasTag", name, er.what() );
75  }
76  return result;
77 }
78 
79 void
80 cond::MetaData::listAllTags( std::vector<std::string>& result ) const{
81  try{
82  m_userSession.storage().listObjectNames( result );
83  }catch(const std::exception& er){
84  throw cond::Exception( std::string("MetaData::listAllTags: " )+er.what() );
85  }
86 }
87 
88 void
90  try{
91  m_userSession.storage().eraseAllNames();
92  }catch(const std::exception& er){
93  throw cond::Exception( std::string("MetaData::deleteAllEntries: " )+er.what() );
94  }
95 }
96 
98  try{
99  m_userSession.storage().eraseObjectName( tag );
100  }catch(const std::exception& er){
101  throw cond::Exception( std::string("MetaData::deleteEntryByTag: " )+er.what() );
102  }
103 }
void deleteAllEntries()
Definition: MetaData.cc:89
Definition: OId.h:8
const std::string getToken(const std::string &tagname) const
Definition: MetaData.cc:52
TimeType
Definition: Time.h:21
MetaData(cond::DbSession &userSession)
Definition: MetaData.cc:31
bool addMapping(const std::string &name, const std::string &token, cond::TimeType timetype=cond::runnumber)
Definition: MetaData.cc:36
bool hasTag(const std::string &name) const
Definition: MetaData.cc:68
tuple result
Definition: query.py:137
std::string toString() const
Definition: OId.cc:58
void deleteEntryByTag(const std::string &tag)
Definition: MetaData.cc:97
void listAllTags(std::vector< std::string > &result) const
Definition: MetaData.cc:80
bool fromString(const std::string &s)
Definition: OId.cc:64
static std::string const source
Definition: EdmProvDump.cc:42