CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/CondFormats/Common/src/IOVSequence.cc

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 namespace cond {
00007   
00008   IOVSequence::IOVSequence() : 
00009     m_iovs(),
00010     m_timetype(-1),
00011     m_lastTill(0),
00012     m_notOrdered(false), 
00013     m_metadata(""),
00014     m_payloadClasses(),
00015     m_scope( Unknown ),
00016     m_sorted(0) {}
00017   
00018   IOVSequence::IOVSequence( cond::TimeType ttype ) :
00019     m_iovs(),
00020     m_timetype(ttype),
00021     m_lastTill(timeTypeSpecs[ttype].endValue),
00022     m_notOrdered(false), 
00023     m_metadata(" "),
00024     m_payloadClasses(),
00025     m_scope( Unknown ),
00026     m_sorted(0) {}
00027 
00028   IOVSequence::IOVSequence(int ttype, 
00029                            cond::Time_t till, 
00030                            std::string const& imetadata) :
00031     m_iovs(),
00032     m_timetype(ttype),
00033     m_lastTill(till),
00034     m_notOrdered(false), 
00035     m_metadata(imetadata),
00036     m_payloadClasses(),
00037     m_scope( Unknown ),
00038     m_sorted(0) {}
00039     
00040   IOVSequence::~IOVSequence(){
00041     delete m_sorted;
00042   }
00043   
00044   IOVSequence::IOVSequence(IOVSequence const & rh) : 
00045     UpdateStamp(rh),
00046     m_iovs(rh.m_iovs),  
00047     m_timetype(rh.m_timetype),
00048     m_lastTill(rh.m_lastTill),
00049     m_notOrdered(rh.m_notOrdered),
00050     m_metadata(rh.m_metadata),
00051     m_payloadClasses(rh.m_payloadClasses),
00052     m_scope( rh.m_scope ),
00053     m_sorted(0) {}
00054   
00055   IOVSequence & IOVSequence::operator=(IOVSequence const & rh) {
00056     delete m_sorted;  m_sorted=0;
00057 
00058     m_iovs = rh.m_iovs;  
00059     m_timetype = rh.m_timetype;
00060     m_lastTill=rh.m_lastTill;
00061     m_notOrdered=rh.m_notOrdered;
00062     m_metadata = rh.m_metadata;
00063     m_payloadClasses = rh.m_payloadClasses;
00064     m_scope = rh.m_scope;
00065     return *this;
00066   }
00067 
00068 
00069   void IOVSequence::loadAll() const {
00070     // m_provenance.get();
00071     // m_description.get();
00072     // m_userMetadata.get();
00073     m_iovs.load();
00074   }
00075   
00076   IOVSequence::Container const & IOVSequence::iovs() const {
00077     if (m_sorted) return *m_sorted;
00078     if (m_notOrdered) return sortMe();
00079     return m_iovs;
00080   }
00081 
00082   IOVSequence::Container const & IOVSequence::sortMe() const {
00083     m_iovs.load();
00084     delete m_sorted; // shall not be necessary;
00085     Container * local = new Container(m_iovs);
00086     std::sort(local->begin(), local->end(), boost::bind(std::less<cond::Time_t>(),
00087                                                         boost::bind(&Item::sinceTime,_1),
00088                                                         boost::bind(&Item::sinceTime,_2)
00089                                                         ) );
00090     m_sorted = local;
00091     return *m_sorted;
00092   }
00093 
00094 
00095   size_t IOVSequence::add(cond::Time_t time, 
00096                           std::string const & token,
00097                           std::string const & payloadClassName ) {
00098     if (!piovs().empty() && ( m_notOrdered || time<piovs().back().sinceTime())) disorder();
00099     piovs().push_back(Item(time, token));
00100     m_payloadClasses.insert( payloadClassName );
00101     return piovs().size()-1;
00102   }
00103   
00104   size_t IOVSequence::truncate() {
00105     if (m_notOrdered) disorder();
00106     piovs().pop_back();
00107     return piovs().size()-1;
00108   }
00109 
00110   IOVSequence::const_iterator IOVSequence::find(cond::Time_t time) const {
00111     if (time>lastTill()) return iovs().end();
00112     IOVSequence::const_iterator p = std::upper_bound(iovs().begin(),iovs().end(),Item(time),
00113                             boost::bind(std::less<cond::Time_t>(),
00114                                         boost::bind(&Item::sinceTime,_1),
00115                                         boost::bind(&Item::sinceTime,_2)
00116                                         )
00117                             );
00118     return (p!=iovs().begin()) ? p-1 : iovs().end(); 
00119   }
00120   
00121 
00122   IOVSequence::const_iterator IOVSequence::findSince(cond::Time_t time) const {
00123     IOVSequence::const_iterator p = find(time);
00124     return (p!=iovs().end() && (*p).sinceTime()==time) ? p : iovs().end();
00125   }
00126   
00127   bool IOVSequence::exist(cond::Time_t time) const {
00128     return findSince(time)!=iovs().end();
00129   }
00130 
00131   void IOVSequence::updateMetadata( const std::string& metadata, 
00132                                     bool append ){
00133     std::string sep(". ");
00134     if( !metadata.empty() ){
00135       if (append && !m_metadata.empty()) {
00136         m_metadata += sep + metadata;
00137       }
00138       else m_metadata = metadata;
00139     }
00140   }
00141 
00142   void  IOVSequence::disorder() {
00143     m_notOrdered=true;
00144     delete m_sorted; m_sorted=0;
00145   }
00146 
00147   void IOVSequence::swapTokens( ora::ITokenParser& parser ) const {
00148     for( IOVSequence::const_iterator iT = m_iovs.begin();
00149          iT != m_iovs.end(); ++iT ){
00150       iT->swapToken( parser );
00151       // adding the classname 'by hand'
00152       std::string className = parser.className( iT->token() );
00153       const_cast<IOVSequence* >(this)->m_payloadClasses.insert( className );
00154     }
00155   }
00156 
00157   void IOVSequence::swapOIds( ora::ITokenWriter& writer ) const {
00158     for( IOVSequence::const_iterator iT = m_iovs.begin();
00159          iT != m_iovs.end(); ++iT ){
00160       iT->swapOId( writer );
00161     }
00162   }
00163 
00164 }
00165