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 #include <mutex>
24 
25 // user include files
35 
37 
39 
42 
43 // forward declarations
44 namespace edm {
45  class EventSetupImpl;
46 }
47 
48 namespace {
49  struct TypeID : public edm::TypeIDBase {
50  explicit TypeID(const std::type_info& iInfo) : edm::TypeIDBase(iInfo) {}
51  TypeID() {}
52  using TypeIDBase::typeInfo;
53  };
54  struct FWLiteESGenericHandle {
55  FWLiteESGenericHandle(const TypeID& iType) : m_type(iType), m_data(nullptr), m_exception(nullptr) {}
56 
57  FWLiteESGenericHandle(const void* iData) : m_type(), m_data(iData), m_exception(nullptr) {}
58 
59  FWLiteESGenericHandle(cms::Exception* iException) : m_type(), m_data(nullptr), m_exception(iException) {}
60 
61  const std::type_info& typeInfo() const { return m_type.typeInfo(); }
62 
63  TypeID m_type;
64  const void* m_data;
65  cms::Exception* m_exception;
66  };
67 
68  class FWLiteProxy : public edm::eventsetup::ESSourceDataProxyNonConcurrentBase {
69  public:
70  FWLiteProxy(const TypeID& iTypeID, const fwlite::Record* iRecord, edm::SerialTaskQueue* iQueue, std::mutex* iMutex)
71  : edm::eventsetup::ESSourceDataProxyNonConcurrentBase(iQueue, iMutex),
72  m_type(iTypeID),
73  m_record(iRecord),
74  m_data{nullptr} {}
75 
76  void prefetch(const edm::eventsetup::DataKey& iKey, edm::EventSetupRecordDetails) final {
77  assert(iKey.type() == m_type);
78 
79  FWLiteESGenericHandle h(m_type);
80  m_record->get(h, iKey.name().value());
81  m_data = h.m_data;
82 
83  if (nullptr != h.m_exception) {
84  throw *(h.m_exception);
85  }
86  }
87 
88  void invalidateCache() override {
90  m_data = nullptr;
91  }
92 
93  void const* getAfterPrefetchImpl() const final { return m_data; }
94 
95  private:
96  TypeID m_type;
97  const fwlite::Record* m_record;
98  void const* m_data;
99  };
100 } // namespace
101 
103 public:
104  FWLiteESSource(edm::ParameterSet const& iPS);
105  FWLiteESSource(const FWLiteESSource&) = delete;
106  const FWLiteESSource& operator=(const FWLiteESSource&) = delete;
107  ~FWLiteESSource() override;
108 
110 
111 private:
112  KeyedProxiesVector registerProxies(const EventSetupRecordKey&, unsigned int iovIndex) override;
113 
115 
116  void delaySettingRecords() override;
117 
118  // ---------- member data --------------------------------
119  std::unique_ptr<TFile> m_file;
121  std::map<EventSetupRecordKey, fwlite::RecordID> m_keyToID;
124 };
125 
127  : m_file(TFile::Open(iPS.getParameter<std::string>("fileName").c_str())), m_es(m_file.get()) {}
128 
130 
132  const EventSetupRecordKey& iRecordKey, unsigned int iovIndex) {
133  KeyedProxiesVector keyedProxiesVector;
135 
136  fwlite::RecordID recID = m_keyToID[iRecordKey];
137  const fwlite::Record& rec = m_es.get(recID);
138  typedef std::vector<std::pair<std::string, std::string> > TypesAndLabels;
139  TypesAndLabels typesAndLabels = rec.typeAndLabelOfAvailableData();
140 
141  std::cout << "Looking for data in record " << iRecordKey.name() << std::endl;
142  for (TypesAndLabels::const_iterator it = typesAndLabels.begin(), itEnd = typesAndLabels.end(); it != itEnd; ++it) {
143  std::cout << " need type " << it->first << std::endl;
144  HCTypeTag tt = HCTypeTag::findType(it->first);
145  if (tt != HCTypeTag()) {
146  edm::eventsetup::DataKey dk(tt, edm::eventsetup::IdTags(it->second.c_str()));
147  keyedProxiesVector.emplace_back(dk, std::make_shared<FWLiteProxy>(TypeID(tt.value()), &rec, &m_queue, &m_mutex));
148  } else {
149  LogDebug("UnknownESType") << "The type '" << it->first << "' is unknown in this job";
150  std::cout << " *****FAILED*****" << std::endl;
151  }
152  }
153  return keyedProxiesVector;
154 }
155 
157  const edm::IOVSyncValue& iSync,
158  edm::ValidityInterval& oIOV) {
159  m_es.syncTo(iSync.eventID(), iSync.time());
160 
161  const fwlite::Record& rec = m_es.get(m_keyToID[iKey]);
162  edm::IOVSyncValue endSync(rec.endSyncValue().eventID(), rec.endSyncValue().time());
163  if (rec.endSyncValue().eventID().run() == 0 && rec.endSyncValue().time().value() == 0ULL) {
164  endSync = edm::IOVSyncValue::endOfTime();
165  }
167 }
168 
171  std::vector<std::string> recordNames = m_es.namesOfAvailableRecords();
172 
173  for (std::vector<std::string>::const_iterator it = recordNames.begin(), itEnd = recordNames.end(); it != itEnd;
174  ++it) {
175  HCTypeTag t = HCTypeTag::findType(*it);
176  if (t != HCTypeTag()) {
180  m_keyToID[key] = m_es.recordID(it->c_str());
181  }
182  }
183 }
184 
std::map< EventSetupRecordKey, fwlite::RecordID > m_keyToID
std::pair< const char *, const std::type_info * > findType(const char *iClassName)
Definition: typelookup.cc:70
void syncTo(const edm::EventID &, const edm::Timestamp &)
Definition: EventSetup.cc:66
const FWLiteESSource & operator=(const FWLiteESSource &)=delete
std::unique_ptr< TFile > m_file
void usingRecordWithKey(const EventSetupRecordKey &key)
static std::mutex mutex
Definition: Proxy.cc:8
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
unsigned int RecordID
Definition: EventSetup.h:65
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
void delaySettingRecords() override
~FWLiteESSource() override
const IOVSyncValue & startSyncValue() const
Definition: Record.cc:152
assert(be >=bs)
fwlite::EventSetup m_es
RecordID recordID(const char *iRecordName) const
Definition: EventSetup.cc:87
std::mutex m_mutex
void setIntervalFor(const EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
const Record & get(const RecordID &) const
Definition: EventSetup.cc:117
std::vector< std::string > namesOfAvailableRecords() const
Definition: EventSetup.cc:122
const IOVSyncValue & endSyncValue() const
Definition: Record.cc:153
std::vector< std::pair< DataKey, std::shared_ptr< DataProxy > >> KeyedProxiesVector
RunNumber_t run() const
Definition: EventID.h:38
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
TimeValue_t value() const
Definition: Timestamp.h:38
const edm::EventID & eventID() const
Definition: IOVSyncValue.h:40
const EventID & eventID() const
Definition: IOVSyncValue.h:40
edm::SerialTaskQueue m_queue
FWLiteESSource(edm::ParameterSet const &iPS)
const Timestamp & time() const
Definition: IOVSyncValue.h:42
HLT enums.
KeyedProxiesVector registerProxies(const EventSetupRecordKey &, unsigned int iovIndex) override
#define get
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
std::vector< std::pair< std::string, std::string > > typeAndLabelOfAvailableData() const
Definition: Record.cc:206
#define LogDebug(id)
const edm::Timestamp & time() const
Definition: IOVSyncValue.h:42