PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
podio::ROOTFrameWriter Class Reference

#include <ROOTFrameWriter.h>

Public Member Functions

 ROOTFrameWriter (const std::string &filename)
 
 ~ROOTFrameWriter ()=default
 
 ROOTFrameWriter (const ROOTFrameWriter &)=delete
 
ROOTFrameWriteroperator= (const ROOTFrameWriter &)=delete
 
void writeFrame (const podio::Frame &frame, const std::string &category)
 
void writeFrame (const podio::Frame &frame, const std::string &category, const std::vector< std::string > &collsToWrite)
 
void finish ()
 

Detailed Description

Definition at line 24 of file ROOTFrameWriter.h.

Constructor & Destructor Documentation

◆ ROOTFrameWriter() [1/2]

podio::ROOTFrameWriter::ROOTFrameWriter ( const std::string &  filename)

Definition at line 13 of file ROOTFrameWriter.cc.

13 {
14 m_file = std::make_unique<TFile>(filename.c_str(), "recreate");
15}

◆ ~ROOTFrameWriter()

podio::ROOTFrameWriter::~ROOTFrameWriter ( )
default

◆ ROOTFrameWriter() [2/2]

podio::ROOTFrameWriter::ROOTFrameWriter ( const ROOTFrameWriter )
delete

Member Function Documentation

◆ finish()

void podio::ROOTFrameWriter::finish ( )

Write the current file, including all the necessary metadata to read it again.

Definition at line 120 of file ROOTFrameWriter.cc.

120 {
121 auto* metaTree = new TTree(root_utils::metaTreeName, "metadata tree for podio I/O functionality");
122 metaTree->SetDirectory(m_file.get());
123
124 // Store the collection id table and collection info for reading in the meta tree
125 for (/*const*/ auto& [category, info] : m_categories) {
126 metaTree->Branch(root_utils::idTableName(category).c_str(), &info.idTable);
127 metaTree->Branch(root_utils::collInfoName(category).c_str(), &info.collInfo);
128 }
129
130 // Store the current podio build version into the meta data tree
131 auto podioVersion = podio::version::build_version;
132 metaTree->Branch(root_utils::versionBranchName, &podioVersion);
133
134 auto edmDefinitions = m_datamodelCollector.getDatamodelDefinitionsToWrite();
135 metaTree->Branch(root_utils::edmDefBranchName, &edmDefinitions);
136
137 metaTree->Fill();
138
139 m_file->Write();
140 m_file->Close();
141}
std::vector< std::tuple< std::string, std::string > > getDatamodelDefinitionsToWrite() const
Get all the names and JSON definitions that need to be written.
std::string idTableName(const std::string &category)
Definition: rootUtils.h:49
std::string collInfoName(const std::string &category)
Definition: rootUtils.h:58

◆ operator=()

ROOTFrameWriter & podio::ROOTFrameWriter::operator= ( const ROOTFrameWriter )
delete

◆ writeFrame() [1/2]

void podio::ROOTFrameWriter::writeFrame ( const podio::Frame frame,
const std::string &  category 
)

Store the given frame with the given category. Store all available collections from the Frame.

NOTE: The contents of the first Frame that is written in this way determines the contents that will be written for all subsequent Frames.

Definition at line 17 of file ROOTFrameWriter.cc.

17 {
18 writeFrame(frame, category, frame.getAvailableCollections());
19}
std::vector< std::string > getAvailableCollections() const
Definition: Frame.h:252
void writeFrame(const podio::Frame &frame, const std::string &category)

Referenced by writeFrame().

◆ writeFrame() [2/2]

void podio::ROOTFrameWriter::writeFrame ( const podio::Frame frame,
const std::string &  category,
const std::vector< std::string > &  collsToWrite 
)

Store the given Frame with the given category. Store only the collections that are passed.

NOTE: The contents of the first Frame that is written in this way determines the contents that will be written for all subsequent Frames.

Definition at line 21 of file ROOTFrameWriter.cc.

22 {
23 auto& catInfo = getCategoryInfo(category);
24 // Use the TTree as proxy here to decide whether this category has already
25 // been initialized
26 if (catInfo.tree == nullptr) {
27 catInfo.idTable = frame.getCollectionIDTableForWrite();
28 catInfo.collsToWrite = collsToWrite;
29 catInfo.tree = new TTree(category.c_str(), (category + " data tree").c_str());
30 catInfo.tree->SetDirectory(m_file.get());
31 }
32
33 std::vector<StoreCollection> collections;
34 collections.reserve(catInfo.collsToWrite.size());
35 for (const auto& name : catInfo.collsToWrite) {
36 auto* coll = frame.getCollectionForWrite(name);
37 collections.emplace_back(name, const_cast<podio::CollectionBase*>(coll));
38
39 m_datamodelCollector.registerDatamodelDefinition(coll, name);
40 }
41
42 // We will at least have a parameters branch, even if there are no
43 // collections
44 if (catInfo.branches.empty()) {
45 initBranches(catInfo, collections, const_cast<podio::GenericParameters&>(frame.getParameters()));
46
47 } else {
48 resetBranches(catInfo.branches, collections, &const_cast<podio::GenericParameters&>(frame.getParameters()));
49 }
50
51 catInfo.tree->Fill();
52}
void registerDatamodelDefinition(const podio::CollectionBase *coll, const std::string &name)
podio::CollectionIDTable getCollectionIDTableForWrite() const
Definition: Frame.h:278
const podio::GenericParameters & getParameters() const
Definition: Frame.h:238
const podio::CollectionBase * getCollectionForWrite(const std::string &name) const
Definition: Frame.h:269

The documentation for this class was generated from the following files: