ATLAS Offline Software
FPGATrackSimOutputHeaderTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef FPGATrackSim_READOUTPUTHEADERTOOL_H
6 #define FPGATrackSim_READOUTPUTHEADERTOOL_H
7 
16 
17 #include "GaudiKernel/ITHistSvc.h"
18 
19 #include "TFile.h"
20 #include "TTree.h"
21 
22 #include <numeric>
23 #include <atomic>
24 
27 
29 {
30 
31 public:
32 
33  FPGATrackSimOutputHeaderTool(const std::string&, const std::string&, const IInterface*);
34  virtual ~FPGATrackSimOutputHeaderTool() = default;
35  virtual StatusCode initialize() override;
36  virtual StatusCode finalize() override;
37 
38  // Helpers to add branches for reading or writing.. Make this completely generic.
39  FPGATrackSimLogicalEventInputHeader* addInputBranch(const std::string& branchName, bool write = true);
40  FPGATrackSimLogicalEventOutputHeader* addOutputBranch(const std::string& branchName, bool write = true);
41 
42  // Helper function; part of initialize that actually sets up the branches for reading.
44 
45  // Actually read or write the corresponding objects.
46  StatusCode readData(bool &last);
48 
49  // Not sure I understand why this is done like this.
50  std::string fileName() { return std::accumulate(m_inpath.value().begin(), m_inpath.value().end(), std::string{}); }
51 
52  // Not sure this is needed, but it was in the interface.
53  TTree* getEventTree() { return m_EventTree; };
54 
55 private:
56  // JO configuration (Converted to Gaudi::Property).
57 
58  // This is a vector because it allows us to read multiple files.
59  // Only relevant for reading, writing multiple files isn't supported.
60  Gaudi::Property<std::vector<std::string>> m_inpath {this, "InFileName", {"."}, "input file paths"};
61 
62  // RECREATE and HEADER are both "write" options. RECREATE (re)creates the output ROOT file.
63  // HEADER does not, it assumes some other tool or service has opened the file.
64  Gaudi::Property<std::string> m_rwoption {this, "RWstatus", std::string("READ"), "define read or write file option: READ, RECREATE, HEADER"};
65 
66  // Name of the output tree to create, can be overridden.
67  Gaudi::Property<std::string> m_treeName {this, "OutputTreeName", "FPGATrackSimLogicalEventTree", "Name of the output TTree to create."};
68 
69  // Service handle for the histogram service.
70  ServiceHandle<ITHistSvc> m_tHistSvc {this, "THistSvc", "THistSvc"};
71 
72  // internal counters
73  std::atomic<unsigned> m_event = 0;
74  std::atomic<unsigned> m_totevent = 0;
75  std::atomic<unsigned> m_file = 0;
76 
77  // These were protected in the interface but I don't think they have to be.
78  std::vector<FPGATrackSimLogicalEventInputHeader*> m_eventInputHeaders;
79  std::vector<FPGATrackSimLogicalEventOutputHeader*> m_eventOutputHeaders;
80 
81  std::vector<std::string> m_branchNameIns;
82  std::vector<std::string> m_branchNameOuts;
83 
84  TFile *m_infile = nullptr;
85  TTree *m_EventTree = nullptr;
86 
87  StatusCode openFile(std::string const & path);
88 
89 };
90 
91 #endif // FPGATrackSim_READOUTPUTHEADERTOOL_H
FPGATrackSimOutputHeaderTool::m_tHistSvc
ServiceHandle< ITHistSvc > m_tHistSvc
Definition: FPGATrackSimOutputHeaderTool.h:70
FPGATrackSimOutputHeaderTool::readData
StatusCode readData(bool &last)
Definition: FPGATrackSimOutputHeaderTool.cxx:213
FPGATrackSimOutputHeaderTool::m_branchNameOuts
std::vector< std::string > m_branchNameOuts
Definition: FPGATrackSimOutputHeaderTool.h:82
FPGATrackSimLogicalEventInputHeader
Definition: FPGATrackSimLogicalEventInputHeader.h:21
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
FPGATrackSimOutputHeaderTool::openFile
StatusCode openFile(std::string const &path)
Definition: FPGATrackSimOutputHeaderTool.cxx:14
FPGATrackSimOutputHeaderTool::getEventTree
TTree * getEventTree()
Definition: FPGATrackSimOutputHeaderTool.h:53
FPGATrackSimOutputHeaderTool
Definition: FPGATrackSimOutputHeaderTool.h:29
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
FPGATrackSimOutputHeaderTool::finalize
virtual StatusCode finalize() override
Definition: FPGATrackSimOutputHeaderTool.cxx:148
FPGATrackSimOutputHeaderTool::m_branchNameIns
std::vector< std::string > m_branchNameIns
Definition: FPGATrackSimOutputHeaderTool.h:81
FPGATrackSimOutputHeaderTool::m_file
std::atomic< unsigned > m_file
Definition: FPGATrackSimOutputHeaderTool.h:75
FPGATrackSimOutputHeaderTool::configureReadBranches
StatusCode configureReadBranches()
Definition: FPGATrackSimOutputHeaderTool.cxx:51
FPGATrackSimOutputHeaderTool::m_rwoption
Gaudi::Property< std::string > m_rwoption
Definition: FPGATrackSimOutputHeaderTool.h:64
FPGATrackSimOutputHeaderTool::addInputBranch
FPGATrackSimLogicalEventInputHeader * addInputBranch(const std::string &branchName, bool write=true)
Definition: FPGATrackSimOutputHeaderTool.cxx:127
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
FPGATrackSimOutputHeaderTool::addOutputBranch
FPGATrackSimLogicalEventOutputHeader * addOutputBranch(const std::string &branchName, bool write=true)
Definition: FPGATrackSimOutputHeaderTool.cxx:137
FPGATrackSimOutputHeaderTool::m_infile
TFile * m_infile
Definition: FPGATrackSimOutputHeaderTool.h:84
FPGATrackSimOutputHeaderTool::m_EventTree
TTree * m_EventTree
Definition: FPGATrackSimOutputHeaderTool.h:85
FPGATrackSimOutputHeaderTool::m_treeName
Gaudi::Property< std::string > m_treeName
Definition: FPGATrackSimOutputHeaderTool.h:67
AthAlgTool.h
python.ByteStreamConfig.write
def write
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:247
FPGATrackSimOutputHeaderTool::m_eventInputHeaders
std::vector< FPGATrackSimLogicalEventInputHeader * > m_eventInputHeaders
Definition: FPGATrackSimOutputHeaderTool.h:78
FPGATrackSimOutputHeaderTool::m_inpath
Gaudi::Property< std::vector< std::string > > m_inpath
Definition: FPGATrackSimOutputHeaderTool.h:60
FPGATrackSimOutputHeaderTool::m_event
std::atomic< unsigned > m_event
Definition: FPGATrackSimOutputHeaderTool.h:73
FPGATrackSimOutputHeaderTool::FPGATrackSimOutputHeaderTool
FPGATrackSimOutputHeaderTool(const std::string &, const std::string &, const IInterface *)
Definition: FPGATrackSimOutputHeaderTool.cxx:9
FPGATrackSimOutputHeaderTool::fileName
std::string fileName()
Definition: FPGATrackSimOutputHeaderTool.h:50
FPGATrackSimOutputHeaderTool::m_totevent
std::atomic< unsigned > m_totevent
Definition: FPGATrackSimOutputHeaderTool.h:74
FPGATrackSimOutputHeaderTool::writeData
StatusCode writeData()
Definition: FPGATrackSimOutputHeaderTool.cxx:172
FPGATrackSimLogicalEventOutputHeader
Definition: FPGATrackSimLogicalEventOutputHeader.h:12
FPGATrackSimOutputHeaderTool::m_eventOutputHeaders
std::vector< FPGATrackSimLogicalEventOutputHeader * > m_eventOutputHeaders
Definition: FPGATrackSimOutputHeaderTool.h:79
AthAlgTool
Definition: AthAlgTool.h:26
FPGATrackSimOutputHeaderTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimOutputHeaderTool.cxx:88
FPGATrackSimOutputHeaderTool::~FPGATrackSimOutputHeaderTool
virtual ~FPGATrackSimOutputHeaderTool()=default
ServiceHandle< ITHistSvc >