ATLAS Offline Software
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 
5 #include "GNNTrackReaderTool.h"
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 
19 MsgStream& InDet::GNNTrackReaderTool::dump( MsgStream& out ) const
20 {
21  out<<std::endl;
22  return dumpevent(out);
23 }
24 
25 std::ostream& InDet::GNNTrackReaderTool::dump( std::ostream& out ) const
26 {
27  return out;
28 }
29 
30 MsgStream& 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 
42  std::vector<std::vector<uint32_t> >& trackCandidates) const
43 {
44  std::string fileName = m_inputTracksDir + "/" + m_csvPrefix + "_" \
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
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(cls);
129  seeds.push_back(sps);
130  }
131  }
132  csvFile.close();
133 
134  ATH_MSG_DEBUG("Length of track list " << trackCandidates.size());
135 }
checkFileSG.line
line
Definition: checkFileSG.py:75
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
InDet::GNNTrackReaderTool::m_csvPrefix
StringProperty m_csvPrefix
Definition: GNNTrackReaderTool.h:67
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
InDet::GNNTrackReaderTool::m_inputTracksDir
StringProperty m_inputTracksDir
Definition: GNNTrackReaderTool.h:66
python.AthDsoLogger.delimiter
delimiter
Definition: AthDsoLogger.py:71
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
GNNTrackReaderTool.h
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
PathResolver.h
python.selection.number
number
Definition: selection.py:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
InDet::GNNTrackReaderTool::GNNTrackReaderTool
GNNTrackReaderTool()=delete
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
InDet::GNNTrackReaderTool::dump
virtual MsgStream & dump(MsgStream &out) const override
Definition: GNNTrackReaderTool.cxx:19
InDet::GNNTrackReaderTool::getTracks
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.
Definition: GNNTrackReaderTool.cxx:41
InDet::GNNTrackReaderTool::dumpevent
MsgStream & dumpevent(MsgStream &out) const
Definition: GNNTrackReaderTool.cxx:30