CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

fwlite::EventSetup Class Reference

#include <EventSetup.h>

List of all members.

Public Member Functions

 EventSetup (TFile *)
bool exists (const char *iRecordName) const
const Recordget (const RecordID &) const
std::vector< std::string > namesOfAvailableRecords () const
RecordID recordID (const char *iRecordName) const
void syncTo (const edm::EventID &, const edm::Timestamp &)
virtual ~EventSetup ()

Private Member Functions

 EventSetup (const EventSetup &)
const EventSetupoperator= (const EventSetup &)

Private Attributes

TFile * m_file
std::vector< Record * > m_records
edm::EventID m_syncedEvent
edm::Timestamp m_syncedTimestamp

Detailed Description

Definition at line 66 of file EventSetup.h.


Constructor & Destructor Documentation

EventSetup::EventSetup ( TFile *  iFile)

Definition at line 39 of file EventSetup.cc.

                                  :
m_file(iFile)
{
}
EventSetup::~EventSetup ( ) [virtual]

Definition at line 49 of file EventSetup.cc.

References m_records.

{
   for(std::vector<Record*>::iterator it = m_records.begin(), itEnd=m_records.end();
    it !=itEnd; ++it) {
       delete *it;
   }
}
fwlite::EventSetup::EventSetup ( const EventSetup ) [private]

Member Function Documentation

bool EventSetup::exists ( const char *  iRecordName) const

Returns true if a record with the name iRecordName is available in the file

Definition at line 83 of file EventSetup.cc.

References kRecordAuxiliaryBranchName, m_file, getGTfromDQMFile::obj, AlCaHLTBitMon_QueryRunRegistry::string, diffTreeTool::tree, and fwlite::unformat_mangled_to_type().

Referenced by main().

{
   std::string realName = unformat_mangled_to_type(iRecordName);
   TObject* obj = m_file->Get(realName.c_str());
   if(0==obj) {
      return false;
   }
   TTree* tree = dynamic_cast<TTree*>(obj);
   if(0==tree) {
      return false;
   }
   return 0 != tree->FindBranch(kRecordAuxiliaryBranchName);
}
const Record & EventSetup::get ( const RecordID iID) const

Definition at line 127 of file EventSetup.cc.

References m_records.

Referenced by main(), FWLiteESSource::registerProxies(), and FWLiteESSource::setIntervalFor().

{
   assert(iID<m_records.size());
   return *(m_records[iID]);
}
std::vector< std::string > EventSetup::namesOfAvailableRecords ( ) const

Definition at line 134 of file EventSetup.cc.

References combine::key, relativeConstraints::keys, m_file, getGTfromDQMFile::obj, and fwlite::unformat_mangled_to_type().

Referenced by FWLiteESSource::delaySettingRecords().

{
   std::vector<std::string> returnValue;
   
   TList* keys = m_file->GetListOfKeys();
   //this is ROOT's recommended way to iterate
   TIter next(keys);
   while(TObject* obj = next() ) {
      TKey* key = static_cast<TKey*> (obj);
      if(0==strcmp(key->GetClassName(),"TTree")) {
         returnValue.push_back(unformat_mangled_to_type(key->GetName()));
      }
   }
   return returnValue;
}
const EventSetup& fwlite::EventSetup::operator= ( const EventSetup ) [private]
RecordID EventSetup::recordID ( const char *  iRecordName) const

Returns the lookup id of the record whose name is iRecordName. The returned id is only valid for the instance of an EventSetup object to which the recordID call was made. If you later create a new EventSetup instance even for the same file the RecordIDs can be different.

Definition at line 98 of file EventSetup.cc.

References Exception, fwlite::format_type_to_mangled(), kRecordAuxiliaryBranchName, m_file, m_records, mergeVDriftHistosByStation::name, getGTfromDQMFile::obj, SiStripGain_Fake_cff::Record, AlCaHLTBitMon_QueryRunRegistry::string, and diffTreeTool::tree.

Referenced by FWLiteESSource::delaySettingRecords(), and main().

{
   std::string treeName = format_type_to_mangled(iRecordName);
   TObject* obj = m_file->Get(treeName.c_str());
   if(0==obj) {
      throw cms::Exception("UnknownRecord")<<"The TTree for the record "<<iRecordName<<" does not exist "<<m_file->GetName();
   }
   TTree* tree = dynamic_cast<TTree*>(obj);
   if(0==tree) {
      throw cms::Exception("UnknownRecord")<<"The object corresponding to "<<iRecordName<<" in file "<<m_file->GetName()<<" is not a TTree and therefore is not a Record";   
   }
   if(0 == tree->FindBranch(kRecordAuxiliaryBranchName)) {
      throw cms::Exception("UnknownRecord")<<"The TTree corresponding to "<<iRecordName<<" in file "<<m_file->GetName()<<" does not have the proper structure to be a Record";
   }
   //do we already have this Record?
   std::string name(iRecordName);
   for(std::vector<Record*>::iterator it = m_records.begin(), itEnd=m_records.end(); it!=itEnd;++it){
      if((*it)->name()==name) {
         return it - m_records.begin();
      }
   }
   
   //Not found so need to make a new one
   Record* rec = new Record(iRecordName, tree);
   m_records.push_back(rec);
   return m_records.size()-1;
}
void EventSetup::syncTo ( const edm::EventID iID,
const edm::Timestamp iTime 
)

Ensures that all Records will access the appropriate data for this instant in time

Definition at line 73 of file EventSetup.cc.

References m_records, and fwlite::Record::syncTo().

Referenced by main(), and FWLiteESSource::setIntervalFor().

                                                                   {
   std::for_each(m_records.begin(),
                 m_records.end(),
                 boost::bind(&Record::syncTo,_1,iID,iTime));
}

Member Data Documentation

TFile* fwlite::EventSetup::m_file [private]

Definition at line 108 of file EventSetup.h.

Referenced by exists(), namesOfAvailableRecords(), and recordID().

std::vector<Record*> fwlite::EventSetup::m_records [mutable, private]

Definition at line 110 of file EventSetup.h.

Referenced by get(), recordID(), syncTo(), and ~EventSetup().

Definition at line 105 of file EventSetup.h.

Definition at line 106 of file EventSetup.h.