CMS 3D CMS Logo

Classes | Public Member Functions | Private Member Functions | Private Attributes

fwlite::Record Class Reference

#include <Record.h>

List of all members.

Classes

class  TypeID

Public Member Functions

const IOVSyncValueendSyncValue () const
template<typename HANDLE >
bool get (HANDLE &, const char *iLabel="") const
const std::string & name () const
 Record (const char *iName, TTree *)
const IOVSyncValuestartSyncValue () const
void syncTo (const edm::EventID &, const edm::Timestamp &)
std::vector< std::pair
< std::string, std::string > > 
typeAndLabelOfAvailableData () const
virtual ~Record ()

Private Member Functions

cms::Exceptionget (const TypeID &, const char *iLabel, const void *&) const
const Recordoperator= (const Record &)
 Record (const Record &)

Private Attributes

std::map< std::pair< TypeID,
std::string >, TBranch * > 
m_branches
IOVSyncValue m_end
long m_entry
std::string m_name
IOVSyncValue m_start
std::map< IOVSyncValue,
unsigned int > 
m_startIOVtoEntry
TTree * m_tree

Detailed Description

Definition at line 47 of file Record.h.


Constructor & Destructor Documentation

Record::Record ( const char *  iName,
TTree *  iTree 
)

Definition at line 36 of file Record.cc.

References printConversionInfo::aux, edm::ESRecordAuxiliary::eventID(), getHLTprescales::index, edm::Timestamp::invalidTimestamp(), m_startIOVtoEntry, m_tree, edm::EventID::run(), cond::rpcobtemp::temp, and edm::ESRecordAuxiliary::timestamp().

                                             :
m_name(iName), m_tree(iTree), m_entry(-1),
m_start(IOVSyncValue::invalidIOVSyncValue()),
m_end(IOVSyncValue::invalidIOVSyncValue())
{
   //read the start iovs and get them in order
   edm::ESRecordAuxiliary aux;
   edm::ESRecordAuxiliary* pAux=&aux;
   TBranch* auxBranch = m_tree->FindBranch("ESRecordAuxiliary");
   auxBranch->SetAddress(&pAux);
   IOVSyncValue temp;
   for(unsigned int index=0; index < m_tree->GetEntries();++index){
      auxBranch->GetEntry(index);
      if(aux.timestamp() != edm::Timestamp::invalidTimestamp()){
         if(aux.eventID().run() != 0) {
            temp = IOVSyncValue(aux.eventID(),aux.timestamp());
         } else {
            temp = IOVSyncValue(aux.timestamp());
         }
      } else {
         temp=IOVSyncValue(aux.eventID());
         assert(aux.eventID().run()!=0);
      }
      
      m_startIOVtoEntry[temp]=index;
   }
}
Record::~Record ( ) [virtual]

Definition at line 69 of file Record.cc.

{
}
fwlite::Record::Record ( const Record ) [private]

Member Function Documentation

const IOVSyncValue & Record::endSyncValue ( ) const

Definition at line 150 of file Record.cc.

References m_end.

Referenced by FWLiteESSource::setIntervalFor().

{
   return m_end;
}
template<typename HANDLE >
bool Record::get ( HANDLE &  iHandle,
const char *  iLabel = "" 
) const

Definition at line 92 of file Record.h.

References relativeConstraints::value.

   {
      const void* value = 0;
      cms::Exception* e = get(TypeID(iHandle.typeInfo()),iLabel,value);
      if(0==e){
         iHandle = HANDLE(value);
      } else {
         iHandle = HANDLE(e);
      }
      return 0==e;
   }
cms::Exception * Record::get ( const TypeID iType,
const char *  iLabel,
const void *&  iData 
) const [private]

Definition at line 157 of file Record.cc.

References Exception, fwlite::format_type_to_mangled(), m_branches, m_entry, m_tree, name(), matplotRender::t, and edm::TypeIDBase::typeInfo().

{
   cms::Exception* returnValue = 0;
   
   TBranch*& branch = m_branches[std::make_pair(iType,iLabel)];
   if(0==branch){
      using namespace ROOT::Reflex;
      Type t = Type::ByTypeInfo(iType.typeInfo());
      if(t == Type()){
         returnValue = new cms::Exception("UnknownType");
         (*returnValue)<<"The type "
         <<iType.typeInfo().name()<<" was requested from Record "<<name()
         <<" but the type has no known dictionary";
         return returnValue;
      }
      //build branch name
      std::string branchName = fwlite::format_type_to_mangled(t.Name(ROOT::Reflex::SCOPED|ROOT::Reflex::FINAL))+"__"+iLabel;
      branch = m_tree->FindBranch(branchName.c_str());
      
      if(0==branch){
         returnValue = new cms::Exception("NoDataAvailable");
         (*returnValue)<<"The data of type "
                       <<t.Name(ROOT::Reflex::SCOPED|ROOT::Reflex::FINAL)
                       <<" with label '"<<iLabel<<"' for Record "<<name()<<" is not in this file.";
         return returnValue;
      }
   }
   if(m_entry<0) {
      returnValue = new cms::Exception("NoValidIOV");
      (*returnValue) <<" The Record "
         <<name()<<" was asked to get data for a 'time' for which it has no data";
      return returnValue;
   }
   branch->SetAddress(&iData);
   branch->GetEntry(m_entry);
   return returnValue;
}
const std::string & Record::name ( ) const

