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 FWLiteProductResolver : public edm::eventsetup::ESSourceProductResolverNonConcurrentBase {
69  public:
70  FWLiteProductResolver(const TypeID& iTypeID,
71  const fwlite::Record* iRecord,
72  edm::SerialTaskQueue* iQueue,
73  std::mutex* iMutex)
74  : edm::eventsetup::ESSourceProductResolverNonConcurrentBase(iQueue, iMutex),
75  m_type(iTypeID),
76  m_record(iRecord),
77  m_data{nullptr} {}
78 
79  void prefetch(const edm::eventsetup::DataKey& iKey, edm::EventSetupRecordDetails) final {
80  assert(iKey.type() == m_type);
81 
82  FWLiteESGenericHandle h(m_type);
83  m_record->get(h, iKey.name().value());
84  m_data = h.m_data;
85 
86  if (nullptr != h.m_exception) {
87  throw *(h.m_exception);
88  }
89  }
90 
91  void invalidateCache() override {
93  m_data = nullptr;
94  }
95 
96  void const* getAfterPrefetchImpl() const final { return m_data; }
97 
98  private:
99  TypeID m_type;
100  const fwlite::Record* m_record;
101  void const* m_data;
102  };
103 } // namespace
104 
106 public:
107  FWLiteESSource(edm::ParameterSet const& iPS);
108  FWLiteESSource(const FWLiteESSource&) = delete;
109  const FWLiteESSource& operator=(const FWLiteESSource&) = delete;
110  ~FWLiteESSource() override;
111 
113 
114 private:
115  KeyedResolversVector registerResolvers(const EventSetupRecordKey&, unsigned int iovIndex) override;
116 
118 
119  void delaySettingRecords() override;
120 
121  // ---------- member data --------------------------------
122  std::unique_ptr<TFile> m_file;
124  std::map<EventSetupRecordKey, fwlite::RecordID> m_keyToID;
127 };
128 
130  : m_file(TFile::Open(iPS.getParameter<std::string>("fileName").c_str())), m_es(m_file.get()) {}
131 
133 
135  const EventSetupRecordKey& iRecordKey, unsigned int iovIndex) {
136  KeyedResolversVector keyedProxiesVector;
138 
139  fwlite::RecordID recID = m_keyToID[iRecordKey];
140  const fwlite::Record& rec = m_es.get(recID);
141  typedef std::vector<std::pair<std::string, std::string> > TypesAndLabels;
142  TypesAndLabels typesAndLabels = rec.typeAndLabelOfAvailableData();
143 
144  std::cout << "Looking for data in record " << iRecordKey.name() << std::endl;
145  for (TypesAndLabels::const_iterator it = typesAndLabels.begin(), itEnd = typesAndLabels.end(); it != itEnd; ++it) {
146  std::cout << " need type " << it->first << std::endl;
147  HCTypeTag tt = HCTypeTag::findType(it->first);
148  if (tt != HCTypeTag()) {
149  edm::eventsetup::DataKey dk(tt, edm::eventsetup::IdTags(it->second.c_str()));
150  keyedProxiesVector.emplace_back(
151  dk, std::make_shared<FWLiteProductResolver>(TypeID(tt.value()), &rec, &m_queue, &m_mutex));
152  } else {
153  LogDebug("UnknownESType") << "The type '" << it->first << "' is unknown in this job";
154  std::cout << " *****FAILED*****" << std::endl;
155  }
156  }
157  return keyedProxiesVector;
158 }
159 
161  const edm::IOVSyncValue& iSync,
162  edm::ValidityInterval& oIOV) {
163  m_es.syncTo(iSync.eventID(), iSync.time());
164 
165  const fwlite::Record& rec = m_es.get(m_keyToID[iKey]);
166  edm::IOVSyncValue endSync(rec.endSyncValue().eventID(), rec.endSyncValue().time());
167  if (rec.endSyncValue().eventID().run() == 0 && rec.endSyncValue().time().value() == 0ULL) {
168  endSync = edm::IOVSyncValue::endOfTime();
169  }
171 }
172 
175  std::vector<std::string> recordNames = m_es.namesOfAvailableRecords();
176 
177  for (std::vector<std::string>::const_iterator it = recordNames.begin(), itEnd = recordNames.end(); it != itEnd;
178  ++it) {
179  HCTypeTag t = HCTypeTag::findType(*it);
180  if (t != HCTypeTag()) {
184  m_keyToID[key] = m_es.recordID(it->c_str());
185  }
186  }
187 }
188 
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
static std::mutex mutex
Definition: Proxy.cc:8
void usingRecordWithKey(const EventSetupRecordKey &key)
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
Definition: TTTypes.h:54
RecordID recordID(const char *iRecordName) const
Definition: EventSetup.cc:87
std::mutex m_mutex
KeyedResolversVector registerResolvers(const EventSetupRecordKey &, unsigned int iovIndex) override
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
RunNumber_t run() const
Definition: EventID.h:38
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
TimeValue_t value() const
Definition: Timestamp.h:38
const edm::EventID & eventID() const
Definition: IOVSyncValue.h:40
std::vector< std::pair< DataKey, std::shared_ptr< ESProductResolver > >> KeyedResolversVector
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.
#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