17#include "Acts/Utilities/Helpers.hpp"
25 template <
class ReadOutEleStoreType,
26 class ReadoutEleReturnType>
27 void insert(
const ElementStorage_t<ReadOutEleStoreType>& eleStore,
28 std::vector<ReadoutEleReturnType>& returnVec) {
29 returnVec.reserve(returnVec.capacity() + eleStore.size());
30 for (
const auto& ele : eleStore) {
31 if (ele) returnVec.push_back(ele.get());
34 template <
class ReadOutEleType,
35 class ReadOutEleReturnType>
36 void insert(std::vector<ReadOutEleType*>&& eleStore,
37 std::vector<ReadOutEleReturnType*>& returnVec) {
38 returnVec.insert(returnVec.end(),
39 std::make_move_iterator(eleStore.begin()),
40 std::make_move_iterator(eleStore.end()));
43 inline unsigned msSectorIdHash(
const ChIndex chIndex,
const int sector,
const int side) {
45 constexpr unsigned chIdxMax = Acts::toUnderlying(StIndex::StIndexMax);
48 (Acts::copySign(1,side) == 1) *
chIdxMax * secMax;
53#define WRITE_SETTER(ELE_TYPE, SETTER, STORAGE_VEC) \
54 StatusCode MuonDetectorManager::SETTER(ElementPtr_t<ELE_TYPE> element) { \
56 ATH_MSG_FATAL(__func__ << " -- nullptr is given."); \
57 return StatusCode::FAILURE; \
59 ATH_CHECK(element->initElement()); \
60 element->releaseUnAlignedTrfs(); \
61 size_t idx = static_cast<size_t>(element->identHash()); \
62 if (idx >= STORAGE_VEC.size()) { \
63 STORAGE_VEC.resize(idx + 1); \
65 std::unique_ptr<ELE_TYPE>& new_element = STORAGE_VEC[idx]; \
67 ATH_MSG_FATAL("The detector element " \
68 << m_idHelperSvc->toStringDetEl(element->identify()) \
69 << " has already been added before " \
70 <<m_idHelperSvc->toStringDetEl(new_element->identify())); \
71 return StatusCode::FAILURE; \
73 linkElements(STORAGE_VEC, element.get()); \
74 new_element = std::move(element); \
75 return StatusCode::SUCCESS; \
77#define ADD_DETECTOR(ELE_TYPE, STORAGE_VEC) \
78 WRITE_SETTER(ELE_TYPE, add##ELE_TYPE, STORAGE_VEC) \
80 std::vector<const ELE_TYPE*> MuonDetectorManager::getAll##ELE_TYPE##s() const { \
81 std::vector<const ELE_TYPE*> allElements{}; \
82 insert(STORAGE_VEC, allElements); \
86 std::vector<ELE_TYPE*> MuonDetectorManager::getAll##ELE_TYPE##s() { \
87 std::vector<ELE_TYPE*> allElements{}; \
88 insert(STORAGE_VEC, allElements); \
91#define WRITE_ALLGETTER(CONSTNESS) \
92 std::vector<CONSTNESS MuonReadoutElement*> \
93 MuonDetectorManager::getAllReadoutElements(const ActsTrk::DetectorType type) CONSTNESS { \
94 std::vector<CONSTNESS MuonReadoutElement*> allEles{}; \
95 using enum ActsTrk::DetectorType; \
96 if (type == UnDefined || type == Mdt) { \
97 insert(getAllMdtReadoutElements(), allEles); \
99 if (type == UnDefined || type == Rpc) { \
100 insert(getAllRpcReadoutElements(), allEles); \
102 if (type == UnDefined || type == Tgc) { \
103 insert(getAllTgcReadoutElements(), allEles); \
105 if (type == UnDefined || type == Mm) { \
106 insert(getAllMmReadoutElements(), allEles); \
108 if (type == UnDefined || type == sTgc) { \
109 insert(getAllsTgcReadoutElements(), allEles); \
114 CONSTNESS MuonReadoutElement* \
115 MuonDetectorManager::getReadoutElement(const Identifier& id) CONSTNESS { \
116 switch(m_idHelperSvc->technologyIndex(id)) { \
117 using enum Muon::MuonStationIndex::TechnologyIndex; \
119 return getMdtReadoutElement(id); \
121 return getRpcReadoutElement(id); \
123 return getTgcReadoutElement(id); \
125 return getsTgcReadoutElement(id); \
127 return getMmReadoutElement(id); \
129 ATH_MSG_WARNING(__FILE__<<":"<<__LINE__<<" Not a muon detector element " \
130 <<m_idHelperSvc->toString(id)); \
138#ifndef SIMULATIONBASE
150#ifndef SIMULATIONBASE
157 THROW_EXCEPTION(__func__<<
"() -- Failed to retrieve the Identifier service");
186 std::vector<ActsTrk::DetectorType>
types{};
195#ifndef SIMULATIONBASE
197 const unsigned hash = msSectorIdHash(chSector->chamberIndex(), chSector->sector(), chSector->side());
198 ATH_MSG_DEBUG(
"Add new sector "<<(*chSector)<<
", hash: "<<hash);
199 const auto [element, isNew] =
m_envelopesById.insert(std::make_pair(hash, chSector.get()));
201 THROW_EXCEPTION(
"Conflicting hash: "<<hash<<
", inserted: \n"<<(*element->second)
202 <<
",\n tried to insert:\n "<<(*chSector));
207 const unsigned sector,
208 const int side)
const {
209 const unsigned hash = msSectorIdHash(chIdx, sector, side);
215 <<
", sector: "<<sector<<
", side: "<<side);
234 std::ranges::transform(ms->chambers(), std::back_inserter(chambers),
244 MuonDetectorType* reEle) {
252 const unsigned mlHash =
static_cast<unsigned>(
m_idHelperSvc->detElementHash(complMlId));
254 if (mlHash >= detStore.size() || !detStore[mlHash]) {
257 detStore[mlHash]->setComplementaryReadoutEle(refEle);
266#undef WRITE_ALLGETTER
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define WRITE_ALLGETTER(CONSTNESS)
static const std::vector< std::string > types
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
Identifier multilayerID(const Identifier &channeldID) const
static int multilayerMax()
Chamber represent the volume enclosing a muon station.
Readout element to describe the Monitored Drift Tube (Mdt) chambers Mdt chambers usually comrpise out...
void setComplementaryReadoutEle(const MdtReadoutElement *other)
Set the link to the second readout element inside the muon station.
unsigned multilayer() const
Returns the multi layer of the readout element [1;\2].
ElementStorage_t< SpectrometerSector > m_secEnvelopes
ElementStorage_t< TgcReadoutElement > m_tgcEles
const Muon::IMuonIdHelperSvc * idHelperSvc() const
Returns a pointer to the central MuonIdHelperSvc.
std::vector< ActsTrk::DetectorType > getDetectorTypes() const
Returns a list of all detector types.
std::vector< ElementPtr_t< MuonDetectorType > > ElementStorage_t
: Abbrivation of the container holding all readout elements of a technology.
ElementStorage_t< sTgcReadoutElement > m_sTgcEles
ElementStorage_t< MmReadoutElement > m_mmEles
std::vector< PVConstLink > m_treeTopVector
void clearTreeTops()
Clears all tree tops helds by the manager.
EnvelopeMap_t m_envelopesById
void addSpectrometerSector(ElementPtr_t< SpectrometerSector > &&chSector)
Add a spectrometer enevelope object to the manager.
const Chamber * getChamber(const Identifier &channelId) const
Retrieves the chamber enclosing the channel's readout element.
PVConstLink getTreeTop(unsigned int i) const override final
Returns the i-the tree top GeoModel volume.
MuonChamberSet getAllChambers() const
ElementStorage_t< RpcReadoutElement > m_rpcEles
std::vector< const Chamber * > MuonChamberSet
MuonSectorSet getAllSectors() const
: Returns all MuonChambers associated with the readout geometry
std::unique_ptr< MuonDetectorType > ElementPtr_t
: Abrivation of the smart pointer holding the readout element
const MuonReadoutElement * getReadoutElement(const Identifier &id) const
Returns a generic Muon readout element.
unsigned int getNumTreeTops() const override final
Declaration of the readout element getters & setter function as described above.
const SpectrometerSector * getSectorEnvelope(const Identifier &channelId) const
Retrieves the spectrometer envelope enclosing the channel's readout element.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
std::vector< const SpectrometerSector * > MuonSectorSet
void linkElements(ElementStorage_t< MuonDetectorType > &allStore, MuonDetectorType *readOutEle)
Method that connects the same elements from the station with the parsed readout Element and vice vers...
void addTreeTop(PVConstLink pv)
Adds a new GeoModelVolume with its children as a new top node of the muon system.
ElementStorage_t< MdtReadoutElement > m_mdtEles
const SpectrometerSector * msSector() const
Returns the pointer to the envelope volume enclosing all chambers in the sector.
Identifier identify() const override final
Return the ATLAS identifier.
const Chamber * chamber() const
Returns the pointer to the chamber enclosing this readout element.
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
GeoModel::TransientConstSharedPtr< Chamber > ChamberPtr
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
std::string to_string(const DetectorType &type)
@ Mm
Maybe not needed in the migration.
@ Tgc
Resitive Plate Chambers.
@ Rpc
Monitored Drift Tubes.
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
MuonDetectorManager::MuonSectorSet MuonSectorSet
MuonDetectorManager::MuonChamberSet MuonChamberSet
ADD_DETECTOR(MdtReadoutElement, m_mdtEles)
ChIndex chIndex(const std::string &index)
convert ChIndex name string to enum
StIndex toStationIndex(ChIndex index)
convert ChIndex into StIndex
constexpr unsigned numberOfSectors()
return total number of sectors
const std::string & chName(ChIndex index)
convert ChIndex into a string
ChIndex
enum to classify the different chamber layers in the muon spectrometer
bool operator()(const SpectrometerSector *a, const SpectrometerSector *b) const
#define THROW_EXCEPTION(MESSAGE)