CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IOVEditor.cc
Go to the documentation of this file.
5 //#include "POOLCore/Token.h"
6 //#include "StorageSvc/DbReflex.h"
7 #include<ostream>
8 #include<sstream>
9 
10 namespace cond {
11 
13 
14  IOVEditor::IOVEditor( cond::DbSession& dbSess):m_dbSess(dbSess),
15  m_isActive(false){
16  }
17 
19  const std::string& token
20  ):m_dbSess(dbSess),m_token(token),
21  m_isActive(false){
22  }
23 
25 
26 
27  void IOVEditor::debugInfo(std::ostream & co) const {
28  co << "IOVEditor: ";
29  co << "db " << m_dbSess.connectionString();
30  if(m_token.empty()) {
31  co << " no token"; return;
32  }
33  if (!m_iov.get() ) {
34  co << " no iov for token " << m_token;
35  return;
36  }
37  co << " iov token " << m_token;
38  co << "\nStamp: " << m_iov->comment()
39  << "; time " << m_iov->timestamp()
40  << "; revision " << m_iov->revision();
41  co <<". TimeType " << cond::timeTypeSpecs[ m_iov->timeType()].name;
42  if( m_iov->iovs().empty() )
43  co << ". empty";
44  else
45  co << ". size " << m_iov->iovs().size()
46  << "; last since " << m_iov->iovs().back().sinceTime();
47  }
48 
49  void IOVEditor::reportError(std::string message) const {
50  std::ostringstream out;
51  out << "Error in ";
52  debugInfo(out);
53  out << "\n" << message;
54  throw cond::Exception(out.str());
55  }
56 
57  void IOVEditor::reportError(std::string message, cond::Time_t time) const {
58  std::ostringstream out;
59  out << "Error in";
60  debugInfo(out);
61  out << "\n" << message << " for time: " << time;
62  throw cond::Exception(out.str());
63  }
64 
65 
66  // create empty default sequence
68  if(!m_token.empty()){
69  // problem??
70  reportError("cond::IOVEditor::create cannot create a IOV using an initialized Editor");
71  }
72 
73  m_iov.reset( new cond::IOVSequence(timetype) );
75  m_isActive=true;
76 
77  }
78 
80  if(!m_token.empty()){
81  // problem??
82  reportError("cond::IOVEditor::create cannot create a IOV using an initialized Editor");
83  }
84 
85  if(!validTime(lastTill, timetype))
86  reportError("cond::IOVEditor::create time not in global range",lastTill);
87 
88  m_iov.reset( new cond::IOVSequence((int)timetype,lastTill," ") );
90  m_isActive=true;
91  }
92 
94  if(m_token.empty()){
95  // problem?
96  reportError("cond::IOVEditor::init cannot init w/o token change");
97  }
98 
100  m_isActive=true;
101 
102  }
103 
104 
106  return m_iov->firstSince();
107  }
108 
110  return m_iov->lastTill();
111  }
112 
114  return m_iov->timeType();
115  }
116 
117 
120 
121  }
122 
124  return validTime(time,timetype());
125  }
126 
127 
128 
129  unsigned int
131  const std::string& payloadToken
132  ){
133  if(!m_isActive) this->init();
134 
135  if( m_iov->iovs().empty() )
136  reportError("cond::IOVEditor::insert cannot inser into empty IOV sequence",tillTime);
137 
138  if(!validTime(tillTime))
139  reportError("cond::IOVEditor::insert time not in global range",tillTime);
140 
141  if(tillTime<=lastTill() )
142  reportError("cond::IOVEditor::insert IOV not in range",tillTime);
143 
144  cond::Time_t newSince=lastTill()+1;
145  unsigned int ret = m_iov->add(newSince, payloadToken);
146  updateClosure(tillTime);
148  return ret;
149  }
150 
151  void
152  IOVEditor::bulkAppend(std::vector< std::pair<cond::Time_t,std::string> >& values){
153  if (values.empty()) return;
154  if(!m_isActive) this->init();
155  cond::Time_t firstTime = values.front().first;
156  cond::Time_t lastTime = values.back().first;
157  if(!validTime(firstTime))
158  reportError("cond::IOVEditor::bulkInsert first time not in global range",firstTime);
159 
160  if(!validTime(lastTime))
161  reportError("cond::IOVEditor::bulkInsert last time not in global range",lastTime);
162 
163  if(lastTime>=lastTill() ||
164  ( !m_iov->iovs().empty() && firstTime<=m_iov->iovs().back().sinceTime())
165  )
166  reportError("cond::IOVEditor::bulkInsert IOV not in range",firstTime);
167 
168  for(std::vector< std::pair<cond::Time_t,std::string> >::const_iterator it=values.begin(); it!=values.end(); ++it){
169  // m_iov->iov.insert(m_iov->iov.end(), values.begin(), values.end());
170  m_iov->add(it->first,it->second);
171  }
173  }
174 
175  void
176  IOVEditor::bulkAppend(std::vector< cond::IOVElement >& values){
177  if (values.empty()) return;
178  if(!m_isActive) this->init();
179  cond::Time_t firstTime = values.front().sinceTime();
180  cond::Time_t lastTime = values.back().sinceTime();
181  if(!validTime(firstTime))
182  reportError("cond::IOVEditor::bulkInsert first time not in global range",firstTime);
183 
184  if(!validTime(lastTime))
185  reportError("cond::IOVEditor::bulkInsert last time not in global range",lastTime);
186 
187  if(lastTime>=lastTill() ||
188  ( !m_iov->iovs().empty() && firstTime<=m_iov->iovs().back().sinceTime())
189  ) reportError("cond::IOVEditor::bulkInsert IOV not in range",firstTime);
190 
192  }
193 
194 
195  void
196  IOVEditor::stamp(std::string const & icomment, bool append) {
197  if(!m_isActive) this->init();
198  m_iov->stamp(icomment, append);
200  }
201 
202 
203  void
205  if( m_token.empty() ) reportError("cond::IOVEditor::updateClosure cannot change non-existing IOV index");
206  if(!m_isActive) this->init();
207  m_iov->updateLastTill(newtillTime);
209  }
210 
211  unsigned int
213  const std::string&payloadToken
214  ){
215  if( m_token.empty() ) {
216  reportError("cond::IOVEditor::appendIOV cannot append to non-existing IOV index");
217  }
218 
219  if(!m_isActive) {
220  this->init();
221  }
222 
223  if(!validTime(sinceTime))
224  reportError("cond::IOVEditor::append time not in global range",sinceTime);
225 
226 
227  if( !m_iov->iovs().empty() ){
228  //range check in case
229  cond::Time_t lastValidSince=m_iov->iovs().back().sinceTime();
230  if( sinceTime<= lastValidSince){
231  reportError("IOVEditor::append Error: since time out of range: below last since",sinceTime);
232  }
233  }
234 
235  // does it make sense? (in case of mixed till and since insertions...)
236  if (lastTill()<=sinceTime) updateClosure(timeTypeSpecs[timetype()].endValue);
237  unsigned int ret = m_iov->add(sinceTime,payloadToken);
239  return ret;
240  }
241 
242 
243  unsigned int
245  const std::string& payloadToken
246  ){
247  // reportError("cond::IOVEditor::freeInsert not supported yet");
248 
249  if( m_token.empty() ) {
250  reportError("cond::IOVEditor::freeInsert cannot append to non-existing IOV index");
251  }
252 
253  if(!m_isActive) {
254  this->init();
255  }
256 
257  // if( m_iov->iov.empty() ) reportError("cond::IOVEditor::freeInsert cannot insert to empty IOV index");
258 
259 
260  if(!validTime(sinceTime))
261  reportError("cond::IOVEditor::freeInsert time not in global range",sinceTime);
262 
263 
264  // we do not support multiple iov with identical since...
265  if (m_iov->exist(sinceTime))
266  reportError("cond::IOVEditor::freeInsert sinceTime already existing",sinceTime);
267 
268 
269 
270  // does it make sense? (in case of mixed till and since insertions...)
272  unsigned int ret = m_iov->add(sinceTime,payloadToken);
273 
275  return ret;
276  }
277 
278 
279  // remove last entry
280  unsigned int IOVEditor::truncate(bool withPayload) {
281  if( m_token.empty() ) reportError("cond::IOVEditor::truncate cannot delete to non-existing IOV sequence");
282  if(!m_isActive) this->init();
283  if (m_iov->piovs().empty()) return 0;
284  if(withPayload){
285  std::string tokenStr = m_iov->piovs().back().wrapperToken();
286  m_dbSess.deleteObject( tokenStr );
287  }
288  unsigned int ret = m_iov->truncate();
290  return ret;
291 
292  }
293 
294 
295  void
296  IOVEditor::deleteEntries(bool withPayload){
297  if( m_token.empty() ) reportError("cond::IOVEditor::deleteEntries cannot delete to non-existing IOV sequence");
298  if(!m_isActive) this->init();
299  if(withPayload){
300  std::string tokenStr;
301  IOVSequence::const_iterator payloadIt;
302  IOVSequence::const_iterator payloadItEnd=m_iov->piovs().end();
303  for(payloadIt=m_iov->piovs().begin();payloadIt!=payloadItEnd;++payloadIt){
304  tokenStr=payloadIt->wrapperToken();
305  m_dbSess.deleteObject( tokenStr );
306  }
307  }
309  m_iov->piovs().clear();
310  }
311 
312  void
313  IOVEditor::import( const std::string& sourceIOVtoken ){
314  if( !m_token.empty() ) reportError("cond::IOVEditor::import IOV sequence already exists, cannot import");
315  m_iov = m_dbSess.getTypedObject<cond::IOVSequence>(sourceIOVtoken);
316  //m_token=m_iov.toString();
317  m_token=sourceIOVtoken;
318  }
319 
320 
321 }
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
const std::string & connectionString() const
Definition: DbSession.cc:133
void debugInfo(std::ostream &co) const
Definition: IOVEditor.cc:27
bool deleteObject(const std::string &objectId)
Definition: DbSession.cc:207
void reportError(std::string message) const
Definition: IOVEditor.cc:49
Time_t beginValue
Definition: Time.h:45
bool validTime(cond::Time_t time, cond::TimeType timetype) const
Definition: IOVEditor.cc:118
Time_t lastTill() const
Definition: IOVEditor.cc:109
std::string m_token
Definition: IOVEditor.h:103
Container::const_iterator const_iterator
Definition: IOVSequence.h:27
unsigned int freeInsert(cond::Time_t sinceTime, const std::string &payloadToken)
insert a payload with known since in any position
Definition: IOVEditor.cc:244
TimeType
Definition: Time.h:21
IOVSequence & iov()
Definition: IOVEditor.cc:24
void create(cond::TimeType timetype)
Definition: IOVEditor.cc:67
unsigned int truncate(bool withPayload=false)
Definition: IOVEditor.cc:280
unsigned long long Time_t
Definition: Time.h:16
TimeType timetype() const
Definition: IOVEditor.cc:113
bool firstTime
Definition: QTestHandle.cc:18
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:104
tuple out
Definition: dbtoconf.py:99
unsigned int insert(cond::Time_t tillTime, const std::string &payloadToken)
Assign a payload with till time. Returns the payload index in the iov sequence.
Definition: IOVEditor.cc:130
void updateClosure(cond::Time_t newtillTime)
Update the closure of the iov sequence.
Definition: IOVEditor.cc:204
unsigned int append(cond::Time_t sinceTime, const std::string &payloadToken)
Append a payload with known since time. The previous last payload&#39;s till time will be adjusted to the...
Definition: IOVEditor.cc:212
std::string name
Definition: Time.h:43
string message
Definition: argparse.py:126
void import(const std::string &sourceIOVtoken)
Definition: IOVEditor.cc:313
static std::string container()
Definition: futureIOVNames.h:7
void bulkAppend(std::vector< std::pair< cond::Time_t, std::string > > &values)
Bulk append of iov chunck.
Definition: IOVEditor.cc:152
boost::shared_ptr< cond::IOVSequence > m_iov
Definition: IOVEditor.h:105
void stamp(std::string const &icomment, bool append=false)
Definition: IOVEditor.cc:196
void deleteEntries(bool withPayload=false)
Definition: IOVEditor.cc:296
Time_t endValue
Definition: Time.h:46
IOVEditor(cond::DbSession &dbSess)
Definition: IOVEditor.cc:14
bool updateObject(const T *object, const std::string &objectId)
Definition: DbSession.h:117
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:98
Time_t firstSince() const
Definition: IOVEditor.cc:105
cond::DbSession m_dbSess
Definition: IOVEditor.h:102
~IOVEditor()
Destructor.
Definition: IOVEditor.cc:12