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 #include <boost/shared_ptr.hpp>
24 
25 // user include files
35 
37 
39 
40 
41 // forward declarations
42 namespace {
43  struct TypeID : public edm::TypeIDBase {
44  explicit TypeID(const type_info& iInfo): edm::TypeIDBase(iInfo) {}
45  TypeID() {}
47  };
48  struct FWLiteESGenericHandle {
49  FWLiteESGenericHandle(const TypeID& iType):
50  m_type(iType),
51  m_data(0),
52  m_exception(0){}
53 
54  FWLiteESGenericHandle(const void* iData):
55  m_type(),
56  m_data(iData),
57  m_exception(0) {}
58 
59  FWLiteESGenericHandle(cms::Exception* iException):
60  m_type(),
61  m_data(0),
62  m_exception(iException){}
63 
64  const std::type_info& typeInfo() const {
65  return m_type.typeInfo();
66  }
67 
68  TypeID m_type;
69  const void* m_data;
70  cms::Exception* m_exception;
71  };
72 
73  class FWLiteProxy : public edm::eventsetup::DataProxy {
74  public:
75  FWLiteProxy(const TypeID& iTypeID, const fwlite::Record* iRecord):
76  m_type(iTypeID),
77  m_record(iRecord){}
78 
79  virtual const void* getImpl(const edm::eventsetup::EventSetupRecord&, const edm::eventsetup::DataKey& iKey) override {
80  assert(iKey.type() == m_type);
81 
82  FWLiteESGenericHandle h(m_type);
83  m_record->get(h,iKey.name().value());
84 
85  if(0!=h.m_exception) {
86  throw *(h.m_exception);
87  }
88  return h.m_data;
89  }
90 
91  virtual void invalidateCache() override {
92  }
93 
94  private:
95  TypeID m_type;
96  const fwlite::Record* m_record;
97  };
98 }
99 
101 
102 public:
103  FWLiteESSource(edm::ParameterSet const& iPS);
104  virtual ~FWLiteESSource();
105 
106  // ---------- const member functions ---------------------
107 
108  // ---------- static member functions --------------------
109 
110  // ---------- member functions ---------------------------
111  virtual void newInterval(const edm::eventsetup::EventSetupRecordKey& iRecordType,
112  const edm::ValidityInterval& iInterval) override;
113 
114 
115 private:
116  FWLiteESSource(const FWLiteESSource&); // stop default
117 
118  const FWLiteESSource& operator=(const FWLiteESSource&); // stop default
119 
120  virtual void registerProxies(const edm::eventsetup::EventSetupRecordKey& iRecordKey ,
121  KeyedProxies& aProxyList) override;
122 
123 
125  const edm::IOVSyncValue& ,
126  edm::ValidityInterval&) override;
127 
128  virtual void delaySettingRecords() override;
129 
130  // ---------- member data --------------------------------
131  std::auto_ptr<TFile> m_file;
133  std::map<edm::eventsetup::EventSetupRecordKey, fwlite::RecordID> m_keyToID;
134 
135 };
136 
137 
138 //
139 // constants, enums and typedefs
140 //
141 
142 //
143 // static data member definitions
144 //
145 
146 //
147 // constructors and destructor
148 //
150 m_file( TFile::Open(iPS.getParameter<std::string>("fileName").c_str())),
151 m_es( m_file.get())
152 {
153 }
154 
155 // FWLiteESSource::FWLiteESSource(const FWLiteESSource& rhs)
156 // {
157 // // do actual copying here;
158 // }
159 
161 {
162 }
163 
164 //
165 // assignment operators
166 //
167 // const FWLiteESSource& FWLiteESSource::operator=(const FWLiteESSource& rhs)
168 // {
169 // //An exception safe implementation is
170 // FWLiteESSource temp(rhs);
171 // swap(rhs);
172 //
173 // return *this;
174 // }
175 
176 //
177 // member functions
178 //
179 void
181  const edm::ValidityInterval& /*iInterval*/)
182 {
183  invalidateProxies(iRecordType);
184 }
185 
186 //
187 // const member functions
188 //
189 void
191  KeyedProxies& aProxyList)
192 {
194 
195  fwlite::RecordID recID = m_keyToID[iRecordKey];
196  const fwlite::Record& rec = m_es.get(recID);
197  typedef std::vector<std::pair<std::string,std::string> > TypesAndLabels;
198  TypesAndLabels typesAndLabels = rec.typeAndLabelOfAvailableData();
199 
200  std::cout <<"Looking for data in record "<<iRecordKey.name()<<std::endl;
201  for(TypesAndLabels::const_iterator it = typesAndLabels.begin(), itEnd = typesAndLabels.end();
202  it != itEnd;
203  ++it) {
204  std::cout <<" need type "<<it->first<<std::endl;
205  HCTypeTag tt = HCTypeTag::findType(it->first);
206  if(tt != HCTypeTag() ) {
207  edm::eventsetup::DataKey dk(tt,edm::eventsetup::IdTags(it->second.c_str()));
208  aProxyList.push_back(std::make_pair(dk,
209  boost::shared_ptr<edm::eventsetup::DataProxy>(new FWLiteProxy(TypeID(tt.value()),&rec))));
210  } else {
211  LogDebug("UnknownESType")<<"The type '"<<it->first<<"' is unknown in this job";
212  std::cout <<" *****FAILED*****"<<std::endl;
213  }
214  }
215 
216 }
217 
218 
219 void
221  const edm::IOVSyncValue& iSync,
222  edm::ValidityInterval& oIOV)
223 {
224  m_es.syncTo(iSync.eventID(), iSync.time());
225 
226  const fwlite::Record& rec = m_es.get(m_keyToID[iKey]);
227  edm::IOVSyncValue endSync(rec.endSyncValue().eventID(),
228  rec.endSyncValue().time());
229  if(rec.endSyncValue().eventID().run()==0 &&
230  rec.endSyncValue().time().value() == 0ULL) {
231  endSync = edm::IOVSyncValue::endOfTime();
232  }
234  rec.startSyncValue().time()),
235  endSync);
236 }
237 
238 void
240 {
242  std::vector<std::string> recordNames = m_es.namesOfAvailableRecords();
243 
244  for(std::vector<std::string>::const_iterator it = recordNames.begin(),
245  itEnd = recordNames.end();
246  it != itEnd;
247  ++it) {
248  HCTypeTag t = HCTypeTag::findType(*it);
249  if(t != HCTypeTag() ) {
252  usingRecordWithKey(key);
253  m_keyToID[key]=m_es.recordID(it->c_str());
254  }
255  }
256 }
257 
258 
259 
260 //
261 // static member functions
262 //
263 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
tuple t
Definition: tree.py:139
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:72
const EventID & eventID() const
Definition: IOVSyncValue.h:42
std::vector< std::string > namesOfAvailableRecords() const
Definition: EventSetup.cc:134
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:63
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
const FWLiteESSource & operator=(const FWLiteESSource &)
fwlite::EventSetup m_es
RecordID recordID(const char *iRecordName) const
Definition: EventSetup.cc:98
virtual void registerProxies(const edm::eventsetup::EventSetupRecordKey &iRecordKey, KeyedProxies &aProxyList) override
void invalidateProxies(const EventSetupRecordKey &iRecordKey)
std::vector< std::pair< DataKey, boost::shared_ptr< DataProxy > > > KeyedProxies
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
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:121
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:127
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