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