diff --git a/Scintillator/ScintDetDescr/ScintIdentifier/ScintIdentifier/VetoID.h b/Scintillator/ScintDetDescr/ScintIdentifier/ScintIdentifier/VetoID.h index 5c247935197cce646371d8fb89965a67a19ed4f1..4565ce2662dd3a57a68f8037bcb5c5ae54d59199 100644 --- a/Scintillator/ScintDetDescr/ScintIdentifier/ScintIdentifier/VetoID.h +++ b/Scintillator/ScintDetDescr/ScintIdentifier/ScintIdentifier/VetoID.h @@ -91,9 +91,6 @@ public: /// For a single plate from a PMT id Identifier plate_id ( const Identifier& pmt_id ) const; - /// From hash - optimized - Identifier plate_id ( IdentifierHash wafer_hash ) const; - /// For an individual pmt Identifier pmt_id ( int station, int plate, @@ -104,149 +101,54 @@ public: //@} - - /// @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. Wafer iterator is sorted - const_id_iterator plate_begin (void) const; - const_id_iterator plate_end (void) const; - /// For strip ids, only expanded id iterators are available. Use - /// following "strip_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 veto id, i.e. NOT trigger or other - //@{ - /// wafer hash from id - optimized + /// plate 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 plate navigation - //@{ - /// Previous plate hash in station (return == 0 for neighbor found) - int get_prev_in_station (const IdentifierHash& id, IdentifierHash& prev) const; - /// Next plate hash in station (return == 0 for neighbor found) - int get_next_in_station (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 plate_context (void) const; - IdContext pmt_context (void) 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 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 pmt 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_wafer_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; id_vec m_plate_vec; - hash_vec m_prev_plate_vec; - hash_vec m_next_plate_vec; - // hash_vec m_prev_eta_wafer_vec; - // hash_vec m_next_eta_wafer_vec; - // bool m_hasRows ; + + const IdDictDictionary* m_dict; + MultiRange m_full_plate_range; + MultiRange m_full_pmt_range; IdDictFieldImplementation m_scint_impl ; IdDictFieldImplementation m_veto_impl ; @@ -279,11 +181,6 @@ VetoID::station_id ( int station ) const m_veto_impl.pack (veto_field_value(), result); m_station_impl.pack (station, result); - // Do checks - if(m_do_checks) { - plate_id_checks ( station, 0 ); - } - return result; } @@ -303,7 +200,6 @@ inline Identifier VetoID::plate_id ( int station, int plate ) const { - // Build identifier Identifier result((Identifier::value_type)0); @@ -313,16 +209,9 @@ VetoID::plate_id ( int station, m_station_impl.pack (station, result); m_plate_impl.pack (plate, result); - // Do checks - if(m_do_checks) { - plate_id_checks ( station, plate ); - } - return result; } - - //---------------------------------------------------------------------------- inline Identifier VetoID::plate_id ( const Identifier& pmt_id ) const @@ -333,14 +222,8 @@ VetoID::plate_id ( const Identifier& pmt_id ) const 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 +inline IdentifierHash +VetoID::plate_hash (Identifier plate_id) const { id_vec_it it = std::lower_bound(m_plate_vec.begin(), m_plate_vec.end(), @@ -353,6 +236,8 @@ inline IdentifierHash VetoID::plate_hash (Identifier plate_id) const return (result); // return hash in invalid state } + + //---------------------------------------------------------------------------- inline Identifier VetoID::pmt_id ( int station, @@ -369,33 +254,6 @@ VetoID::pmt_id ( int station, m_plate_impl.pack (plate, result); m_pmt_impl.pack (pmt, result); - // Do checks - if(m_do_checks) { - pmt_id_checks ( station, plate, pmt ); - } - return result; -} - -//---------------------------------------------------------------------------- -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; } @@ -410,59 +268,8 @@ VetoID::pmt_id ( const Identifier& plate_id, int pmt ) const 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 diff --git a/Scintillator/ScintDetDescr/ScintIdentifier/src/VetoID.cxx b/Scintillator/ScintDetDescr/ScintIdentifier/src/VetoID.cxx index b886cca6e905be3a10731382ddc2adc60334ac08..10bcf37825c613301c1139f697a03e6cd75fda44 100644 --- a/Scintillator/ScintDetDescr/ScintIdentifier/src/VetoID.cxx +++ b/Scintillator/ScintDetDescr/ScintIdentifier/src/VetoID.cxx @@ -41,111 +41,67 @@ VetoID::VetoID(void) 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) + m_pmt_hash_max(0), + m_dict(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 +int +VetoID::init_hashes(void) { - // 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); + // + // 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"); + // wafer 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]; - if (range.match(expId)) { - const Range::field& station_field = range[m_STATION_INDEX]; - if (station_field.has_maximum()) { - return (station_field.get_maximum()); + 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++; } } - return (-999); // default -} + 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); + } -int -Veto_ID::pmt_max (const Identifier& id) const -{ - // get max from dictionary - ExpandedIdentifier expId; - IdContext plate_context1(expId, 0, m_PLATE_INDEX); - get_expanded_id(id, expId, &plate_context1); - 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; - } - } + 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++; } - return (result); -} + // pmt hash - we do not keep a vec for the strips + m_pmt_hash_max = m_full_pmt_range.cardinality(); -int -VetoID::plate_max(const Identifier& id) const -{ - // get max from dictionary - ExpandedIdentifier expId; - IdContext station_context(expId, id, m_STATION_INDEX); - get_expanded_id(id, expId, &station_context); - 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; + return (0); } + int VetoID::initialize_from_dictionary(const IdDictMgr& dict_mgr) { @@ -186,488 +142,164 @@ VetoID::initialize_from_dictionary(const IdDictMgr& dict_mgr) // - // Find value for the field InnerDetector - const IdDictDictionary* atlasDict = dict_mgr.find_dictionary ("ATLAS"); - int inDetField = -1; - if (atlasDict->get_label_value("subdet", "InnerDetector", inDetField)) { - log << MSG::ERROR << "Could not get value for label 'InnerDetector' of field 'subdet' in dictionary " - << atlasDict->m_name + // 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 SCT - int sctField = -1; - if (m_dict->get_label_value("part", "SCT", sctField)) { - log << MSG::ERROR << "Could not get value for label 'SCT' of field 'part' in dictionary " + // 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 << " SCT_ID::initialize_from_dict " - << "Found field values: SCT " - << sctField + log << MSG::DEBUG << " VetoID::initialize_from_dict " + << "Found field values: Veto " + << vetoField << std::endl; } else { - std::cout << " DEBUG SCT_ID::initialize_from_dict " - << "Found field values: SCT " - << sctField + 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(inDetField); - region_id.add(sctField); + region_id.add(scintField); + region_id.add(vetoField); Range prefix; - m_full_wafer_range = m_dict->build_multirange(region_id, prefix, "side"); - m_full_strip_range = m_dict->build_multirange(region_id, prefix); - - // Setup the hash tables - if(init_hashes()) return (1); + m_full_plate_range = m_dict->build_multirange(region_id, prefix, "plate"); + m_full_pmt_range = m_dict->build_multirange(region_id, prefix); - // Setup hash tables for finding neighbors - if(init_neighbors()) return (1); if (m_msgSvc) { - log << MSG::INFO << " SCT_ID::initialize_from_dict " << endmsg; + log << MSG::INFO << " VetoID::initialize_from_dict " << endmsg; log << MSG::DEBUG - << "Wafer range -> " << (std::string)m_full_wafer_range + << "Plate range -> " << (std::string)m_full_plate_range << endmsg; log << MSG::DEBUG - << "Strip range -> " << (std::string)m_full_strip_range + << "Pmt range -> " << (std::string)m_full_pmt_range << endmsg; } else { - std::cout << " INFO SCT_ID::initialize_from_dict " << std::endl; - std::cout << " DEBUG Wafer range -> " << (std::string)m_full_wafer_range + 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 Strip range -> " << (std::string)m_full_strip_range + std::cout << " DEBUG Pmt range -> " << (std::string)m_full_pmt_range << std::endl; } return 0; } -int -SCT_ID::init_hashes(void) -{ - - // - // create a vector(s) to retrieve the hashes for compact ids. For - // the moment, we implement a hash for wafers but NOT for strips - // (too many) - // - MsgStream log(m_msgSvc, "SCT_ID"); - // wafer hash - m_wafer_hash_max = m_full_wafer_range.cardinality(); - m_wafer_vec.resize(m_wafer_hash_max); - unsigned int nids = 0; - std::set<Identifier> ids; - for (unsigned int i = 0; i < m_full_wafer_range.size(); ++i) { - const Range& range = m_full_wafer_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 = 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(!(ids.insert(id)).second) { - log << MSG::ERROR << " SCT_ID::init_hashes " - << " Error: duplicated id for wafer id. nid " << nids - << " compact id " << id.getString() - << " id " << (std::string)exp_id << endmsg; - return (1); - } - nids++; - } - } - if(ids.size() != m_wafer_hash_max) { - log << MSG::ERROR << " SCT_ID::init_hashes " - << " Error: set size NOT EQUAL to hash max. size " << ids.size() - << " hash max " << m_wafer_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_wafer_vec.size(); ++first) { - m_wafer_vec[nids] = (*first); - nids++; - } - - // strip hash - we do not keep a vec for the strips - too large - m_strip_hash_max = m_full_strip_range.cardinality(); - - return (0); -} - -int -SCT_ID::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 -SCT_ID::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 -SCT_ID::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 -SCT_ID::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 -SCT_ID::init_neighbors(void) -{ - // - // create a vector(s) to retrieve the hashes for compact ids for - // wafer neighbors. - // - - MsgStream log(m_msgSvc, "SCT_ID"); - if (m_msgSvc) { - log << MSG::DEBUG << "SCT_ID::init_neighbors " << endmsg; - } - else { - std::cout << " DEBUG SCT_ID::init_neighbors " << 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 << " SCT_ID::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 << " SCT_ID::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 << " SCT_ID::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 << " SCT_ID::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 << " SCT_ID::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 << " SCT_ID::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 -SCT_ID::initLevelsFromDict() +VetoID::initLevelsFromDict() { - MsgStream log(m_msgSvc, "SCT_ID"); + MsgStream log(m_msgSvc, "VetoID"); if(!m_dict) { - log << MSG::ERROR << " SCT_ID::initLevelsFromDict - dictionary NOT initialized " << endmsg; + 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_INDET_INDEX = 999; - m_SCT_INDEX = 999; - m_BARREL_EC_INDEX = 999; - m_LAYER_DISK_INDEX = 999; - m_PHI_MODULE_INDEX = 999; - m_ETA_MODULE_INDEX = 999; - m_SIDE_INDEX = 999; - m_ROW_INDEX = 999; - m_STRIP_INDEX = 999; - m_hasRows = false; + m_SCINT_INDEX = 999; + m_VETO_INDEX = 999; + m_STATION_INDEX = 999; + m_PLATE_INDEX = 999; + m_PMT_INDEX = 999; - // Save index to a SCT region for unpacking + // Save index to a Veto region for unpacking ExpandedIdentifier id; - id << indet_field_value() << sct_field_value(); - if (m_dict->find_region(id, m_sct_region_index)) { - log << MSG::ERROR << "SCT_ID::initLevelsFromDict - unable to find sct region index: id, reg " - << (std::string)id << " " << m_sct_region_index + 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 SCT region + // Find a Vetp region IdDictField* field = m_dict->find_field("subdet"); if (field) { - m_INDET_INDEX = field->m_index; + m_SCINT_INDEX = field->m_index; } else { - log << MSG::ERROR << "SCT_ID::initLevelsFromDict - unable to find 'subdet' field " << endmsg; + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'subdet' field " << endmsg; return (1); } field = m_dict->find_field("part"); if (field) { - m_SCT_INDEX = field->m_index; - } - else { - log << MSG::ERROR << "SCT_ID::initLevelsFromDict - unable to find 'part' field " << endmsg; - return (1); - } - field = m_dict->find_field("barrel_endcap"); - if (field) { - m_BARREL_EC_INDEX = field->m_index; + m_VETO_INDEX = field->m_index; } else { - log << MSG::ERROR << "SCT_ID::initLevelsFromDict - unable to find 'barrel_endcap' field " << endmsg; + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'part' field " << endmsg; return (1); } - field = m_dict->find_field("layer"); + field = m_dict->find_field("station"); if (field) { - m_LAYER_DISK_INDEX = field->m_index; + m_STATION_INDEX = field->m_index; } else { - log << MSG::ERROR << "SCT_ID::initLevelsFromDict - unable to find 'layer' field " << endmsg; + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'station' field " << endmsg; return (1); } - field = m_dict->find_field("phi_module"); + field = m_dict->find_field("plate"); if (field) { - m_PHI_MODULE_INDEX = field->m_index; + m_PLATE_INDEX = field->m_index; } else { - log << MSG::ERROR<< "SCT_ID::initLevelsFromDict - unable to find 'phi_module' field " << endmsg; + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'plate' field " << endmsg; return (1); } - field = m_dict->find_field("eta_module"); + field = m_dict->find_field("pmt"); if (field) { - m_ETA_MODULE_INDEX = field->m_index; + m_PMT_INDEX = field->m_index; } else { - log << MSG::ERROR << "SCT_ID::initLevelsFromDict - unable to find 'eta_module' field " << endmsg; + log << MSG::ERROR<< "VetoID::initLevelsFromDict - unable to find 'pmt' field " << endmsg; return (1); } - field = m_dict->find_field("side"); - if (field) { - m_SIDE_INDEX = field->m_index; - } - else { - log << MSG::ERROR << "SCT_ID::initLevelsFromDict - unable to find 'side' field " << endmsg; - return (1); - } - - - field = m_dict->find_field("row"); - if (field) { - m_ROW_INDEX = field->m_index; - m_hasRows = true ; - } - - else { + + // Set the field implementations: for station, plate, pmt - //log << MSG::ERROR << "SCT_ID::initLevelsFromDict - unable to find 'row' field " << endmsg; - //return (1); - } + const IdDictRegion& region = *m_dict->m_regions[m_veto_region_index]; - - field = m_dict->find_field("strip"); - if (field) { - m_STRIP_INDEX = field->m_index; - } - else { - log << MSG::ERROR << "SCT_ID::initLevelsFromDict - unable to find 'strip' field " << endmsg; - return (1); - } - - // Set the field implementations: for bec, lay/disk, eta/phi mod - - const IdDictRegion& region = *m_dict->m_regions[m_sct_region_index]; - - m_indet_impl = region.m_implementation[m_INDET_INDEX]; - m_sct_impl = region.m_implementation[m_SCT_INDEX]; - m_bec_impl = region.m_implementation[m_BARREL_EC_INDEX]; - m_lay_disk_impl = region.m_implementation[m_LAYER_DISK_INDEX]; - m_phi_mod_impl = region.m_implementation[m_PHI_MODULE_INDEX]; - m_eta_mod_impl = region.m_implementation[m_ETA_MODULE_INDEX]; - m_side_impl = region.m_implementation[m_SIDE_INDEX]; - if (m_hasRows){ - m_row_impl = region.m_implementation[m_ROW_INDEX]; - } - m_strip_impl = region.m_implementation[m_STRIP_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 << "indet " << m_indet_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "sct " << m_sct_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "bec " << m_bec_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "lay_disk " << m_lay_disk_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "phi_mod " << m_phi_mod_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "eta_mod " << m_eta_mod_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "side " << m_side_impl.show_to_string() << endmsg; - if (m_hasRows){ - log << MSG::DEBUG << "row " << m_row_impl.show_to_string() << endmsg; - } - log << MSG::DEBUG << "strip " << m_strip_impl.show_to_string() << 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 indet " << m_indet_impl.show_to_string() << std::endl; - std::cout << " DEBUG sct " << m_sct_impl.show_to_string() << std::endl; - std::cout << " DEBUG bec " << m_bec_impl.show_to_string() << std::endl; - std::cout << " DEBUG lay_disk " << m_lay_disk_impl.show_to_string() << std::endl; - std::cout << " DEBUG phi_mod " << m_phi_mod_impl.show_to_string() << std::endl; - std::cout << " DEBUG eta_mod " << m_eta_mod_impl.show_to_string() << std::endl; - std::cout << " DEBUG side " << m_side_impl.show_to_string() << std::endl; - if ( m_hasRows ){ - log <<" DEBUG row " << m_row_impl.show_to_string() << std::endl; - } - std::cout << " DEBUG strip " << m_strip_impl.show_to_string() << 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; @@ -680,191 +312,46 @@ SCT_ID::initLevelsFromDict() // std::cout << "side " << m_SIDE_INDEX << std::endl; // std::cout << "strip " << m_STRIP_INDEX << std::endl; - std::cout << "indet " << m_indet_impl.decode_index() << " " - << (std::string)m_indet_impl.ored_field() << " " - << std::hex << m_indet_impl.mask() << " " - << m_indet_impl.zeroing_mask() << " " - << std::dec << m_indet_impl.shift() << " " - << m_indet_impl.bits() << " " - << m_indet_impl.bits_offset() - << std::endl; - std::cout << "sct" << m_sct_impl.decode_index() << " " - << (std::string)m_sct_impl.ored_field() << " " - << std::hex << m_sct_impl.mask() << " " - << m_sct_impl.zeroing_mask() << " " - << std::dec << m_sct_impl.shift() << " " - << m_sct_impl.bits() << " " - << m_sct_impl.bits_offset() + 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 << "bec" << m_bec_impl.decode_index() << " " - << (std::string)m_bec_impl.ored_field() << " " - << std::hex << m_bec_impl.mask() << " " - << m_bec_impl.zeroing_mask() << " " - << std::dec << m_bec_impl.shift() << " " - << m_bec_impl.bits() << " " - << m_bec_impl.bits_offset() + 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 << "lay_disk"<< m_lay_disk_impl.decode_index() << " " - << (std::string)m_lay_disk_impl.ored_field() << " " - << std::hex << m_lay_disk_impl.mask() << " " - << m_lay_disk_impl.zeroing_mask() << " " - << std::dec << m_lay_disk_impl.shift() << " " - << m_lay_disk_impl.bits() << " " - << m_lay_disk_impl.bits_offset() + 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 << "phi_mod" << m_phi_mod_impl.decode_index() << " " - << (std::string)m_phi_mod_impl.ored_field() << " " - << std::hex << m_phi_mod_impl.mask() << " " - << m_phi_mod_impl.zeroing_mask() << " " - << std::dec << m_phi_mod_impl.shift() << " " - << m_phi_mod_impl.bits() << " " - << m_phi_mod_impl.bits_offset() + 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 << "eta_mod" << m_eta_mod_impl.decode_index() << " " - << (std::string)m_eta_mod_impl.ored_field() << " " - << std::hex << m_eta_mod_impl.mask() << " " - << m_eta_mod_impl.zeroing_mask() << " " - << std::dec << m_eta_mod_impl.shift() << " " - << m_eta_mod_impl.bits() << " " - << m_eta_mod_impl.bits_offset() - << std::endl; - std::cout << "side" << m_side_impl.decode_index() << " " - << (std::string)m_side_impl.ored_field() << " " - << std::hex << m_side_impl.mask() << " " - << m_side_impl.zeroing_mask() << " " - << std::dec << m_side_impl.shift() << " " - << m_side_impl.bits() << " " - << m_side_impl.bits_offset() - << std::endl; - - if ( m_hasRows ){ - std::cout << "row" << m_row_impl.decode_index() << " " - << (std::string)m_row_impl.ored_field() << " " - << std::hex << m_row_impl.mask() << " " - << m_row_impl.zeroing_mask() << " " - << std::dec << m_row_impl.shift() << " " - << m_row_impl.bits() << " " - << m_row_impl.bits_offset() - << std::endl; - } - - - std::cout << "strip" << m_strip_impl.decode_index() << " " - << (std::string)m_strip_impl.ored_field() << " " - << std::hex << m_strip_impl.mask() << " " - << m_strip_impl.zeroing_mask() << " " - << std::dec << m_strip_impl.shift() << " " - << m_strip_impl.bits() << " " - << m_strip_impl.bits_offset() + 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 plates) 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); -}