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::ESSourceDataProxyBase {
69  public:
70  FWLiteProxy(const TypeID& iTypeID, const fwlite::Record* iRecord, edm::SerialTaskQueue* iQueue, std::mutex* iMutex)
71  : edm::eventsetup::ESSourceDataProxyBase(iQueue, iMutex), m_type(iTypeID), m_record(iRecord), m_data{nullptr} {}
72 
73  void prefetch(const edm::eventsetup::DataKey& iKey, edm::EventSetupRecordDetails) final {
74  assert(iKey.type() == m_type);
75 
76  FWLiteESGenericHandle h(m_type);
77  m_record->get(h, iKey.name().value());
78  m_data = h.m_data;
79 
80  if (nullptr != h.m_exception) {
81  throw *(h.m_exception);
82  }
83  }
84 
85  void invalidateCache() override {
87  m_data = nullptr;
88  }
89 
90  void const* getAfterPrefetchImpl() const final { return m_data; }
91 
92  private:
93  TypeID m_type;
94  const fwlite::Record* m_record;
95  void const* m_data;
96  };
97 } // namespace
98 
100 public:
101  FWLiteESSource(edm::ParameterSet const& iPS);
102  FWLiteESSource(const FWLiteESSource&) = delete;
103  const FWLiteESSource& operator=(const FWLiteESSource&) = delete;
104  ~FWLiteESSource() override;
105 
107 
108 private:
109  KeyedProxiesVector registerProxies(const EventSetupRecordKey&, unsigned int iovIndex) override;
110 
112 
113  void delaySettingRecords() override;
114 
115  // ---------- member data --------------------------------
116  std::unique_ptr<TFile> m_file;
118  std::map<EventSetupRecordKey, fwlite::RecordID> m_keyToID;
121 };
122 
124  : m_file(TFile::Open(iPS.getParameter<std::string>("fileName").c_str())), m_es(m_file.get()) {}
125 
127 
129  const EventSetupRecordKey& iRecordKey, unsigned int iovIndex) {
130  KeyedProxiesVector keyedProxiesVector;
132 
133  fwlite::RecordID recID = m_keyToID[iRecordKey];
134  const fwlite::Record& rec = m_es.get(recID);
135  typedef std::vector<std::pair<std::string, std::string> > TypesAndLabels;
136  TypesAndLabels typesAndLabels = rec.typeAndLabelOfAvailableData();
137 
138  std::cout << "Looking for data in record " << iRecordKey.name() << std::endl;
139  for (TypesAndLabels::const_iterator it = typesAndLabels.begin(), itEnd = typesAndLabels.end(); it != itEnd; ++it) {
140  std::cout << " need type " << it->first << std::endl;
141  HCTypeTag tt = HCTypeTag::findType(it->first);
142  if (tt != HCTypeTag()) {
143  edm::eventsetup::DataKey dk(tt, edm::eventsetup::IdTags(it->second.c_str()));
144  keyedProxiesVector.emplace_back(dk, std::make_shared<FWLiteProxy>(TypeID(tt.value()), &rec, &m_queue, &m_mutex));
145  } else {
146  LogDebug("UnknownESType") << "The type '" << it->first << "' is unknown in this job";
147  std::cout << " *****FAILED*****" << std::endl;
148  }
149  }
150  return keyedProxiesVector;
151 }
152 
154  const edm::IOVSyncValue& iSync,
155  edm::ValidityInterval& oIOV) {
156  m_es.syncTo(iSync.eventID(), iSync.time());
157 
158  const fwlite::Record& rec = m_es.get(m_keyToID[iKey]);
159  edm::IOVSyncValue endSync(rec.endSyncValue().eventID(), rec.endSyncValue().time());
160  if (rec.endSyncValue().eventID().run() == 0 && rec.endSyncValue().time().value() == 0ULL) {
161  endSync = edm::IOVSyncValue::endOfTime();
162  }
164 }
165 
168  std::vector<std::string> recordNames = m_es.namesOfAvailableRecords();
169 
170  for (std::vector<std::string>::const_iterator it = recordNames.begin(), itEnd = recordNames.end(); it != itEnd;
171  ++it) {
172  HCTypeTag t = HCTypeTag::findType(*it);
173  if (t != HCTypeTag()) {
177  m_keyToID[key] = m_es.recordID(it->c_str());
178  }
179  }
180 }
181 
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::eventsetup::ESSourceDataProxyBase::invalidateCache
void invalidateCache() override
Definition: ESSourceDataProxyBase.h:48
edm::typelookup::findType
std::pair< const char *, const std::type_info * > findType(const char *iClassName)
Definition: typelookup.cc:69
FWLiteESSource::m_queue
edm::SerialTaskQueue m_queue
Definition: FWLiteESSource.cc:119
MessageLogger.h
FWLiteESSource::registerProxies
KeyedProxiesVector registerProxies(const EventSetupRecordKey &, unsigned int iovIndex) override
Definition: FWLiteESSource.cc:128
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
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::m_mutex
std::mutex m_mutex
Definition: FWLiteESSource.cc:120
FWLiteESSource::delaySettingRecords
void delaySettingRecords() override
Definition: FWLiteESSource.cc:166
edm::ValidityInterval
Definition: ValidityInterval.h:28
FWLiteESSource
Definition: FWLiteESSource.cc:99
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::SerialTaskQueue
Definition: SerialTaskQueue.h:67
edm::Timestamp::value
TimeValue_t value() const
Definition: Timestamp.h:45
FWLiteESSource::~FWLiteESSource
~FWLiteESSource() override
Definition: FWLiteESSource.cc:126
watchdog.const
const
Definition: watchdog.py:83
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
SerialTaskQueue.h
DataProxyProvider.h
TypeIDBase.h
FWLiteESSource::operator=
const FWLiteESSource & operator=(const FWLiteESSource &)=delete
edm::EventSetupRecordIntervalFinder::findingRecordWithKey
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
Definition: EventSetupRecordIntervalFinder.cc:44
edm::eventsetup::ESSourceDataProxyBase
Definition: ESSourceDataProxyBase.h:39
edm::EventSetupRecordDetails
Definition: EventSetupRecordDetails.h:29
ESSourceDataProxyBase
FWLiteESSource::m_file
std::unique_ptr< TFile > m_file
Definition: FWLiteESSource.cc:116
edm::eventsetup::EventSetupRecordKey::name
const char * name() const
Definition: EventSetupRecordKey.h:46
h
EventSetup.h
ESSourceDataProxyBase.h
FWLiteESSource::setIntervalFor
void setIntervalFor(const EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
Definition: FWLiteESSource.cc:153
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
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:233
edm::ParameterSet
Definition: ParameterSet.h:47
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:118
mutex
static std::mutex mutex
Definition: Proxy.cc:8
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::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:123
edm::eventsetup::NameTag
Definition: DataKeyTags.h:45
Exception.h
FWLiteESSource::m_es
fwlite::EventSetup m_es
Definition: FWLiteESSource.cc:117
edm::TypeIDBase
Definition: TypeIDBase.h:29
fwlite::IOVSyncValue::time
const edm::Timestamp & time() const
Definition: IOVSyncValue.h:42
WaitingTaskList.h
cms::Exception
Definition: Exception.h:70
Record.h
ParameterSet.h
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
crabWrapper.key
key
Definition: crabWrapper.py:19
fwlite::EventSetup
Definition: EventSetup.h:68
HCTypeTag.h
fwlite::IOVSyncValue::eventID
const edm::EventID & eventID() const
Definition: IOVSyncValue.h:40