ATLAS Offline Software
FPGATrackSimMappingSvc.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
6 
7 FPGATrackSimMappingSvc::FPGATrackSimMappingSvc(const std::string& name, ISvcLocator*svc) :
8  base_class(name, svc),
9  m_EvtSel("FPGATrackSimEventSelectionSvc", name)
10 {
11 }
12 
13 
15 {
16  if (m_pmap_path.value().empty())
17  ATH_MSG_FATAL("Main plane map definition missing");
18  else if (m_rmap_path.value().empty())
19  ATH_MSG_FATAL("Missing region map path");
20  else if (m_modulelut_path.value().empty())
21  ATH_MSG_FATAL("Module LUT file is missing");
22  else
23  return StatusCode::SUCCESS;
24 
25  return StatusCode::FAILURE;
26 }
27 
28 
30 {
31  if (m_pmap_vector_1st.empty())
32  {
33  ATH_MSG_FATAL("Error using 1st stage plane map no elements of vector made: " << m_pmap_vector_1st);
34  return StatusCode::FAILURE;
35  }
36  if (!m_numberOfPmaps){
37  ATH_MSG_FATAL("Error with declared number of plane maps: " << m_pmap_path);
38  return StatusCode::FAILURE;
39  }
40  if (m_numberOfPmaps != (m_pmap_vector_1st.size())){
41  ATH_MSG_FATAL("Error using number of declared plane maps does not equal number of loaded plane maps: " << m_pmap_path<<"=/="<<m_pmap_vector_1st.size());
42  return StatusCode::FAILURE;
43  }
44  for (size_t a = 0 ; a < m_pmap_vector_1st.size() ;a++)
45  {
46  if(!m_pmap_vector_1st.at(a)){
47  ATH_MSG_FATAL("Error using 1st stage plane map for slice: " << a <<" of "<< m_pmap_vector_1st.size());
48  return StatusCode::FAILURE;
49  }
50  }
51  if (m_pmap_vector_2nd.empty())
52  {
53  ATH_MSG_FATAL("Error using 2nd stage plane map no elements of vector made: " << m_pmap_vector_2nd);
54  return StatusCode::FAILURE;
55  }
56  if (!m_numberOfPmaps){
57  ATH_MSG_FATAL("Error with declared number of plane maps: " << m_pmap_path);
58  return StatusCode::FAILURE;
59  }
60  if (m_numberOfPmaps != (m_pmap_vector_2nd.size())){
61  ATH_MSG_FATAL("Error using number of declared plane maps does not equal number of loaded plane maps: " << m_pmap_path<<"=/="<<m_pmap_vector_2nd.size());
62  return StatusCode::FAILURE;
63  }
64  for (size_t a = 0 ; a < m_pmap_vector_2nd.size() ;a++)
65  {
66  if(!m_pmap_vector_2nd.at(a)){
67  ATH_MSG_FATAL("Error using 1st stage plane map for slice: " << a <<" of "<< m_pmap_vector_2nd.size());
68  return StatusCode::FAILURE;
69  }
70  }
71  if (!m_rmap_1st){
72  ATH_MSG_FATAL("Error creating region map for 1st stage from: " << m_rmap_path);
73  return StatusCode::FAILURE;
74  }
75  if (!m_rmap_2nd){
76  ATH_MSG_FATAL("Error creating region map for 2nd stage from: " << m_rmap_path);
77  return StatusCode::FAILURE;
78  }
79  if (!m_subrmap){
80  ATH_MSG_FATAL("Error creating sub-region map from: " << m_subrmap_path);
81  return StatusCode::FAILURE;
82  }
83  if (!m_subrmap_2nd){
84  ATH_MSG_FATAL("Error creating second stage sub-region map from: " << m_subrmap_path);
85  return StatusCode::FAILURE;
86  }
87  return StatusCode::SUCCESS;
88 }
89 
90 
92  if (m_NNmap_fake != nullptr) {
93  return m_NNmap_fake->getNNMap();
94  }
95  else{
96  return ""; // Handle null case appropriately
97  }
98 }
99 
101  if (m_NNmap_param != nullptr) {
102  return m_NNmap_param->getNNMap();
103  }
104  else{
105  return ""; // Handle null case appropriately
106  }
107 }
108 
109 
110 int FPGATrackSimMappingSvc::countPmapSize(std::ifstream& fileIn)
111 {
112  std::string line;
113 
114  getline(fileIn, line);
115  std::istringstream sline(line);
116  std::string geoKeyCheck;
117  sline >> geoKeyCheck;
118  m_numberOfPmaps = 1;
119  while (getline(fileIn,line)){
120  std::istringstream sline(line);
121  std::string geoKeyCandidate;
122  sline >> geoKeyCandidate;
123  if(geoKeyCheck.compare(geoKeyCandidate)==0){
124  m_numberOfPmaps++;
125  }
126  }
127  return m_numberOfPmaps;
128 }
130 {
131  ATH_CHECK(m_EvtSel.retrieve());
133 
134  if (m_mappingType.value() == "FILE")
135  {
136  const std::string & filepath = PathResolverFindCalibFile(m_pmap_path.value());
137  std::ifstream fin(filepath);
138  if (!fin.is_open())
139  {
140  ATH_MSG_DEBUG("Couldn't open " << filepath);
141  throw ("FPGATrackSimPlaneMap Couldn't open " + filepath);
142  }
143 
145  fin.close();
146  fin.open(filepath);
147  ATH_MSG_DEBUG("Creating the 1st stage plane map");
148  for (size_t i = 0; i<m_numberOfPmaps; i++)
149  {
150  m_pmap_vector_1st.emplace_back(std::make_unique<FPGATrackSimPlaneMap>(fin, m_EvtSel->getRegionID(), 1, m_layerOverrides));
151  }
152 
153  fin.close();
154  fin.open(filepath);
155  ATH_MSG_DEBUG("Creating the 2nd stage plane map");
156  for (size_t i = 0; i<m_numberOfPmaps; i++)
157  {
158  m_pmap_vector_2nd.emplace_back(std::make_unique<FPGATrackSimPlaneMap>(fin, m_EvtSel->getRegionID(), 2, m_layerOverrides));
159  }
160  fin.close();
161 
162  ATH_MSG_DEBUG("Creating the 1st stage region map");
163  m_rmap_1st = std::unique_ptr<FPGATrackSimRegionMap>(new FPGATrackSimRegionMap(m_pmap_vector_1st, PathResolverFindCalibFile(m_rmap_path.value())));
164 
165  ATH_MSG_DEBUG("Creating the 2nd stage region map");
166  m_rmap_2nd = std::unique_ptr<FPGATrackSimRegionMap>(new FPGATrackSimRegionMap(m_pmap_vector_2nd, PathResolverFindCalibFile(m_rmap_path.value())));
167 
168  ATH_MSG_DEBUG("Creating the sub-region map");
169  m_subrmap = std::unique_ptr<FPGATrackSimRegionMap>(new FPGATrackSimRegionMap(m_pmap_vector_1st, PathResolverFindCalibFile(m_subrmap_path.value())));
170 
171  ATH_MSG_DEBUG("Creating the 2nd stage sub-region map");
172  m_subrmap_2nd = std::make_unique<FPGATrackSimRegionMap>(m_pmap_vector_2nd, PathResolverFindCalibFile(m_subrmap_path.value()));
173 
174  ATH_MSG_DEBUG("Setting the Modules LUT for Region Maps");
175  m_rmap_1st->loadModuleIDLUT(PathResolverFindCalibFile(m_modulelut_path.value()));
176  m_rmap_2nd->loadModuleIDLUT(PathResolverFindCalibFile(m_modulelut_path.value()));
177 
178  // We probably need two versions of this path for the second stage.
179  ATH_MSG_DEBUG("Setting the average radius per logical layer for Region and Subregion Maps");
180  m_rmap_1st->loadRadiiFile(PathResolverFindCalibFile(m_radii_path.value()));
181  m_subrmap->loadRadiiFile(PathResolverFindCalibFile(m_radii_path.value()));
182 
183  ATH_MSG_DEBUG("Creating NN weighting map");
184  ATH_MSG_INFO("MappingSVc using " << m_NNmap_path_fake.value() << " and " << m_NNmap_path_param.value());
185  if ( ! m_NNmap_path_fake.empty() ) {
186  m_NNmap_fake = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(m_NNmap_path_fake.value()));
187  } else {
188  m_NNmap_fake = nullptr;
189  }
190 
191  if ( ! m_NNmap_path_param.empty() ) {
192  m_NNmap_param = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(m_NNmap_path_param.value()));
193  } else {
194  m_NNmap_param = nullptr;
195  }
196  }
198  return StatusCode::SUCCESS;
199 }
200 
201 
FPGATrackSimMappingSvc::m_NNmap_path_fake
Gaudi::Property< std::string > m_NNmap_path_fake
Definition: FPGATrackSimMappingSvc.h:50
FPGATrackSimMappingSvc::m_rmap_2nd
std::unique_ptr< FPGATrackSimRegionMap > m_rmap_2nd
Definition: FPGATrackSimMappingSvc.h:62
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
checkFileSG.line
line
Definition: checkFileSG.py:75
FPGATrackSimMappingSvc::FPGATrackSimMappingSvc
FPGATrackSimMappingSvc(const std::string &name, ISvcLocator *svc)
Definition: FPGATrackSimMappingSvc.cxx:7
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FPGATrackSimMappingSvc::m_NNmap_fake
std::unique_ptr< FPGATrackSimNNMap > m_NNmap_fake
Definition: FPGATrackSimMappingSvc.h:65
FPGATrackSimMappingSvc::m_numberOfPmaps
size_t m_numberOfPmaps
Definition: FPGATrackSimMappingSvc.h:68
FPGATrackSimMappingSvc::m_radii_path
Gaudi::Property< std::string > m_radii_path
Definition: FPGATrackSimMappingSvc.h:52
FPGATrackSimMappingSvc::checkAllocs
StatusCode checkAllocs()
Definition: FPGATrackSimMappingSvc.cxx:29
FPGATrackSimMappingSvc::m_rmap_1st
std::unique_ptr< FPGATrackSimRegionMap > m_rmap_1st
Definition: FPGATrackSimMappingSvc.h:61
FPGATrackSimMappingSvc::getParamNNMapString
virtual std::string getParamNNMapString() const override
Definition: FPGATrackSimMappingSvc.cxx:100
FPGATrackSimMappingSvc::m_layerOverrides
Gaudi::Property< std::vector< int > > m_layerOverrides
Definition: FPGATrackSimMappingSvc.h:53
FPGATrackSimMappingSvc::m_subrmap_2nd
std::unique_ptr< FPGATrackSimRegionMap > m_subrmap_2nd
Definition: FPGATrackSimMappingSvc.h:64
FPGATrackSimMappingSvc::getFakeNNMapString
virtual std::string getFakeNNMapString() const override
Definition: FPGATrackSimMappingSvc.cxx:91
lumiFormat.i
int i
Definition: lumiFormat.py:85
FPGATrackSimMappingSvc::m_pmap_path
Gaudi::Property< std::string > m_pmap_path
Definition: FPGATrackSimMappingSvc.h:48
FPGATrackSimMappingSvc::m_EvtSel
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_EvtSel
Definition: FPGATrackSimMappingSvc.h:41
FPGATrackSimMappingSvc::m_modulelut_path
Gaudi::Property< std::string > m_modulelut_path
Definition: FPGATrackSimMappingSvc.h:49
FPGATrackSimMappingSvc::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimMappingSvc.cxx:129
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
FPGATrackSimMappingSvc::m_NNmap_path_param
Gaudi::Property< std::string > m_NNmap_path_param
Definition: FPGATrackSimMappingSvc.h:51
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
FPGATrackSimMappingSvc::m_pmap_vector_1st
std::vector< std::unique_ptr< FPGATrackSimPlaneMap > > m_pmap_vector_1st
Definition: FPGATrackSimMappingSvc.h:57
PathResolver.h
FPGATrackSimMappingSvc::m_rmap_path
Gaudi::Property< std::string > m_rmap_path
Definition: FPGATrackSimMappingSvc.h:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
FPGATrackSimMappingSvc::m_pmap_vector_2nd
std::vector< std::unique_ptr< FPGATrackSimPlaneMap > > m_pmap_vector_2nd
Definition: FPGATrackSimMappingSvc.h:58
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
FPGATrackSimMappingSvc::m_mappingType
Gaudi::Property< std::string > m_mappingType
Definition: FPGATrackSimMappingSvc.h:45
FPGATrackSimMappingSvc::m_subrmap_path
Gaudi::Property< std::string > m_subrmap_path
Definition: FPGATrackSimMappingSvc.h:47
a
TList * a
Definition: liststreamerinfos.cxx:10
IFPGATrackSimEventSelectionSvc.h
FPGATrackSimMappingSvc::m_subrmap
std::unique_ptr< FPGATrackSimRegionMap > m_subrmap
Definition: FPGATrackSimMappingSvc.h:63
FPGATrackSimMappingSvc::checkInputs
StatusCode checkInputs()
Definition: FPGATrackSimMappingSvc.cxx:14
compute_lumi.fin
fin
Definition: compute_lumi.py:19
FPGATrackSimRegionMap
Definition: FPGATrackSimRegionMap.h:62
FPGATrackSimMappingSvc.h
FPGATrackSimMappingSvc::m_NNmap_param
std::unique_ptr< FPGATrackSimNNMap > m_NNmap_param
Definition: FPGATrackSimMappingSvc.h:66
FPGATrackSimMappingSvc::countPmapSize
int countPmapSize(std::ifstream &fileIn)
Definition: FPGATrackSimMappingSvc.cxx:110