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