CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IOVService.cc
Go to the documentation of this file.
3 
8 
10 
11 
12 
13 
15  m_dbSess(dbSess) {}
16 
18 
20 cond::IOVService::newIOVEditor( const std::string& token ){
21  return new cond::IOVEditor( m_dbSess,token);
22 }
23 
24 
25 
26 
27 cond::IOVSequence const & cond::IOVService::iovSeq(const std::string& iovToken) {
28  if (m_token!=iovToken) {
29  m_iov = m_dbSess.getTypedObject<cond::IOVSequence>( iovToken );
30  m_token=iovToken;
31  }
32  return *m_iov;
33 }
34 
35 
36 
37 std::string
38 cond::IOVService::payloadToken( const std::string& iovToken,
39  cond::Time_t currenttime ){
40  cond::IOVSequence const & iov=iovSeq(iovToken);
41  cond::IOVSequence::const_iterator iEnd=iov.find(currenttime);
42  if( iEnd==iov.iovs().end() ){
43  return "";
44  }else{
45  return iEnd->wrapperToken();
46  }
47 }
48 
49 cond::TimeType cond::IOVService::timeType( const std::string& iovToken ) {
50  cond::IOVSequence const & iov=iovSeq(iovToken);
51  return iov.timeType();
52 }
53 
54 bool cond::IOVService::isValid( const std::string& iovToken,
55  cond::Time_t currenttime ){
56 
57  cond::IOVSequence const & iov=iovSeq(iovToken);
58  return ( currenttime >= iov.firstSince() &&
59  currenttime <= iov.lastTill() );
60 }
61 
62 std::pair<cond::Time_t, cond::Time_t>
63 cond::IOVService::validity( const std::string& iovToken, cond::Time_t currenttime ){
64 
65  cond::IOVSequence const & iov=iovSeq(iovToken);
66 
67  cond::Time_t since=iov.firstSince();
68  cond::Time_t till=iov.lastTill();
69  IOVSequence::const_iterator iter=iov.find(currenttime);
70  if (iter!=iov.iovs().end()) {
71  since=iter->sinceTime();
72  iter++;
73  if (iter!=iov.iovs().end())
74  till = iter->sinceTime()-1;
75  }
76  else {
77  since=iov.lastTill();
78  }
79  return std::pair<cond::Time_t, cond::Time_t>(since,till);
80 }
81 
82 std::string
83 cond::IOVService::payloadContainerName( const std::string& iovToken ){
84  cond::IOVSequence const & iov=iovSeq(iovToken);
85 
86  // FIXME move to metadata
87  std::string payloadtokstr=iov.iovs().front().wrapperToken();
88  std::pair<std::string,int> oidData = parseToken( payloadtokstr );
89  return oidData.first;
90 }
91 
92 
93 
94 
95 void
96 cond::IOVService::deleteAll(bool withPayload){
97  ora::Database& db = m_dbSess.storage();
99  ora::ContainerIterator it = cont.iterator();
100  while ( it.next() ) {
101  if(withPayload){
102  std::string tokenStr;
103  IOVSequence::const_iterator payloadIt;
104  boost::shared_ptr<cond::IOVSequence> iov = it.get<cond::IOVSequence>();
105  IOVSequence::const_iterator payloadItBegin=iov->iovs().begin();
106  IOVSequence::const_iterator payloadItEnd=iov->iovs().end();
107  for(payloadIt=payloadItBegin;payloadIt!=payloadItEnd;++payloadIt){
108  tokenStr=payloadIt->wrapperToken();
109  m_dbSess.deleteObject( tokenStr );
110  }
111  }
112  cont.erase( it.itemId() );
113  }
114  cont.flush();
115 }
116 
117 std::string
119  const std::string& iovToken){
120  cond::IOVSequence const & iov=iovSeq(iovToken);
121 
122  boost::shared_ptr<cond::IOVSequence> newiov(new cond::IOVSequence(iov.timeType(), iov.lastTill(),iov.metadataToken()));
123 
124  for( IOVSequence::const_iterator it=iov.iovs().begin();
125  it!=iov.iovs().end(); ++it){
126  std::string newPToken = destDB.importObject( m_dbSess, it->wrapperToken());
127  newiov->add(it->sinceTime(),newPToken);
128  }
129  return destDB.storeObject(newiov.get(), cond::IOVNames::container());
130 }
131 
133 /*
134 void cond::IOVService::loadDicts( const std::string& iovToken) {
135  // loadlib
136  boost::shared_ptr<cond::IOVSequence> iov = m_dbSess.getTypedObject<cond::IOVSequence>(iovToken);
137  // FIXME use iov metadata
138  std::string ptok = iov->iovs().front().wrapperToken();
139  m_dbSess.transaction().commit();
140  cond::reflexTypeByToken(ptok);
141  m_dbSess.transaction().start(true);
142 }
143 */
144 
145 std::string
147  const std::string& iovToken,
148  const std::string& destToken,
149  cond::Time_t since,
150  cond::Time_t till,
151  bool outOfOrder
152  ){
153 
154 
156  //loadDicts(iovToken);
157  cond::IOVSequence const & iov=iovSeq(iovToken);
158  since = std::max(since, iov.firstSince());
159  IOVSequence::const_iterator ifirstTill=iov.find(since);
160  IOVSequence::const_iterator isecondTill=iov.find(till);
161  if( isecondTill!=iov.iovs().end() ) isecondTill++;
162 
163  if (ifirstTill==isecondTill)
164  throw cond::Exception("IOVServiceImpl::exportIOVRangeWithPayload Error: empty input range");
165 
166  // since > ifirstTill->sinceTime() used to overwrite the actual time
167  //since = ifirstTill->sinceTime();
168 
169  boost::shared_ptr<cond::IOVSequence> newiovref;
170  //FIXME more option and eventually ability to resume (roll back is difficult)
171  std::string dToken = destToken;
172  if (dToken.empty()) {
173  // create a new one
174  newiovref.reset( new cond::IOVSequence(iov.timeType(), iov.lastTill(),iov.metadataToken()));
175  dToken = destDB.storeObject( newiovref.get(),cond::IOVNames::container());
176  } else {
177  newiovref = destDB.getTypedObject<cond::IOVSequence>(destToken);
178  if (newiovref->iovs().empty()) ; // do not waist time
179  else if (outOfOrder) {
180  for( IOVSequence::const_iterator it=ifirstTill;
181  it!=isecondTill; ++it)
182  if (newiovref->exist(it->sinceTime()))
183  throw cond::Exception("IOVServiceImpl::exportIOVRangeWithPayload Error: since time already exists");
184  } else if (since <= newiovref->iovs().back().sinceTime())
185  throw cond::Exception("IOVServiceImpl::exportIOVRangeWithPayload Error: since time out of range, below last since");
186  destDB.updateObject( newiovref.get(),destToken );
187  }
188 
189  cond::Time_t lsince = since;
190  for( IOVSequence::const_iterator it=ifirstTill;
191  it!=isecondTill; ++it, lsince=it->sinceTime()){
192  // first since overwritten by global since...
193 
194  std::string newPtoken = destDB.importObject( m_dbSess,it->wrapperToken());
195  newiovref->add(lsince, newPtoken);
196  }
197  newiovref->stamp(cond::userInfo(),false);
198  destDB.updateObject( newiovref.get(),dToken );
199  return dToken;
200 }
201 
IOVService(cond::DbSession &dbSess)
Definition: IOVService.cc:14
cond::Time_t lastTill() const
Definition: IOVSequence.h:63
iterator end()
Definition: PVector.h:67
std::string const & metadataToken() const
Definition: IOVSequence.h:74
std::pair< std::string, int > parseToken(const std::string &objectId)
Definition: PoolToken.cc:16
virtual ~IOVService()
Definition: IOVService.cc:17
const_iterator find(cond::Time_t time) const
Definition: IOVSequence.cc:85
std::string exportIOVWithPayload(cond::DbSession &destDB, const std::string &iovToken)
Definition: IOVService.cc:118
iterator begin()
Definition: PVector.h:62
boost::shared_ptr< T > get()
Definition: Container.h:105
cond::Time_t firstSince() const
Definition: IOVSequence.h:61
Container const & iovs() const
Definition: IOVSequence.cc:54
tuple db
Definition: EcalCondDB.py:151
IOVEditor * newIOVEditor(const std::string &token="")
Definition: IOVService.cc:20
void deleteAll(bool withPayload=false)
Definition: IOVService.cc:96
Container::const_iterator const_iterator
Definition: IOVSequence.h:27
std::string payloadToken(const std::string &iovToken, cond::Time_t currenttime)
Definition: IOVService.cc:38
TimeType
Definition: Time.h:21
unsigned long long Time_t
Definition: Time.h:16
tuple iov
Definition: o2o.py:307
const T & max(const T &a, const T &b)
Container containerHandle(const std::string &name)
Definition: Database.cc:236
reference front()
Definition: PVector.h:152
std::pair< cond::Time_t, cond::Time_t > validity(const std::string &iovToken, cond::Time_t currenttime)
Definition: IOVService.cc:63
bool isValid(const std::string &iovToken, cond::Time_t currenttime)
Definition: IOVService.cc:54
std::string payloadContainerName(const std::string &iovtoken)
Definition: IOVService.cc:83
cond::TimeType timeType(const std::string &iovToken)
Definition: IOVService.cc:49
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:104
void erase(int itemId)
Definition: Container.cc:133
std::string exportIOVRangeWithPayload(cond::DbSession &destDB, const std::string &iovToken, const std::string &destToken, cond::Time_t since, cond::Time_t till, bool outOfOrder)
Definition: IOVService.cc:146
int cont
std::string importObject(cond::DbSession &fromDatabase, const std::string &objectId)
Definition: DbSession.cc:215
static std::string container()
Definition: futureIOVNames.h:7
std::string userInfo()
Definition: IOVInfo.cc:9
bool updateObject(const T *object, const std::string &objectId)
Definition: DbSession.h:117
cond::IOVSequence const & iovSeq(const std::string &iovToken)
Definition: IOVService.cc:27
ContainerIterator iterator()
Definition: Container.cc:79
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:98
cond::TimeType timeType() const
Definition: IOVSequence.h:58