ATLAS Offline Software
Loading...
Searching...
No Matches
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
13namespace 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
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
101std::istream& operator>>(std::istream& is, MuonCalib::RegionDataFromFile& data) { return data.read(is); }
102
103std::ostream& operator<<(std::ostream& os, const MuonCalib::RegionDataFromFile& data) { return data.write(os); }
#define endmsg
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::istream & operator>>(std::istream &is, MuonCalib::RegionDataFromFile &data)
#define MAX_VALUE
std::ostream & operator<<(std::ostream &os, const MuonCalib::RegionDataFromFile &data)
Manages the I/O of the list of multilayers belonging to a calibration region.
std::ostream & write(std::ostream &os) const
std::istream & read(std::istream &is)
unsigned int m_nregions
map containing all identifiers for a given region id
id_vec getIdentifiers(int regionId) const
returns a vector containing all identifiers for the given regionId, returns an empty vector if the re...
bool addRegion(int regionIndex, const id_vec &ids)
returns false if the region was already present, nothing is added in that case
std::vector< id_type > id_vec
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Holds the station, eta, phi and multilayer Ids for a given multilayer.