CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
fwlite::EventSetup Class Reference

#include <EventSetup.h>

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

const edm::EventBasem_event
 
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.

39  :
40 m_event(0),
41 m_file(iFile)
42 {
43 }
const edm::EventBase * m_event
Definition: EventSetup.h:105
EventSetup::~EventSetup ( )
virtual

Definition at line 50 of file EventSetup.cc.

References m_records.

51 {
52  for(std::vector<Record*>::iterator it = m_records.begin(), itEnd=m_records.end();
53  it !=itEnd; ++it) {
54  delete *it;
55  }
56 }
std::vector< Record * > m_records
Definition: EventSetup.h:111
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 84 of file EventSetup.cc.

References kRecordAuxiliaryBranchName, m_file, getGTfromDQMFile::obj, MainPageGenerator::tree, and fwlite::unformat_mangled_to_type().

Referenced by main().

85 {
86  std::string realName = unformat_mangled_to_type(iRecordName);
87  TObject* obj = m_file->Get(realName.c_str());
88  if(0==obj) {
89  return false;
90  }
91  TTree* tree = dynamic_cast<TTree*>(obj);
92  if(0==tree) {
93  return false;
94  }
95  return 0 != tree->FindBranch(kRecordAuxiliaryBranchName);
96 }
static const char *const kRecordAuxiliaryBranchName
Definition: EventSetup.cc:31
std::string unformat_mangled_to_type(const std::string &)
given a mangled name return the C++ class name
const Record & EventSetup::get ( const RecordID iID) const
std::vector< std::string > EventSetup::namesOfAvailableRecords ( ) const

Definition at line 135 of file EventSetup.cc.

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

Referenced by FWLiteESSource::delaySettingRecords().

136 {
137  std::vector<std::string> returnValue;
138 
139  TList* keys = m_file->GetListOfKeys();
140  //this is ROOT's recommended way to iterate
141  TIter next(keys);
142  while(TObject* obj = next() ) {
143  TKey* key = static_cast<TKey*> (obj);
144  if(0==strcmp(key->GetClassName(),"TTree")) {
145  returnValue.push_back(unformat_mangled_to_type(key->GetName()));
146  }
147  }
148  return returnValue;
149 }
std::string unformat_mangled_to_type(const std::string &)
given a mangled name return the C++ class name
list key
Definition: combine.py:13
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 99 of file EventSetup.cc.

References edm::hlt::Exception, fwlite::format_type_to_mangled(), kRecordAuxiliaryBranchName, m_file, m_records, mergeVDriftHistosByStation::name, getGTfromDQMFile::obj, SiStripGain_Fake_cff::Record, and MainPageGenerator::tree.

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

100 {
101  std::string treeName = format_type_to_mangled(iRecordName);
102  TObject* obj = m_file->Get(treeName.c_str());
103  if(0==obj) {
104  throw cms::Exception("UnknownRecord")<<"The TTree for the record "<<iRecordName<<" does not exist "<<m_file->GetName();
105  }
106  TTree* tree = dynamic_cast<TTree*>(obj);
107  if(0==tree) {
108  throw cms::Exception("UnknownRecord")<<"The object corresponding to "<<iRecordName<<" in file "<<m_file->GetName()<<" is not a TTree and therefore is not a Record";
109  }
110  if(0 == tree->FindBranch(kRecordAuxiliaryBranchName)) {
111  throw cms::Exception("UnknownRecord")<<"The TTree corresponding to "<<iRecordName<<" in file "<<m_file->GetName()<<" does not have the proper structure to be a Record";
112  }
113  //do we already have this Record?
114  std::string name(iRecordName);
115  for(std::vector<Record*>::iterator it = m_records.begin(), itEnd=m_records.end(); it!=itEnd;++it){
116  if((*it)->name()==name) {
117  return it - m_records.begin();
118  }
119  }
120 
121  //Not found so need to make a new one
122  Record* rec = new Record(iRecordName, tree);
123  m_records.push_back(rec);
124  return m_records.size()-1;
125 }
static const char *const kRecordAuxiliaryBranchName
Definition: EventSetup.cc:31
std::vector< Record * > m_records
Definition: EventSetup.h:111
std::string format_type_to_mangled(const std::string &)
given a C++ class name returned a mangled name
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 74 of file EventSetup.cc.

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

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

74  {
75  std::for_each(m_records.begin(),
76  m_records.end(),
77  boost::bind(&Record::syncTo,_1,iID,iTime));
78 }
std::vector< Record * > m_records
Definition: EventSetup.h:111
void syncTo(const edm::EventID &, const edm::Timestamp &)
Definition: Record.cc:90

Member Data Documentation

const edm::EventBase* fwlite::EventSetup::m_event
private

Definition at line 105 of file EventSetup.h.

TFile* fwlite::EventSetup::m_file
private

Definition at line 109 of file EventSetup.h.

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

std::vector<Record*> fwlite::EventSetup::m_records
mutableprivate

Definition at line 111 of file EventSetup.h.

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

edm::EventID fwlite::EventSetup::m_syncedEvent
private

Definition at line 106 of file EventSetup.h.

edm::Timestamp fwlite::EventSetup::m_syncedTimestamp
private

Definition at line 107 of file EventSetup.h.