CMS 3D CMS Logo

FWLiteESSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondLiteIO
4 // Class : FWLiteESSource
5 //
14 //
15 // Original Author: Chris Jones
16 // Created: Thu Jun 17 15:47:35 CDT 2010
17 //
18 
19 // system include files
20 #include <iostream>
21 #include <memory>
22 #include "TFile.h"
23 
24 // user include files
34 
36 
38 
39 // forward declarations
40 namespace edm {
41  class EventSetupImpl;
42 }
43 
44 namespace {
45  struct TypeID : public edm::TypeIDBase {
46  explicit TypeID(const std::type_info& iInfo) : edm::TypeIDBase(iInfo) {}
47  TypeID() {}
48  using TypeIDBase::typeInfo;
49  };
50  struct FWLiteESGenericHandle {
51  FWLiteESGenericHandle(const TypeID& iType) : m_type(iType), m_data(nullptr), m_exception(nullptr) {}
52 
53  FWLiteESGenericHandle(const void* iData) : m_type(), m_data(iData), m_exception(nullptr) {}
54 
55  FWLiteESGenericHandle(cms::Exception* iException) : m_type(), m_data(nullptr), m_exception(iException) {}
56 
57  const std::type_info& typeInfo() const { return m_type.typeInfo(); }
58 
59  TypeID m_type;
60  const void* m_data;
61  cms::Exception* m_exception;
62  };
63 
64  class FWLiteProxy : public edm::eventsetup::DataProxy {
65  public:
66  FWLiteProxy(const TypeID& iTypeID, const fwlite::Record* iRecord) : m_type(iTypeID), m_record(iRecord) {}
67 
68  const void* getImpl(const edm::eventsetup::EventSetupRecordImpl&,
69  const edm::eventsetup::DataKey& iKey,
70  edm::EventSetupImpl const*) override {
71  assert(iKey.type() == m_type);
72 
73  FWLiteESGenericHandle h(m_type);
74  m_record->get(h, iKey.name().value());
75 
76  if (nullptr != h.m_exception) {
77  throw *(h.m_exception);
78  }
79  return h.m_data;
80  }
81 
82  void invalidateCache() override {}
83 
84  private:
85  TypeID m_type;
86  const fwlite::Record* m_record;
87  };
88 } // namespace
89 
91 public:
93  FWLiteESSource(const FWLiteESSource&) = delete;
94  const FWLiteESSource& operator=(const FWLiteESSource&) = delete;
95  ~FWLiteESSource() override;
96 
98 
99 private:
100  KeyedProxiesVector registerProxies(const EventSetupRecordKey&, unsigned int iovIndex) override;
101 
103 
104  void delaySettingRecords() override;
105 
106  // ---------- member data --------------------------------
107  std::unique_ptr<TFile> m_file;
109  std::map<EventSetupRecordKey, fwlite::RecordID> m_keyToID;
110 };
111 
113  : m_file(TFile::Open(iPS.getParameter<std::string>("fileName").c_str())), m_es(m_file.get()) {}
114 
116 
118  const EventSetupRecordKey& iRecordKey, unsigned int iovIndex) {
119  KeyedProxiesVector keyedProxiesVector;
121 
122  fwlite::RecordID recID = m_keyToID[iRecordKey];
123  const fwlite::Record& rec = m_es.get(recID);
124  typedef std::vector<std::pair<std::string, std::string> > TypesAndLabels;
125  TypesAndLabels typesAndLabels = rec.typeAndLabelOfAvailableData();
126 
127  std::cout << "Looking for data in record " << iRecordKey.name() << std::endl;
128  for (TypesAndLabels::const_iterator it = typesAndLabels.begin(), itEnd = typesAndLabels.end(); it != itEnd; ++it) {
129  std::cout << " need type " << it->first << std::endl;
130  HCTypeTag tt = HCTypeTag::findType(it->first);
131  if (tt != HCTypeTag()) {
132  edm::eventsetup::DataKey dk(tt, edm::eventsetup::IdTags(it->second.c_str()));
133  keyedProxiesVector.emplace_back(dk, std::make_shared<FWLiteProxy>(TypeID(tt.value()), &rec));
134  } else {
135  LogDebug("UnknownESType") << "The type '" << it->first << "' is unknown in this job";
136  std::cout << " *****FAILED*****" << std::endl;
137  }
138  }
139  return keyedProxiesVector;
140 }
141 
143  const edm::IOVSyncValue& iSync,
144  edm::ValidityInterval& oIOV) {
145  m_es.syncTo(iSync.eventID(), iSync.time());
146 
147  const fwlite::Record& rec = m_es.get(m_keyToID[iKey]);
148  edm::IOVSyncValue endSync(rec.endSyncValue().eventID(), rec.endSyncValue().time());
149  if (rec.endSyncValue().eventID().run() == 0 && rec.endSyncValue().time().value() == 0ULL) {
150  endSync = edm::IOVSyncValue::endOfTime();
151  }
153 }
154 
157  std::vector<std::string> recordNames = m_es.namesOfAvailableRecords();
158 
159  for (std::vector<std::string>::const_iterator it = recordNames.begin(), itEnd = recordNames.end(); it != itEnd;
160  ++it) {
161  HCTypeTag t = HCTypeTag::findType(*it);
162  if (t != HCTypeTag()) {
166  m_keyToID[key] = m_es.recordID(it->c_str());
167  }
168  }
169 }
170 
edm::eventsetup::DataProxyProvider
Definition: DataProxyProvider.h:64
fwlite::EventSetup::get
const Record & get(const RecordID &) const
Definition: EventSetup.cc:117
fwlite::Record::startSyncValue
const IOVSyncValue & startSyncValue() const
Definition: Record.cc:152
edm::typelookup::findType
std::pair< const char *, const std::type_info * > findType(const char *iClassName)
Definition: typelookup.cc:69
MessageLogger.h
FWLiteESSource::registerProxies
KeyedProxiesVector registerProxies(const EventSetupRecordKey &, unsigned int iovIndex) override
Definition: FWLiteESSource.cc:117
fwlite::EventSetup::recordID
RecordID recordID(const char *iRecordName) const
Definition: EventSetup.cc:87
fwlite::EventSetup::namesOfAvailableRecords
std::vector< std::string > namesOfAvailableRecords() const
Definition: EventSetup.cc:122
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
edm::EventSetupImpl
Definition: EventSetupImpl.h:44
edm
HLT enums.
Definition: AlignableModifier.h:19
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
gather_cfg.cout
cout
Definition: gather_cfg.py:144
FWLiteESSource::delaySettingRecords
void delaySettingRecords() override
Definition: FWLiteESSource.cc:155
edm::ValidityInterval
Definition: ValidityInterval.h:28
FWLiteESSource
Definition: FWLiteESSource.cc:90
cms::cuda::assert
assert(be >=bs)
fwlite::Record::endSyncValue
const IOVSyncValue & endSyncValue() const
Definition: Record.cc:153
edm::eventsetup::DataKey
Definition: DataKey.h:29
edm::Timestamp::value
TimeValue_t value() const
Definition: Timestamp.h:45
FWLiteESSource::~FWLiteESSource
~FWLiteESSource() override
Definition: FWLiteESSource.cc:115
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
DataProxy.h
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
DataProxyProvider.h
TypeIDBase.h
edm::eventsetup::DataKey::name
const NameTag & name() const
Definition: DataKey.h:53
FWLiteESSource::operator=
const FWLiteESSource & operator=(const FWLiteESSource &)=delete
edm::EventSetupRecordIntervalFinder::findingRecordWithKey
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
Definition: EventSetupRecordIntervalFinder.cc:48
FWLiteESSource::m_file
std::unique_ptr< TFile > m_file
Definition: FWLiteESSource.cc:107
edm::eventsetup::SimpleStringTag::value
const char * value() const
Definition: DataKeyTags.h:39
edm::eventsetup::EventSetupRecordKey::name
const char * name() const
Definition: EventSetupRecordKey.h:46
h
EventSetup.h
OrderedSet.t
t
Definition: OrderedSet.py:90
FWLiteESSource::setIntervalFor
void setIntervalFor(const EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
Definition: FWLiteESSource.cc:142
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
edm::EventID::run
RunNumber_t run() const
Definition: EventID.h:38
DEFINE_FWK_EVENTSETUP_SOURCE
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
EventSetupRecordIntervalFinder.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::eventsetup::EventSetupRecordImpl
Definition: EventSetupRecordImpl.h:73
fwlite::Record
Definition: Record.h:47
SourceFactory.h
edm::IOVSyncValue::eventID
const EventID & eventID() const
Definition: IOVSyncValue.h:40
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
edm::IOVSyncValue::endOfTime
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
fwlite::RecordID
unsigned int RecordID
Definition: EventSetup.h:65
edm::eventsetup::heterocontainer::HCTypeTag
Definition: HCTypeTag.h:38
fwlite::EventSetup::syncTo
void syncTo(const edm::EventID &, const edm::Timestamp &)
Definition: EventSetup.cc:66
FWLiteESSource::m_keyToID
std::map< EventSetupRecordKey, fwlite::RecordID > m_keyToID
Definition: FWLiteESSource.cc:109
fwlite::Record::typeAndLabelOfAvailableData
std::vector< std::pair< std::string, std::string > > typeAndLabelOfAvailableData() const
Definition: Record.cc:206
edm::eventsetup::DataProxyProvider::KeyedProxiesVector
std::vector< std::pair< DataKey, std::shared_ptr< DataProxy > >> KeyedProxiesVector
Definition: DataProxyProvider.h:196
get
#define get
edm::eventsetup::DataProxy
Definition: DataProxy.h:38
edm::eventsetup::DataProxyProvider::usingRecordWithKey
void usingRecordWithKey(const EventSetupRecordKey &key)
Definition: DataProxyProvider.h:194
TypeIDBase
edm::IOVSyncValue::time
const Timestamp & time() const
Definition: IOVSyncValue.h:42
cond::ValidityInterval
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
std
Definition: JetResolutionObject.h:76
FWLiteESSource::FWLiteESSource
FWLiteESSource(edm::ParameterSet const &iPS)
Definition: FWLiteESSource.cc:112
edm::eventsetup::NameTag
Definition: DataKeyTags.h:45
Exception.h
FWLiteESSource::m_es
fwlite::EventSetup m_es
Definition: FWLiteESSource.cc:108
edm::TypeIDBase
Definition: TypeIDBase.h:29
fwlite::IOVSyncValue::time
const edm::Timestamp & time() const
Definition: IOVSyncValue.h:42
cms::Exception
Definition: Exception.h:70
Record.h
ParameterSet.h
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::eventsetup::DataKey::type
const TypeTag & type() const
Definition: DataKey.h:52
fwlite::EventSetup
Definition: EventSetup.h:68
HCTypeTag.h
fwlite::IOVSyncValue::eventID
const edm::EventID & eventID() const
Definition: IOVSyncValue.h:40