CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecordWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWCondLite
4 // Class : RecordWriter
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author:
10 // Created: Wed Dec 9 17:01:03 CST 2009
11 //
12 
13 // system include files
14 #include <cassert>
15 #include "TFile.h"
16 #include "TTree.h"
17 #include "TBranch.h"
20 
21 // user include files
25 
26 using namespace fwlite;
27 //
28 // constants, enums and typedefs
29 //
30 
31 //
32 // static data member definitions
33 //
34 
35 //
36 // constructors and destructor
37 //
38 RecordWriter::RecordWriter(const char* iName, TFile* iFile):
39 pAux_(&aux_)
40 {
41  tree_ = new TTree(fwlite::format_type_to_mangled(iName).c_str(),"Holds data for an EventSetup Record");
42  tree_->SetDirectory(iFile);
43 
44  auxBranch_ = tree_->Branch("ESRecordAuxiliary","edm::ESRecordAuxiliary",&pAux_);
45 }
46 
47 // RecordWriter::RecordWriter(const RecordWriter& rhs)
48 // {
49 // // do actual copying here;
50 // }
51 
53 {
54 }
55 
56 //
57 // assignment operators
58 //
59 // const RecordWriter& RecordWriter::operator=(const RecordWriter& rhs)
60 // {
61 // //An exception safe implementation is
62 // RecordWriter temp(rhs);
63 // swap(rhs);
64 //
65 // return *this;
66 // }
67 
68 //
69 // member functions
70 //
71 void
72 RecordWriter::update(const void* iData, const std::type_info& iType, const char* iLabel)
73 {
74  const char* label = iLabel;
75  if(0==iLabel) {
76  label = "";
77  }
78  std::map<std::pair<edm::TypeIDBase,std::string>, DataBuffer>::iterator itFound = idToBuffer_.find(std::make_pair(edm::TypeIDBase(iType),
79  std::string(iLabel)));
80  if(itFound == idToBuffer_.end()) {
81  //first request
82  DataBuffer buffer;
83  buffer.pBuffer_=iData;
84  edm::TypeWithDict t(iType);
85  assert(bool(t));
86 
88 
89  //now find actual type
90  edm::ObjectWithDict o(t,const_cast<void*>(iData));
91  edm::TypeWithDict trueType(o.dynamicType());
92  buffer.trueType_ = edm::TypeIDBase(trueType.typeInfo());
93  std::string trueClassName = trueType.name();
94 
95  buffer.branch_ = tree_->Branch((fwlite::format_type_to_mangled(className)+"__"+label).c_str(),
96  trueClassName.c_str(),
97  &buffer.pBuffer_);
98  idToBuffer_.insert(std::make_pair(std::make_pair(edm::TypeIDBase(iType),std::string(iLabel)),buffer));
99  itFound = idToBuffer_.find(std::make_pair(edm::TypeIDBase(iType),
100  std::string(iLabel)));
101  }
102  edm::TypeWithDict t(iType);
103  edm::ObjectWithDict o(t,const_cast<void*>(iData));
104  edm::TypeWithDict trueType(o.dynamicType());
105  assert(edm::TypeIDBase(trueType.typeInfo())==itFound->second.trueType_);
106  itFound->second.branch_->SetAddress(&(itFound->second.pBuffer_));
107  itFound->second.pBuffer_ = iData;
108 }
109 
110 //call update before calling write
111 void
113 {
114  for(std::map<std::pair<edm::TypeIDBase,std::string>, DataBuffer>::iterator it=idToBuffer_.begin(),itEnd=idToBuffer_.end();
115  it!=itEnd;++it) {
116  if(0==it->second.pBuffer_) {
117  throw cms::Exception("MissingESData")<<"The EventSetup data "<<it->first.first.name()<<" '"<<it->first.second<<"' was not supplied";
118  }
119  }
120 
121  aux_ = iValue;
122  tree_->Fill();
123  for(std::map<std::pair<edm::TypeIDBase,std::string>, DataBuffer>::iterator it=idToBuffer_.begin(),itEnd=idToBuffer_.end();
124  it!=itEnd;++it) {
125  it->second.pBuffer_=0;
126  }
127 }
128 
129 void
131 {
132  tree_->Write();
133 }
134 //
135 // const member functions
136 //
137 
138 //
139 // static member functions
140 //
assert(m_qm.get())
TypeWithDict dynamicType() const
std::string name() const
edm::ESRecordAuxiliary aux_
Definition: RecordWriter.h:64
std::string format_type_to_mangled(const std::string &)
given a C++ class name returned a mangled name
edm::ESRecordAuxiliary * pAux_
Definition: RecordWriter.h:65
void fill(const edm::ESRecordAuxiliary &)
std::map< std::pair< edm::TypeIDBase, std::string >, DataBuffer > idToBuffer_
Definition: RecordWriter.h:67
void update(const void *iData, const std::type_info &iType, const char *iLabel)
Definition: RecordWriter.cc:72
std::string className(const T &t)
Definition: ClassName.h:30
RecordWriter(const char *iName, TFile *iFile)
Definition: RecordWriter.cc:38