ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimInputHeaderTool Class Reference

#include <FPGATrackSimInputHeaderTool.h>

Inheritance diagram for FPGATrackSimInputHeaderTool:
Collaboration diagram for FPGATrackSimInputHeaderTool:

Public Member Functions

 FPGATrackSimInputHeaderTool (const std::string &, const std::string &, const IInterface *)
virtual ~FPGATrackSimInputHeaderTool ()=default
virtual StatusCode initialize () override
virtual StatusCode finalize () override
virtual StatusCode readData (FPGATrackSimEventInputHeader *header, bool &last) override
virtual StatusCode writeData (FPGATrackSimEventInputHeader *header) override

Private Member Functions

StatusCode openFile (std::string const &path)

Private Attributes

StringArrayProperty m_inpath {this, "InFileName", {"."}, "input file paths"}
StringProperty m_rwoption {this, "RWstatus", std::string("READ"), "define read or write file option: READ, RECREATE, HEADER"}
std::atomic< unsigned > m_event = 0
std::atomic< unsigned > m_totevent = 0
std::atomic< unsigned > m_file = 0
std::string m_branchName

Detailed Description

Definition at line 22 of file FPGATrackSimInputHeaderTool.h.

Constructor & Destructor Documentation

◆ FPGATrackSimInputHeaderTool()

FPGATrackSimInputHeaderTool::FPGATrackSimInputHeaderTool ( const std::string & algname,
const std::string & name,
const IInterface * ifc )

Definition at line 9 of file FPGATrackSimInputHeaderTool.cxx.

9 :
10 base_class(algname,name,ifc)
11{}

◆ ~FPGATrackSimInputHeaderTool()

virtual FPGATrackSimInputHeaderTool::~FPGATrackSimInputHeaderTool ( )
virtualdefault

Member Function Documentation

◆ finalize()

StatusCode FPGATrackSimInputHeaderTool::finalize ( )
overridevirtual

Definition at line 92 of file FPGATrackSimInputHeaderTool.cxx.

92 {
93 ATH_MSG_INFO ( "finalize: closing files");
94 if (m_rwoption.value()==std::string("RECREATE")){
95 m_EventTree->Print();
96 // close the output files, but check that it exists (for athenaMP)
97 m_infile ->Write();
98 }
99 if (m_rwoption.value()!=std::string("HEADER"))
100 m_infile ->Close();
101
102 delete m_eventHeader;
103 return StatusCode::SUCCESS;
104}
#define ATH_MSG_INFO(x)

◆ initialize()

StatusCode FPGATrackSimInputHeaderTool::initialize ( )
overridevirtual

Definition at line 56 of file FPGATrackSimInputHeaderTool.cxx.

56 {
57
58 m_eventHeader = new FPGATrackSimEventInputHeader();
59 // set default name
60 m_branchName="FPGATrackSimEventInputHeader";
61
62 // open input file
63 if( m_rwoption.value()!=std::string("HEADER"))
64 {
65 if (m_inpath.value().empty())
66 {
67 ATH_MSG_ERROR("Empty input file list");
68 return StatusCode::FAILURE;
69 }
70 ATH_CHECK(openFile(m_inpath.value().front()));
71 }
72 if (m_rwoption.value()==std::string("READ") ) {
73 ATH_MSG_DEBUG ("Initialized in READ MODE");
74 }
75 else if (m_rwoption.value()==std::string("RECREATE") || m_rwoption.value()==std::string("HEADER")) {
76 ATH_MSG_INFO ("Creating empty brnaches in output file");
77 m_EventTree = new TTree("FPGATrackSimEventTree","data");
78 m_EventTree->Branch(m_branchName.c_str(),
79 m_branchName.c_str(),// class name
80 &m_eventHeader);
81 }
82 else {
83 ATH_MSG_ERROR("RWstatus =" <<m_rwoption.value()<<" not allowed!");
84 return StatusCode::FAILURE;
85 }
86 m_event=0; // in file
87 m_totevent=0; // total counter
88 return StatusCode::SUCCESS;
89}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
StatusCode openFile(std::string const &path)

◆ openFile()

StatusCode FPGATrackSimInputHeaderTool::openFile ( std::string const & path)
private

Definition at line 13 of file FPGATrackSimInputHeaderTool.cxx.

