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

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 38 of file EventSetup.cc.

38  :
39 m_file(iFile)
40 {
41 }
EventSetup::~EventSetup ( )
virtual

Definition at line 48 of file EventSetup.cc.

References m_records.

49 {
50  for(std::vector<Record*>::iterator it = m_records.begin(), itEnd=m_records.end();
51  it !=itEnd; ++it) {
52  delete *it;
53  }
54 }
std::vector< Record * > m_records
Definition: EventSetup.h:110
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, MainPageGenerator::tree, and fwlite::unformat_mangled_to_type().

Referenced by main().

84 {
85  std::string realName = unformat_mangled_to_type(iRecordName);
86  TObject* obj = m_file->Get(realName.c_str());
87  if(0==obj) {
88  return false;
89  }
90  TTree* tree = dynamic_cast<TTree*>(obj);
91  if(0==tree) {
92  return false;
93  }
94  return 0 != tree->FindBranch(kRecordAuxiliaryBranchName);
95 }
static const char *const kRecordAuxiliaryBranchName
Definition: EventSetup.cc:30
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 134 of file EventSetup.cc.

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

Referenced by FWLiteESSource::delaySettingRecords().

135 {
136  std::vector<std::string> returnValue;
137 
138  TList* keys = m_file->GetListOfKeys();
139  //this is ROOT's recommended way to iterate
140  TIter next(keys);
141  while(TObject* obj = next() ) {
142  TKey* key = static_cast<TKey*> (obj);
143  if(0==strcmp(key->GetClassName(),"TTree")) {
144  returnValue.push_back(unformat_mangled_to_type(key->GetName()));
145  }
146  }
147  return returnValue;
148 }
std::string unformat_mangled_to_type(const std::string &)
given a mangled name return the C++ class name
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
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 MainPageGenerator::tree.

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

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

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

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

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

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
mutableprivate

Definition at line 110 of file EventSetup.h.

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

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

Definition at line 105 of file EventSetup.h.

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

Definition at line 106 of file EventSetup.h.