File indexing completed on 2024-04-06 12:23:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <cassert>
0015 #include "TFile.h"
0016 #include "TTree.h"
0017 #include "TBranch.h"
0018 #include "FWCore/Reflection/interface/TypeWithDict.h"
0019 #include "FWCore/Reflection/interface/ObjectWithDict.h"
0020
0021
0022 #include "PhysicsTools/CondLiteIO/interface/RecordWriter.h"
0023 #include "DataFormats/FWLite/interface/format_type_name.h"
0024 #include "FWCore/Utilities/interface/Exception.h"
0025
0026 using namespace fwlite;
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 RecordWriter::RecordWriter(const char* iName, TFile* iFile) : pAux_(&aux_) {
0039 tree_ = new TTree(fwlite::format_type_to_mangled(iName).c_str(), "Holds data for an EventSetup Record");
0040 tree_->SetDirectory(iFile);
0041
0042 auxBranch_ = tree_->Branch("ESRecordAuxiliary", "edm::ESRecordAuxiliary", &pAux_);
0043 }
0044
0045
0046
0047
0048
0049
0050 RecordWriter::~RecordWriter() {}
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 void RecordWriter::update(const void* iData, const std::type_info& iType, const char* iLabel) {
0068 const char* label = iLabel;
0069 if (nullptr == iLabel) {
0070 label = "";
0071 }
0072 std::map<std::pair<edm::TypeIDBase, std::string>, DataBuffer>::iterator itFound =
0073 idToBuffer_.find(std::make_pair(edm::TypeIDBase(iType), std::string(iLabel)));
0074 if (itFound == idToBuffer_.end()) {
0075
0076 DataBuffer buffer;
0077 buffer.pBuffer_ = iData;
0078 edm::TypeWithDict t(iType);
0079 assert(bool(t));
0080
0081 std::string className = t.name();
0082
0083
0084 edm::ObjectWithDict o(t, const_cast<void*>(iData));
0085 edm::TypeWithDict trueType(o.dynamicType());
0086 buffer.trueType_ = edm::TypeIDBase(trueType.typeInfo());
0087 std::string trueClassName = trueType.name();
0088
0089 buffer.branch_ = tree_->Branch(
0090 (fwlite::format_type_to_mangled(className) + "__" + label).c_str(), trueClassName.c_str(), &buffer.pBuffer_);
0091 idToBuffer_.insert(std::make_pair(std::make_pair(edm::TypeIDBase(iType), std::string(iLabel)), buffer));
0092 itFound = idToBuffer_.find(std::make_pair(edm::TypeIDBase(iType), std::string(iLabel)));
0093 }
0094 edm::TypeWithDict t(iType);
0095 edm::ObjectWithDict o(t, const_cast<void*>(iData));
0096 edm::TypeWithDict trueType(o.dynamicType());
0097 assert(edm::TypeIDBase(trueType.typeInfo()) == itFound->second.trueType_);
0098 itFound->second.branch_->SetAddress(&(itFound->second.pBuffer_));
0099 itFound->second.pBuffer_ = iData;
0100 }
0101
0102
0103 void RecordWriter::fill(const edm::ESRecordAuxiliary& iValue) {
0104 for (std::map<std::pair<edm::TypeIDBase, std::string>, DataBuffer>::iterator it = idToBuffer_.begin(),
0105 itEnd = idToBuffer_.end();
0106 it != itEnd;
0107 ++it) {
0108 if (nullptr == it->second.pBuffer_) {
0109 throw cms::Exception("MissingESData")
0110 << "The EventSetup data " << it->first.first.name() << " '" << it->first.second << "' was not supplied";
0111 }
0112 }
0113
0114 aux_ = iValue;
0115 tree_->Fill();
0116 for (std::map<std::pair<edm::TypeIDBase, std::string>, DataBuffer>::iterator it = idToBuffer_.begin(),
0117 itEnd = idToBuffer_.end();
0118 it != itEnd;
0119 ++it) {
0120 it->second.pBuffer_ = nullptr;
0121 }
0122 }
0123
0124 void RecordWriter::write() { tree_->Write(); }
0125
0126
0127
0128
0129
0130
0131