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 
56 
57 private:
58  // JO configuration (Converted to Gaudi::Property).
59 
60  // This is a vector because it allows us to read multiple files.
61  // Only relevant for reading, writing multiple files isn't supported.
62  Gaudi::Property<std::vector<std::string>> m_inpath {this, "InFileName", {"."}, "input file paths"};
63 
64  // RECREATE and HEADER are both "write" options. RECREATE (re)creates the output ROOT file.
65  // HEADER does not, it assumes some other tool or service has opened the file.
66  Gaudi::Property<std::string> m_rwoption {this, "RWstatus", std::string("READ"), "define read or write file option: READ, RECREATE, HEADER"};
67 
68  // Name of the output tree to create, can be overridden.
69  Gaudi::Property<std::string> m_treeName {this, "OutputTreeName", "FPGATrackSimLogicalEventTree", "Name of the output TTree to create."};
70 
71  // Service handle for the histogram service.
72  ServiceHandle<ITHistSvc> m_tHistSvc {this, "THistSvc", "THistSvc"};
73 
74  // Max output events
75  Gaudi::Property<int> m_eventLimit {this, "EventLimit", 10000 , "Maximum Number of Events to Output"};
76 
77  // For event level output control
78  Gaudi::Property<bool> m_requireActivation {this, "RequireActivation", false , "Only output if activated on event, good for doing a single region in a large file"};
79 
80  // internal counters
81  std::atomic<unsigned> m_event = 0;
82  std::atomic<unsigned> m_totevent = 0;
83  std::atomic<unsigned> m_file = 0;
84  bool m_activated{false}; // static so if any instance is active they all are
85 
86  // These were protected in the interface but I don't think they have to be.
87  std::vector<FPGATrackSimLogicalEventInputHeader*> m_eventInputHeaders;
88  std::vector<FPGATrackSimLogicalEventOutputHeader*> m_eventOutputHeaders;
89 
90  std::vector<std::string> m_branchNameIns;
91  std::vector<std::string> m_branchNameOuts;
92 
93  TFile *m_infile = nullptr;
94  TTree *m_EventTree = nullptr;
95 
96  StatusCode openFile(std::string const & path);
97 
98 };
99 
100 #endif // FPGATrackSim_READOUTPUTHEADERTOOL_H
FPGATrackSimOutputHeaderTool::m_tHistSvc
ServiceHandle< ITHistSvc > m_tHistSvc
Definition: FPGATrackSimOutputHeaderTool.h:72
FPGATrackSimOutputHeaderTool::readData
StatusCode readData(bool &last)
Definition: FPGATrackSimOutputHeaderTool.cxx:229
FPGATrackSimOutputHeaderTool::m_branchNameOuts
std::vector< std::string > m_branchNameOuts
Definition: FPGATrackSimOutputHeaderTool.h:91
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
ByteStreamConfig.write
def write
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:249
runITkAlign.accumulate
accumulate
Update flags based on parser line args.
Definition: runITkAlign.py:62
FPGATrackSimOutputHeaderTool
Definition: FPGATrackSimOutputHeaderTool.h:29
FPGATrackSimOutputHeaderTool::m_eventLimit
Gaudi::Property< int > m_eventLimit
Definition: FPGATrackSimOutputHeaderTool.h:75
FPGATrackSimOutputHeaderTool::finalize
virtual StatusCode finalize() override
Definition: FPGATrackSimOutputHeaderTool.cxx:155
FPGATrackSimOutputHeaderTool::m_branchNameIns
std::vector< std::string > m_branchNameIns
Definition: FPGATrackSimOutputHeaderTool.h:90
FPGATrackSimOutputHeaderTool::m_file
std::atomic< unsigned > m_file
Definition: FPGATrackSimOutputHeaderTool.h:83
FPGATrackSimOutputHeaderTool::configureReadBranches
StatusCode configureReadBranches()
Definition: FPGATrackSimOutputHeaderTool.cxx:51
FPGATrackSimOutputHeaderTool::activateEventOutput
void activateEventOutput()
Definition: FPGATrackSimOutputHeaderTool.h:55
FPGATrackSimOutputHeaderTool::m_rwoption
Gaudi::Property< std::string > m_rwoption
Definition: FPGATrackSimOutputHeaderTool.h:66
FPGATrackSimOutputHeaderTool::addInputBranch
FPGATrackSimLogicalEventInputHeader * addInputBranch(const std::string &branchName, bool write=true)
Definition: FPGATrackSimOutputHeaderTool.cxx:134
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:144
FPGATrackSimOutputHeaderTool::m_infile
TFile * m_infile
Definition: FPGATrackSimOutputHeaderTool.h:93
FPGATrackSimOutputHeaderTool::m_EventTree
TTree * m_EventTree
Definition: FPGATrackSimOutputHeaderTool.h:94
FPGATrackSimOutputHeaderTool::m_treeName
Gaudi::Property< std::string > m_treeName
Definition: FPGATrackSimOutputHeaderTool.h:69
AthAlgTool.h
FPGATrackSimOutputHeaderTool::m_eventInputHeaders
std::vector< FPGATrackSimLogicalEventInputHeader * > m_eventInputHeaders
Definition: FPGATrackSimOutputHeaderTool.h:87
FPGATrackSimOutputHeaderTool::m_inpath
Gaudi::Property< std::vector< std::string > > m_inpath
Definition: FPGATrackSimOutputHeaderTool.h:62
FPGATrackSimOutputHeaderTool::m_activated
bool m_activated
Definition: FPGATrackSimOutputHeaderTool.h:84
FPGATrackSimOutputHeaderTool::m_event
std::atomic< unsigned > m_event
Definition: FPGATrackSimOutputHeaderTool.h:81
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:82
FPGATrackSimOutputHeaderTool::m_requireActivation
Gaudi::Property< bool > m_requireActivation
Definition: FPGATrackSimOutputHeaderTool.h:78
FPGATrackSimOutputHeaderTool::writeData
StatusCode writeData()
Definition: FPGATrackSimOutputHeaderTool.cxx:179
FPGATrackSimLogicalEventOutputHeader
Definition: FPGATrackSimLogicalEventOutputHeader.h:12
FPGATrackSimOutputHeaderTool::m_eventOutputHeaders
std::vector< FPGATrackSimLogicalEventOutputHeader * > m_eventOutputHeaders
Definition: FPGATrackSimOutputHeaderTool.h:88
AthAlgTool
Definition: AthAlgTool.h:26
FPGATrackSimOutputHeaderTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimOutputHeaderTool.cxx:88
FPGATrackSimOutputHeaderTool::~FPGATrackSimOutputHeaderTool
virtual ~FPGATrackSimOutputHeaderTool()=default
ServiceHandle< ITHistSvc >