Definition at line 140 of file Record.cc.

References m_name.

Referenced by get(), and typeAndLabelOfAvailableData().

{
   return m_name;
}
const Record& fwlite::Record::operator= ( const Record ) [private]
const IOVSyncValue & Record::startSyncValue ( ) const

Definition at line 146 of file Record.cc.

References m_start.

Referenced by FWLiteESSource::setIntervalFor().

                             {
   return m_start;
}
void Record::syncTo ( const edm::EventID iEvent,
const edm::Timestamp iTime 
)

Definition at line 89 of file Record.cc.

References fwlite::IOVSyncValue::invalidIOVSyncValue(), edm::Timestamp::invalidTimestamp(), m_end, m_entry, m_start, m_startIOVtoEntry, edm::EventID::run(), and cond::rpcobtemp::temp.

Referenced by fwlite::EventSetup::syncTo().

{
   
   IOVSyncValue temp;
   if(iTime != edm::Timestamp::invalidTimestamp()){
      if(iEvent.run() != 0) {
         temp = IOVSyncValue(iEvent,iTime);
      } else {
         temp = IOVSyncValue(iTime);
      }
   } else {
      temp=IOVSyncValue(iEvent);
      assert(iEvent.run()!=0);
   }

   //already synched
   if( (m_start != IOVSyncValue::invalidIOVSyncValue()) && 
       (m_start <=temp ) && 
       ( (m_end == IOVSyncValue::invalidIOVSyncValue()) ||
         (temp <m_end))) {
      return;
   }
   std::pair<StartIOVtoEntryMap::iterator, StartIOVtoEntryMap::iterator> range =
      m_startIOVtoEntry.equal_range(temp);
   if(range.first!=range.second){
      //happens to be the start of the IOV
      m_start = range.first->first;
      m_entry = range.first->second;
   } else {
      if(range.first!=m_startIOVtoEntry.begin()){
         //we have overshot
         --range.first;
         m_start = range.first->first;
         m_entry = range.first->second;
      } else {
         //off the beginning
         m_start=IOVSyncValue::invalidIOVSyncValue();
         m_entry = -1;
      }
   }
   if(range.second==m_startIOVtoEntry.end()){
      m_end = IOVSyncValue::invalidIOVSyncValue();
   } else {
      m_end = range.second->first;
   }
}
std::vector< std::pair< std::string, std::string > > Record::typeAndLabelOfAvailableData ( ) const

Definition at line 198 of file Record.cc.

References label, m_tree, name(), VarParsing::obj, and fwlite::unformat_mangled_to_type().

Referenced by FWLiteESSource::registerProxies().

{
   std::vector<std::pair<std::string,std::string> > returnValue;
   
   TObjArray* branches = m_tree->GetListOfBranches();
   TIter next( branches );
   while (TObject* obj = next()) {
      TBranch* branch = static_cast<TBranch*> (obj);
      const char* name = branch->GetName();
      if (0!=strcmp(name, "ESRecordAuxiliary") ) {
         //The type and label are separated by a double underscore so we need to find that
         size_t len = strlen(name);
         const char* cIndex = name+len;
         std::string label;
         while (name != --cIndex) {
            if(*cIndex == '_') {
               if( *(cIndex-1)=='_') {
                  label = std::string(cIndex+1);
                  break;
               }
            }
         }
         std::string type(name, cIndex-name-1);
         type = fwlite::unformat_mangled_to_type(type);
         returnValue.push_back(std::make_pair(type,label));
      }
   }
   return returnValue;
}

Member Data Documentation

std::map<std::pair<TypeID,std::string>, TBranch*> fwlite::Record::m_branches [mutable, private]

Definition at line 87 of file Record.h.

Referenced by get().

Definition at line 85 of file Record.h.

Referenced by endSyncValue(), and syncTo().

long fwlite::Record::m_entry [private]

Definition at line 83 of file Record.h.

Referenced by get(), and syncTo().

std::string fwlite::Record::m_name [private]

Definition at line 80 of file Record.h.

Referenced by name().

Definition at line 84 of file Record.h.

Referenced by startSyncValue(), and syncTo().

std::map<IOVSyncValue,unsigned int> fwlite::Record::m_startIOVtoEntry [private]

Definition at line 82 of file Record.h.

Referenced by Record(), and syncTo().

TTree* fwlite::Record::m_tree [private]

Definition at line 81 of file Record.h.

Referenced by get(), Record(), and typeAndLabelOfAvailableData().