CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GTEditor.cc
Go to the documentation of this file.
2 #include "SessionImpl.h"
3 //
4 
5 namespace cond {
6 
7  namespace persistency {
8 
9  // GT data...
10  class GTEditorData {
11  public:
12  explicit GTEditorData():
13  name( "" ),
14  description(""),
15  release(""),
16  snapshotTime(),
17  tagListBuffer(){
18  }
19  // GT data
24  boost::posix_time::ptime snapshotTime;
25  bool change = false;
26  bool exists = false;
27  // buffer for the GT tag map
28  std::vector<std::tuple<std::string,std::string,std::string> > tagListBuffer;
29  };
30 
31  GTEditor::GTEditor( const std::shared_ptr<SessionImpl>& session ):
32  m_data( new GTEditorData ),
33  m_session( session ){
34  }
35 
36  GTEditor::GTEditor( const std::shared_ptr<SessionImpl>& session,
37  const std::string& gtName ):
38  m_data( new GTEditorData ),
39  m_session( session ){
40  m_data->name = gtName;
41  m_data->change = true;
42  }
43 
45  m_data( rhs.m_data ){
46  }
47 
49  m_data = rhs.m_data;
50  return *this;
51  }
52 
53  void GTEditor::load( const std::string& gtName ){
54  checkTransaction( "GTEditor::load" );
55 
56  // loads the current header data in memory
57  if( !m_session->gtSchema().gtTable().select( gtName, m_data->validity, m_data->description, m_data->release, m_data->snapshotTime ) ){
58  throwException( "Global Tag \""+gtName+"\" has not been found in the database.","GTEditor::load");
59  }
60  m_data->name = gtName;
61  m_data->exists = true;
62  m_data->change = false;
63  }
64 
66  return m_data.get()? m_data->name : "" ;
67  }
68 
70  return m_data.get()? m_data->validity : cond::time::MIN_VAL;
71  }
72 
74  if( m_data.get() ) {
75  m_data->validity = validity;
76  m_data->change = true;
77  }
78  }
79 
81  return m_data.get()? m_data->description : "";
82  }
83 
85  if( m_data.get() ) {
86  m_data->description = description;
87  m_data->change = true;
88  }
89  }
90 
92  return m_data.get()? m_data->release : "";
93  }
94 
96  if( m_data.get() ) {
97  m_data->release = release;
98  m_data->change = true;
99  }
100  }
101 
102  boost::posix_time::ptime GTEditor::snapshotTime() const {
103  return m_data.get()? m_data->snapshotTime : boost::posix_time::ptime();
104  }
105 
106  void GTEditor::setSnapshotTime( const boost::posix_time::ptime& snapshotTime ){
107  if( m_data.get() ) {
108  m_data->snapshotTime = snapshotTime;
109  m_data->change = true;
110  }
111  }
112 
113  void GTEditor::insert( const std::string& recordName, const std::string& tagName, bool checkType ){
114  insert( recordName, "-", tagName, checkType );
115  }
116 
117  void GTEditor::insert( const std::string& recordName, const std::string& recordLabel, const std::string& tagName, bool ){
118  if( m_data.get() ){
119  // here the type check could be added
120 
121  std::string rlabel = recordLabel;
122  if( rlabel.empty() ){
123  rlabel = "-";
124  }
125  m_data->tagListBuffer.push_back( std::tie( recordName, rlabel, tagName ) );
126  }
127  }
128 
129  bool GTEditor::flush( const boost::posix_time::ptime& operationTime ){
130  bool ret = false;
131  checkTransaction( "GTEditor::flush" );
132  if( m_data->change ){
133  if( m_data->description.empty() ) throwException( "A non-empty Description string is mandatory.","GTEditor::flush" );
134  if( m_data->release.empty() ) throwException( "A non-empty Release string is mandatory.","GTEditor::flush" );
135  if( !m_data->exists ){
136  m_session->gtSchema().gtTable().insert( m_data->name, m_data->validity, m_data->description,
137  m_data->release, m_data->snapshotTime, operationTime );
138  ret = true;
139  m_data->exists = true;
140  } else {
141  m_session->gtSchema().gtTable().update( m_data->name, m_data->validity, m_data->description,
142  m_data->release,m_data->snapshotTime, operationTime );
143  ret = true;
144  }
145  m_data->change = false;
146  }
147  if( m_data->tagListBuffer.size() ) {
148 
149  // insert the new iovs
150  m_session->gtSchema().gtMapTable().insert( m_data->name, m_data->tagListBuffer );
151  m_data->tagListBuffer.clear();
152  ret = true;
153  }
154  return ret;
155  }
156 
158  return flush( boost::posix_time::microsec_clock::universal_time() );
159  }
160 
161 
163  if( !m_session.get() ) throwException("The session is not active.",ctx );
164  if( !m_session->isTransactionActive( false ) ) throwException("The transaction is not active.",ctx );
165  }
166 
167  }
168 }
169 
170 
GTEditor(const std::shared_ptr< SessionImpl > &session)
Definition: GTEditor.cc:31
void setDescription(const std::string &description)
Definition: GTEditor.cc:84
std::string description() const
Definition: GTEditor.cc:80
const Time_t MIN_VAL(0)
void insert(const std::string &recordName, const std::string &tagName, bool checkType=false)
Definition: GTEditor.cc:113
std::shared_ptr< SessionImpl > m_session
Definition: GTEditor.h:76
unsigned long long Time_t
Definition: Time.h:16
void checkTransaction(const std::string &ctx)
Definition: GTEditor.cc:162
boost::posix_time::ptime snapshotTime
Definition: GTEditor.cc:24
boost::posix_time::ptime snapshotTime() const
Definition: GTEditor.cc:102
void setSnapshotTime(const boost::posix_time::ptime &snapshotTime)
Definition: GTEditor.cc:106
GTEditor & operator=(const GTEditor &rhs)
Definition: GTEditor.cc:48
tuple description
Definition: idDealer.py:66
std::string name() const
Definition: GTEditor.cc:65
std::string release() const
Definition: GTEditor.cc:91
void load(const std::string &gtName)
Definition: GTEditor.cc:53
std::vector< std::tuple< std::string, std::string, std::string > > tagListBuffer
Definition: GTEditor.cc:28
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:11
cond::Time_t validity() const
Definition: GTEditor.cc:69
void setRelease(const std::string &release)
Definition: GTEditor.cc:95
std::shared_ptr< GTEditorData > m_data
Definition: GTEditor.h:75
void setValidity(cond::Time_t validity)
Definition: GTEditor.cc:73