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 
8  std::pair<std::string,std::string> parseTag( const std::string& tag ){
9  std::string pfn("");
10  std::string t(tag);
11  size_t pos = tag.rfind('@');
12  if( pos != std::string::npos && tag.size() >= pos+3 ){
13  if( tag[pos+1]=='[' && tag[tag.size()-1]==']' ) {
14  pfn = tag.substr( pos+2,tag.size()-pos-3 );
15  t = tag.substr( 0, pos );
16  }
17  }
18  return std::make_pair( t, pfn );
19  }
20 
21  // implementation details...
22  // only hosting data in this case
23  class GTProxyData {
24  public:
25 
27  name(""),
28  preFix(""),
29  postFix(""),
30  tagList(){
31  }
32 
34  // will become useless after the transition...
38  boost::posix_time::ptime snapshotTime;
39  // tag list
41  };
42 
44  m_current(){
45  }
46 
47  GTProxy::Iterator::Iterator( GTContainer::const_iterator current ):
48  m_current( current ){
49  }
50 
52  m_current( rhs.m_current ){
53  }
54 
56  if( this != &rhs ){
57  m_current = rhs.m_current;
58  }
59  return *this;
60  }
61 
63  return cond::GTEntry_t( *m_current );
64  }
65 
67  m_current++;
68  return *this;
69  }
70 
72  Iterator tmp( *this );
73  operator++();
74  return tmp;
75  }
76 
77  bool GTProxy::Iterator::operator==( const Iterator& rhs ) const {
78  if( m_current != rhs.m_current ) return false;
79  return true;
80  }
81 
82  bool GTProxy::Iterator::operator!=( const Iterator& rhs ) const {
83  return !operator==( rhs );
84  }
85 
87  m_data(),
88  m_session(){
89  }
90 
91  GTProxy::GTProxy( const std::shared_ptr<SessionImpl>& session ):
92  m_data( new GTProxyData ),
93  m_session( session ){
94  }
95 
96  GTProxy::GTProxy( const GTProxy& rhs ):
97  m_data( rhs.m_data ),
98  m_session( rhs.m_session ){
99  }
100 
102  m_data = rhs.m_data;
103  m_session = rhs.m_session;
104  return *this;
105  }
106 
124  // overloading for pre- and post-fix. Used in the ORA implementation
125  void GTProxy::load( const std::string& gtName, const std::string& pref, const std::string& postf ){
126  // clear
127  reset();
128 
129  checkTransaction( "GTProxy::load" );
130 
131  if(!m_session->gtSchema().gtTable().select( gtName, m_data->validity, m_data->snapshotTime ) ){
132  throwException( "Global Tag \""+gtName+"\" has not been found in the database.","GTProxy::load");
133  }
134  m_data->name = gtName;
135  m_data->preFix = pref;
136  m_data->postFix = postf;
137 
138  m_session->gtSchema().gtMapTable().select( m_data->name, pref, postf, m_data->tagList );
139 
140  }
141 
142 
144  load( m_data->name );
145  }
146 
148  if( m_data.get() ){
149  m_data->tagList.clear();
150  }
151  }
152 
154  return m_data.get() ? m_data->name : std::string("");
155  }
156 
158  return m_data.get() ? m_data->validity : cond::time::MIN_VAL;
159  }
160 
161  boost::posix_time::ptime GTProxy::snapshotTime() const {
162  return m_data.get() ? m_data->snapshotTime : boost::posix_time::ptime();
163  }
164 
166  if( !m_session.get() ) throwException("The session is not active.",ctx );
167  if( !m_session->isTransactionActive( false ) ) throwException("The transaction is not active.",ctx );
168  }
169 
171  if( m_data.get() ){
172  return Iterator( m_data->tagList.begin() );
173  }
174  return Iterator();
175  }
176 
178  if( m_data.get() ){
179  return Iterator( m_data->tagList.end() );
180  }
181  return Iterator();
182  }
183 
184  int GTProxy::size() const {
185  return m_data.get()? m_data->tagList.size() : 0;
186  }
187 
188  }
189 }
GTContainer::const_iterator m_current
Definition: GTProxy.h:58
std::vector< std::tuple< std::string, std::string, std::string > > GTContainer
Definition: GTProxy.h:33
list pfn
Definition: dbtoconf.py:76
GTProxy & operator=(const GTProxy &rhs)
Definition: GTProxy.cc:101
Iterator & operator=(const Iterator &rhs)
Definition: GTProxy.cc:55
const Time_t MIN_VAL(0)
bool operator==(const Iterator &rhs) const
Definition: GTProxy.cc:77
void checkTransaction(const std::string &ctx)
Definition: GTProxy.cc:165
bool operator==(const CaloTower &t1, const CaloTower &t2)
Definition: CaloTower.h:209
cond::Time_t validity() const
Definition: GTProxy.cc:157
unsigned long long Time_t
Definition: Time.h:16
boost::posix_time::ptime snapshotTime
Definition: GTProxy.cc:38
std::pair< std::string, std::string > parseTag(const std::string &tag)
Definition: GTProxy.cc:8
void load(const std::string &gtName, const std::string &preFix="", const std::string &postFix="")
Definition: GTProxy.cc:125
GTProxy::GTContainer tagList
Definition: GTProxy.cc:40
std::shared_ptr< GTProxyData > m_data
Definition: GTProxy.h:103
boost::posix_time::ptime snapshotTime() const
Definition: GTProxy.cc:161
Iterator begin() const
Definition: GTProxy.cc:170
Iterator end() const
Definition: GTProxy.cc:177
std::string name() const
Definition: GTProxy.cc:153
bool operator!=(const Iterator &rhs) const
Definition: GTProxy.cc:82
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::shared_ptr< SessionImpl > m_session
Definition: GTProxy.h:104
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:11