CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GTProxy.cc
Go to the documentation of this file.
2 #include "SessionImpl.h"
3 
4 namespace cond {
5 
6  namespace persistency {
7 
9  if(connectionString.empty()) return tag;
10  return tag+"@["+connectionString+"]";
11  }
12 
13  std::pair<std::string,std::string> parseTag( const std::string& tag ){
14  std::string pfn("");
15  std::string t(tag);
16  size_t pos = tag.rfind("[");
17  if( pos != std::string::npos && tag.size() >= pos+2 ){
18  if( tag[pos-1]=='@' && tag[tag.size()-1]==']' ) {
19  pfn = tag.substr( pos+1,tag.size()-pos-2 );
20  t = tag.substr( 0, pos-1 );
21  }
22  }
23  return std::make_pair( t, pfn );
24  }
25 
26  // implementation details...
27  // only hosting data in this case
28  class GTProxyData {
29  public:
30 
32  name(""),
33  preFix(""),
34  postFix(""),
35  tagList(){
36  }
37 
39  // will become useless after the transition...
43  boost::posix_time::ptime snapshotTime;
44  // tag list
46  };
47 
49  m_current(){
50  }
51 
52  GTProxy::Iterator::Iterator( GTContainer::const_iterator current ):
53  m_current( current ){
54  }
55 
57  m_current( rhs.m_current ){
58  }
59 
61  if( this != &rhs ){
62  m_current = rhs.m_current;
63  }
64  return *this;
65  }
66 
68  return cond::GTEntry_t( *m_current );
69  }
70 
72  m_current++;
73  return *this;
74  }
75 
77  Iterator tmp( *this );
78  operator++();
79  return tmp;
80  }
81 
82  bool GTProxy::Iterator::operator==( const Iterator& rhs ) const {
83  if( m_current != rhs.m_current ) return false;
84  return true;
85  }
86 
87  bool GTProxy::Iterator::operator!=( const Iterator& rhs ) const {
88  return !operator==( rhs );
89  }
90 
92  m_data(),
93  m_session(){
94  }
95 
96  GTProxy::GTProxy( const std::shared_ptr<SessionImpl>& session ):
97  m_data( new GTProxyData ),
98  m_session( session ){
99  }
100 
101  GTProxy::GTProxy( const GTProxy& rhs ):
102  m_data( rhs.m_data ),
103  m_session( rhs.m_session ){
104  }
105 
107  m_data = rhs.m_data;
108  m_session = rhs.m_session;
109  return *this;
110  }
111 
129  // overloading for pre- and post-fix. Used in the ORA implementation
130  void GTProxy::load( const std::string& gtName, const std::string& pref, const std::string& postf ){
131  // clear
132  reset();
133 
134  checkTransaction( "GTProxy::load" );
135 
136  if(!m_session->gtSchema().gtTable().select( gtName, m_data->validity, m_data->snapshotTime ) ){
137  throwException( "Global Tag \""+gtName+"\" has not been found in the database.","GTProxy::load");
138  }
139  m_data->name = gtName;
140  m_data->preFix = pref;
141  m_data->postFix = postf;
142 
143  m_session->gtSchema().gtMapTable().select( m_data->name, pref, postf, m_data->tagList );
144 
145  }
146 
147 
149  load( m_data->name );
150  }
151 
153  if( m_data.get() ){
154  m_data->tagList.clear();
155  }
156  }
157 
159  return m_data.get() ? m_data->name : std::string("");
160  }
161 
163  return m_data.get() ? m_data->validity : cond::time::MIN_VAL;
164  }
165 
166  boost::posix_time::ptime GTProxy::snapshotTime() const {
167  return m_data.get() ? m_data->snapshotTime : boost::posix_time::ptime();
168  }
169 
171  if( !m_session.get() ) throwException("The session is not active.",ctx );
172  if( !m_session->isTransactionActive( false ) ) throwException("The transaction is not active.",ctx );
173  }
174 
176  if( m_data.get() ){
177  return Iterator( m_data->tagList.begin() );
178  }
179  return Iterator();
180  }
181 
183  if( m_data.get() ){
184  return Iterator( m_data->tagList.end() );
185  }
186  return Iterator();
187  }
188 
189  int GTProxy::size() const {
190  return m_data.get()? m_data->tagList.size() : 0;
191  }
192 
193  }
194 }
GTContainer::const_iterator m_current
Definition: GTProxy.h:59
std::vector< std::tuple< std::string, std::string, std::string > > GTContainer
Definition: GTProxy.h:34
GTProxy & operator=(const GTProxy &rhs)
Definition: GTProxy.cc:106
Iterator & operator=(const Iterator &rhs)
Definition: GTProxy.cc:60
const Time_t MIN_VAL(0)
bool operator==(const Iterator &rhs) const
Definition: GTProxy.cc:82
void checkTransaction(const std::string &ctx)
Definition: GTProxy.cc:170
cond::Time_t validity() const
Definition: GTProxy.cc:162
unsigned long long Time_t
Definition: Time.h:16
boost::posix_time::ptime snapshotTime
Definition: GTProxy.cc:43
std::pair< std::string, std::string > parseTag(const std::string &tag)
Definition: GTProxy.cc:13
void load(const std::string &gtName, const std::string &preFix="", const std::string &postFix="")
Definition: GTProxy.cc:130
GTProxy::GTContainer tagList
Definition: GTProxy.cc:45
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
std::shared_ptr< GTProxyData > m_data
Definition: GTProxy.h:104
boost::posix_time::ptime snapshotTime() const
Definition: GTProxy.cc:166
std::string fullyQualifiedTag(const std::string &tag, const std::string &connectionString)
Definition: GTProxy.cc:8
Iterator begin() const
Definition: GTProxy.cc:175
Iterator end() const
Definition: GTProxy.cc:182
string connectionString
Definition: autoCondHLT.py:4
std::string name() const
Definition: GTProxy.cc:158
bool operator!=(const Iterator &rhs) const
Definition: GTProxy.cc:87
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::shared_ptr< SessionImpl > m_session
Definition: GTProxy.h:105
session
Definition: models.py:201
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:14