14{
15 // close old file
16 if (m_infile && m_infile->IsOpen())
17 {
18 m_infile->Close();
19 // I don't think we delete the pointer cause root handles that?
20 }
21
22 // open new file
23 ATH_MSG_DEBUG ( "Opening file " << path << " in " << m_rwoption.value() <<" mode" );
24 m_infile = TFile::Open(path.c_str(), m_rwoption.value().c_str());
25
26 if (m_infile == nullptr)
27 {
28 ATH_MSG_FATAL("Could not open input file: " << path);
29 return StatusCode::FAILURE;
30 }
31 if (m_rwoption.value()==std::string("READ") )
32 {
33 //get the tree, try the old name and also the new name for backwards compatability
34 m_EventTree = (TTree*) m_infile->Get("FPGATrackSimEventTree");
35
36 if (m_EventTree == nullptr || m_EventTree->GetEntries() == -1 ){
37 ATH_MSG_FATAL ("Input file: " << path << " has no entries");
38 return StatusCode::FAILURE;
39 }
40 ATH_MSG_INFO ( "Input file: " << path << " has "<< m_EventTree->GetEntries() <<" event entries" );
41
42 if(!m_EventTree->GetListOfBranches()->FindObject(m_branchName.c_str())){
43 ATH_MSG_FATAL ("Branch: " << m_branchName << " not found!");
44 return StatusCode::FAILURE;
45 }
46 ATH_MSG_INFO ( "Getting branch and set EventHeader" );
47 TBranch *branch = m_EventTree->GetBranch(m_branchName.c_str());
48 branch->SetAddress(&m_eventHeader);
49 }
50 m_event=0;
51 return StatusCode::SUCCESS;
52}
#define ATH_MSG_FATAL(x)
path
python interpreter configuration --------------------------------------—
Definition athena.py:128

◆ readData()

StatusCode FPGATrackSimInputHeaderTool::readData ( FPGATrackSimEventInputHeader * header,
bool & last )
overridevirtual

Definition at line 126 of file FPGATrackSimInputHeaderTool.cxx.

127{
128 if (m_rwoption.value()!=std::string("READ") ){
129 ATH_MSG_WARNING ("Asked to read file that is not in READ mode");
130 return StatusCode::SUCCESS;
131 }
132
133 last=false;
134
135 ATH_MSG_DEBUG ("Asked Event "<<m_event <<" in this file; current total is "<<m_totevent);
136 if (m_event >= m_EventTree->GetEntries())
137 {
138 if (++m_file < m_inpath.value().size())
139 ATH_CHECK(openFile(m_inpath.value().at(m_file)));
140 else {
141 last=true;
142 return StatusCode::SUCCESS;
143 }
144 }
145
146
147 // increase counters
148 m_EventTree->GetEntry(m_event++);
149 ATH_MSG_DEBUG("Reading event "<<m_eventHeader->event() );
150 *header= *m_eventHeader; //copy object to the external pointer
151
152 m_totevent++;
153
154 return StatusCode::SUCCESS;
155
156}
#define ATH_MSG_WARNING(x)

◆ writeData()

StatusCode FPGATrackSimInputHeaderTool::writeData ( FPGATrackSimEventInputHeader * header)
overridevirtual

Definition at line 107 of file FPGATrackSimInputHeaderTool.cxx.

107 {
108 if (m_rwoption.value()==std::string("READ") ){
109 ATH_MSG_WARNING ("Asked to write file in READ mode");
110 return StatusCode::SUCCESS;
111 }
112
113 if (header != nullptr){
114 *m_eventHeader= *header;//copy object
115 m_EventTree->Fill();
116 ATH_MSG_DEBUG ("Wrote Event "<<m_event <<" in header event "<<m_eventHeader->event() );
117 m_event++;
118 }
119
120 // Do we need this? TODO
121 //m_eventHeader->Clear(); //clean the pointer
122
123 return StatusCode::SUCCESS;
124}

Member Data Documentation

◆ m_branchName

std::string FPGATrackSimInputHeaderTool::m_branchName
private

Definition at line 43 of file FPGATrackSimInputHeaderTool.h.

◆ m_event

std::atomic<unsigned> FPGATrackSimInputHeaderTool::m_event = 0
private

Definition at line 39 of file FPGATrackSimInputHeaderTool.h.

◆ m_file

std::atomic<unsigned> FPGATrackSimInputHeaderTool::m_file = 0
private

Definition at line 41 of file FPGATrackSimInputHeaderTool.h.

◆ m_inpath

StringArrayProperty FPGATrackSimInputHeaderTool::m_inpath {this, "InFileName", {"."}, "input file paths"}
private

Definition at line 34 of file FPGATrackSimInputHeaderTool.h.

34{this, "InFileName", {"."}, "input file paths"};

◆ m_rwoption

StringProperty FPGATrackSimInputHeaderTool::m_rwoption {this, "RWstatus", std::string("READ"), "define read or write file option: READ, RECREATE, HEADER"}
private

Definition at line 35 of file FPGATrackSimInputHeaderTool.h.

35{this, "RWstatus", std::string("READ"), "define read or write file option: READ, RECREATE, HEADER"};

◆ m_totevent

std::atomic<unsigned> FPGATrackSimInputHeaderTool::m_totevent = 0
private

Definition at line 40 of file FPGATrackSimInputHeaderTool.h.


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