ATLAS Offline Software
Loading...
Searching...
No Matches
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
14
16
17#include "GaudiKernel/ITHistSvc.h"
18
19#include "TFile.h"
20#include "TTree.h"
21
22#include <numeric>
23#include <atomic>
24#include <mutex>
25
28
30{
31
32public:
33
34 FPGATrackSimOutputHeaderTool(const std::string&, const std::string&, const IInterface*);
35 virtual ~FPGATrackSimOutputHeaderTool() = default;
36 virtual StatusCode initialize() override;
37 virtual StatusCode finalize() override;
38
39 // Helpers to add branches for reading or writing.. Make this completely generic.
40 FPGATrackSimLogicalEventInputHeader* addInputBranch(const std::string& branchName, bool write = true);
41 FPGATrackSimLogicalEventOutputHeader* addOutputBranch(const std::string& branchName, bool write = true);
42
43 // Helper function; part of initialize that actually sets up the branches for reading.
44 StatusCode configureReadBranches() const;
45
46 // Actually read or write the corresponding objects.
47 StatusCode readData(bool &last) const;
48 StatusCode writeData() const;
49
50 // Not sure I understand why this is done like this.
51 std::string fileName() { return std::accumulate(m_inpath.value().begin(), m_inpath.value().end(), std::string{}); }
52
53 // Not sure this is needed, but it was in the interface.
54 TTree* getEventTree() { return m_EventTree; }
55
56 void activateEventOutput() const {m_activated=true;}
57
58private:
59 // JO configuration (Converted to Gaudi::Property).
60
61 // This is a vector because it allows us to read multiple files.
62 // Only relevant for reading, writing multiple files isn't supported.
63 Gaudi::Property<std::vector<std::string>> m_inpath {this, "InFileName", {"."}, "input file paths"};
64
65 // RECREATE and HEADER are both "write" options. RECREATE (re)creates the output ROOT file.
66 // HEADER does not, it assumes some other tool or service has opened the file.
67 Gaudi::Property<std::string> m_rwoption {this, "RWstatus", std::string("READ"), "define read or write file option: READ, RECREATE, HEADER"};
68
69 // Name of the output tree to create, can be overridden.
70 Gaudi::Property<std::string> m_treeName {this, "OutputTreeName", "FPGATrackSimLogicalEventTree", "Name of the output TTree to create."};
71
72 // Service handle for the histogram service.
73 ServiceHandle<ITHistSvc> m_tHistSvc {this, "THistSvc", "THistSvc"};
74
75 // Max output events
76 Gaudi::Property<int> m_eventLimit {this, "EventLimit", 10000 , "Maximum Number of Events to Output"};
77
78 // For event level output control
79 Gaudi::Property<bool> m_requireActivation {this, "RequireActivation", false , "Only output if activated on event, good for doing a single region in a large file"};
80
81 // internal counters
82 mutable std::atomic<unsigned> m_event = 0;
83 mutable std::atomic<unsigned> m_totevent = 0;
84 mutable std::atomic<unsigned> m_file = 0;
85 mutable std::atomic<bool> m_activated{false}; // static so if any instance is active they all are
86 mutable std::mutex m_writeMutex; // Protect all ROOT I/O operations in const methods
87
88 // ROOT I/O containers modified in const methods. Protected by m_writeMutex.
89 mutable std::vector<FPGATrackSimLogicalEventInputHeader*> m_eventInputHeaders ATLAS_THREAD_SAFE;
90 mutable std::vector<FPGATrackSimLogicalEventOutputHeader*> m_eventOutputHeaders ATLAS_THREAD_SAFE;
91
92 std::vector<std::string> m_branchNameIns;
93 std::vector<std::string> m_branchNameOuts;
94
95 // ROOT file/tree pointers modified in const methods. Protected by m_writeMutex.
96 mutable TFile *m_infile ATLAS_THREAD_SAFE = nullptr;
97 mutable TTree *m_EventTree ATLAS_THREAD_SAFE = nullptr;
98
99 StatusCode openFile(std::string const & path) const;
100
101};
102
103#endif // FPGATrackSim_READOUTPUTHEADERTOOL_H
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
std::vector< FPGATrackSimLogicalEventInputHeader * > m_eventInputHeaders ATLAS_THREAD_SAFE
StatusCode openFile(std::string const &path) const
virtual ~FPGATrackSimOutputHeaderTool()=default
FPGATrackSimLogicalEventOutputHeader * addOutputBranch(const std::string &branchName, bool write=true)
std::vector< std::string > m_branchNameIns
Gaudi::Property< std::string > m_treeName
Gaudi::Property< std::string > m_rwoption
std::vector< std::string > m_branchNameOuts
virtual StatusCode initialize() override
FPGATrackSimOutputHeaderTool(const std::string &, const std::string &, const IInterface *)
Gaudi::Property< std::vector< std::string > > m_inpath
FPGATrackSimLogicalEventInputHeader * addInputBranch(const std::string &branchName, bool write=true)