CMS 3D CMS Logo

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())
10  return tag;
11  return tag + "@[" + connectionString + "]";
12  }
13 
14  std::pair<std::string, std::string> parseTag(const std::string& tag) {
15  std::string pfn("");
16  std::string t(tag);
17  size_t pos = tag.rfind("[");
18  if (pos != std::string::npos && tag.size() >= pos + 2) {
19  if (tag[pos - 1] == '@' && tag[tag.size() - 1] == ']') {
20  pfn = tag.substr(pos + 1, tag.size() - pos - 2);
21  t = tag.substr(0, pos - 1);
22  }
23  }
24  return std::make_pair(t, pfn);
25  }
26 
27  // implementation details...
28  // only hosting data in this case
29  class GTProxyData {
30  public:
31  GTProxyData() : name(""), preFix(""), postFix(""), tagList() {}
32 
34  // will become useless after the transition...
38  boost::posix_time::ptime snapshotTime;
39  // tag list
41  };
42 
43  GTProxy::Iterator::Iterator() : m_current() {}
44 
45  GTProxy::Iterator::Iterator(GTContainer::const_iterator current) : m_current(current) {}
46 
48 
50  if (this != &rhs) {
51  m_current = rhs.m_current;
52  }
53  return *this;
54  }
55 
57 
59  m_current++;
60  return *this;
61  }
62 
64  Iterator tmp(*this);
65  operator++();
66  return tmp;
67  }
68 
69  bool GTProxy::Iterator::operator==(const Iterator& rhs) const {
70  if (m_current != rhs.m_current)
71  return false;
72  return true;
73  }
74 
75  bool GTProxy::Iterator::operator!=(const Iterator& rhs) const { return !operator==(rhs); }
76 
78 
79  GTProxy::GTProxy(const std::shared_ptr<SessionImpl>& session) : m_data(new GTProxyData), m_session(session) {}
80 
82 
84  m_data = rhs.m_data;
85  m_session = rhs.m_session;
86  return *this;
87  }
88 
106  // overloading for pre- and post-fix. Used in the ORA implementation
107  void GTProxy::load(const std::string& gtName, const std::string& pref, const std::string& postf) {
108  // clear
109  reset();
110 
111  checkTransaction("GTProxy::load");
112 
113  if (!m_session->gtSchema().gtTable().select(gtName, m_data->validity, m_data->snapshotTime)) {
114  throwException("Global Tag \"" + gtName + "\" has not been found in the database.", "GTProxy::load");
115  }
116  m_data->name = gtName;
117  m_data->preFix = pref;
118  m_data->postFix = postf;
119 
120  m_session->gtSchema().gtMapTable().select(m_data->name, pref, postf, m_data->tagList);
121  }
122 
123  void GTProxy::reload() { load(m_data->name); }
124 
125  void GTProxy::reset() {
126  if (m_data.get()) {
127  m_data->tagList.clear();
128  }
129  }
130 
131  std::string GTProxy::name() const { return m_data.get() ? m_data->name : std::string(""); }
132 
133  cond::Time_t GTProxy::validity() const { return m_data.get() ? m_data->validity : cond::time::MIN_VAL; }
134 
135  boost::posix_time::ptime GTProxy::snapshotTime() const {
136  return m_data.get() ? m_data->snapshotTime : boost::posix_time::ptime();
137  }
138 
140  if (!m_session.get())
141  throwException("The session is not active.", ctx);
142  if (!m_session->isTransactionActive(false))
143  throwException("The transaction is not active.", ctx);
144  }
145 
147  if (m_data.get()) {
148  return Iterator(m_data->tagList.begin());
149  }
150  return Iterator();
151  }
152 
154  if (m_data.get()) {
155  return Iterator(m_data->tagList.end());
156  }
157  return Iterator();
158  }
159 
160  int GTProxy::size() const { return m_data.get() ? m_data->tagList.size() : 0; }
161 
162  } // namespace persistency
163 } // namespace cond
GTContainer::const_iterator m_current
Definition: GTProxy.h:60
GTProxy & operator=(const GTProxy &rhs)
Definition: GTProxy.cc:83
Iterator & operator=(const Iterator &rhs)
Definition: GTProxy.cc:49
const Time_t MIN_VAL(0)
bool operator==(const Iterator &rhs) const
Definition: GTProxy.cc:69
void checkTransaction(const std::string &ctx)
Definition: GTProxy.cc:139
cond::Time_t validity() const
Definition: GTProxy.cc:133
TGeoIterator Iterator
unsigned long long Time_t
Definition: Time.h:14
boost::posix_time::ptime snapshotTime
Definition: GTProxy.cc:38
std::pair< std::string, std::string > parseTag(const std::string &tag)
Definition: GTProxy.cc:14
void load(const std::string &gtName, const std::string &preFix="", const std::string &postFix="")
Definition: GTProxy.cc:107
GTProxy::GTContainer tagList
Definition: GTProxy.cc:40
std::shared_ptr< GTProxyData > m_data
Definition: GTProxy.h:105
boost::posix_time::ptime snapshotTime() const
Definition: GTProxy.cc:135
std::string fullyQualifiedTag(const std::string &tag, const std::string &connectionString)
Definition: GTProxy.cc:8
std::vector< std::tuple< std::string, std::string, std::string > > GTContainer
Definition: GTProxy.h:34
Iterator begin() const
Definition: GTProxy.cc:146
Iterator end() const
Definition: GTProxy.cc:153
std::string name() const
Definition: GTProxy.cc:131
bool operator!=(const Iterator &rhs) const
Definition: GTProxy.cc:75
Definition: plugin.cc:23
std::shared_ptr< SessionImpl > m_session
Definition: GTProxy.h:106
tmp
align.sh
Definition: createJobs.py:716
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12