ATLAS Offline Software
RegionDataFromFile.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 #include "GaudiKernel/MsgStream.h"
9 #include <iostream>
10 
11 #define MAX_VALUE 100000
12 
13 namespace MuonCalib {
14 
16  if (regionId >= 0 && regionId < (int)m_identifiersPerRegions.size()) {
17  return m_identifiersPerRegions[regionId];
18  } else {
19  MsgStream log(Athena::getMessageSvc(), "RegionDataFromFile");
20  log << MSG::WARNING << "getIdentifiers() <index out of range> " << regionId << " size " << m_identifiersPerRegions.size()
21  << endmsg;
22  return id_vec();
23  }
24  }
25 
26  bool RegionDataFromFile::addRegion(int regionId, const id_vec& ids) {
27  if (regionId >= 0 && regionId < (int)m_identifiersPerRegions.size()) {
28  m_identifiersPerRegions[regionId] = ids;
29  return true;
30  } else {
31  MsgStream log(Athena::getMessageSvc(), "RegionDataFromFile");
32  log << MSG::WARNING << "addRegion() <index out of range> " << regionId << " size " << m_identifiersPerRegions.size() << endmsg;
33  return false;
34  }
35  }
36 
38  m_nregions = 0;
40  }
41 
42  std::istream& RegionDataFromFile::read(std::istream& is) {
43  // clear vector before starting to read
45 
46  std::string dummy;
47 
48  // read header containing the total number of regions
49  is >> dummy >> m_nregions;
51  // loop over all regions in file
52  int regionId, nelements;
53  for (int i = 0; i < static_cast<int>(m_nregions); ++i) {
54  // read region header containing the region id and the number of identifiers
55  is >> dummy >> regionId >> nelements;
56  nelements = (nelements > MAX_VALUE) ? MAX_VALUE : nelements;
57  if (regionId != i) {
58  MsgStream log(Athena::getMessageSvc(), "RegionDataFromFile");
59  log << MSG::WARNING << "read() <read wrong regionId> " << regionId << " current " << i << ". Aborting reading" << endmsg;
60  clear();
61  return is;
62  }
63 
64  id_vec ids;
65  ids.reserve(nelements);
66 
67  // loop over identifiers in file
68  int s, e, p, m;
69  for (int j = 0; j < nelements; ++j) {
70  // read stName,eta,phi,ml
71  is >> s >> e >> p >> m;
72  ids.push_back(MultilayerId(s, e, p, m));
73  }
74 
75  m_identifiersPerRegions.push_back(std::move(ids));
76  }
77 
78  return is;
79  }
80 
81  std::ostream& RegionDataFromFile::write(std::ostream& os) const {
82  // write header
83  os << "Regions " << m_identifiersPerRegions.size() << std::endl;
84 
85  // write regions
86  for (unsigned int i = 0; i < m_identifiersPerRegions.size(); ++i) {
87  unsigned int ids = m_identifiersPerRegions[i].size();
88  os << "RegionId " << i << " " << ids << std::endl;
89 
90  // write ids
91  for (unsigned int j = 0; j < ids; ++j) {
93  os << " " << id.stName << " " << id.eta << " " << id.phi << " " << id.ml << std::endl;
94  }
95  }
96  return os;
97  }
98 
99 } // namespace MuonCalib
100 
101 std::istream& operator>>(std::istream& is, MuonCalib::RegionDataFromFile& data) { return data.read(is); }
102 
103 std::ostream& operator<<(std::ostream& os, const MuonCalib::RegionDataFromFile& data) { return data.write(os); }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
MuonCalib::RegionDataFromFile::id_vec
std::vector< id_type > id_vec
Definition: RegionDataFromFile.h:31
MuonCalib::RegionDataFromFile::m_identifiersPerRegions
id_vec_vec m_identifiersPerRegions
Definition: RegionDataFromFile.h:61
MuonCalib::RegionDataFromFile::getIdentifiers
id_vec getIdentifiers(int regionId) const
returns a vector containing all identifiers for the given regionId, returns an empty vector if the re...
Definition: RegionDataFromFile.cxx:15
MuonCalib::RegionDataFromFile::m_nregions
unsigned int m_nregions
map containing all identifiers for a given region id
Definition: RegionDataFromFile.h:60
MuonCalib::RegionDataFromFile::write
std::ostream & write(std::ostream &os) const
Definition: RegionDataFromFile.cxx:81
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
MuonCalib::RegionDataFromFile::clear
void clear()
clear entries
Definition: RegionDataFromFile.cxx:37
MuonCalib::MultilayerId
Holds the station, eta, phi and multilayer Ids for a given multilayer.
Definition: RegionDataFromFile.h:16
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
operator>>
std::istream & operator>>(std::istream &is, MuonCalib::RegionDataFromFile &data)
Definition: RegionDataFromFile.cxx:101
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
CalibDbCompareRT.dummy
dummy
Definition: CalibDbCompareRT.py:59
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
MuonCalib::RegionDataFromFile::addRegion
bool addRegion(int regionIndex, const id_vec &ids)
returns false if the region was already present, nothing is added in that case
Definition: RegionDataFromFile.cxx:26
RegionDataFromFile.h
operator<<
std::ostream & operator<<(std::ostream &os, const MuonCalib::RegionDataFromFile &data)
Definition: RegionDataFromFile.cxx:103
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuonCalib::RegionDataFromFile::read
std::istream & read(std::istream &is)
Definition: RegionDataFromFile.cxx:42
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
MAX_VALUE
#define MAX_VALUE
Definition: RegionDataFromFile.cxx:11
MuonCalib::RegionDataFromFile
Manages the I/O of the list of multilayers belonging to a calibration region.
Definition: RegionDataFromFile.h:28
python.SystemOfUnits.m
float m
Definition: SystemOfUnits.py:106