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

#include <ROOTWriter.h>

Public Member Functions

 ROOTWriter (const std::string &filename, EventStore *store)
 
 ~ROOTWriter ()
 
 ROOTWriter (const ROOTWriter &)=delete
 
ROOTWriteroperator= (const ROOTWriter &)=delete
 
bool registerForWrite (const std::string &name)
 
void writeEvent ()
 
void finish ()
 

Detailed Description

Definition at line 22 of file ROOTWriter.h.

Constructor & Destructor Documentation

◆ ROOTWriter() [1/2]

podio::ROOTWriter::ROOTWriter ( const std::string &  filename,
EventStore store 
)

Definition at line 14 of file ROOTWriter.cc.

14 :
15 m_filename(filename),
16 m_store(store),
17 m_file(new TFile(filename.c_str(), "RECREATE", "data file")),
18 m_datatree(new TTree("events", "Events tree")),
19 m_metadatatree(new TTree("metadata", "Metadata tree")),
20 m_runMDtree(new TTree("run_metadata", "Run metadata tree")),
21 m_evtMDtree(new TTree("evt_metadata", "Event metadata tree")),
22 m_colMDtree(new TTree("col_metadata", "Collection metadata tree")) {
23
24 m_evtMDtree->Branch("evtMD", "GenericParameters", m_store->eventMetaDataPtr());
25}
GenericParameters * eventMetaDataPtr()
Definition: EventStore.h:107

◆ ~ROOTWriter()

podio::ROOTWriter::~ROOTWriter ( )

Definition at line 27 of file ROOTWriter.cc.

27 {
28 delete m_file;
29}

◆ ROOTWriter() [2/2]

podio::ROOTWriter::ROOTWriter ( const ROOTWriter )
delete

Member Function Documentation

◆ finish()

void podio::ROOTWriter::finish ( )

Definition at line 99 of file ROOTWriter.cc.

99 {
100 // now we want to safe the metadata. This includes info about the
101 // collections
102 const auto collIDTable = m_store->getCollectionIDTable();
103 m_metadatatree->Branch("CollectionIDs", collIDTable);
104
105 // collectionID, collection type, subset collection
106 std::vector<root_utils::CollectionInfoT> collectionInfo;
107 collectionInfo.reserve(m_collectionsToWrite.size());
108 for (const auto& name : m_collectionsToWrite) {
109 const auto collID = collIDTable->collectionID(name);
110 const podio::CollectionBase* coll{nullptr};
111 // No check necessary, only registered collections possible
112 m_store->get(name, coll);
113 const auto collType = coll->getTypeName();
114 // const auto collType = "std::vector<" + coll->getDataTypeName() + ">";
115 collectionInfo.emplace_back(collID, std::move(collType), coll->isSubsetCollection());
116 }
117
118 m_metadatatree->Branch("CollectionTypeInfo", &collectionInfo);
119
120 podio::version::Version podioVersion = podio::version::build_version;
121 m_metadatatree->Branch("PodioVersion", &podioVersion);
122
123 m_metadatatree->Fill();
124
125 m_colMDtree->Branch("colMD", "std::map<int,podio::GenericParameters>", m_store->getColMetaDataMap());
126 m_colMDtree->Fill();
127 m_runMDtree->Branch("runMD", "std::map<int,podio::GenericParameters>", m_store->getRunMetaDataMap());
128 m_runMDtree->Fill();
129
130 m_file->Write();
131 m_file->Close();
132}
bool get(const std::string &name, const T *&collection)
access a collection by name. returns true if successful
Definition: EventStore.h:143
ColMDMap * getColMetaDataMap()
Definition: EventStore.h:104
CollectionIDTable * getCollectionIDTable() const
Definition: EventStore.h:86
RunMDMap * getRunMetaDataMap()
Definition: EventStore.h:101

Referenced by testWithIO(), and writeCollection().

◆ operator=()

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

◆ registerForWrite()

bool podio::ROOTWriter::registerForWrite ( const std::string &  name)

Definition at line 134 of file ROOTWriter.cc.

134 {
135 const podio::CollectionBase* tmp_coll(nullptr);
136 if (!m_store->get(name, tmp_coll)) {
137 std::cerr << "no such collection to write, throw exception." << std::endl;
138 return false;
139 }
140
141 m_collectionsToWrite.push_back(name);
142 return true;
143}

Referenced by testWithIO(), and writeCollection().

◆ writeEvent()

void podio::ROOTWriter::writeEvent ( )

Definition at line 31 of file ROOTWriter.cc.

31 {
32 std::vector<StoreCollection> collections;
33 collections.reserve(m_collectionsToWrite.size());
34 for (const auto& name : m_collectionsToWrite) {
35 const podio::CollectionBase* coll;
36 m_store->get(name, coll);
37 collections.emplace_back(name, const_cast<podio::CollectionBase*>(coll));
38 collections.back().second->prepareForWrite();
39 }
40
41 if (m_firstEvent) {
42 createBranches(collections);
43 m_firstEvent = false;
44 } else {
45 setBranches(collections);
46 }
47
48 m_datatree->Fill();
49 m_evtMDtree->Fill();
50}

Referenced by testWithIO(), and writeCollection().


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