ATLAS Offline Software
Loading...
Searching...
No Matches
GNNTrackReaderTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// Framework include(s).
9#include <cmath>
10#include <fstream>
11
13 const std::string& type, const std::string& name, const IInterface* parent):
14 base_class(type, name, parent)
15{
16 declareInterface<IGNNTrackReaderTool>(this);
17}
18
19MsgStream& InDet::GNNTrackReaderTool::dump( MsgStream& out ) const
20{
21 out<<std::endl;
22 return dumpevent(out);
23}
24
25std::ostream& InDet::GNNTrackReaderTool::dump( std::ostream& out ) const
26{
27 return out;
28}
29
30MsgStream& InDet::GNNTrackReaderTool::dumpevent( MsgStream& out ) const
31{
32 out<<"|---------------------------------------------------------------------|"
33 <<std::endl;
34 out<<"| Number output tracks | "<<std::setw(12)
35 <<" |"<<std::endl;
36 out<<"|---------------------------------------------------------------------|"
37 <<std::endl;
38 return out;
39}
40
41void InDet::GNNTrackReaderTool::getTracks(uint32_t runNumber, uint32_t eventNumber,
42 std::vector<std::vector<uint32_t> >& trackCandidates) const
43{
44 std::string fileName = m_inputTracksDir + "/" + m_csvPrefix + "_" \
45 + std::to_string(runNumber) + "_" + std::to_string(eventNumber) + ".csv";
46
47 trackCandidates.clear();
48 std::ifstream csvFile(fileName);
49
50 if (!csvFile.is_open()) {
51 ATH_MSG_ERROR("Cannot open file " << fileName);
52 return;
53 } else {
54 ATH_MSG_INFO("File " << fileName << " is opened.");
55 }
56
57 std::string line;
58 while(std::getline(csvFile, line)){
59 std::stringstream lineStream(line);
60 std::string cell;
61 std::vector<uint32_t> trackCandidate;
62 // allow both "," and " " as delimiter
63 char delimiter = ',';
64 if (line.find(delimiter) == std::string::npos) {
65 delimiter = ' ';
66 }
67 while (std::getline(lineStream, cell, delimiter)) {
68 uint32_t cellId = 0;
69 try {
70 cellId = std::stoi(cell);
71 } catch (const std::invalid_argument& ia) {
72 std::cout << "Invalid argument: " << ia.what() << " for cell " << cell << std::endl;
73 continue;
74 }
75
76 if (std::find(trackCandidate.begin(), trackCandidate.end(), cellId) == trackCandidate.end()) {
77 trackCandidate.push_back(cellId);
78 }
79 }
80 trackCandidates.push_back(std::move(trackCandidate));
81 }
82}
83
84// this function reads each track candidate as 2 lists, a list of sp and
85// a list of clusters, the trackCandidates vector will be the clusters,
86// the seeds vector will be the SPs
88 uint32_t runNumber, uint32_t eventNumber,
89 std::vector<std::vector<uint32_t>>& trackCandidates,
90 std::vector<std::vector<uint32_t>>& seeds) const {
91 std::string fileName = m_inputTracksDir + "/" + m_csvPrefix + "_" +
92 std::to_string(runNumber) + "_" +
93 std::to_string(eventNumber) + ".csv";
94
95 trackCandidates.clear();
96 std::ifstream csvFile(fileName);
97
98 if (!csvFile.is_open()) {
99 ATH_MSG_ERROR("Cannot open file " << fileName);
100 return;
101 } else {
102 ATH_MSG_INFO("File " << fileName << " is opened.");
103 }
104
105 std::string line;
106 while (std::getline(csvFile, line)) {
107 std::istringstream lineStream(line);
108 std::string CLString, SPString;
109 char delimiter = ',';
110 if (line.find(delimiter) == std::string::npos) {
111 delimiter = ' ';
112 }
113
114 if (std::getline(lineStream, CLString, '|') &&
115 std::getline(lineStream, SPString)) {
116 std::istringstream CLStream(CLString), SPStream(SPString);
117 std::vector<uint32_t> cls, sps;
118 std::string number;
119
120 while (std::getline(CLStream, number, delimiter)) {
121 cls.push_back(std::stoi(number));
122 }
123
124 while (std::getline(SPStream, number, delimiter)) {
125 sps.push_back(std::stoi(number));
126 }
127
128 trackCandidates.push_back(std::move(cls));
129 seeds.push_back(std::move(sps));
130 }
131 }
132 csvFile.close();
133
134 ATH_MSG_DEBUG("Length of track list " << trackCandidates.size());
135}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
virtual void getTracks(uint32_t runNumber, uint32_t eventNumber, std::vector< std::vector< uint32_t > > &tracks) const override final
Get track candidates from a CSV file named by runNumber and eventNumber.
virtual MsgStream & dump(MsgStream &out) const override
MsgStream & dumpevent(MsgStream &out) const
std::string number(const double &d, const std::string &s)
Definition utils.cxx:186