test
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 
32  m_data(),
33  m_session(){
34  }
35 
36  GTEditor::GTEditor( const std::shared_ptr<SessionImpl>& session ):
37  m_data( new GTEditorData ),
38  m_session( session ){
39  }
40 
41  GTEditor::GTEditor( const std::shared_ptr<SessionImpl>& session,
42  const std::string& gtName ):
43  m_data( new GTEditorData ),
44  m_session( session ){
45  m_data->name = gtName;
46  m_data->change = true;
47  }
48 
50  m_data( rhs.m_data ),
51  m_session( rhs.m_session ){
52  }
53 
55  m_data = rhs.m_data;
56  m_session = rhs.m_session;
57  return *this;
58  }
59 
60  void GTEditor::load( const std::string& gtName ){
61  checkTransaction( "GTEditor::load" );
62 
63  // loads the current header data in memory
64  if( !m_session->gtSchema().gtTable().select( gtName, m_data->validity, m_data->description, m_data->release, m_data->snapshotTime ) ){
65  throwException( "Global Tag \""+gtName+"\" has not been found in the database.","GTEditor::load");
66  }
67  m_data->name = gtName;
68  m_data->exists = true;
69  m_data->change = false;
70  }
71 
73  return m_data.get()? m_data->name : "" ;
74  }
75 
77  return m_data.get()? m_data->validity : cond::time::MIN_VAL;
78  }
79 
81  if( m_data.get() ) {
82  m_data->validity = validity;
83  m_data->change = true;
84  }
85  }
86 
88  return m_data.get()? m_data->description : "";
89  }
90 
92  if( m_data.get() ) {
93  m_data->description = description;
94  m_data->change = true;
95  }
96  }
97 
99  return m_data.get()? m_data->release : "";
100  }
101 
103  if( m_data.get() ) {
104  m_data->release = release;
105  m_data->change = true;
106  }
107  }
108 
109  boost::posix_time::ptime GTEditor::snapshotTime() const {
110  return m_data.get()? m_data->snapshotTime : boost::posix_time::ptime();
111  }
112 
113  void GTEditor::setSnapshotTime( const boost::posix_time::ptime& snapshotTime ){
114  if( m_data.get() ) {
115  m_data->snapshotTime = snapshotTime;
116  m_data->change = true;
117  }
118  }
119 
120  void GTEditor::insert( const std::string& recordName, const std::string& tagName, bool checkType ){
121  insert( recordName, "-", tagName, checkType );
122  }
123 
124  void GTEditor::insert( const std::string& recordName, const std::string& recordLabel, const std::string& tagName, bool ){
125  if( m_data.get() ){
126  // here the type check could be added
127 
128  std::string rlabel = recordLabel;
129  if( rlabel.empty() ){
130  rlabel = "-";
131  }
132  m_data->tagListBuffer.push_back( std::tie( recordName, rlabel, tagName ) );
133  }
134  }
135 
136  bool GTEditor::flush( const boost::posix_time::ptime& operationTime ){
137  bool ret = false;
138  checkTransaction( "GTEditor::flush" );
139  if( m_data->change ){
140  if( m_data->description.empty() ) throwException( "A non-empty Description string is mandatory.","GTEditor::flush" );
141  if( m_data->release.empty() ) throwException( "A non-empty Release string is mandatory.","GTEditor::flush" );
142  if( !m_data->exists ){
143  m_session->gtSchema().gtTable().insert( m_data->name, m_data->validity, m_data->description,
144  m_data->release, m_data->snapshotTime, operationTime );
145  ret = true;
146  m_data->exists = true;
147  } else {
148  m_session->gtSchema().gtTable().update( m_data->name, m_data->validity, m_data->description,
149  m_data->release,m_data->snapshotTime, operationTime );
150  ret = true;
151  }
152  m_data->change = false;
153  }
154  if( m_data->tagListBuffer.size() ) {
155 
156  // insert the new iovs
157  m_session->gtSchema().gtMapTable().insert( m_data->name, m_data->tagListBuffer );
158  m_data->tagListBuffer.clear();
159  ret = true;
160  }
161  return ret;
162  }
163 
165  return flush( boost::posix_time::microsec_clock::universal_time() );
166  }
167 
168 
170  if( !m_session.get() ) throwException("The session is not active.",ctx );
171  if( !m_session->isTransactionActive( false ) ) throwException("The transaction is not active.",ctx );
172  }
173 
174  }
175 }
176 
177 
tuple ret
prodAgent to be discontinued
void setDescription(const std::string &description)
Definition: GTEditor.cc:91
std::string description() const
Definition: GTEditor.cc:87
const Time_t MIN_VAL(0)
void insert(const std::string &recordName, const std::string &tagName, bool checkType=false)
Definition: GTEditor.cc:120
tuple recordName
Definition: align_cfg.py:66
std::shared_ptr< SessionImpl > m_session
Definition: GTEditor.h:79
unsigned long long Time_t
Definition: Time.h:16
void checkTransaction(const std::string &ctx)
Definition: GTEditor.cc:169
boost::posix_time::ptime snapshotTime
Definition: GTEditor.cc:24
boost::posix_time::ptime snapshotTime() const
Definition: GTEditor.cc:109
void setSnapshotTime(const boost::posix_time::ptime &snapshotTime)
Definition: GTEditor.cc:113
GTEditor & operator=(const GTEditor &rhs)
Definition: GTEditor.cc:54
tuple description
Definition: idDealer.py:66
std::string name() const
Definition: GTEditor.cc:72
std::string release() const
Definition: GTEditor.cc:98
session
Definition: models.py:201
void load(const std::string &gtName)
Definition: GTEditor.cc:60
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:14
cond::Time_t validity() const
Definition: GTEditor.cc:76
void setRelease(const std::string &release)
Definition: GTEditor.cc:102
std::shared_ptr< GTEditorData > m_data
Definition: GTEditor.h:78
void setValidity(cond::Time_t validity)
Definition: GTEditor.cc:80