PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
ROOTWriter.h
Go to the documentation of this file.
1#ifndef PODIO_ROOTWRITER_H
2#define PODIO_ROOTWRITER_H
3
6#include "podio/EventStore.h"
8
9#include "TBranch.h"
10
11#include <iostream>
12#include <string>
13#include <string_view>
14#include <utility>
15#include <vector>
16
17// forward declarations
18class TFile;
19class TTree;
20
21namespace podio {
23
24public:
25 ROOTWriter(const std::string& filename, EventStore* store);
27
28 // non-copyable
29 ROOTWriter(const ROOTWriter&) = delete;
30 ROOTWriter& operator=(const ROOTWriter&) = delete;
31
32 bool registerForWrite(const std::string& name);
33 void writeEvent();
34 void finish();
35
36private:
37 using StoreCollection = std::pair<const std::string&, podio::CollectionBase*>;
38 void createBranches(const std::vector<StoreCollection>& collections);
39 void setBranches(const std::vector<StoreCollection>& collections);
40
41 // members
42 std::string m_filename;
43 EventStore* m_store;
44 TFile* m_file;
45 TTree* m_datatree;
46 TTree* m_metadatatree;
47 TTree* m_runMDtree;
48 TTree* m_evtMDtree;
49 TTree* m_colMDtree;
50 std::vector<std::string> m_collectionsToWrite{};
51 // In order to avoid having to look up the branches from the datatree for
52 // every event, we cache them in this vector, that is populated the first
53 // time we write an event. Since the collections and their order do not
54 // change between events, the assocation between the collections to write
55 // and their branches is simply index based
56 std::vector<root_utils::CollectionBranches> m_collectionBranches{};
57
58 bool m_firstEvent{true};
59};
60
61} // namespace podio
62#endif
#define DEPR_EVTSTORE
Definition: Deprecated.h:4
ROOTWriter & operator=(const ROOTWriter &)=delete
ROOTWriter(const ROOTWriter &)=delete