Go to the documentation of this file.00001 #include "CondFormats/Common/interface/IOVSequence.h"
00002 #include "CondFormats/Common/interface/Time.h"
00003 #include <algorithm>
00004 #include <boost/bind.hpp>
00005
00006
00007 namespace cond {
00008
00009
00010 IOVSequence::IOVSequence() : m_notOrdered(false), m_sorted(0) {}
00011
00012 IOVSequence::IOVSequence(cond::TimeType ttype) :
00013 m_timetype(ttype), m_lastTill(timeTypeSpecs[ttype].endValue),
00014 m_notOrdered(false), m_metadata(" "), m_sorted(0) {}
00015
00016
00017
00018 IOVSequence::IOVSequence(int type, cond::Time_t till,
00019 std::string const& imetadata) :
00020 m_timetype(type), m_lastTill(till),m_notOrdered(false),
00021 m_metadata(imetadata), m_sorted(0) {}
00022
00023 IOVSequence::~IOVSequence(){
00024 delete m_sorted;
00025 }
00026
00027 IOVSequence::IOVSequence(IOVSequence const & rh) :
00028 UpdateStamp(rh),
00029 m_iovs(rh.m_iovs),
00030 m_timetype(rh.m_timetype),
00031 m_lastTill(rh.m_lastTill),
00032 m_notOrdered(rh.m_notOrdered),
00033 m_metadata(rh.m_metadata),
00034 m_sorted(0) {}
00035
00036 IOVSequence & IOVSequence::operator=(IOVSequence const & rh) {
00037 delete m_sorted; m_sorted=0;
00038
00039 m_iovs = rh.m_iovs;
00040 m_timetype = rh.m_timetype;
00041 m_lastTill=rh.m_lastTill;
00042 m_notOrdered=rh.m_notOrdered;
00043 m_metadata = rh.m_metadata;
00044 return *this;
00045 }
00046
00047
00048 void IOVSequence::loadAll() const {
00049
00050
00051
00052 }
00053
00054 IOVSequence::Container const & IOVSequence::iovs() const {
00055 if (m_sorted) return *m_sorted;
00056 if (m_notOrdered) return sortMe();
00057 return m_iovs;
00058 }
00059
00060 IOVSequence::Container const & IOVSequence::sortMe() const {
00061 delete m_sorted;
00062 Container * local = new Container(m_iovs);
00063 std::sort(local->begin(), local->end(), boost::bind(std::less<cond::Time_t>(),
00064 boost::bind(&Item::sinceTime,_1),
00065 boost::bind(&Item::sinceTime,_2)
00066 ) );
00067 m_sorted = local;
00068 return *m_sorted;
00069 }
00070
00071
00072 size_t IOVSequence::add(cond::Time_t time,
00073 std::string const & wrapperToken) {
00074 if (!piovs().empty() && ( m_notOrdered || time<piovs().back().sinceTime())) disorder();
00075 piovs().push_back(Item(time, wrapperToken));
00076 return piovs().size()-1;
00077 }
00078
00079 size_t IOVSequence::truncate() {
00080 if (m_notOrdered) disorder();
00081 piovs().pop_back();
00082 return piovs().size()-1;
00083 }
00084
00085 IOVSequence::const_iterator IOVSequence::find(cond::Time_t time) const {
00086 if (time>lastTill()) return iovs().end();
00087 IOVSequence::const_iterator p = std::upper_bound(iovs().begin(),iovs().end(),Item(time),
00088 boost::bind(std::less<cond::Time_t>(),
00089 boost::bind(&Item::sinceTime,_1),
00090 boost::bind(&Item::sinceTime,_2)
00091 )
00092 );
00093 return (p!=iovs().begin()) ? p-1 : iovs().end();
00094 }
00095
00096
00097 IOVSequence::const_iterator IOVSequence::findSince(cond::Time_t time) const {
00098 IOVSequence::const_iterator p = find(time);
00099 return (p!=iovs().end() && (*p).sinceTime()==time) ? p : iovs().end();
00100 }
00101
00102 bool IOVSequence::exist(cond::Time_t time) const {
00103 return findSince(time)!=iovs().end();
00104 }
00105
00106
00107 void IOVSequence::disorder() {
00108 m_notOrdered=true;
00109 delete m_sorted; m_sorted=0;
00110 }
00111
00112 }