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 67 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, and record.

49 {
50  for(auto const& record : m_records) {
51  delete record;
52  }
53 }
JetCorrectorParameters::Record record
Definition: classes.h:7
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 82 of file EventSetup.cc.

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

Referenced by main().

83 {
84  std::string realName = unformat_mangled_to_type(iRecordName);
85  TObject* obj = m_file->Get(realName.c_str());
86  if(nullptr == obj) {
87  return false;
88  }
89  TTree* tree = dynamic_cast<TTree*>(obj);
90  if(nullptr == tree) {
91  return false;
92  }
93  return nullptr != tree->FindBranch(kRecordAuxiliaryBranchName);
94 }
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

Definition at line 126 of file EventSetup.cc.

References assert(), and m_records.

Referenced by Options.Options::__getitem__(), and main().

127 {
128  assert(iID<m_records.size());
129  return *(m_records[iID]);
130 }
assert(m_qm.get())
std::vector< Record * > m_records
Definition: EventSetup.h:111
std::vector< std::string > EventSetup::namesOfAvailableRecords ( ) const

Definition at line 133 of file EventSetup.cc.

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

134 {
135  std::vector<std::string> returnValue;
136 
137  TList* keys = m_file->GetListOfKeys();
138  //this is ROOT's recommended way to iterate
139  TIter next(keys);
140  while(TObject* obj = next() ) {
141  TKey* key = static_cast<TKey*> (obj);
142  if(0==strcmp(key->GetClassName(),"TTree")) {
143  returnValue.push_back(unformat_mangled_to_type(key->GetName()));
144  }
145  }
146  return returnValue;
147 }
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 97 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 main().

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

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

Referenced by main().

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

Member Data Documentation

TFile* fwlite::EventSetup::m_file
mutableprivate

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.