ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
EFTracking
FPGATrackSim
FPGATrackSimInput
src
FPGATrackSimInputHeaderTool.cxx
Go to the documentation of this file.
1
/*
2
0;95;0c Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
FPGATrackSimInputHeaderTool.h
"
6
#include "
FPGATrackSimObjects/FPGATrackSimEventInputHeader.h
"
7
8
9
FPGATrackSimInputHeaderTool::FPGATrackSimInputHeaderTool
(
const
std::string& algname,
const
std::string &name,
const
IInterface *ifc) :
10
base_class(algname,name,ifc)
11
{}
12
13
StatusCode
FPGATrackSimInputHeaderTool::openFile
(std::string
const
& path)
const
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
}
53
54
55
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
56
StatusCode
FPGATrackSimInputHeaderTool::initialize
(){
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
}
90
91
92
StatusCode
FPGATrackSimInputHeaderTool::finalize
(){
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
}
105
106
107
StatusCode
FPGATrackSimInputHeaderTool::writeData
(
FPGATrackSimEventInputHeader
*
header
)
const
{
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
}
125
126
StatusCode
FPGATrackSimInputHeaderTool::readData
(
FPGATrackSimEventInputHeader
*
header
,
bool
&last)
const
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
>=
static_cast<
unsigned
>
(m_EventTree->GetEntries()))
137
{
138
std::lock_guard<std::mutex>
lock
(
m_fileMutex
);
139
if
(
m_event
>=
static_cast<
unsigned
>
(m_EventTree->GetEntries()))
140
{
141
unsigned
current_file =
m_file
++;
142
if
(current_file <
m_inpath
.value().size())
143
ATH_CHECK
(
openFile
(
m_inpath
.value().at(current_file)));
144
else
{
145
last=
true
;
146
return
StatusCode::SUCCESS;
147
}
148
}
149
}
150
151
// Protect ROOT I/O with mutex
152
{
153
std::lock_guard<std::mutex>
lock
(
m_fileMutex
);
154
m_EventTree->GetEntry(
m_event
);
155
}
156
157
// increase counters
158
m_event
++;
159
m_totevent
++;
160
161
ATH_MSG_DEBUG
(
"Reading event "
<<m_eventHeader->event() );
162
*
header
= *m_eventHeader;
//copy object to the external pointer
163
164
return
StatusCode::SUCCESS;
165
166
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
FPGATrackSimEventInputHeader.h
FPGATrackSimInputHeaderTool.h
This class reads FPGATrackSim input data from a ROOT file (wrapper file) Designed to be not thread-sa...
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
FPGATrackSimEventInputHeader
Definition
FPGATrackSimEventInputHeader.h:22
FPGATrackSimInputHeaderTool::finalize
virtual StatusCode finalize() override
Definition
FPGATrackSimInputHeaderTool.cxx:92
FPGATrackSimInputHeaderTool::FPGATrackSimInputHeaderTool
FPGATrackSimInputHeaderTool(const std::string &, const std::string &, const IInterface *)
Definition
FPGATrackSimInputHeaderTool.cxx:9
FPGATrackSimInputHeaderTool::initialize
virtual StatusCode initialize() override
Definition
FPGATrackSimInputHeaderTool.cxx:56
FPGATrackSimInputHeaderTool::readData
virtual StatusCode readData(FPGATrackSimEventInputHeader *header, bool &last) const override
Definition
FPGATrackSimInputHeaderTool.cxx:126
FPGATrackSimInputHeaderTool::m_rwoption
StringProperty m_rwoption
Definition
FPGATrackSimInputHeaderTool.h:35
FPGATrackSimInputHeaderTool::m_file
std::atomic< unsigned > m_file
Definition
FPGATrackSimInputHeaderTool.h:41
FPGATrackSimInputHeaderTool::m_inpath
StringArrayProperty m_inpath
Definition
FPGATrackSimInputHeaderTool.h:34
FPGATrackSimInputHeaderTool::openFile
StatusCode openFile(std::string const &path) const
Definition
FPGATrackSimInputHeaderTool.cxx:13
FPGATrackSimInputHeaderTool::m_fileMutex
std::mutex m_fileMutex
Definition
FPGATrackSimInputHeaderTool.h:42
FPGATrackSimInputHeaderTool::writeData
virtual StatusCode writeData(FPGATrackSimEventInputHeader *header) const override
Definition
FPGATrackSimInputHeaderTool.cxx:107
FPGATrackSimInputHeaderTool::m_totevent
std::atomic< unsigned > m_totevent
Definition
FPGATrackSimInputHeaderTool.h:40
FPGATrackSimInputHeaderTool::m_branchName
std::string m_branchName
Definition
FPGATrackSimInputHeaderTool.h:44
FPGATrackSimInputHeaderTool::m_event
std::atomic< unsigned > m_event
Definition
FPGATrackSimInputHeaderTool.h:39
header
Definition
hcg.cxx:529
Generated on
for ATLAS Offline Software by
1.17.0