Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <cassert>
00016 #include "TFile.h"
00017 #include "TTree.h"
00018 #include "TBranch.h"
00019 #include "Reflex/Type.h"
00020 #include "Reflex/Object.h"
00021
00022
00023 #include "PhysicsTools/CondLiteIO/interface/RecordWriter.h"
00024 #include "DataFormats/FWLite/interface/format_type_name.h"
00025 #include "FWCore/Utilities/interface/Exception.h"
00026
00027 using namespace fwlite;
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 RecordWriter::RecordWriter(const char* iName, TFile* iFile):
00040 pAux_(&aux_)
00041 {
00042 tree_ = new TTree(fwlite::format_type_to_mangled(iName).c_str(),"Holds data for an EventSetup Record");
00043 tree_->SetDirectory(iFile);
00044
00045 auxBranch_ = tree_->Branch("ESRecordAuxiliary","edm::ESRecordAuxiliary",&pAux_);
00046 }
00047
00048
00049
00050
00051
00052
00053 RecordWriter::~RecordWriter()
00054 {
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 void
00073 RecordWriter::update(const void* iData, const std::type_info& iType, const char* iLabel)
00074 {
00075 const char* label = iLabel;
00076 if(0==iLabel) {
00077 label = "";
00078 }
00079 std::map<std::pair<edm::TypeIDBase,std::string>, DataBuffer>::iterator itFound = idToBuffer_.find(std::make_pair(edm::TypeIDBase(iType),
00080 std::string(iLabel)));
00081 if(itFound == idToBuffer_.end()) {
00082
00083 DataBuffer buffer;
00084 buffer.pBuffer_=iData;
00085 ROOT::Reflex::Type t = ROOT::Reflex::Type::ByTypeInfo(iType);
00086 assert(t != ROOT::Reflex::Type());
00087
00088 std::string className = t.Name(ROOT::Reflex::SCOPED|ROOT::Reflex::FINAL);
00089
00090
00091 ROOT::Reflex::Object o(t,const_cast<void*>(iData));
00092 ROOT::Reflex::Type trueType = o.DynamicType();
00093 buffer.trueType_ = edm::TypeIDBase(trueType.TypeInfo());
00094 std::string trueClassName = trueType.Name(ROOT::Reflex::SCOPED|ROOT::Reflex::FINAL);
00095
00096 buffer.branch_ = tree_->Branch((fwlite::format_type_to_mangled(className)+"__"+label).c_str(),
00097 trueClassName.c_str(),
00098 &buffer.pBuffer_);
00099 idToBuffer_.insert(std::make_pair(std::make_pair(edm::TypeIDBase(iType),std::string(iLabel)),buffer));
00100 itFound = idToBuffer_.find(std::make_pair(edm::TypeIDBase(iType),
00101 std::string(iLabel)));
00102 }
00103 ROOT::Reflex::Type t = ROOT::Reflex::Type::ByTypeInfo(iType);
00104 ROOT::Reflex::Object o(t,const_cast<void*>(iData));
00105 ROOT::Reflex::Type trueType = o.DynamicType();
00106 assert(edm::TypeIDBase(trueType.TypeInfo())==itFound->second.trueType_);
00107 itFound->second.branch_->SetAddress(&(itFound->second.pBuffer_));
00108 itFound->second.pBuffer_ = iData;
00109 }
00110
00111
00112 void
00113 RecordWriter::fill(const edm::ESRecordAuxiliary& iValue)
00114 {
00115 for(std::map<std::pair<edm::TypeIDBase,std::string>, DataBuffer>::iterator it=idToBuffer_.begin(),itEnd=idToBuffer_.end();
00116 it!=itEnd;++it) {
00117 if(0==it->second.pBuffer_) {
00118 throw cms::Exception("MissingESData")<<"The EventSetup data "<<it->first.first.name()<<" '"<<it->first.second<<"' was not supplied";
00119 }
00120 }
00121
00122 aux_ = iValue;
00123 tree_->Fill();
00124 for(std::map<std::pair<edm::TypeIDBase,std::string>, DataBuffer>::iterator it=idToBuffer_.begin(),itEnd=idToBuffer_.end();
00125 it!=itEnd;++it) {
00126 it->second.pBuffer_=0;
00127 }
00128 }
00129
00130 void
00131 RecordWriter::write()
00132 {
00133 tree_->Write();
00134 }
00135
00136
00137
00138
00139
00140
00141