CMS 3D CMS Logo

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 &)=delete
 
const EventSetupoperator= (const EventSetup &)=delete
 

Private Attributes

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

Detailed Description

Definition at line 68 of file EventSetup.h.

Constructor & Destructor Documentation

◆ EventSetup() [1/2]

EventSetup::EventSetup ( TFile *  iFile)

Definition at line 38 of file EventSetup.cc.

38 : m_file(iFile) {}

◆ ~EventSetup()

EventSetup::~EventSetup ( )
virtual

Definition at line 45 of file EventSetup.cc.

45  {
46  for (auto const& record : m_records) {
47  delete record;
48  }
49 }

References m_records, and GlobalPosition_Frontier_DevDB_cff::record.

◆ EventSetup() [2/2]

fwlite::EventSetup::EventSetup ( const EventSetup )
privatedelete

Member Function Documentation

◆ exists()

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

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

Definition at line 74 of file EventSetup.cc.

74  {
75  std::string realName = unformat_mangled_to_type(iRecordName);
76  TObject* obj = m_file->Get(realName.c_str());
77  if (nullptr == obj) {
78  return false;
79  }
80  TTree* tree = dynamic_cast<TTree*>(obj);
81  if (nullptr == tree) {
82  return false;
83  }
84  return nullptr != tree->FindBranch(kRecordAuxiliaryBranchName);
85 }

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

Referenced by main().

◆ get()

const Record & EventSetup::get ( const RecordID iID) const

◆ namesOfAvailableRecords()

std::vector< std::string > EventSetup::namesOfAvailableRecords ( ) const

Definition at line 122 of file EventSetup.cc.

122  {
123  std::vector<std::string> returnValue;
124 
125  TList* keys = m_file->GetListOfKeys();
126  //this is ROOT's recommended way to iterate
127  TIter next(keys);
128  while (TObject* obj = next()) {
129  TKey* key = static_cast<TKey*>(obj);
130  if (0 == strcmp(key->GetClassName(), "TTree")) {
131  returnValue.push_back(unformat_mangled_to_type(key->GetName()));
132  }
133  }
134  return returnValue;
135 }

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

Referenced by FWLiteESSource::delaySettingRecords().

◆ operator=()

const EventSetup& fwlite::EventSetup::operator= ( const EventSetup )
privatedelete

◆ recordID()

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

87  {
88  std::string treeName = format_type_to_mangled(iRecordName);
89  TObject* obj = m_file->Get(treeName.c_str());
90  if (nullptr == obj) {
91  throw cms::Exception("UnknownRecord")
92  << "The TTree for the record " << iRecordName << " does not exist " << m_file->GetName();
93  }
94  TTree* tree = dynamic_cast<TTree*>(obj);
95  if (nullptr == tree) {
96  throw cms::Exception("UnknownRecord") << "The object corresponding to " << iRecordName << " in file "
97  << m_file->GetName() << " is not a TTree and therefore is not a Record";
98  }
99  if (nullptr == tree->FindBranch(kRecordAuxiliaryBranchName)) {
100  throw cms::Exception("UnknownRecord") << "The TTree corresponding to " << iRecordName << " in file "
101  << m_file->GetName() << " does not have the proper structure to be a Record";
102  }
103  //do we already have this Record?
104  std::string name(iRecordName);
105  for (std::vector<Record*>::const_iterator it = m_records.begin(), itEnd = m_records.end(); it != itEnd; ++it) {
106  if ((*it)->name() == name) {
107  return it - m_records.begin();
108  }
109  }
110 
111  //Not found so need to make a new one
112  Record* rec = new Record(iRecordName, tree);
113  m_records.push_back(rec);
114  return m_records.size() - 1;
115 }

References Exception, fwlite::format_type_to_mangled(), kRecordAuxiliaryBranchName, m_file, m_records, Skims_PA_cff::name, getGTfromDQMFile::obj, and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ syncTo()

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

66  {
67  using std::placeholders::_1;
68  std::for_each(m_records.begin(), m_records.end(), std::bind(&Record::syncTo, _1, iID, iTime));
69 }

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

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

Member Data Documentation

◆ m_file

TFile* fwlite::EventSetup::m_file
mutableprivate

Definition at line 109 of file EventSetup.h.

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

◆ m_records

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

Definition at line 111 of file EventSetup.h.

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

◆ m_syncedEvent

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

Definition at line 105 of file EventSetup.h.

◆ m_syncedTimestamp

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

Definition at line 106 of file EventSetup.h.

fwlite::format_type_to_mangled
std::string format_type_to_mangled(const std::string &)
given a C++ class name returned a mangled name
Definition: format_type_name.cc:38
tree
Definition: tree.py:1
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
cms::cuda::assert
assert(be >=bs)
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fwlite::Record
Definition: Record.h:47
fwlite::EventSetup::m_file
TFile * m_file
Definition: EventSetup.h:109
kRecordAuxiliaryBranchName
static const char *const kRecordAuxiliaryBranchName
Definition: EventSetup.cc:30
fwlite::EventSetup::m_records
std::vector< Record * > m_records
Definition: EventSetup.h:111
Exception
Definition: hltDiff.cc:246
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
fwlite::unformat_mangled_to_type
std::string unformat_mangled_to_type(const std::string &)
given a mangled name return the C++ class name
Definition: format_type_name.cc:69
crabWrapper.key
key
Definition: crabWrapper.py:19
fwlite::Record::syncTo
void syncTo(const edm::EventID &, const edm::Timestamp &)
Definition: Record.cc:86
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31