CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IOVSequence.cc
Go to the documentation of this file.
3 #include <algorithm>
4 #include <boost/bind.hpp>
5 
6 namespace cond {
7 
9  m_iovs(),
10  m_timetype(-1),
11  m_lastTill(0),
12  m_notOrdered(false),
13  m_metadata(""),
14  m_payloadClasses(),
15  m_scope( Unknown ),
16  m_sorted(0) {}
17 
19  m_iovs(),
20  m_timetype(ttype),
21  m_lastTill(timeTypeSpecs[ttype].endValue),
22  m_notOrdered(false),
23  m_metadata(" "),
24  m_payloadClasses(),
25  m_scope( Unknown ),
26  m_sorted(0) {}
27 
29  cond::Time_t till,
30  std::string const& imetadata) :
31  m_iovs(),
32  m_timetype(ttype),
33  m_lastTill(till),
34  m_notOrdered(false),
35  m_metadata(imetadata),
36  m_payloadClasses(),
37  m_scope( Unknown ),
38  m_sorted(0) {}
39 
41  delete m_sorted;
42  }
43 
45  UpdateStamp(rh),
46  m_iovs(rh.m_iovs),
47  m_timetype(rh.m_timetype),
48  m_lastTill(rh.m_lastTill),
49  m_notOrdered(rh.m_notOrdered),
50  m_metadata(rh.m_metadata),
51  m_payloadClasses(rh.m_payloadClasses),
52  m_scope( rh.m_scope ),
53  m_sorted(0) {}
54 
56  delete m_sorted; m_sorted=0;
57 
58  m_iovs = rh.m_iovs;
64  m_scope = rh.m_scope;
65  return *this;
66  }
67 
68 
69  void IOVSequence::loadAll() const {
70  // m_provenance.get();
71  // m_description.get();
72  // m_userMetadata.get();
73  m_iovs.load();
74  }
75 
77  if (m_sorted) return *m_sorted;
78  if (m_notOrdered) return sortMe();
79  return m_iovs;
80  }
81 
83  m_iovs.load();
84  delete m_sorted; // shall not be necessary;
85  Container * local = new Container(m_iovs);
86  std::sort(local->begin(), local->end(), boost::bind(std::less<cond::Time_t>(),
87  boost::bind(&Item::sinceTime,_1),
88  boost::bind(&Item::sinceTime,_2)
89  ) );
90  m_sorted = local;
91  return *m_sorted;
92  }
93 
94 
96  std::string const & token,
97  std::string const & payloadClassName ) {
98  if (!piovs().empty() && ( m_notOrdered || time<piovs().back().sinceTime())) disorder();
99  piovs().push_back(Item(time, token));
100  m_payloadClasses.insert( payloadClassName );
101  return piovs().size()-1;
102  }
103 
105  if (m_notOrdered) disorder();
106  piovs().pop_back();
107  return piovs().size()-1;
108  }
109 
111  if (time>lastTill()) return iovs().end();
112  IOVSequence::const_iterator p = std::upper_bound(iovs().begin(),iovs().end(),Item(time),
113  boost::bind(std::less<cond::Time_t>(),
114  boost::bind(&Item::sinceTime,_1),
115  boost::bind(&Item::sinceTime,_2)
116  )
117  );
118  return (p!=iovs().begin()) ? p-1 : iovs().end();
119  }
120 
121 
124  return (p!=iovs().end() && (*p).sinceTime()==time) ? p : iovs().end();
125  }
126 
128  return findSince(time)!=iovs().end();
129  }
130 
131  void IOVSequence::updateMetadata( const std::string& metadata,
132  bool append ){
133  std::string sep(". ");
134  if( !metadata.empty() ){
135  if (append && !m_metadata.empty()) {
136  m_metadata += sep + metadata;
137  }
138  else m_metadata = metadata;
139  }
140  }
141 
143  m_notOrdered=true;
144  delete m_sorted; m_sorted=0;
145  }
146 
149  iT != m_iovs.end(); ++iT ){
150  iT->swapToken( parser );
151  // adding the classname 'by hand'
152  std::string className = parser.className( iT->token() );
153  const_cast<IOVSequence* >(this)->m_payloadClasses.insert( className );
154  }
155  }
156 
157  void IOVSequence::swapOIds( ora::ITokenWriter& writer ) const {
159  iT != m_iovs.end(); ++iT ){
160  iT->swapOId( writer );
161  }
162  }
163 
164 }
165 
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
cond::Time_t lastTill() const
Definition: IOVSequence.h:65
Container & piovs()
Definition: IOVSequence.h:90
virtual std::string className(const std::string &poolToken)=0
std::string m_metadata
Definition: IOVSequence.h:116
const_iterator find(cond::Time_t time) const
Definition: IOVSequence.cc:110
void swapOIds(ora::ITokenWriter &writer) const
Definition: IOVSequence.cc:157
Container const & iovs() const
Definition: IOVSequence.cc:76
std::string const & metadata() const
Definition: IOVSequence.h:79
IOVSequence & operator=(IOVSequence const &rh)
Definition: IOVSequence.cc:55
ora::QueryableVector< Item > Container
Definition: IOVSequence.h:27
Container m_iovs
Definition: IOVSequence.h:112
Container::const_iterator const_iterator
Definition: IOVSequence.h:29
Container const & sortMe() const
Definition: IOVSequence.cc:82
TimeType
Definition: Time.h:21
bool exist(cond::Time_t time) const
Definition: IOVSequence.cc:127
unsigned long long Time_t
Definition: Time.h:16
void loadAll() const
Definition: IOVSequence.cc:69
size_t add(cond::Time_t time, std::string const &token, std::string const &payloadClassName)
Definition: IOVSequence.cc:95
void push_back(const Tp &x)
#define end
Definition: vmac.h:37
void swapTokens(ora::ITokenParser &parser) const
Definition: IOVSequence.cc:147
const_iterator findSince(cond::Time_t time) const
Definition: IOVSequence.cc:122
std::set< std::string > m_payloadClasses
Definition: IOVSequence.h:117
cond::IOVElement Item
Definition: IOVSequence.h:26
cond::Time_t sinceTime() const
Definition: IOVElement.h:33
#define begin
Definition: vmac.h:30
ScopeType m_scope
Definition: IOVSequence.h:118
char const * className(const std::type_info &t)
Definition: ClassID.cc:8
volatile std::atomic< bool > shutdown_flag false
Container * m_sorted
Definition: IOVSequence.h:120
cond::Time_t m_lastTill
Definition: IOVSequence.h:114
void updateMetadata(const std::string &metadata, bool append=true)
Definition: IOVSequence.cc:131