CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
40 // forward declarations
41 namespace {
42  struct TypeID : public edm::TypeIDBase {
43  explicit TypeID(const std::type_info& iInfo): edm::TypeIDBase(iInfo) {}
44  TypeID() {}
46  };
47  struct FWLiteESGenericHandle {
48  FWLiteESGenericHandle(const TypeID& iType):
49  m_type(iType),
50  m_data(0),
51  m_exception(0){}
52 
53  FWLiteESGenericHandle(const void* iData):
54  m_type(),
55  m_data(iData),
56  m_exception(0) {}
57 
58  FWLiteESGenericHandle(cms::Exception* iException):
59  m_type(),
60  m_data(0),
61  m_exception(iException){}
62 
63  const std::type_info& typeInfo() const {
64  return m_type.typeInfo();
65  }
66 
67  TypeID m_type;
68  const void* m_data;
69  cms::Exception* m_exception;
70  };
71 
72  class FWLiteProxy : public edm::eventsetup::DataProxy {
73  public:
74  FWLiteProxy(const TypeID& iTypeID, const fwlite::Record* iRecord):
75  m_type(iTypeID),
76  m_record(iRecord){}
77 
78  virtual const void* getImpl(const edm::eventsetup::EventSetupRecord&, const edm::eventsetup::DataKey& iKey) override {
79  assert(iKey.type() == m_type);
80 
81  FWLiteESGenericHandle h(m_type);
82  m_record->get(h,iKey.name().value());
83 
84  if(0!=h.m_exception) {
85  throw *(h.m_exception);
86  }
87  return h.m_data;
88  }
89 
90  virtual void invalidateCache() override {
91  }
92 
93  private:
94  TypeID m_type;
95  const fwlite::Record* m_record;
96  };
97 }
98 
100 
101 public:
102  FWLiteESSource(edm::ParameterSet const& iPS);
103  virtual ~FWLiteESSource();
104 
105  // ---------- const member functions ---------------------
106 
107  // ---------- static member functions --------------------
108 
109  // ---------- member functions ---------------------------
110  virtual void newInterval(const edm::eventsetup::EventSetupRecordKey& iRecordType,
111  const edm::ValidityInterval& iInterval) override;
112 
113 
114 private:
115  FWLiteESSource(const FWLiteESSource&); // stop default
116 
117  const FWLiteESSource& operator=(const FWLiteESSource&); // stop default
118 
119  virtual void registerProxies(const edm::eventsetup::EventSetupRecordKey& iRecordKey ,
120  KeyedProxies& aProxyList) override;
121 
122 
124  const edm::IOVSyncValue& ,
125  edm::ValidityInterval&) override;
126 
127  virtual void delaySettingRecords() override;
128 
129  // ---------- member data --------------------------------
130  std::auto_ptr<TFile> m_file;
132  std::map<edm::eventsetup::EventSetupRecordKey, fwlite::RecordID> m_keyToID;
133 
134 };
135 
136 
137 //
138 // constants, enums and typedefs
139 //
140 
141 //
142 // static data member definitions
143 //
144 
145 //
146 // constructors and destructor
147 //
149 m_file( TFile::Open(iPS.getParameter<std::string>("fileName").c_str())),
150 m_es( m_file.get())
151 {
152 }
153 
154 // FWLiteESSource::FWLiteESSource(const FWLiteESSource& rhs)
155 // {
156 // // do actual copying here;
157 // }
158 
160 {
161 }
162 
163 //
164 // assignment operators
165 //
166 // const FWLiteESSource& FWLiteESSource::operator=(const FWLiteESSource& rhs)
167 // {
168 // //An exception safe implementation is
169 // FWLiteESSource temp(rhs);
170 // swap(rhs);
171 //
172 // return *this;
173 // }
174 
175 //
176 // member functions
177 //
178 void
180  const edm::ValidityInterval& /*iInterval*/)
181 {
182  invalidateProxies(iRecordType);
183 }
184 
185 //
186 // const member functions
187 //
188 void
190  KeyedProxies& aProxyList)
191 {
193 
194  fwlite::RecordID recID = m_keyToID[iRecordKey];
195  const fwlite::Record& rec = m_es.get(recID);
196  typedef std::vector<std::pair<std::string,std::string> > TypesAndLabels;
197  TypesAndLabels typesAndLabels = rec.typeAndLabelOfAvailableData();
198 
199  std::cout <<"Looking for data in record "<<iRecordKey.name()<<std::endl;
200  for(TypesAndLabels::const_iterator it = typesAndLabels.begin(), itEnd = typesAndLabels.end();
201  it != itEnd;
202  ++it) {
203  std::cout <<" need type "<<it->first<<std::endl;
204  HCTypeTag tt = HCTypeTag::findType(it->first);
205  if(tt != HCTypeTag() ) {
206  edm::eventsetup::DataKey dk(tt,edm::eventsetup::IdTags(it->second.c_str()));
207  aProxyList.push_back(std::make_pair(dk,
208  std::make_shared<FWLiteProxy>(TypeID(tt.value()),&rec)));
209  } else {
210  LogDebug("UnknownESType")<<"The type '"<<it->first<<"' is unknown in this job";
211  std::cout <<" *****FAILED*****"<<std::endl;
212  }
213  }
214 
215 }
216 
217 
218 void
220  const edm::IOVSyncValue& iSync,
221  edm::ValidityInterval& oIOV)
222 {
223  m_es.syncTo(iSync.eventID(), iSync.time());
224 
225  const fwlite::Record& rec = m_es.get(m_keyToID[iKey]);
226  edm::IOVSyncValue endSync(rec.endSyncValue().eventID(),
227  rec.endSyncValue().time());
228  if(rec.endSyncValue().eventID().run()==0 &&
229  rec.endSyncValue().time().value() == 0ULL) {
230  endSync = edm::IOVSyncValue::endOfTime();
231  }
233  rec.startSyncValue().time()),
234  endSync);
235 }
236 
237 void
239 {
241  std::vector<std::string> recordNames = m_es.namesOfAvailableRecords();
242 
243  for(std::vector<std::string>::const_iterator it = recordNames.begin(),
244  itEnd = recordNames.end();
245  it != itEnd;
246  ++it) {
247  HCTypeTag t = HCTypeTag::findType(*it);
248  if(t != HCTypeTag() ) {
251  usingRecordWithKey(key);
252  m_keyToID[key]=m_es.recordID(it->c_str());
253  }
254  }
255 }
256 
257 
258 
259 //
260 // static member functions
261 //
262 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
std::pair< const char *, const std::type_info * > findType(const char *iClassName)
Definition: typelookup.cc:76
void syncTo(const edm::EventID &, const edm::Timestamp &)
Definition: EventSetup.cc:71
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
const EventID & eventID() const
Definition: IOVSyncValue.h:42
std::vector< std::string > namesOfAvailableRecords() const
Definition: EventSetup.cc:133
assert(m_qm.get())
std::map< edm::eventsetup::EventSetupRecordKey, fwlite::RecordID > m_keyToID
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
unsigned int RecordID
Definition: EventSetup.h:64
const IOVSyncValue & startSyncValue() const
Definition: Record.cc:166
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
virtual void delaySettingRecords() override
void usingRecordWithKey(const EventSetupRecordKey &)
std::auto_ptr< TFile > m_file
const std::type_info & typeInfo() const
Definition: TypeIDBase.h:58
std::vector< std::pair< DataKey, edm::propagate_const< std::shared_ptr< DataProxy > > > > KeyedProxies
const FWLiteESSource & operator=(const FWLiteESSource &)
fwlite::EventSetup m_es
RecordID recordID(const char *iRecordName) const
Definition: EventSetup.cc:97
virtual void registerProxies(const edm::eventsetup::EventSetupRecordKey &iRecordKey, KeyedProxies &aProxyList) override
void invalidateProxies(const EventSetupRecordKey &iRecordKey)
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::vector< std::pair< std::string, std::string > > typeAndLabelOfAvailableData() const
Definition: Record.cc:236
virtual ~FWLiteESSource()
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
const TypeTag & type() const
Definition: DataKey.h:65
FWLiteESSource(edm::ParameterSet const &iPS)
const edm::Timestamp & time() const
Definition: IOVSyncValue.h:44
const NameTag & name() const
Definition: DataKey.h:66
const char * value() const
Definition: DataKeyTags.h:39
const Timestamp & time() const
Definition: IOVSyncValue.h:44
tuple cout
Definition: gather_cfg.py:145
virtual void newInterval(const edm::eventsetup::EventSetupRecordKey &iRecordType, const edm::ValidityInterval &iInterval) override
called when a new interval of validity occurs for iRecordType
const Record & get(const RecordID &) const
Definition: EventSetup.cc:126
virtual void invalidateCache()=0
virtual void const * getImpl(EventSetupRecord const &, DataKey const &iKey)=0
TimeValue_t value() const
Definition: Timestamp.h:56
T get(const Candidate &c)
Definition: component.h:55
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
const edm::EventID & eventID() const
Definition: IOVSyncValue.h:42
const IOVSyncValue & endSyncValue() const
Definition: Record.cc:170