diff --git a/DetectorDescription/DetDescrCnvSvc/src/DetDescrCnvSvc.cxx b/DetectorDescription/DetDescrCnvSvc/src/DetDescrCnvSvc.cxx index 3d37d16d2bb460ffc08821d464789a8b98ad7363..d4482743f1ca1811f90c6d25e1ef150a832fabb3 100644 --- a/DetectorDescription/DetDescrCnvSvc/src/DetDescrCnvSvc.cxx +++ b/DetectorDescription/DetDescrCnvSvc/src/DetDescrCnvSvc.cxx @@ -40,7 +40,7 @@ DetDescrCnvSvc::DetDescrCnvSvc(const std::string& name, ISvcLocator* svc) { declareProperty("DetectorManagers", m_detMgrs); declareProperty("DetectorNodes", m_detNodes ); - declareProperty("DecodeIdDict", m_decodeIdDict ); + declareProperty("DecodeIdDict", m_decodeIdDict ); declareProperty("IdDictName", m_idDictName ); declareProperty("IdDictFromRDB", m_idDictFromRDB ); declareProperty("IdDictGlobalTag", m_idDictGlobalTag ); @@ -116,8 +116,8 @@ DetDescrCnvSvc::initialize() { // IdHelpers status = addToDetStore(125694213, "FaserID"); if (status != StatusCode::SUCCESS) return status; - // status = addToDetStore(2516, "ScintID"); - // if (status != StatusCode::SUCCESS) return status; + status = addToDetStore(131395045, "VetoID"); + if (status != StatusCode::SUCCESS) return status; // status = addToDetStore(2517, "SCT_ID"); // if (status != StatusCode::SUCCESS) return status; diff --git a/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetectorID.hOld b/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetectorID.hOld deleted file mode 100644 index 7cfac9bddf1fae6d1396e0283d0018559ab38985..0000000000000000000000000000000000000000 --- a/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetectorID.hOld +++ /dev/null @@ -1,453 +0,0 @@ -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -#ifndef FASERDETDESCR_FASERDETECTORID_H -#define FASERDETDESCR_FASERDETECTORID_H -/** - * @file FaserDetectorID.h - * - * @brief This is an Identifier helper class for the all - * subdetectors. This class is a factory for creating compact - * Identifier objects and IdentifierHash or hash ids. And it also - * allows decoding of these ids. - * - */ - -//<<<<<< INCLUDES >>>>>> - -#include "FaserDetDescr/FaserDetectorIDBase.h" -#include "Identifier/Identifier.h" -#include "Identifier/IdentifierHash.h" -#include "Identifier/Range.h" -#include "Identifier/IdHelper.h" -#include "IdDict/IdDictFieldImplementation.h" -#include "AthenaKernel/CLASS_DEF.h" - -#include <string> -#include <assert.h> -#include <algorithm> - -//<<<<<< PUBLIC DEFINES >>>>>> -//<<<<<< PUBLIC CONSTANTS >>>>>> -//<<<<<< PUBLIC TYPES >>>>>> - -class IdDictDictionary; - -//<<<<<< PUBLIC VARIABLES >>>>>> -//<<<<<< PUBLIC FUNCTIONS >>>>>> -//<<<<<< CLASS DECLARATIONS >>>>>> - -/** - ** @class FaserDetectorID - ** - ** @brief This is an Identifier helper class for the FASER - ** subdetectors. This class is a factory for creating compact - ** Identifier objects and IdentifierHash or hash ids. And it also - ** allows decoding of these ids. - ** - ** Definition and the range of values for the levels of the - ** identifier are: - ** - ** @verbatim - ** element range meaning - ** ------- ----- ------- - ** - ** station - ** veto 0 - 1 front/back - ** trigger 0 single station - ** preshower 0 single station - ** sct 0 - 2 front, middle, back - ** ecal 0 single station - ** plane - ** veto 0 single plane - ** trigger 0 single plane - ** preshower 0 single plane - ** sct 0 - 2 three planes per station - ** ecal 0 single plane - ** module - ** veto 0 single plate - ** trigger 0 - 1 upper/lower plate - ** preshower 0 single plate - ** sct 0 - 7 eight modules per plane - ** ecal 0 - 3 four modules - ** submodule - ** veto 0 no segmentation - ** trigger 0 no segmentation - ** preshower 0 no segmentation - ** sct 0 - 1 two sides per module - ** ecal 0 - 66 scintillator layers - ** sensor - ** veto 0 single pmt - ** trigger 0 - 1 left/right pmt - ** preshower 0 single pmt - ** sct 0 - 767 strips - ** ecal 0 one tower per layer - ** @endverbatim - ** - */ -class FaserDetectorID : public FaserDetectorIDBase -{ -public: - - /// @name public typedefs - //@{ - typedef Identifier::size_type size_type; - typedef std::vector<Identifier>::const_iterator const_id_iterator; - typedef MultiRange::const_identifier_factory const_expanded_id_iterator; - //@} - - /// @name strutors - //@{ - FaserDetectorID(void); - virtual ~FaserDetectorID(void) = default; - //@} - - /// @name Creators for station, ids and pmt ids - //@{ - /// For a single module - virtual Identifier module_id( int station, - int plane, - int module ) const = 0; - - /// For a module from a submodule id - Identifier module_id ( const Identifier& submodule_id ) const; - - /// For a single submodule - virtual Identifier submodule_id ( int station, - int plane, - int module, - int submodule ) const = 0; - - /// For a single submodule from a sensor id - Identifier submodule_id ( const Identifier& sensor_id ) const; - - /// From hash - optimized - Identifier submodule_id( IdentifierHash submodule_hash) const; - - /// For an individual sensor - virtual Identifier sensor_id ( int station, - int plane, - int module, - int submodule, - int sensor ) const = 0; - - - Identifier sensor_id ( const Identifier& submodule_id, - int sensor ) const; - - //@} - - /// @name Hash table maximum sizes - //@{ - size_type submodule_hash_max (void) const; - size_type sensor_hash_max (void) const; - //@} - - /// @name Access to all ids - //@{ - /// Iterators over full set of ids. Submodule iterator is sorted - const_id_iterator submodule_begin (void) const; - const_id_iterator submodule_end (void) const; - /// For sensor ids, only expanded id iterators are available. Use - /// following "sensor_id" method to obtain a compact identifier - const_expanded_id_iterator sensor_begin (void) const; - const_expanded_id_iterator sensor_end (void) const; - //@} - - - /// submodule hash from id - optimized - IdentifierHash submodule_hash (Identifier submodule_id) const; - - - /// Values of different levels (failure returns 0) - int station (const Identifier& id) const; - int plane (const Identifier& id) const; - int module (const Identifier& id) const; - int submodule (const Identifier& id) const; - int sensor (const Identifier& id) const; - - // /// Max values for each field (-999 == failure) - int station_max (const Identifier& id) const; - int plane_max (const Identifier& id) const; - int module_max (const Identifier& id) const; - int submodule_max (const Identifier& id) const; - int sensor_max (const Identifier& id) const; - //@} - - // /// @name module eta/phi navigation - // //@{ - // /// Previous wafer hash in phi (return == 0 for neighbor found) - // int get_prev_in_phi (const IdentifierHash& id, IdentifierHash& prev) const; - // /// Next wafer hash in phi (return == 0 for neighbor found) - // int get_next_in_phi (const IdentifierHash& id, IdentifierHash& next) const; - // /// Previous wafer hash in eta (return == 0 for neighbor found) - // int get_prev_in_eta (const IdentifierHash& id, IdentifierHash& prev) const; - // /// Next wafer hash in eta (return == 0 for neighbor found) - // int get_next_in_eta (const IdentifierHash& id, IdentifierHash& next) const; - // /// Wafer hash on other side - // int get_other_side (const IdentifierHash& id, IdentifierHash& other) const; - - // // To check for when phi wrap around may be needed, use - // bool is_phi_module_max(const Identifier& id) const; - // /// For the barrel - // bool is_eta_module_min(const Identifier& id) const; - // /// For the barrel - // bool is_eta_module_max(const Identifier& id) const; - // //@} - - // /// @name contexts to distinguish wafer id from pixel id - // //@{ - // IdContext wafer_context (void) const; - // IdContext strip_context (void) const; - // //@} - - /// @name methods from abstract interface - slower than opt version - //@{ - /// Create compact id from hash id (return == 0 for OK) - virtual int get_id (const IdentifierHash& hash_id, - Identifier& id, - const IdContext* context = 0) const; - - /// Create hash id from compact id (return == 0 for OK) - virtual int get_hash (const Identifier& id, - IdentifierHash& hash_id, - const IdContext* context = 0) const; - //@} - - /// Return the lowest bit position used in the channel id - int base_bit (void) const; - - // /// Calculate a channel offset between the two identifiers. - // Identifier::diff_type calc_offset(const Identifier& base, - // const Identifier& target) const; - - // /// Create an identifier with a given base and channel offset - // Identifier strip_id_offset(const Identifier& base, - // Identifier::diff_type offset) const; - - /// @name interaction with id dictionary - //@{ - /// Create sensor Identifier from expanded id, which is returned by the - /// id_iterators - Identifier sensor_id (const ExpandedIdentifier& sensor_id) const; - - /// Create expanded id from compact id (return == 0 for OK) - void get_expanded_id (const Identifier& id, - ExpandedIdentifier& exp_id, - const IdContext* context = 0) const; - - /// Initialization from the identifier dictionary - virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr); - -private: - - typedef std::vector<Identifier> id_vec; - typedef id_vec::const_iterator id_vec_it; - typedef std::vector<unsigned short> hash_vec; - typedef hash_vec::const_iterator hash_vec_it; - - void submodule_id_checks ( int station, - int plane, - int module, - int submodule ) const; - - void sensor_id_checks ( int station, - int plane, - int module, - int submodule, - int sensor) const; - - int initLevelsFromDict(void); - - int init_hashes(void); - - int init_neighbors(void); - - size_type m_faser_region_index; - size_type m_SUBDET_INDEX; - size_type m_PART_INDEX; - size_type m_STATION_INDEX; - size_type m_PLANE_INDEX; - size_type m_MODULE_INDEX; - size_type m_SUBMODULE_INDEX; - size_type m_SENSOR_INDEX; - - const IdDictDictionary* m_dict; - MultiRange m_full_submodule_range; - MultiRange m_full_sensor_range; - size_type m_submodule_hash_max; - size_type m_sensor_hash_max; - id_vec m_submodule_vec; - // hash_vec m_prev_phi_wafer_vec; - // hash_vec m_next_phi_wafer_vec; - // hash_vec m_prev_eta_wafer_vec; - // hash_vec m_next_eta_wafer_vec; - - IdDictFieldImplementation m_subdet_impl ; - IdDictFieldImplementation m_part_impl ; - IdDictFieldImplementation m_station_impl ; - IdDictFieldImplementation m_plane_impl ; - IdDictFieldImplementation m_module_impl ; - IdDictFieldImplementation m_submodule_impl; - IdDictFieldImplementation m_sensor_impl ; -}; - - -//<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> - -///////////////////////////////////////////////////////////////////////////// -//<<<<<< INLINE MEMBER FUNCTIONS >>>>>> -///////////////////////////////////////////////////////////////////////////// - -//using the macros below we can assign an identifier (and a version) -//This is required and checked at compile time when you try to record/retrieve -CLASS_DEF(FaserDetectorID, 125694213, 1) - -//---------------------------------------------------------------------------- -// inline Identifier -// FaserDetectorID::module_id ( int station, -// int plane, -// int module ) const -// { - -// // Build identifier -// Identifier result((Identifier::value_type)0); - -// // Pack fields independently -// m_scint_impl.pack (scint_field_value(), result); -// m_veto_impl.pack (veto_field_value(), result); -// m_station_impl.pack (station, result); - -// return result; -// } - -//---------------------------------------------------------------------------- -inline Identifier -FaserDetectorID::module_id ( const Identifier& submodule_id ) const -{ - Identifier result(submodule_id); - // Reset the plate and pmt fields - m_submodule_impl.reset(result); - m_sensor_impl.reset(result); - return (result); -} - -//---------------------------------------------------------------------------- -// inline Identifier -// FaserDetectorID::submodule_id ( int station, -// int plane, -// int module, -// int submodule ) const -// { -// // Build identifier -// Identifier result((Identifier::value_type)0); - -// // Pack fields independently -// m_scint_impl.pack (scint_field_value(), result); -// m_veto_impl.pack (veto_field_value(), result); -// m_station_impl.pack (station, result); -// m_plane_impl.pack (plane, result); -// m_module_impl.pack (module, result); -// m_submodule_impl.pack(submodule, result); - -// return result; -// } - -//---------------------------------------------------------------------------- -inline Identifier -FaserDetectorID::submodule_id ( const Identifier& sensor_id ) const -{ - Identifier result(sensor_id); - // reset the strip field - m_sensor_impl.reset(result); - return (result); -} - -inline IdentifierHash -FaserDetectorID::submodule_hash (Identifier submodule_id) const -{ - id_vec_it it = std::lower_bound(m_submodule_vec.begin(), - m_submodule_vec.end(), - submodule_id); - // Require that submodule_id matches the one in vector - if (it != m_submodule_vec.end() && submodule_id == (*it)) { - return (it - m_submodule_vec.begin()); - } - IdentifierHash result; - return (result); // return hash in invalid state -} - -//---------------------------------------------------------------------------- -// inline Identifier -// FaserDetectorID::sensor_id ( int station, -// int plane, -// int module, -// int submodule, -// int sensor ) const -// { -// // Build identifier -// Identifier result((Identifier::value_type)0); - -// // Pack fields independently -// m_scint_impl.pack (scint_field_value(), result); -// m_veto_impl.pack (veto_field_value(), result); -// m_station_impl.pack (station, result); -// m_plane_impl.pack (plane, result); -// m_module_impl.pack (module, result); -// m_submodule_impl.pack(submodule, result); -// m_sensor_impl.pack (sensor, result); - -// return result; -// } - -//---------------------------------------------------------------------------- -inline Identifier -FaserDetectorID::sensor_id ( const Identifier& submodule_id, int sensor ) const -{ - // Build identifier - Identifier result(submodule_id); - - // Reset sensor and then add in value - m_sensor_impl.reset (result); - m_sensor_impl.pack (sensor, result); - - return result; -} - -//---------------------------------------------------------------------------- -inline int -FaserDetectorID::station (const Identifier& id) const -{ - return (m_station_impl.unpack(id)); -} - -//---------------------------------------------------------------------------- -inline int -FaserDetectorID::plane (const Identifier& id) const -{ - return (m_plane_impl.unpack(id)); -} -//---------------------------------------------------------------------------- -inline int -FaserDetectorID::module (const Identifier& id) const -{ - return (m_module_impl.unpack(id)); -} - -//---------------------------------------------------------------------------- -inline int -FaserDetectorID::submodule (const Identifier& id) const -{ - return (m_submodule_impl.unpack(id)); -} - -//---------------------------------------------------------------------------- -inline int -FaserDetectorID::sensor (const Identifier& id) const -{ - return (m_sensor_impl.unpack(id)); -} - - -#endif // FASERDETDESCR_FASERDETECTORID_H diff --git a/DetectorDescription/FaserDetDescr/src/FaserDetectorID.cxxOld b/DetectorDescription/FaserDetDescr/src/FaserDetectorID.cxxOld deleted file mode 100644 index 29b4ff691ac0ebc4974fafe3a17ef7cd49bd97ee..0000000000000000000000000000000000000000 --- a/DetectorDescription/FaserDetDescr/src/FaserDetectorID.cxxOld +++ /dev/null @@ -1,363 +0,0 @@ -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -/*************************************************************************** - Scintillator identifier package - ------------------------------------------- -***************************************************************************/ - -//<<<<<< INCLUDES >>>>>> -#include "GaudiKernel/MsgStream.h" - -#include "FaserDetDescr/FaserDetectorID.h" -#include "Identifier/IdentifierHash.h" -#include "IdDict/IdDictDefs.h" -#include <set> -#include <algorithm> -#include <iostream> - -//<<<<<< PRIVATE DEFINES >>>>>> -//<<<<<< PRIVATE CONSTANTS >>>>>> -//<<<<<< PRIVATE TYPES >>>>>> -//<<<<<< PRIVATE VARIABLE DEFINITIONS >>>>>> -//<<<<<< PUBLIC VARIABLE DEFINITIONS >>>>>> -//<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>> -//<<<<<< PRIVATE FUNCTION DEFINITIONS >>>>>> -//<<<<<< PUBLIC FUNCTION DEFINITIONS >>>>>> -//<<<<<< MEMBER FUNCTION DEFINITIONS >>>>>> - - -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - - -FaserDetectorID::FaserDetectorID(void) - : - m_faser_region_index(0), - m_SUBDET_INDEX(0), - m_PART_INDEX(1), - m_STATION_INDEX(2), - m_PLANE_INDEX(3), - m_MODULE_INDEX(4), - m_SUBMODULE_INDEX(5), - m_SENSOR_INDEX(6), - m_dict(0), - m_submodule_hash_max(0), - m_sensor_hash_max(0) -{ -} - -int -FaserDetectorID::init_hashes(void) -{ - - // - // create a vector(s) to retrieve the hashes for compact ids. For - // the moment, we implement a hash for submodules but NOT for sensors - // - MsgStream log(m_msgSvc, "FaserDetectorID"); - // wafer hash - m_submodule_hash_max = m_full_submodule_range.cardinality(); - m_submodule_vec.resize(m_submodule_hash_max); - unsigned int nids = 0; - std::set<Identifier> ids; - for (unsigned int i = 0; i < m_full_submodule_range.size(); ++i) { - const Range& range = m_full_submodule_range[i]; - Range::const_identifier_factory first = range.factory_begin(); - Range::const_identifier_factory last = range.factory_end(); - for (; first != last; ++first) { - const ExpandedIdentifier& exp_id = (*first); - Identifier id = submodule_id(exp_id[m_STATION_INDEX], - exp_id[m_PLANE_INDEX], - exp_id[m_MODULE_INDEX], - exp_id[m_SUBMODULE_INDEX]); - if(!(ids.insert(id)).second) { - log << MSG::ERROR << " FaserDetectorID::init_hashes " - << " Error: duplicated id for plate id. nid " << nids - << " compact id " << id.getString() - << " id " << (std::string)exp_id << endmsg; - return (1); - } - nids++; - } - } - if(ids.size() != m_submodule_hash_max) { - log << MSG::ERROR << " FaserDetectorID::init_hashes " - << " Error: set size NOT EQUAL to hash max. size " << ids.size() - << " hash max " << m_submodule_hash_max - << endmsg; - return (1); - } - - nids = 0; - std::set<Identifier>::const_iterator first = ids.begin(); - std::set<Identifier>::const_iterator last = ids.end(); - for (; first != last && nids < m_submodule_vec.size(); ++first) { - m_submodule_vec[nids] = (*first); - nids++; - } - - // sensor hash - we do not keep a vec for the sensors - m_sensor_hash_max = m_full_sensor_range.cardinality(); - - return (0); -} - - -int -FaserDetectorID::initialize_from_dictionary(const IdDictMgr& dict_mgr) -{ - MsgStream log(m_msgSvc, "FaserDetectorID"); - log << MSG::INFO << "Initialize from dictionary" << endmsg; - - // Check whether this helper should be reinitialized - if (!reinitialize(dict_mgr)) { - log << MSG::INFO << "Request to reinitialize not satisfied - tags have not changed" << endmsg; - return (0); - } - else { - if (m_msgSvc) { - log << MSG::DEBUG << "(Re)initialize" << endmsg; - } - else { - std::cout << " DEBUG (Re)initialize" << std::endl; - } - } - - // init base object - if(FaserDetectorIDBase::initialize_from_dictionary(dict_mgr)) return (1); - - // Register version of InnerDetector dictionary - if (register_dict_tag(dict_mgr, "Scintillator")) return(1); - - m_dict = dict_mgr.find_dictionary ("Scintillator"); - if(!m_dict) { - log << MSG::ERROR << " FaserDetectorID::initialize_from_dict - cannot access Scintillator dictionary " << endmsg; - return 1; - } - - // Initialize the field indices - if(initLevelsFromDict()) return (1); - - // - // Build multirange for the valid set of identifiers - // - - - // Find value for the field Scintillator - const IdDictDictionary* faserDict = dict_mgr.find_dictionary ("FASER"); - int scintField = -1; - if (faserDict->get_label_value("subdet", "Scintillator", scintField)) { - log << MSG::ERROR << "Could not get value for label 'Scintillator' of field 'subdet' in dictionary " - << faserDict->m_name - << endmsg; - return (1); - } - - // Find value for the field Veto - int vetoField = -1; - if (m_dict->get_label_value("part", "Veto", vetoField)) { - log << MSG::ERROR << "Could not get value for label 'Veto' of field 'part' in dictionary " - << m_dict->m_name - << endmsg; - return (1); - } - if (m_msgSvc) { - log << MSG::DEBUG << " VetoID::initialize_from_dict " - << "Found field values: Veto " - << vetoField - << std::endl; - } - else { - std::cout << " DEBUG VetoID::initialize_from_dict " - << "Found field values: Veto " - << vetoField - << std::endl; - } - - // Set up id for region and range prefix - ExpandedIdentifier region_id; - region_id.add(scintField); - region_id.add(vetoField); - Range prefix; - m_full_plate_range = m_dict->build_multirange(region_id, prefix, "plate"); - m_full_pmt_range = m_dict->build_multirange(region_id, prefix); - - - if (m_msgSvc) { - log << MSG::INFO << " VetoID::initialize_from_dict " << endmsg; - log << MSG::DEBUG - << "Plate range -> " << (std::string)m_full_plate_range - << endmsg; - log << MSG::DEBUG - << "Pmt range -> " << (std::string)m_full_pmt_range - << endmsg; - } - else { - std::cout << " INFO VetoID::initialize_from_dict " << std::endl; - std::cout << " DEBUG Plate range -> " << (std::string)m_full_plate_range - << std::endl; - std::cout << " DEBUG Pmt range -> " << (std::string)m_full_pmt_range - << std::endl; - } - - return 0; -} - -int -FaserDetectorID::initLevelsFromDict() -{ - - - MsgStream log(m_msgSvc, "FaserDetectorID"); - if(!m_dict) { - log << MSG::ERROR << " FaserDetectorID::initLevelsFromDict - dictionary NOT initialized " << endmsg; - return (1); - } - - // Find out which identifier field corresponds to each level. Use - // names to find each field/leve. - - m_SUBDET_INDEX = 999; - m_PART_INDEX = 999; - m_STATION_INDEX = 999; - m_PLANE_INDEX = 999; - m_MODULE_INDEX = 999; - m_SUBMODULE_INDEX = 999; - m_SENSOR_INDEX = 999; - - - // Save index to a Veto region for unpacking - ExpandedIdentifier id; - id << scint_field_value() << veto_field_value(); - if (m_dict->find_region(id, m_veto_region_index)) { - log << MSG::ERROR << "FaserDetectorID::initLevelsFromDict - unable to find veto region index: id, reg " - << (std::string)id << " " << m_veto_region_index - << endmsg; - return (1); - } - - // Find a Vetp region - IdDictField* field = m_dict->find_field("subdet"); - if (field) { - m_SCINT_INDEX = field->m_index; - } - else { - log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'subdet' field " << endmsg; - return (1); - } - field = m_dict->find_field("part"); - if (field) { - m_VETO_INDEX = field->m_index; - } - else { - log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'part' field " << endmsg; - return (1); - } - field = m_dict->find_field("station"); - if (field) { - m_STATION_INDEX = field->m_index; - } - else { - log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'station' field " << endmsg; - return (1); - } - field = m_dict->find_field("plate"); - if (field) { - m_PLATE_INDEX = field->m_index; - } - else { - log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'plate' field " << endmsg; - return (1); - } - field = m_dict->find_field("pmt"); - if (field) { - m_PMT_INDEX = field->m_index; - } - else { - log << MSG::ERROR<< "VetoID::initLevelsFromDict - unable to find 'pmt' field " << endmsg; - return (1); - } - - // Set the field implementations: for station, plate, pmt - - const IdDictRegion& region = *m_dict->m_regions[m_veto_region_index]; - - m_scint_impl = region.m_implementation[m_SCINT_INDEX]; - m_veto_impl = region.m_implementation[m_VETO_INDEX]; - m_station_impl = region.m_implementation[m_STATION_INDEX]; - m_plate_impl = region.m_implementation[m_PLATE_INDEX]; - m_pmt_impl = region.m_implementation[m_PMT_INDEX]; - - if (m_msgSvc) { - log << MSG::DEBUG << "decode index and bit fields for each level: " << endmsg; - log << MSG::DEBUG << "scint " << m_scint_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "veto " << m_veto_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "station " << m_station_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "plate " << m_plate_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "pmt " << m_pmt_impl.show_to_string() << endmsg; - } - else { - std::cout << " DEBUG decode index and bit fields for each level: " << std::endl; - std::cout << " DEBUG scint " << m_scint_impl.show_to_string() << std::endl; - std::cout << " DEBUG veto " << m_veto_impl.show_to_string() << std::endl; - std::cout << " DEBUG station " << m_station_impl.show_to_string() << std::endl; - std::cout << " DEBUG plate " << m_plate_impl.show_to_string() << std::endl; - std::cout << " DEBUG pmt " << m_pmt_impl.show_to_string() << std::endl; - } - -// std::cout << "SCT_ID::initLevelsFromDict - found levels " << std::endl; -// std::cout << "subdet " << m_INDET_INDEX << std::endl; -// std::cout << "part " << m_SCT_INDEX << std::endl; -// std::cout << "barrel_endcap " << m_BARREL_EC_INDEX << std::endl; -// std::cout << "layer or disk " << m_LAYER_DISK_INDEX << std::endl; -// std::cout << "phi_module " << m_PHI_MODULE_INDEX << std::endl; -// std::cout << "eta_module " << m_ETA_MODULE_INDEX << std::endl; -// std::cout << "side " << m_SIDE_INDEX << std::endl; -// std::cout << "strip " << m_STRIP_INDEX << std::endl; - - std::cout << "scint " << m_scint_impl.decode_index() << " " - << (std::string)m_scint_impl.ored_field() << " " - << std::hex << m_scint_impl.mask() << " " - << m_scint_impl.zeroing_mask() << " " - << std::dec << m_scint_impl.shift() << " " - << m_scint_impl.bits() << " " - << m_scint_impl.bits_offset() - << std::endl; - std::cout << "veto" << m_veto_impl.decode_index() << " " - << (std::string)m_veto_impl.ored_field() << " " - << std::hex << m_veto_impl.mask() << " " - << m_veto_impl.zeroing_mask() << " " - << std::dec << m_veto_impl.shift() << " " - << m_veto_impl.bits() << " " - << m_veto_impl.bits_offset() - << std::endl; - std::cout << "station" << m_station_impl.decode_index() << " " - << (std::string)m_station_impl.ored_field() << " " - << std::hex << m_station_impl.mask() << " " - << m_station_impl.zeroing_mask() << " " - << std::dec << m_station_impl.shift() << " " - << m_station_impl.bits() << " " - << m_station_impl.bits_offset() - << std::endl; - std::cout << "plate"<< m_plate_impl.decode_index() << " " - << (std::string)m_plate_impl.ored_field() << " " - << std::hex << m_plate_impl.mask() << " " - << m_plate_impl.zeroing_mask() << " " - << std::dec << m_plate_impl.shift() << " " - << m_plate_impl.bits() << " " - << m_plate_impl.bits_offset() - << std::endl; - std::cout << "pmt" << m_pmt_impl.decode_index() << " " - << (std::string)m_pmt_impl.ored_field() << " " - << std::hex << m_pmt_impl.mask() << " " - << m_pmt_impl.zeroing_mask() << " " - << std::dec << m_pmt_impl.shift() << " " - << m_pmt_impl.bits() << " " - << m_pmt_impl.bits_offset() - << std::endl; - return (0); -} - diff --git a/Scintillator/ScintDetDescr/ScintGeoModel/CMakeLists.txt b/Scintillator/ScintDetDescr/ScintGeoModel/CMakeLists.txt index 47bba2ec4ef3a913db35c32ab6ada34838a1cf6a..ba1cbe806d32331db700a23e82611b078cb45449 100644 --- a/Scintillator/ScintDetDescr/ScintGeoModel/CMakeLists.txt +++ b/Scintillator/ScintDetDescr/ScintGeoModel/CMakeLists.txt @@ -38,7 +38,7 @@ atlas_add_component( ScintGeoModel src/*.cxx src/components/*.cxx INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} - LINK_LIBRARIES ${Boost_LIBRARIES} ${CORAL_LIBRARIES} ${GEOMODEL_LIBRARIES} AthenaKernel GeoModelUtilities GeoModelFaserUtilities GaudiKernel SGTools StoreGateLib SGtests AthenaPoolUtilities InDetGeoModelUtils DetDescrConditions FaserDetDescr Identifier ) + LINK_LIBRARIES ${Boost_LIBRARIES} ${CORAL_LIBRARIES} ${GEOMODEL_LIBRARIES} AthenaKernel GeoModelUtilities GeoModelFaserUtilities GaudiKernel SGTools StoreGateLib SGtests AthenaPoolUtilities InDetGeoModelUtils DetDescrConditions FaserDetDescr ScintIdentifier Identifier ) #atlas_add_test( SCT_GMConfig_test # SCRIPT test/SCT_GMConfig_test.py diff --git a/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/VetoDetectorTool.h b/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/VetoDetectorTool.h index 9e98acde0a54dfcc12b6472e1d306701aa4b48b2..0b6d32fe5de36cff06f706281351eaf72b334908 100644 --- a/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/VetoDetectorTool.h +++ b/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/VetoDetectorTool.h @@ -20,8 +20,8 @@ namespace ScintDD { class VetoDetectorManager; } -//class VetoID; -class FaserDetectorID; +class VetoID; +// class FaserDetectorID; class VetoDetectorTool : public GeoModelTool { @@ -46,7 +46,7 @@ private: const ScintDD::VetoDetectorManager* m_manager; - ScintGeoModelAthenaComps<FaserDetectorID> m_athenaComps; + ScintGeoModelAthenaComps<VetoID> m_athenaComps; // ScintGeoModelAthenaComps<VetoID> m_athenaComps; ServiceHandle< IGeoDbTagSvc > m_geoDbTagSvc; diff --git a/Scintillator/ScintDetDescr/ScintGeoModel/src/VetoDetectorTool.cxx b/Scintillator/ScintDetDescr/ScintGeoModel/src/VetoDetectorTool.cxx index ae32e5ded705ab6aef78337dc43cb8ac64ecc65f..0d440a2eb2b9655d08922a23b8d2ec3367b5b236 100644 --- a/Scintillator/ScintDetDescr/ScintGeoModel/src/VetoDetectorTool.cxx +++ b/Scintillator/ScintDetDescr/ScintGeoModel/src/VetoDetectorTool.cxx @@ -12,7 +12,8 @@ // temporary // #include "InDetIdentifier/SCT_ID.h" // #include "ScintReadoutGeometry/VetoDetectorManager.h" -#include "FaserDetDescr/FaserDetectorID.h" +// #include "FaserDetDescr/FaserDetectorID.h" +#include "ScintIdentifier/VetoID.h" #include "DetDescrConditions/AlignableTransformContainer.h" #include "GeoModelUtilities/GeoModelExperiment.h" @@ -123,8 +124,8 @@ VetoDetectorTool::create() m_athenaComps.setGeoDbTagSvc(&*m_geoDbTagSvc); m_athenaComps.setGeometryDBSvc(&*m_geometryDBSvc); m_athenaComps.setRDBAccessSvc(&*m_rdbAccessSvc); - const FaserDetectorID* idHelper{nullptr}; - ATH_CHECK(detStore()->retrieve(idHelper, "FaserID")); + const VetoID* idHelper{nullptr}; + ATH_CHECK(detStore()->retrieve(idHelper, "VetoID")); m_athenaComps.setIdHelper(idHelper); // diff --git a/Scintillator/ScintDetDescr/ScintIdDictFiles/data/IdDictScintillator.xml b/Scintillator/ScintDetDescr/ScintIdDictFiles/data/IdDictScintillator.xml index d7cabdf6fce023b657c51b5aadcdf35f902843b7..fbec1a8aa8e7fec1c1e5e20244125c1ad1dcf922 100644 --- a/Scintillator/ScintDetDescr/ScintIdDictFiles/data/IdDictScintillator.xml +++ b/Scintillator/ScintDetDescr/ScintIdDictFiles/data/IdDictScintillator.xml @@ -9,13 +9,13 @@ <region> <range field="part" value="Veto" /> <range field="station" minvalue="0" maxvalue="1" /> - <range field="plate" value="0" /> - <range field="pmt" value="0" /> + <range field="plate" minvalue="0" maxvalue="0" /> + <range field="pmt" minvalue="0" maxvalue="0" /> </region> <region> <range field="part" value="Trigger"/> - <range field="station" value="0" /> + <range field="station" minvalue="0" maxvalue="0" /> <range field="plate" minvalue="0" maxvalue="1" /> <range field="pmt" minvalue="0" maxvalue="1" /> </region> @@ -23,7 +23,7 @@ <region> <range field="part" value="Preshower" /> <range field="station" minvalue="0" maxvalue="1" /> - <range field="plate" value="0" /> - <range field="pmt" value="0" /> + <range field="plate" minvalue="0" maxvalue="0" /> + <range field="pmt" minvalue="0" maxvalue="0" /> </region> </IdDictionary> \ No newline at end of file diff --git a/Scintillator/ScintDetDescr/ScintIdentifier/CMakeLists.txt b/Scintillator/ScintDetDescr/ScintIdentifier/CMakeLists.txt index ae742293cc0fe6b2f47105e9aca6158b7c0084bc..660ea8422bc728b3b0bb12c687f6291a4516b1e5 100644 --- a/Scintillator/ScintDetDescr/ScintIdentifier/CMakeLists.txt +++ b/Scintillator/ScintDetDescr/ScintIdentifier/CMakeLists.txt @@ -19,21 +19,21 @@ atlas_depends_on_subdirs( PUBLIC find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread ) # Component(s) in the package: -#atlas_add_library( ScintIdentifier -# src/VetoID.cxx +atlas_add_library( ScintIdentifier + src/VetoID.cxx # src/TriggerID.cxx # src/PreshowerID.cxx # src/ScintillatorID.cxx -# PUBLIC_HEADERS ScintIdentifier -# PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} -# LINK_LIBRARIES AthenaKernel FaserDetDescr IdDict Identifier -# PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} IdDictParser GaudiKernel ) + PUBLIC_HEADERS ScintIdentifier + PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} + LINK_LIBRARIES AthenaKernel FaserDetDescr IdDict Identifier + PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} IdDictParser GaudiKernel ) -#atlas_add_dictionary( ScintIdentifierDict -# ScintIdentifier/ScintIdentifierDict.h -# ScintIdentifier/selection.xml -# INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} -# LINK_LIBRARIES ${ROOT_LIBRARIES} FaserDetDescr IdDict Identifier IdDictParser GaudiKernel ScintIdentifier ) +atlas_add_dictionary( ScintIdentifierDict + ScintIdentifier/ScintIdentifierDict.h + ScintIdentifier/selection.xml + INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} + LINK_LIBRARIES ${ROOT_LIBRARIES} FaserDetDescr IdDict Identifier IdDictParser GaudiKernel ScintIdentifier ) #atlas_add_executable( test_indet_id # test/test_indet_id.cxx diff --git a/Scintillator/ScintDetDescr/ScintIdentifier/ScintIdentifier/VetoID.h b/Scintillator/ScintDetDescr/ScintIdentifier/ScintIdentifier/VetoID.h new file mode 100644 index 0000000000000000000000000000000000000000..5a3801689840a9ca3d005d7e9d09d13053c8f8e0 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintIdentifier/ScintIdentifier/VetoID.h @@ -0,0 +1,528 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef SCINTIDENTIFIER_VETOID_H +#define SCINTIDENTIFIER_VETOID_H +/** + * @file VetoID.h + * + * @brief This is an Identifier helper class for the Veto + * subdetector. This class is a factory for creating compact + * Identifier objects and IdentifierHash or hash ids. And it also + * allows decoding of these ids. + * + */ + +//<<<<<< INCLUDES >>>>>> + +#include "FaserDetDescr/FaserDetectorID.h" +#include "Identifier/Identifier.h" +#include "Identifier/IdentifierHash.h" +#include "Identifier/Range.h" +#include "Identifier/IdHelper.h" +#include "IdDict/IdDictFieldImplementation.h" +#include "AthenaKernel/CLASS_DEF.h" + +#include <string> +#include <assert.h> +#include <algorithm> + +//<<<<<< PUBLIC DEFINES >>>>>> +//<<<<<< PUBLIC CONSTANTS >>>>>> +//<<<<<< PUBLIC TYPES >>>>>> + +class IdDictDictionary; + +//<<<<<< PUBLIC VARIABLES >>>>>> +//<<<<<< PUBLIC FUNCTIONS >>>>>> +//<<<<<< CLASS DECLARATIONS >>>>>> + +/** + ** @class VetoID + ** + ** @brief This is an Identifier helper class for the Veto + ** subdetector. This class is a factory for creating compact + ** Identifier objects and IdentifierHash or hash ids. And it also + ** allows decoding of these ids. + ** + ** Definition and the range of values for the levels of the + ** identifier are: + ** + ** @verbatim + ** element range meaning + ** ------- ----- ------- + ** + ** station 0 to 1 longitudinal location + ** plate 0 single plate per station + ** pmt 0 single pmt per plate + ** + ** @endverbatim + ** + */ +class VetoID : public FaserDetectorID +{ +public: + + /// @name public typedefs + //@{ + typedef Identifier::size_type size_type; + typedef std::vector<Identifier>::const_iterator const_id_iterator; + typedef MultiRange::const_identifier_factory const_expanded_id_iterator; + //@} + + /// @name strutors + //@{ + VetoID(void); + virtual ~VetoID(void) = default; + //@} + + /// @name Creators for plate ids and pmt ids + //@{ + /// For a single station + Identifier station_id ( int station ) const; + Identifier station_id ( int station, + bool checks) const; + + /// For a station from a plate id + Identifier station_id ( const Identifier& plate_id ) const; + + /// For a single plate + Identifier plate_id ( int station, + int plate ) const; + Identifier plate_id ( int station, + int plate, + bool checks) const; + + /// For a single plate from a pmt id + Identifier plate_id ( const Identifier& pmt_id ) const; + + /// From hash - optimized + Identifier plate_id ( IdentifierHash plate_hash ) const; + + /// For an individual pmt + Identifier pmt_id ( int station, + int plate, + int pmt ) const; + + Identifier pmt_id ( int station, + int plate, + int pmt, + bool check ) const; + + Identifier pmt_id ( const Identifier& plate_id, + int pmt ) const; + + //@} + + + /// @name Hash table maximum sizes + //@{ + size_type plate_hash_max (void) const; + size_type pmt_hash_max (void) const; + //@} + + /// @name Access to all ids + //@{ + /// Iterators over full set of ids. Plate iterator is sorted + const_id_iterator plate_begin (void) const; + const_id_iterator plate_end (void) const; + /// For pmt ids, only expanded id iterators are available. Use + /// following "pmt_id" method to obtain a compact identifier + const_expanded_id_iterator pmt_begin (void) const; + const_expanded_id_iterator pmt_end (void) const; + //@} + + + /// @name Optimized accessors - ASSUMES id IS a sct id, i.e. NOT pixel or other + //@{ + /// wafer hash from id - optimized + IdentifierHash plate_hash (Identifier plate_id) const; + + /// Values of different levels (failure returns 0) + int station (const Identifier& id) const; + int plate (const Identifier& id) const; + int pmt (const Identifier& id) const; + + /// Max/Min values for each field (-999 == failure) + int station_max (const Identifier& id) const; + int plate_max (const Identifier& id) const; + int pmt_max (const Identifier& id) const; + //@} + + /// @name module eta/phi navigation + //@{ + // /// Previous wafer hash in phi (return == 0 for neighbor found) + // int get_prev_in_phi (const IdentifierHash& id, IdentifierHash& prev) const; + // /// Next wafer hash in phi (return == 0 for neighbor found) + // int get_next_in_phi (const IdentifierHash& id, IdentifierHash& next) const; + // /// Previous wafer hash in eta (return == 0 for neighbor found) + // int get_prev_in_eta (const IdentifierHash& id, IdentifierHash& prev) const; + // /// Next wafer hash in eta (return == 0 for neighbor found) + // int get_next_in_eta (const IdentifierHash& id, IdentifierHash& next) const; + // /// Wafer hash on other side + // int get_other_side (const IdentifierHash& id, IdentifierHash& other) const; + + // // To check for when phi wrap around may be needed, use + // bool is_phi_module_max(const Identifier& id) const; + // /// For the barrel + // bool is_eta_module_min(const Identifier& id) const; + // /// For the barrel + // bool is_eta_module_max(const Identifier& id) const; + //@} + + /// @name contexts to distinguish plate id from pixel id + //@{ + IdContext plate_context (void) const; + IdContext pmt_context (void) const; + //@} + + /// @name methods from abstract interface - slower than opt version + //@{ + /// Create compact id from hash id (return == 0 for OK) + virtual int get_id (const IdentifierHash& hash_id, + Identifier& id, + const IdContext* context = 0) const; + + /// Create hash id from compact id (return == 0 for OK) + virtual int get_hash (const Identifier& id, + IdentifierHash& hash_id, + const IdContext* context = 0) const; + //@} + + /// Return the lowest bit position used in the channel id + int base_bit (void) const; + + /// Calculate a channel offset between the two identifiers. + Identifier::diff_type calc_offset(const Identifier& base, + const Identifier& target) const; + + /// Create an identifier with a given base and channel offset + Identifier pmt_id_offset(const Identifier& base, + Identifier::diff_type offset) const; + + /// @name interaction with id dictionary + //@{ + /// Create strip Identifier from expanded id, which is returned by the + /// id_iterators + Identifier pmt_id (const ExpandedIdentifier& pmt_id) const; + + /// Create expanded id from compact id (return == 0 for OK) + void get_expanded_id (const Identifier& id, + ExpandedIdentifier& exp_id, + const IdContext* context = 0) const; + + /// Initialization from the identifier dictionary + virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr); + + /// Tests of packing + void test_plate_packing (void) const; + //@} + +private: + + enum {NOT_VALID_HASH = 64000}; + + typedef std::vector<Identifier> id_vec; + typedef id_vec::const_iterator id_vec_it; + typedef std::vector<unsigned short> hash_vec; + typedef hash_vec::const_iterator hash_vec_it; + + void plate_id_checks ( int station, + int plate ) const; + + void pmt_id_checks ( int station, + int plate, + int pmt ) const; + + + int initLevelsFromDict(void); + + int init_hashes(void); + + int init_neighbors(void); + + // Temporary method for adapting an identifier for the MultiRange + // check - MR is missing the InnerDetector level + // Identifier idForCheck (const Identifier& id) const; + + size_type m_veto_region_index; + size_type m_SCINT_INDEX; + size_type m_VETO_INDEX; + size_type m_STATION_INDEX; + size_type m_PLATE_INDEX; + size_type m_PMT_INDEX; + + const IdDictDictionary* m_dict; + MultiRange m_full_plate_range; + MultiRange m_full_pmt_range; + size_type m_plate_hash_max; + size_type m_pmt_hash_max; + // Range::field m_barrel_field; + id_vec m_plate_vec; + // hash_vec m_prev_phi_wafer_vec; + // hash_vec m_next_phi_wafer_vec; + // hash_vec m_prev_eta_wafer_vec; + // hash_vec m_next_eta_wafer_vec; + // bool m_hasRows ; + + IdDictFieldImplementation m_scint_impl ; + IdDictFieldImplementation m_veto_impl ; + IdDictFieldImplementation m_station_impl ; + IdDictFieldImplementation m_plate_impl ; + IdDictFieldImplementation m_pmt_impl ; +}; + + +//<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> + +///////////////////////////////////////////////////////////////////////////// +//<<<<<< INLINE MEMBER FUNCTIONS >>>>>> +///////////////////////////////////////////////////////////////////////////// + +//using the macros below we can assign an identifier (and a version) +//This is required and checked at compile time when you try to record/retrieve +CLASS_DEF(VetoID, 131395045, 1) + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::station_id ( int station, + bool checks) const +{ + + // Build identifier + Identifier result((Identifier::value_type)0); + + // Pack fields independently + m_scint_impl.pack (scint_field_value(), result); + m_veto_impl.pack (veto_field_value(), result); + m_station_impl.pack (station, result); + // Do checks + if(checks) + { + plate_id_checks ( station, 0 ); + } + + return result; +} + +inline Identifier +VetoID::station_id ( int station ) const +{ + return station_id (station, do_checks()); +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::station_id ( const Identifier& plate_id ) const +{ + Identifier result(plate_id); + // Reset the plate and pmt fields + m_plate_impl.reset(result); + m_pmt_impl.reset(result); + return (result); +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::plate_id ( int station, + int plate, + bool checks) const +{ + // Build identifier + Identifier result((Identifier::value_type)0); + + // Pack fields independently + m_scint_impl.pack (scint_field_value(), result); + m_veto_impl.pack (veto_field_value(), result); + m_station_impl.pack (station, result); + m_plate_impl.pack (plate, result); + + // Do checks + if(checks) + { + plate_id_checks ( station, plate ); + } + return result; +} + +inline Identifier +VetoID::plate_id ( int station, + int plate ) const +{ + return plate_id (station, plate, do_checks()); +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::plate_id ( const Identifier& pmt_id ) const +{ + Identifier result(pmt_id); + // reset the pmt field + m_pmt_impl.reset(result); + return (result); +} + +//---------------------------------------------------------------------------- +inline Identifier VetoID::plate_id ( IdentifierHash plate_hash ) const +{ + return (m_plate_vec[plate_hash]); +} + +//---------------------------------------------------------------------------- +inline IdentifierHash VetoID::plate_hash (Identifier plate_id) const +{ + id_vec_it it = std::lower_bound(m_plate_vec.begin(), + m_plate_vec.end(), + plate_id); + // Require that plate_id matches the one in vector + if (it != m_plate_vec.end() && plate_id == (*it)) { + return (it - m_plate_vec.begin()); + } + IdentifierHash result; + return (result); // return hash in invalid state +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::pmt_id ( int station, + int plate, + int pmt, + bool checks) const +{ + // Build identifier + Identifier result((Identifier::value_type)0); + + // Pack fields independently + m_scint_impl.pack (scint_field_value(), result); + m_veto_impl.pack (veto_field_value(), result); + m_station_impl.pack (station, result); + m_plate_impl.pack (plate, result); + m_pmt_impl.pack (pmt, result); + + // Do checks + if(checks) { + pmt_id_checks ( station, plate, pmt ); + } + return result; +} + +inline Identifier +VetoID::pmt_id ( int station, + int plate, + int pmt ) const +{ + return pmt_id (station, plate, pmt, do_checks()); +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::pmt_id (const ExpandedIdentifier& id) const +{ + // Build identifier + Identifier result((Identifier::value_type)0); + + // Pack fields independently + m_scint_impl.pack (scint_field_value(), result); + m_veto_impl.pack (veto_field_value(), result); + m_station_impl.pack (id[m_STATION_INDEX], result); + m_plate_impl.pack (id[m_PLATE_INDEX], result); + m_pmt_impl.pack (id[m_PMT_INDEX], result); + + // Do checks + if(m_do_checks) + { + pmt_id_checks ( id[m_STATION_INDEX], + id[m_PLATE_INDEX], + id[m_PMT_INDEX]); + } + return result; +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::pmt_id ( const Identifier& plate_id, int pmt ) const +{ + // Build identifier + Identifier result(plate_id); + + // Reset strip and then add in value + m_pmt_impl.reset (result); + m_pmt_impl.pack (pmt, result); + + if(m_do_checks) + { + pmt_id_checks ( station(result), + plate(result), + pmt ); + } + return result; +} + +//---------------------------------------------------------------------------- +inline Identifier::diff_type +VetoID::calc_offset(const Identifier& base, const Identifier& target) const +{ + Identifier::diff_type tval = static_cast<Identifier::diff_type>(target.get_compact() >> base_bit()); + Identifier::diff_type bval = static_cast<Identifier::diff_type>(base.get_compact() >> base_bit()); + return (tval - bval); +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::pmt_id_offset(const Identifier& base, + Identifier::diff_type offset) const +{ + Identifier::value_type bval = base.get_compact() >> base_bit(); + return Identifier((bval + offset) << base_bit()); +} + +//---------------------------------------------------------------------------- +inline int +VetoID::base_bit ( void ) const +{ + int base = static_cast<int>(m_pmt_impl.shift()); // lowest field base + return (base > 32) ? 32 : base; + // max base is 32 so we can still read old strip id's and differences + // from non-SLHC releases. +} + +//---------------------------------------------------------------------------- +inline IdContext +VetoID::plate_context (void) const +{ + ExpandedIdentifier id; + return (IdContext(id, 0, m_PLATE_INDEX)); +} + +//---------------------------------------------------------------------------- +inline IdContext +VetoID::pmt_context (void) const +{ + ExpandedIdentifier id; + return (IdContext(id, 0, m_PMT_INDEX)); +} + +//---------------------------------------------------------------------------- +inline int +VetoID::station (const Identifier& id) const +{ + return (m_station_impl.unpack(id)); +} + +//---------------------------------------------------------------------------- +inline int +VetoID::plate (const Identifier& id) const +{ + return (m_plate_impl.unpack(id)); +} + +//---------------------------------------------------------------------------- +inline int +VetoID::pmt (const Identifier& id) const +{ + return (m_pmt_impl.unpack(id)); +} + + +#endif // SCINTIDENTIFIER_VETOID_H diff --git a/Scintillator/ScintDetDescr/ScintIdentifier/src/VetoID.cxx b/Scintillator/ScintDetDescr/ScintIdentifier/src/VetoID.cxx new file mode 100644 index 0000000000000000000000000000000000000000..589c032d415689f952b361430da8cf63251d570c --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintIdentifier/src/VetoID.cxx @@ -0,0 +1,889 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +/*************************************************************************** + Scintillator identifier package + ------------------------------------------- +***************************************************************************/ + +//<<<<<< INCLUDES >>>>>> +#include "GaudiKernel/MsgStream.h" + +#include "ScintIdentifier/VetoID.h" +#include "Identifier/IdentifierHash.h" +#include "IdDict/IdDictDefs.h" +#include <set> +#include <algorithm> +#include <iostream> + +//<<<<<< PRIVATE DEFINES >>>>>> +//<<<<<< PRIVATE CONSTANTS >>>>>> +//<<<<<< PRIVATE TYPES >>>>>> +//<<<<<< PRIVATE VARIABLE DEFINITIONS >>>>>> +//<<<<<< PUBLIC VARIABLE DEFINITIONS >>>>>> +//<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>> +//<<<<<< PRIVATE FUNCTION DEFINITIONS >>>>>> +//<<<<<< PUBLIC FUNCTION DEFINITIONS >>>>>> +//<<<<<< MEMBER FUNCTION DEFINITIONS >>>>>> + + +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// + + +VetoID::VetoID(void) + : + m_veto_region_index(0), + m_SCINT_INDEX(0), + m_VETO_INDEX(1), + m_STATION_INDEX(2), + m_PLATE_INDEX(3), + m_PMT_INDEX(4), + m_dict(0), + m_plate_hash_max(0), + m_pmt_hash_max(0) +{ +} + +void +VetoID::plate_id_checks ( int station, + int plate ) const +{ + + // Check that id is within allowed range + + // Fill expanded id + ExpandedIdentifier id; + id << scint_field_value() << veto_field_value() + << station << plate; + + if (!m_full_plate_range.match(id)) { // module range check is sufficient + MsgStream log(m_msgSvc, "VetoID"); + log << MSG::ERROR << " VetoID::plate_id result is NOT ok. ID, range " + << (std::string)id << " " << (std::string)m_full_plate_range << endmsg; + } +} + +void +VetoID::pmt_id_checks ( int station, + int plate, + int pmt) const +{ + + // Check that id is within allowed range + + // Fill expanded id + ExpandedIdentifier id; + id << scint_field_value() << veto_field_value() + << station << plate << pmt; + + if (!m_full_pmt_range.match(id)) { + MsgStream log(m_msgSvc, "VetoID"); + log << MSG::ERROR << " VetoID::pmt_id result is NOT ok. ID, range " + << (std::string)id << " " << (std::string)m_full_pmt_range << std::endl; + } +} + +int +VetoID::station_max(const Identifier& id) const +{ + // get max from dictionary + ExpandedIdentifier expId; + IdContext plate_context1 = plate_context(); + get_expanded_id(id, expId, &plate_context1); + for (unsigned int i = 0; i < m_full_plate_range.size(); ++i) { + const Range& range = m_full_plate_range[i]; + if (range.match(expId)) { + const Range::field& station_field = range[m_STATION_INDEX]; + if (station_field.has_maximum()) { + return (station_field.get_maximum()); + } + } + } + return (-999); // default +} + +int +VetoID::pmt_max (const Identifier& id) const +{ + ExpandedIdentifier expId; + IdContext station_context(expId, 0, m_STATION_INDEX); + get_expanded_id(id, expId, &station_context); + int result = -999; + for (unsigned int i = 0; i < m_full_pmt_range.size(); ++i) { + const Range& range = m_full_pmt_range[i]; + if (range.match(expId)) { + const Range::field& pmt_field = range[m_PMT_INDEX]; + if (pmt_field.has_maximum()) { + int pmt = pmt_field.get_maximum(); + if (result < pmt) result = pmt; + } + } + } + return (result); +} + +int +VetoID::plate_max(const Identifier& id) const +{ + // get max from dictionary + ExpandedIdentifier expId; + IdContext plate_context1 = plate_context(); + get_expanded_id(id, expId, &plate_context1); + for (unsigned int i = 0; i < m_full_plate_range.size(); ++i) { + const Range& range = m_full_plate_range[i]; + if (range.match(expId)) { + const Range::field& plate_field = range[m_PLATE_INDEX]; + if (plate_field.has_maximum()) { + return (plate_field.get_maximum()); + } + } + } + return -1; +} + +int +VetoID::initialize_from_dictionary(const IdDictMgr& dict_mgr) +{ + MsgStream log(m_msgSvc, "VetoID"); + log << MSG::INFO << "Initialize from dictionary" << endmsg; + + // Check whether this helper should be reinitialized + if (!reinitialize(dict_mgr)) { + log << MSG::INFO << "Request to reinitialize not satisfied - tags have not changed" << endmsg; + return (0); + } + else { + if (m_msgSvc) { + log << MSG::DEBUG << "(Re)initialize" << endmsg; + } + else { + std::cout << " DEBUG (Re)initialize" << std::endl; + } + } + + // init base object + if(FaserDetectorID::initialize_from_dictionary(dict_mgr)) return (1); + + // Register version of InnerDetector dictionary + if (register_dict_tag(dict_mgr, "Scintillator")) return(1); + + m_dict = dict_mgr.find_dictionary ("Scintillator"); + if(!m_dict) { + log << MSG::ERROR << " VetoID::initialize_from_dict - cannot access Scintillator dictionary " << endmsg; + return 1; + } + + // Initialize the field indices + if(initLevelsFromDict()) return (1); + + // + // Build multirange for the valid set of identifiers + // + + + // Find value for the field Scintillator + const IdDictDictionary* faserDict = dict_mgr.find_dictionary ("FASER"); + int scintField = -1; + if (faserDict->get_label_value("subdet", "Scintillator", scintField)) { + log << MSG::ERROR << "Could not get value for label 'Scintillator' of field 'subdet' in dictionary " + << faserDict->m_name + << endmsg; + return (1); + } + + // Find value for the field Veto + int vetoField = -1; + if (m_dict->get_label_value("part", "Veto", vetoField)) { + log << MSG::ERROR << "Could not get value for label 'Veto' of field 'part' in dictionary " + << m_dict->m_name + << endmsg; + return (1); + } + if (m_msgSvc) { + log << MSG::DEBUG << " VetoID::initialize_from_dict " + << "Found field values: Veto " + << vetoField + << std::endl; + } + else { + std::cout << " DEBUG VetoID::initialize_from_dict " + << "Found field values: Veto " + << vetoField + << std::endl; + } + + // Set up id for region and range prefix + ExpandedIdentifier region_id; + region_id.add(scintField); + region_id.add(vetoField); + Range prefix; + m_full_plate_range = m_dict->build_multirange(region_id, prefix, "plate"); + m_full_pmt_range = m_dict->build_multirange(region_id, prefix); + + // Setup the hash tables + if(init_hashes()) return (1); + + // Setup hash tables for finding neighbors + if(init_neighbors()) return (1); + + if (m_msgSvc) { + log << MSG::INFO << " VetoID::initialize_from_dict " << endmsg; + log << MSG::DEBUG + << "Plate range -> " << (std::string)m_full_plate_range + << endmsg; + log << MSG::DEBUG + << "Pmt range -> " << (std::string)m_full_pmt_range + << endmsg; + } + else { + std::cout << " INFO VetoID::initialize_from_dict " << std::endl; + std::cout << " DEBUG Plate range -> " << (std::string)m_full_plate_range + << std::endl; + std::cout << " DEBUG Pmt range -> " << (std::string)m_full_pmt_range + << std::endl; + } + + return 0; +} + +int +VetoID::init_hashes(void) +{ + + // + // create a vector(s) to retrieve the hashes for compact ids. For + // the moment, we implement a hash for plates but NOT for pmts + // + MsgStream log(m_msgSvc, "VetoID"); + // plate hash + m_plate_hash_max = m_full_plate_range.cardinality(); + m_plate_vec.resize(m_plate_hash_max); + unsigned int nids = 0; + std::set<Identifier> ids; + for (unsigned int i = 0; i < m_full_plate_range.size(); ++i) { + const Range& range = m_full_plate_range[i]; + Range::const_identifier_factory first = range.factory_begin(); + Range::const_identifier_factory last = range.factory_end(); + for (; first != last; ++first) { + const ExpandedIdentifier& exp_id = (*first); + Identifier id = plate_id(exp_id[m_STATION_INDEX], + exp_id[m_PLATE_INDEX]); + if(!(ids.insert(id)).second) { + log << MSG::ERROR << " VetoID::init_hashes " + << " Error: duplicated id for plate id. nid " << nids + << " compact id " << id.getString() + << " id " << (std::string)exp_id << endmsg; + return (1); + } + nids++; + } + } + if(ids.size() != m_plate_hash_max) { + log << MSG::ERROR << " VetoID::init_hashes " + << " Error: set size NOT EQUAL to hash max. size " << ids.size() + << " hash max " << m_plate_hash_max + << endmsg; + return (1); + } + + nids = 0; + std::set<Identifier>::const_iterator first = ids.begin(); + std::set<Identifier>::const_iterator last = ids.end(); + for (; first != last && nids < m_plate_vec.size(); ++first) { + m_plate_vec[nids] = (*first); + nids++; + } + + // pmt hash - we do not keep a vec for the pmts + m_pmt_hash_max = m_full_pmt_range.cardinality(); + + return (0); +} + +// int +// VetoID::get_prev_in_phi(const IdentifierHash& id, IdentifierHash& prev) const +// { +// unsigned short index = id; +// if (index < m_prev_phi_wafer_vec.size()) { +// if (m_prev_phi_wafer_vec[index] == NOT_VALID_HASH) return (1); +// prev = m_prev_phi_wafer_vec[index]; +// return (0); +// } +// return (1); +// } + +// int +// VetoID::get_next_in_phi(const IdentifierHash& id, IdentifierHash& next) const +// { +// unsigned short index = id; +// if (index < m_next_phi_wafer_vec.size()) { +// if (m_next_phi_wafer_vec[index] == NOT_VALID_HASH) return (1); +// next = m_next_phi_wafer_vec[index]; +// return (0); +// } +// return (1); +// } + +// int +// VetoID::get_prev_in_eta(const IdentifierHash& id, IdentifierHash& prev) const +// { +// unsigned short index = id; +// if (index < m_prev_eta_wafer_vec.size()) { +// if (m_prev_eta_wafer_vec[index] == NOT_VALID_HASH) return (1); +// prev = m_prev_eta_wafer_vec[index]; +// return (0); +// } +// return (1); +// } + +// int +// VetoID::get_next_in_eta(const IdentifierHash& id, IdentifierHash& next) const +// { +// unsigned short index = id; +// if (index < m_next_eta_wafer_vec.size()) { +// if (m_next_eta_wafer_vec[index] == NOT_VALID_HASH) return (1); +// next = m_next_eta_wafer_vec[index]; +// return (0); +// } +// return (1); +// } + +// int +// VetoID::get_other_side (const IdentifierHash& hashId, IdentifierHash& other) const +// { +// if (m_dict) { +// // get max from dictionary +// Identifier id; +// IdContext wafer_context1 = wafer_context(); +// if(!get_id(hashId, id, &wafer_context1)) { +// other = side(id) ? hashId - 1 : hashId + 1; +// return (0); +// } +// } +// return (1); +// } + +int +VetoID::init_neighbors(void) +{ + // + // create a vector(s) to retrieve the hashes for compact ids for + // wafer neighbors. + // + + MsgStream log(m_msgSvc, "VetoID"); + if (m_msgSvc) { + log << MSG::DEBUG << "VetoID::init_neighbors not yet implemented" << endmsg; + } + else { + std::cout << " DEBUG VetoID::init_neighbors not yet implemented" << std::endl; + } + + + // m_prev_phi_wafer_vec.resize(m_wafer_hash_max, NOT_VALID_HASH); + // m_next_phi_wafer_vec.resize(m_wafer_hash_max, NOT_VALID_HASH); + // m_prev_eta_wafer_vec.resize(m_wafer_hash_max, NOT_VALID_HASH); + // m_next_eta_wafer_vec.resize(m_wafer_hash_max, NOT_VALID_HASH); + + // for (unsigned int i = 0; i < m_full_wafer_range.size(); ++i) { + // const Range& range = m_full_wafer_range[i]; + // const Range::field& phi_field = range[m_PHI_MODULE_INDEX]; + // const Range::field& eta_field = range[m_ETA_MODULE_INDEX]; + // Range::const_identifier_factory first = range.factory_begin(); + // Range::const_identifier_factory last = range.factory_end(); + // for (; first != last; ++first) { + // const ExpandedIdentifier& exp_id = (*first); + // ExpandedIdentifier::element_type previous_phi; + // ExpandedIdentifier::element_type next_phi; + // ExpandedIdentifier::element_type previous_eta; + // ExpandedIdentifier::element_type next_eta; + // bool pphi = phi_field.get_previous(exp_id[m_PHI_MODULE_INDEX], previous_phi); + // bool nphi = phi_field.get_next (exp_id[m_PHI_MODULE_INDEX], next_phi); + // bool peta = eta_field.get_previous(exp_id[m_ETA_MODULE_INDEX], previous_eta); + // bool neta = eta_field.get_next (exp_id[m_ETA_MODULE_INDEX], next_eta); + + // IdContext wcontext = wafer_context(); + + // // First get primary hash id + // IdentifierHash hash_id; + // Identifier id = wafer_id(exp_id[m_BARREL_EC_INDEX], + // exp_id[m_LAYER_DISK_INDEX], + // exp_id[m_PHI_MODULE_INDEX], + // exp_id[m_ETA_MODULE_INDEX], + // exp_id[m_SIDE_INDEX]); + // if (get_hash(id, hash_id, &wcontext)) { + // log << MSG::ERROR << " VetoID::init_neighbors - unable to get hash, exp/compact " + // << show_to_string(id, &wcontext) + // << " " << (std::string)m_full_wafer_range << endmsg; + // return (1); + // } + + // // index for the subsequent arrays + // unsigned short index = hash_id; + // assert (hash_id < m_prev_phi_wafer_vec.size()); + // assert (hash_id < m_next_phi_wafer_vec.size()); + // assert (hash_id < m_prev_eta_wafer_vec.size()); + // assert (hash_id < m_next_eta_wafer_vec.size()); + + // if (pphi) { + // // Get previous phi hash id + // ExpandedIdentifier expId = exp_id; + // expId[m_PHI_MODULE_INDEX] = previous_phi; + // Identifier id = wafer_id(expId[m_BARREL_EC_INDEX], + // expId[m_LAYER_DISK_INDEX], + // expId[m_PHI_MODULE_INDEX], + // expId[m_ETA_MODULE_INDEX], + // expId[m_SIDE_INDEX]); + // if (get_hash(id, hash_id, &wcontext)) { + // log << MSG::ERROR << " VetoID::init_neighbors - unable to get previous phi hash, exp/compact " << id.getString() << " " + // << endmsg; + // return (1); + // } + // m_prev_phi_wafer_vec[index] = hash_id; + // } + + // if (nphi) { + // // Get next phi hash id + // ExpandedIdentifier expId = exp_id; + // expId[m_PHI_MODULE_INDEX] = next_phi; + // Identifier id = wafer_id(expId[m_BARREL_EC_INDEX], + // expId[m_LAYER_DISK_INDEX], + // expId[m_PHI_MODULE_INDEX], + // expId[m_ETA_MODULE_INDEX], + // expId[m_SIDE_INDEX]); + // if (get_hash(id, hash_id, &wcontext)) { + // log << MSG::ERROR << " VetoID::init_neighbors - unable to get next phi hash, exp/compact " << id.getString() << + // " " << MSG::hex << id.getString() << MSG::dec << endmsg; + // return (1); + // } + // m_next_phi_wafer_vec[index] = hash_id; + // } + + // if (peta) { + // // Get previous eta hash id + // ExpandedIdentifier expId = exp_id; + // expId[m_ETA_MODULE_INDEX] = previous_eta; + // Identifier id = wafer_id(expId[m_BARREL_EC_INDEX], + // expId[m_LAYER_DISK_INDEX], + // expId[m_PHI_MODULE_INDEX], + // expId[m_ETA_MODULE_INDEX], + // expId[m_SIDE_INDEX]); + // if (get_hash(id, hash_id, &wcontext)) { + // log << MSG::ERROR << " VetoID::init_neighbors - unable to get previous eta hash, exp/compact " << id.getString() + // << " " << std::endl; + // return (1); + // } + // m_prev_eta_wafer_vec[index] = hash_id; + // } + + // if (neta) { + // // Get next eta hash id + // ExpandedIdentifier expId = exp_id; + // expId[m_ETA_MODULE_INDEX] = next_eta; + // Identifier id = wafer_id(expId[m_BARREL_EC_INDEX], + // expId[m_LAYER_DISK_INDEX], + // expId[m_PHI_MODULE_INDEX], + // expId[m_ETA_MODULE_INDEX], + // expId[m_SIDE_INDEX]); + // if (get_hash(id, hash_id, &wcontext)) { + // log << MSG::ERROR << " VetoID::init_neighbors - unable to get next eta hash, exp/compact " << id.getString() + // << " " << endmsg; + // return (1); + // } + // m_next_eta_wafer_vec[index] = hash_id; + // } + + +// std::cout << " VetoID::init_neighbors " +// << " phi, previous, next " << id[m_PHI_MODULE_INDEX] +// << " " << pphi +// << " " << previous_phi +// << " " << nphi +// << " " << next_phi +// << " eta, previous, next " << id[m_ETA_MODULE_INDEX] +// << " " << peta +// << " " << previous_eta +// << " " << neta +// << " " << next_eta +// << " id " << (std::string)(*first) +// << std::endl; + // } + // } + return (0); +} + + + +int +VetoID::initLevelsFromDict() +{ + + + MsgStream log(m_msgSvc, "VetoID"); + if(!m_dict) { + log << MSG::ERROR << " VetoID::initLevelsFromDict - dictionary NOT initialized " << endmsg; + return (1); + } + + // Find out which identifier field corresponds to each level. Use + // names to find each field/leve. + + m_SCINT_INDEX = 999; + m_VETO_INDEX = 999; + m_STATION_INDEX = 999; + m_PLATE_INDEX = 999; + m_PMT_INDEX = 999; + + // Save index to a Veto region for unpacking + ExpandedIdentifier id; + id << scint_field_value() << veto_field_value(); + if (m_dict->find_region(id, m_veto_region_index)) { + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find veto region index: id, reg " + << (std::string)id << " " << m_veto_region_index + << endmsg; + return (1); + } + + // Find a Veto region + IdDictField* field = m_dict->find_field("subdet"); + if (field) { + m_SCINT_INDEX = field->m_index; + } + else { + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'subdet' field " << endmsg; + return (1); + } + field = m_dict->find_field("part"); + if (field) { + m_VETO_INDEX = field->m_index; + } + else { + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'part' field " << endmsg; + return (1); + } + field = m_dict->find_field("station"); + if (field) { + m_STATION_INDEX = field->m_index; + } + else { + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'station' field " << endmsg; + return (1); + } + field = m_dict->find_field("plate"); + if (field) { + m_PLATE_INDEX = field->m_index; + } + else { + log << MSG::ERROR<< "VetoID::initLevelsFromDict - unable to find 'plate' field " << endmsg; + return (1); + } + field = m_dict->find_field("pmt"); + if (field) { + m_PMT_INDEX = field->m_index; + } + else { + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'pmt' field " << endmsg; + return (1); + } + + // Set the field implementations + + const IdDictRegion& region = *m_dict->m_regions[m_veto_region_index]; + + m_scint_impl = region.m_implementation[m_SCINT_INDEX]; + m_veto_impl = region.m_implementation[m_VETO_INDEX]; + m_station_impl = region.m_implementation[m_STATION_INDEX]; + m_plate_impl = region.m_implementation[m_PLATE_INDEX]; + m_pmt_impl = region.m_implementation[m_PMT_INDEX]; + + if (m_msgSvc) { + log << MSG::DEBUG << "decode index and bit fields for each level: " << endmsg; + log << MSG::DEBUG << "scint " << m_scint_impl.show_to_string() << endmsg; + log << MSG::DEBUG << "veto " << m_veto_impl.show_to_string() << endmsg; + log << MSG::DEBUG << "station " << m_station_impl.show_to_string() << endmsg; + log << MSG::DEBUG << "plate " << m_plate_impl.show_to_string() << endmsg; + log << MSG::DEBUG << "pmt " << m_pmt_impl.show_to_string() << endmsg; + } + else { + std::cout << " DEBUG decode index and bit fields for each level: " << std::endl; + std::cout << " DEBUG scint " << m_scint_impl.show_to_string() << std::endl; + std::cout << " DEBUG veto " << m_veto_impl.show_to_string() << std::endl; + std::cout << " DEBUG station " << m_station_impl.show_to_string() << std::endl; + std::cout << " DEBUG plate " << m_plate_impl.show_to_string() << std::endl; + std::cout << " DEBUG pmt " << m_pmt_impl.show_to_string() << std::endl; + } + +// std::cout << "VetoID::initLevelsFromDict - found levels " << std::endl; +// std::cout << "subdet " << m_INDET_INDEX << std::endl; +// std::cout << "part " << m_SCT_INDEX << std::endl; +// std::cout << "barrel_endcap " << m_BARREL_EC_INDEX << std::endl; +// std::cout << "layer or disk " << m_LAYER_DISK_INDEX << std::endl; +// std::cout << "phi_module " << m_PHI_MODULE_INDEX << std::endl; +// std::cout << "eta_module " << m_ETA_MODULE_INDEX << std::endl; +// std::cout << "side " << m_SIDE_INDEX << std::endl; +// std::cout << "strip " << m_STRIP_INDEX << std::endl; + + std::cout << "scint " << m_scint_impl.decode_index() << " " + << (std::string)m_scint_impl.ored_field() << " " + << std::hex << m_scint_impl.mask() << " " + << m_scint_impl.zeroing_mask() << " " + << std::dec << m_scint_impl.shift() << " " + << m_scint_impl.bits() << " " + << m_scint_impl.bits_offset() + << std::endl; + std::cout << "veto" << m_veto_impl.decode_index() << " " + << (std::string)m_veto_impl.ored_field() << " " + << std::hex << m_veto_impl.mask() << " " + << m_veto_impl.zeroing_mask() << " " + << std::dec << m_veto_impl.shift() << " " + << m_veto_impl.bits() << " " + << m_veto_impl.bits_offset() + << std::endl; + std::cout << "station"<< m_station_impl.decode_index() << " " + << (std::string)m_station_impl.ored_field() << " " + << std::hex << m_station_impl.mask() << " " + << m_station_impl.zeroing_mask() << " " + << std::dec << m_station_impl.shift() << " " + << m_station_impl.bits() << " " + << m_station_impl.bits_offset() + << std::endl; + std::cout << "plate" << m_plate_impl.decode_index() << " " + << (std::string)m_plate_impl.ored_field() << " " + << std::hex << m_plate_impl.mask() << " " + << m_plate_impl.zeroing_mask() << " " + << std::dec << m_plate_impl.shift() << " " + << m_plate_impl.bits() << " " + << m_plate_impl.bits_offset() + << std::endl; + std::cout << "pmt" << m_pmt_impl.decode_index() << " " + << (std::string)m_pmt_impl.ored_field() << " " + << std::hex << m_pmt_impl.mask() << " " + << m_pmt_impl.zeroing_mask() << " " + << std::dec << m_pmt_impl.shift() << " " + << m_pmt_impl.bits() << " " + << m_pmt_impl.bits_offset() + << std::endl; + + return (0); +} + +VetoID::size_type +VetoID::plate_hash_max (void) const +{ + return m_plate_hash_max; +} + +VetoID::size_type +VetoID::pmt_hash_max (void) const +{ + return m_pmt_hash_max; +} + +VetoID::const_id_iterator VetoID::plate_begin (void) const +{ + return (m_plate_vec.begin()); +} + +VetoID::const_id_iterator VetoID::plate_end (void) const +{ + return (m_plate_vec.end()); +} + +VetoID::const_expanded_id_iterator VetoID::pmt_begin (void) const +{ + return (m_full_pmt_range.factory_begin()); +} + +VetoID::const_expanded_id_iterator VetoID::pmt_end (void) const +{ + return (m_full_pmt_range.factory_end()); +} + +// From hash get Identifier +int +VetoID::get_id (const IdentifierHash& hash_id, + Identifier& id, + const IdContext* context) const +{ + + int result = 1; + id.clear(); + + size_t begin = (context) ? context->begin_index(): 0; + // cannot get hash if end is 0: + size_t end = (context) ? context->end_index() : 0; + if (0 == begin) { + // No hashes yet for ids with prefixes + if (m_PLATE_INDEX == end) { + if (hash_id < (unsigned int)(m_plate_vec.end() - m_plate_vec.begin())) { + id = m_plate_vec[hash_id]; + result = 0; + } + } + else if (m_PMT_INDEX == end) { + // Do not know how to calculate strip id from hash yet!! + std::cout << "Do not know how to calculate pmt id from hash yet!!" << std::endl; + } + } + return (result); +} + +void +VetoID::get_expanded_id (const Identifier& id, + ExpandedIdentifier& exp_id, + const IdContext* context) const +{ + exp_id.clear(); + exp_id << scint_field_value() + << veto_field_value() + << station(id) + << plate(id); + if(!context || context->end_index() == m_PMT_INDEX) + { + exp_id << pmt(id); + } +} + +int +VetoID::get_hash (const Identifier& id, + IdentifierHash& hash_id, + const IdContext* context) const +{ + + // Get the hash code from either a vec (for plate) or calculate + // it (pmts). For the former, we convert to compact and call + // get_hash again. For the latter, we calculate the hash from the + // Identifier. + + int result = 1; + hash_id = 0; + size_t begin = (context) ? context->begin_index(): 0; + size_t end = (context) ? context->end_index() : 0; + if (0 == begin) { + // No hashes yet for ids with prefixes + if (m_PLATE_INDEX == end) { + hash_id = plate_hash(id); + if (hash_id.is_valid()) result = 0; + } + else if (context && context->end_index() == m_PMT_INDEX) { + // Must calculate for strip hash + ExpandedIdentifier new_id; + get_expanded_id(id, new_id); + hash_id = m_full_pmt_range.cardinalityUpTo(new_id); + result = 0; + } + } + return (result); +} + + +void +VetoID::test_plate_packing (void) const +{ + MsgStream log(m_msgSvc, "VetoID"); + + if (m_dict) { + + int nids = 0; + int nerr = 0; + IdContext context = plate_context(); + const_id_iterator first = m_plate_vec.begin(); + const_id_iterator last = m_plate_vec.end(); + for (; first != last; ++first, ++nids) { + Identifier id = (*first); + ExpandedIdentifier exp_id; + get_expanded_id(id, exp_id, &context); + Identifier new_id = plate_id(exp_id[m_STATION_INDEX], + exp_id[m_PLATE_INDEX]); + if (id != new_id) { + log << MSG::ERROR << "VetoID::test_plate_packing: new and old compacts not equal. New/old/expanded ids " + << MSG::hex << show_to_string(id) << " " << show_to_string(new_id) << " " << MSG::dec + << (std::string)exp_id << endmsg; + nerr++; + continue; + } + // check station id + if (!exp_id[m_PLATE_INDEX]) { + + Identifier new_id1 = station_id(exp_id[m_STATION_INDEX]); + if (id != new_id1) { + log << MSG::ERROR << "VetoID::test_plate_packing: new and old station ids not equal. New/old/expanded ids " + << MSG::hex << show_to_string(id) << " " << show_to_string(new_id1) << " " << MSG::dec + << (std::string)exp_id << endmsg; + nerr++; + continue; + } + } + } + + if (m_msgSvc) { + log << MSG::DEBUG << "VetoID::test_plate_packing: tested plate and station ids. nids, errors " + << nids << " " << nerr << endmsg; + } + else { + std::cout << " DEBUG VetoID::test_plate_packing: tested plate and station ids. nids, errors " + << nids << " " << nerr << std::endl; + } + + nids = 0; + context = pmt_context(); + const_expanded_id_iterator first_veto = pmt_begin(); + const_expanded_id_iterator last_veto = pmt_end(); + for (; first_veto != last_veto; ++first_veto, ++nids) { + if (nids%10000 != 1) continue; + const ExpandedIdentifier& exp_id = *first_veto; + ExpandedIdentifier new_exp_id; + + Identifier id = plate_id(exp_id[m_STATION_INDEX], + exp_id[m_PLATE_INDEX]); + get_expanded_id(id, new_exp_id, &context); + if (exp_id[0] != new_exp_id[0] || + exp_id[1] != new_exp_id[1] || + exp_id[2] != new_exp_id[2] || + exp_id[3] != new_exp_id[3] || + exp_id[4] != new_exp_id[4]) { + log << MSG::ERROR << "VetoID::test_plate_packing: new and old ids not equal. New/old/compact ids " + << (std::string)new_exp_id << " " << (std::string)exp_id + << " " << show_to_string(id) << endmsg; + continue; + } + + Identifier pmtid ; + Identifier pmtid1 ; + pmtid = pmt_id ( + exp_id[m_STATION_INDEX], + exp_id[m_PLATE_INDEX], + exp_id[m_PMT_INDEX]); + + pmtid1 = pmt_id ( + station(pmtid), + plate(pmtid), + pmt(pmtid)); + + if (pmtid != pmtid1) { + log << MSG::ERROR << "VetoID::test_plate_packing: new and old pixel ids not equal. New/old ids " + << " " << show_to_string(pmtid1) << " " + << show_to_string(pmtid) << endmsg; + } + } + + if (m_msgSvc) { + log << MSG::DEBUG << "VetoID::test_plate_packing: Successful tested " + << nids << " ids. " + << endmsg; + } + else { + std::cout << " DEBUG VetoID::test_plate_packing: Successful tested " + << nids << " ids. " + << std::endl; + } + } + else { + log << MSG::ERROR << "VetoID::test_plate_packing: Unable to test plate packing - no dictionary has been defined. " + << endmsg; + } +} + diff --git a/Scintillator/ScintDetDescrCnv/ScintIdCnv/CMakeLists.txt b/Scintillator/ScintDetDescrCnv/ScintIdCnv/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..07a22222000efd637c17104579776ca6bd6c38ea --- /dev/null +++ b/Scintillator/ScintDetDescrCnv/ScintIdCnv/CMakeLists.txt @@ -0,0 +1,23 @@ +################################################################################ +# Package: ScintIdCnv +################################################################################ + +# Declare the package name: +atlas_subdir( ScintIdCnv ) + +# Declare the package's dependencies: +atlas_depends_on_subdirs( PRIVATE + Control/StoreGate + DetectorDescription/DetDescrCnvSvc + DetectorDescription/IdDictDetDescr + GaudiKernel + Scintillator/ScintDetDescr/ScintIdentifier ) + +# Component(s) in the package: +atlas_add_component( ScintIdCnv + src/*.cxx + LINK_LIBRARIES StoreGateLib SGtests DetDescrCnvSvcLib IdDictDetDescr GaudiKernel ScintIdentifier ) + +# Install files from the package: +atlas_install_joboptions( share/*.py ) + diff --git a/Scintillator/ScintDetDescrCnv/ScintIdCnv/share/ScintIdCnv_jobOptions.py b/Scintillator/ScintDetDescrCnv/ScintIdCnv/share/ScintIdCnv_jobOptions.py new file mode 100644 index 0000000000000000000000000000000000000000..a5d750a92fcb87a90d0ba60c47aad8d8c1da4cdb --- /dev/null +++ b/Scintillator/ScintDetDescrCnv/ScintIdCnv/share/ScintIdCnv_jobOptions.py @@ -0,0 +1,6 @@ +# +# Joboptions for the loading of the of ScintIdCnv +# + +# DLLs +theApp.Dlls += [ "ScintIdCnv" ] diff --git a/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/ScintIdCnv_entries.cxx b/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/ScintIdCnv_entries.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6c2fee3310e2db91d2dd59fd532990b60ec4057c --- /dev/null +++ b/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/ScintIdCnv_entries.cxx @@ -0,0 +1,11 @@ +// #include "PixelIDDetDescrCnv.h" +// #include "SCT_IDDetDescrCnv.h" +// #include "SiliconIDDetDescrCnv.h" +// #include "TRT_IDDetDescrCnv.h" +#include "VetoIDDetDescrCnv.h" + +// DECLARE_CONVERTER(SCT_IDDetDescrCnv) +// DECLARE_CONVERTER(PixelIDDetDescrCnv) +// DECLARE_CONVERTER(SiliconIDDetDescrCnv) +// DECLARE_CONVERTER(TRT_IDDetDescrCnv) +DECLARE_CONVERTER(VetoIDDetDescrCnv) diff --git a/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/VetoIDDetDescrCnv.cxx b/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/VetoIDDetDescrCnv.cxx new file mode 100644 index 0000000000000000000000000000000000000000..bc84cdae1665010a4e7f905e66cf05a747c87510 --- /dev/null +++ b/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/VetoIDDetDescrCnv.cxx @@ -0,0 +1,239 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/*************************************************************************** + Scint DetDescrCnv package + ----------------------------------------- + ***************************************************************************/ + +//<<<<<< INCLUDES >>>>>> + +#include "VetoIDDetDescrCnv.h" + +#include "DetDescrCnvSvc/DetDescrConverter.h" +#include "DetDescrCnvSvc/DetDescrAddress.h" +#include "GaudiKernel/MsgStream.h" +#include "StoreGate/StoreGate.h" + +#include "IdDictDetDescr/IdDictManager.h" +#include "ScintIdentifier/VetoID.h" + + +//<<<<<< PRIVATE DEFINES >>>>>> +//<<<<<< PRIVATE CONSTANTS >>>>>> +//<<<<<< PRIVATE TYPES >>>>>> +//<<<<<< PRIVATE VARIABLE DEFINITIONS >>>>>> +//<<<<<< PUBLIC VARIABLE DEFINITIONS >>>>>> +//<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>> +//<<<<<< PRIVATE FUNCTION DEFINITIONS >>>>>> +//<<<<<< PUBLIC FUNCTION DEFINITIONS >>>>>> +//<<<<<< MEMBER FUNCTION DEFINITIONS >>>>>> + +//-------------------------------------------------------------------- + +long int +VetoIDDetDescrCnv::repSvcType() const +{ + return (storageType()); +} + +//-------------------------------------------------------------------- + +StatusCode +VetoIDDetDescrCnv::initialize() +{ + // First call parent init + StatusCode sc = DetDescrConverter::initialize(); + MsgStream log(msgSvc(), "VetoIDDetDescrCnv"); + log << MSG::DEBUG << "in initialize" << endmsg; + + if (sc.isFailure()) { + log << MSG::ERROR << "DetDescrConverter::initialize failed" << endmsg; + return sc; + } + + // The following is an attempt to "bootstrap" the loading of a + // proxy for SCT_ID into the detector store. However, + // SCT_IDDetDescrCnv::initialize is NOT called by the conversion + // service. So for the moment, this cannot be use. Instead the + // DetDescrCnvSvc must do the bootstrap from a parameter list. + + +// // Add InDet_DetDescrManager proxy as entry point to the detector store +// // - this is ONLY needed for the manager of each system +// sc = addToDetStore(classID(), "PidelID"); +// if (sc.isFailure()) { +// log << MSG::FATAL << "Unable to add proxy for SCT_ID to the Detector Store!" << endmsg; +// return StatusCode::FAILURE; +// } else {} + + return StatusCode::SUCCESS; +} + +//-------------------------------------------------------------------- + +StatusCode +VetoIDDetDescrCnv::finalize() +{ + MsgStream log(msgSvc(), "VetoIDDetDescrCnv"); + log << MSG::DEBUG << "in finalize" << endmsg; + + return StatusCode::SUCCESS; +} + +//-------------------------------------------------------------------- + +StatusCode +VetoIDDetDescrCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) +{ + //StatusCode sc = StatusCode::SUCCESS; + MsgStream log(msgSvc(), "VetoIDDetDescrCnv"); + log << MSG::INFO << "in createObj: creating a VetoID helper object in the detector store" << endmsg; + + // Create a new VetoID + + DetDescrAddress* ddAddr; + ddAddr = dynamic_cast<DetDescrAddress*> (pAddr); + if(!ddAddr) { + log << MSG::FATAL << "Could not cast to DetDescrAddress." << endmsg; + return StatusCode::FAILURE; + } + + // Get the StoreGate key of this container. + std::string helperKey = *( ddAddr->par() ); + if ("" == helperKey) { + log << MSG::DEBUG << "No Helper key " << endmsg; + } + else { + log << MSG::DEBUG << "Helper key is " << helperKey << endmsg; + } + + + // get DetectorStore service + StoreGateSvc * detStore; + StatusCode status = serviceLocator()->service("DetectorStore", detStore); + if (status.isFailure()) { + log << MSG::FATAL << "DetectorStore service not found !" << endmsg; + return StatusCode::FAILURE; + } else {} + + // Get the dictionary manager from the detector store + const DataHandle<IdDictManager> idDictMgr; + status = detStore->retrieve(idDictMgr, "IdDict"); + if (status.isFailure()) { + log << MSG::FATAL << "Could not get IdDictManager !" << endmsg; + return StatusCode::FAILURE; + } + else { + log << MSG::DEBUG << " Found the IdDictManager. " << endmsg; + } + + // Only create new helper if it is the first pass or if there is a + // change in the the file or tag + bool initHelper = false; + + const IdDictMgr* mgr = idDictMgr->manager(); + + // Internal InDet id tag + std::string scintIDTag = mgr->tag(); + + // DoChecks flag + bool doChecks = mgr->do_checks(); + + IdDictDictionary* dict = mgr->find_dictionary("Scintillator"); + if (!dict) { + log << MSG::ERROR + << "unable to find idDict for Scintillator" + << endmsg; + return StatusCode::FAILURE; + } + + // File to be read for InDet ids + std::string scintIDFileName = dict->file_name(); + + // Tag of RDB record for InDet ids + std::string scintIdDictTag = dict->dict_tag(); + + + if (m_vetoId) { + + // Veto id helper already exists - second pass. Check for a + // change + if (scintIDTag != m_scintIDTag) { + // Internal InDet id tag + initHelper = true; + log << MSG::DEBUG << " Changed internal Scint id tag: " + << scintIDTag << endmsg; + } + if (scintIDFileName != m_scintIDFileName) { + // File to be read for Scint ids + initHelper = true; + log << MSG::DEBUG << " Changed ScintFileName:" + << scintIDFileName << endmsg; + } + if (scintIdDictTag != m_scintIdDictTag) { + // Tag of RDB record for Scint ids + initHelper = true; + log << MSG::DEBUG << " Changed ScintIdDictTag: " + << scintIdDictTag + << endmsg; + } + if (doChecks != m_doChecks) { + // DoChecks flag + initHelper = true; + log << MSG::DEBUG << " Changed doChecks flag: " + << doChecks + << endmsg; + } + } + else { + // create the helper + m_vetoId = new VetoID; + initHelper = true; + // add in message service for printout + m_vetoId->setMessageSvc(msgSvc()); + } + + if (initHelper) { + if (idDictMgr->initializeHelper(*m_vetoId)) { + log << MSG::ERROR << "Unable to initialize VetoID" << endmsg; + return StatusCode::FAILURE; + } + // Save state: + m_scintIDTag = scintIDTag; + m_scintIDFileName = scintIDFileName; + m_scintIdDictTag = scintIdDictTag; + m_doChecks = doChecks; + } + + // Pass a pointer to the container to the Persistency service by reference. + pObj = StoreGateSvc::asStorable(m_vetoId); + + return StatusCode::SUCCESS; + +} + +//-------------------------------------------------------------------- + +long +VetoIDDetDescrCnv::storageType() +{ + return DetDescr_StorageType; +} + +//-------------------------------------------------------------------- +const CLID& +VetoIDDetDescrCnv::classID() { + return ClassID_traits<VetoID>::ID(); +} + +//-------------------------------------------------------------------- +VetoIDDetDescrCnv::VetoIDDetDescrCnv(ISvcLocator* svcloc) + : + DetDescrConverter(ClassID_traits<VetoID>::ID(), svcloc), + m_vetoId(0), + m_doChecks(false) + +{} + diff --git a/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/VetoIDDetDescrCnv.h b/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/VetoIDDetDescrCnv.h new file mode 100644 index 0000000000000000000000000000000000000000..89be75c3a577671aad8e21dc71b40e6b0b88c7c0 --- /dev/null +++ b/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/VetoIDDetDescrCnv.h @@ -0,0 +1,71 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/*************************************************************************** + Scint DetDescrCnv package + ----------------------------------------- + ***************************************************************************/ + +#ifndef SCINTIDCNV_VETOIDDETDESCRCNV_H +#define SCINTIDCNV_VETOIDDETDESCRCNV_H + +//<<<<<< INCLUDES >>>>>> + +#include "DetDescrCnvSvc/DetDescrConverter.h" + +//<<<<<< PUBLIC DEFINES >>>>>> +//<<<<<< PUBLIC CONSTANTS >>>>>> +//<<<<<< PUBLIC TYPES >>>>>> + +class VetoID; + +//<<<<<< PUBLIC VARIABLES >>>>>> +//<<<<<< PUBLIC FUNCTIONS >>>>>> +//<<<<<< CLASS DECLARATIONS >>>>>> + + +/** + ** This class is a converter for the SCT_ID an IdHelper which is + ** stored in the detector store. This class derives from + ** DetDescrConverter which is a converter of the DetDescrCnvSvc. + ** + **/ + +class VetoIDDetDescrCnv: public DetDescrConverter { + +public: + virtual long int repSvcType() const; + virtual StatusCode initialize(); + virtual StatusCode finalize(); + virtual StatusCode createObj(IOpaqueAddress* pAddr, DataObject*& pObj); + + // Storage type and class ID (used by CnvFactory) + static long storageType(); + static const CLID& classID(); + + VetoIDDetDescrCnv(ISvcLocator* svcloc); + +private: + /// The helper - only will create it once + VetoID* m_vetoId; + + /// File to be read for InDet ids + std::string m_scintIDFileName; + + /// Tag of RDB record for InDet ids + std::string m_scintIdDictTag; + + /// Internal InDet id tag + std::string m_scintIDTag; + + /// Whether or not + bool m_doChecks; + +}; + + +//<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> +//<<<<<< INLINE MEMBER FUNCTIONS >>>>>> + +#endif // SCINTIDCNV_VETOIDDETDESCRCNV_H