CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
fwlite::EventSetup Class Reference

#include <EventSetup.h>

Public Member Functions

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

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() [2/2]

fwlite::EventSetup::EventSetup ( const EventSetup )
delete

◆ ~EventSetup()

EventSetup::~EventSetup ( )
virtual

Definition at line 45 of file EventSetup.cc.

References m_records, and AlCaHarvesting_cff::record.

45  {
46  for (auto const& record : m_records) {
47  delete record;
48  }
49 }
std::vector< Record * > m_records
Definition: EventSetup.h:112

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.

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

Referenced by main().

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 }
std::string unformat_mangled_to_type(const std::string &)
given a mangled name return the C++ class name
static const char *const kRecordAuxiliaryBranchName
Definition: EventSetup.cc:30
Definition: tree.py:1

◆ 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.

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

Referenced by FWLiteESSource::delaySettingRecords().

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 }
std::string unformat_mangled_to_type(const std::string &)
given a mangled name return the C++ class name
key
prepare the HTCondor submission files and eventually submit them

◆ operator=()

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

◆ 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.

References Exception, fwlite::format_type_to_mangled(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, kRecordAuxiliaryBranchName, m_file, m_records, Skims_PA_cff::name, getGTfromDQMFile::obj, HLT_2024v14_cff::Record, and AlCaHLTBitMon_QueryRunRegistry::string.

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

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 }
std::vector< Record * > m_records
Definition: EventSetup.h:112
std::string format_type_to_mangled(const std::string &)
given a C++ class name returned a mangled name
static const char *const kRecordAuxiliaryBranchName
Definition: EventSetup.cc:30
Definition: tree.py:1

◆ 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.

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

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

66  {
67  using std::placeholders::_1;
68  std::for_each(m_records.begin(), m_records.end(), std::bind(&Record::syncTo, _1, iID, iTime));
69 }
std::vector< Record * > m_records
Definition: EventSetup.h:112
void syncTo(const edm::EventID &, const edm::Timestamp &)
Definition: Record.cc:86

Member Data Documentation

◆ m_file

TFile* fwlite::EventSetup::m_file
mutableprivate

Definition at line 110 of file EventSetup.h.

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

◆ m_records

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

Definition at line 112 of file EventSetup.h.

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

◆ m_syncedEvent

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

Definition at line 106 of file EventSetup.h.

◆ m_syncedTimestamp

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

Definition at line 107 of file EventSetup.h.