ATLAS Offline Software
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
InDet::GNNTrackReaderTool Class Reference

InDet::GNNTrackReaderTool is a tool that reads track candidates of each event from a CSV file named as "track_runNumber_eventNumber.csv" or with a customized pre-fix. The directory, inputTracksDir, contains CSV files for all events. 1) If the inputTracksDir is not specified, the tool will read the CSV files from the current directory. 2) If the corresponding CSV file does not exist for a given event (runNumber, eventNumber), the tool will print an error message and return an empty list. More...

#include <GNNTrackReaderTool.h>

Inheritance diagram for InDet::GNNTrackReaderTool:
Collaboration diagram for InDet::GNNTrackReaderTool:

Public Member Functions

 GNNTrackReaderTool (const std::string &type, const std::string &name, const IInterface *parent)
 
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. More...
 
virtual void getTracks (uint32_t runNumber, uint32_t eventNumber, std::vector< std::vector< uint32_t >> &tracks, std::vector< std::vector< uint32_t >> &seeds) const override final
 
virtual MsgStream & dump (MsgStream &out) const override
 
virtual std::ostream & dump (std::ostream &out) const override
 

Protected Member Functions

 GNNTrackReaderTool ()=delete
 
 GNNTrackReaderTool (const GNNTrackReaderTool &)=delete
 
GNNTrackReaderTooloperator= (const GNNTrackReaderTool &)=delete
 
MsgStream & dumpevent (MsgStream &out) const
 

Protected Attributes

StringProperty m_inputTracksDir {this, "inputTracksDir", "."}
 
StringProperty m_csvPrefix {this, "csvPrefix", "track"}
 

Detailed Description

InDet::GNNTrackReaderTool is a tool that reads track candidates of each event from a CSV file named as "track_runNumber_eventNumber.csv" or with a customized pre-fix. The directory, inputTracksDir, contains CSV files for all events. 1) If the inputTracksDir is not specified, the tool will read the CSV files from the current directory. 2) If the corresponding CSV file does not exist for a given event (runNumber, eventNumber), the tool will print an error message and return an empty list.

Author
xiang.nosp@m.yang.nosp@m..ju@c.nosp@m.ern..nosp@m.ch

Definition at line 32 of file GNNTrackReaderTool.h.

Constructor & Destructor Documentation

◆ GNNTrackReaderTool() [1/3]

InDet::GNNTrackReaderTool::GNNTrackReaderTool ( const std::string &  type,
const std::string &  name,
const IInterface *  parent 
)

Definition at line 12 of file GNNTrackReaderTool.cxx.

13  :
14  base_class(type, name, parent)
15 {
16  declareInterface<IGNNTrackReaderTool>(this);
17 }

◆ GNNTrackReaderTool() [2/3]

InDet::GNNTrackReaderTool::GNNTrackReaderTool ( )
protecteddelete

◆ GNNTrackReaderTool() [3/3]

InDet::GNNTrackReaderTool::GNNTrackReaderTool ( const GNNTrackReaderTool )
protecteddelete

Member Function Documentation

◆ dump() [1/2]

MsgStream & InDet::GNNTrackReaderTool::dump ( MsgStream &  out) const
overridevirtual

Definition at line 19 of file GNNTrackReaderTool.cxx.

20 {
21  out<<std::endl;
22  return dumpevent(out);
23 }

◆ dump() [2/2]

std::ostream & InDet::GNNTrackReaderTool::dump ( std::ostream &  out) const
overridevirtual

Definition at line 25 of file GNNTrackReaderTool.cxx.

26 {
27  return out;
28 }

◆ dumpevent()

MsgStream & InDet::GNNTrackReaderTool::dumpevent ( MsgStream &  out) const
protected

Definition at line 30 of file GNNTrackReaderTool.cxx.

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 }

◆ getTracks() [1/2]

void InDet::GNNTrackReaderTool::getTracks ( uint32_t  runNumber,
uint32_t  eventNumber,
std::vector< std::vector< uint32_t > > &  tracks 
) const
finaloverridevirtual

Get track candidates from a CSV file named by runNumber and eventNumber.

Parameters
runNumberrun number of the event.
eventNumberevent number of the event.
tracksa list of track candidates in terms of spacepoint indices as read from the CSV file.

Definition at line 41 of file GNNTrackReaderTool.cxx.

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 }

◆ getTracks() [2/2]

void InDet::GNNTrackReaderTool::getTracks ( uint32_t  runNumber,
uint32_t  eventNumber,
std::vector< std::vector< uint32_t >> &  tracks,
std::vector< std::vector< uint32_t >> &  seeds 
) const
finaloverridevirtual

Definition at line 87 of file GNNTrackReaderTool.cxx.

90  {
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 }

◆ operator=()

GNNTrackReaderTool& InDet::GNNTrackReaderTool::operator= ( const GNNTrackReaderTool )
protecteddelete

Member Data Documentation

◆ m_csvPrefix

StringProperty InDet::GNNTrackReaderTool::m_csvPrefix {this, "csvPrefix", "track"}
protected

Definition at line 67 of file GNNTrackReaderTool.h.

◆ m_inputTracksDir

StringProperty InDet::GNNTrackReaderTool::m_inputTracksDir {this, "inputTracksDir", "."}
protected

Definition at line 66 of file GNNTrackReaderTool.h.


The documentation for this class was generated from the following files:
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
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
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
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
InDet::GNNTrackReaderTool::dumpevent
MsgStream & dumpevent(MsgStream &out) const
Definition: GNNTrackReaderTool.cxx:30