ATLAS Offline Software
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 
7 
8 
9 FPGATrackSimInputHeaderTool::FPGATrackSimInputHeaderTool(const std::string& algname, const std::string &name, const IInterface *ifc) :
10  base_class(algname,name,ifc)
11 {}
12 
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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 
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 
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  m_eventHeader->Clear(); //clean the pointer
120 
121  return StatusCode::SUCCESS;
122 }
123 
125 {
126  if (m_rwoption.value()!=std::string("READ") ){
127  ATH_MSG_WARNING ("Asked to read file that is not in READ mode");
128  return StatusCode::SUCCESS;
129  }
130 
131  last=false;
132 
133  ATH_MSG_DEBUG ("Asked Event "<<m_event <<" in this file; current total is "<<m_totevent);
134  if (m_event >= m_EventTree->GetEntries())
135  {
136  if (++m_file < m_inpath.value().size())
137  ATH_CHECK(openFile(m_inpath.value().at(m_file)));
138  else {
139  last=true;
140  return StatusCode::SUCCESS;
141  }
142  }
143 
144 
145  // increase counters
146  m_EventTree->GetEntry(m_event++);
147  ATH_MSG_DEBUG("Reading event "<<m_eventHeader->event() );
148  *header= *m_eventHeader; //copy object to the external pointer
149 
150  m_totevent++;
151 
152  return StatusCode::SUCCESS;
153 
154 }
getMenu.algname
algname
Definition: getMenu.py:53
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
header
Definition: hcg.cxx:526
FPGATrackSimInputHeaderTool::readData
virtual StatusCode readData(FPGATrackSimEventInputHeader *header, bool &last) override
Definition: FPGATrackSimInputHeaderTool.cxx:124
FPGATrackSimInputHeaderTool::m_rwoption
StringProperty m_rwoption
Definition: FPGATrackSimInputHeaderTool.h:35
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:126
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FPGATrackSimInputHeaderTool::m_file
std::atomic< unsigned > m_file
Definition: FPGATrackSimInputHeaderTool.h:41
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
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
FPGATrackSimInputHeaderTool::m_event
std::atomic< unsigned > m_event
Definition: FPGATrackSimInputHeaderTool.h:39
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
FPGATrackSimEventInputHeader
Definition: FPGATrackSimEventInputHeader.h:22
FPGATrackSimInputHeaderTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimInputHeaderTool.cxx:56
FPGATrackSimInputHeaderTool::writeData
virtual StatusCode writeData(FPGATrackSimEventInputHeader *header) override
Definition: FPGATrackSimInputHeaderTool.cxx:107
FPGATrackSimEventInputHeader.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
FPGATrackSimInputHeaderTool::m_totevent
std::atomic< unsigned > m_totevent
Definition: FPGATrackSimInputHeaderTool.h:40
FPGATrackSimInputHeaderTool::openFile
StatusCode openFile(std::string const &path)
Definition: FPGATrackSimInputHeaderTool.cxx:13
RTTAlgmain.branch
branch
Definition: RTTAlgmain.py:61
FPGATrackSimInputHeaderTool::m_inpath
StringArrayProperty m_inpath
Definition: FPGATrackSimInputHeaderTool.h:34
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
FPGATrackSimInputHeaderTool::m_branchName
std::string m_branchName
Definition: FPGATrackSimInputHeaderTool.h:43
FPGATrackSimInputHeaderTool.h
makeTOC.header
header
Definition: makeTOC.py:28