Commit 1a3887c7 authored by scott snyder's avatar scott snyder Committed by scott snyder
Browse files

LArRawConditions: Add index tracking for LArMCSym.

Extend LArMCSym so that it can also return the index of the symmetric
cell in the list of all symmetric cells.

Add a unit test for it.
parent ac28b5e0
......@@ -20,6 +20,7 @@ atlas_depends_on_subdirs( PUBLIC
LArCalorimeter/LArCabling
LArCalorimeter/LArRecConditions
PRIVATE
DetectorDescription/IdDictParser
LArCalorimeter/LArTools )
# External dependencies:
......@@ -62,3 +63,7 @@ atlas_add_test( LArConditionsSubset_test
SOURCES test/LArConditionsSubset_test.cxx
LINK_LIBRARIES LArRawConditions )
atlas_add_test( LArMCSym_test
SOURCES test/LArMCSym_test.cxx
LINK_LIBRARIES LArRawConditions IdDictParser )
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#ifndef LARRAWCONDITIONS_LARMCSYM_H
......@@ -10,52 +10,141 @@
*/
#include "Identifier/HWIdentifier.h"
#include "Identifier/Identifier32.h"
#include "Identifier/IdentifierHash.h"
#include "LArIdentifier/LArOnlineID.h"
#include "CaloIdentifier/CaloCell_ID.h"
class LArMCSym {
public:
class LArMCSym
{
public:
LArMCSym() = delete;
/**
* @brief Contructor.
* @brief onlId Online ID helper.
* @brief caloId Offline ID helper.
* @brief oflHashtoSymOnl Symmetric HWID corresponding to each offline hash.
* @brief onlHashtoSymOnl Symmetric HWID corresponding to each online hash.
* @brief symIds List of all symmetric HWIDs. MUST BE SORTED.
*/
LArMCSym(const LArOnlineID* onlId,
const CaloCell_ID* caloId,
std::vector<HWIdentifier>&& oflHashtoSymOnl,
std::vector<HWIdentifier>&& onlHashtoSymOnl,
std::vector<HWIdentifier>&& symIds
);
);
/// Return for an index if there's no valid symmetric identifier.
static constexpr size_t NO_INDEX = static_cast<size_t> (-1);
/**
* @brief Find the symmetric HWID for an offline cell identifier.
* May return an invalid identifier.
*/
HWIdentifier ZPhiSymOfl(const Identifier notSymOffId) const {
if (m_caloCellID->is_tile(notSymOffId)) return HWIdentifier();
const IdentifierHash h=m_caloCellID->calo_cell_hash(notSymOffId);
return ZPhiSymOfl(h);
}
/**
* @brief Find the symmetric HWID for an offline cell hash.
* May return an invalid identifier.
*/
HWIdentifier ZPhiSymOfl(const IdentifierHash notSymOffHash) const {
assert(notSymOffHash < m_oflHashtoSymOnl.size());
return m_oflHashtoSymOnl[notSymOffHash];
return HWIdentifier (m_oflHashtoSymOnl[notSymOffHash].first);
}
/**
* @brief Find the index in symIds() of the symmetric HWID for
* an offline cell identifier.
* Returns NO_INDEX if no symmetric identifier is defined.
*/
size_t ZPhiSymOflIndex(const Identifier notSymOffId) const {
if (m_caloCellID->is_tile(notSymOffId)) return NO_INDEX;
const IdentifierHash h=m_caloCellID->calo_cell_hash(notSymOffId);
return ZPhiSymOflIndex(h);
}
/**
* @brief Find the index in symIds() of the symmetric HWID for
* an offline cell hash.
* Returns NO_INDEX if no symmetric identifier is defined.
*/
size_t ZPhiSymOflIndex(const IdentifierHash notSymOffHash) const {
assert(notSymOffHash < m_oflHashtoSymOnl.size());
return m_oflHashtoSymOnl[notSymOffHash].second;
}
/**
* @brief Find the symmetric HWID for an online channel identifier.
* May return an invalid identifier.
*/
HWIdentifier ZPhiSymOnl(const HWIdentifier notSymOnlId) const {
const IdentifierHash h=m_onlineID->channel_Hash(notSymOnlId);
return ZPhiSymOnl(h);
}
/**
* @brief Find the symmetric HWID for an online channel hash.
* May return an invalid identifier.
*/
HWIdentifier ZPhiSymOnl(const IdentifierHash notSymOnlHash) const {
assert(notSymOnlHash < m_onlHashtoSymOnl.size());
return m_onlHashtoSymOnl[notSymOnlHash];
return HWIdentifier (m_onlHashtoSymOnl[notSymOnlHash].first);
}
/**
* @brief Find the index in symIds() of the symmetric HWID for
* an online channel identifier.
* Returns NO_INDEX if no symmetric identifier is defined.
*/
size_t ZPhiSymOnlIndex(const HWIdentifier notSymOnlId) const {
const IdentifierHash h=m_onlineID->channel_Hash(notSymOnlId);
return ZPhiSymOnlIndex(h);
}
/**
* @brief Find the index in symIds() of the symmetric HWID for
* an online channel hash.
* Returns NO_INDEX if no symmetric identifier is defined.
*/
size_t ZPhiSymOnlIndex(const IdentifierHash notSymOnlHash) const {
assert(notSymOnlHash < m_onlHashtoSymOnl.size());
return m_onlHashtoSymOnl[notSymOnlHash].second;
}
/**
* @brief Return the list of symmetric hashes.
*/
const std::vector<HWIdentifier>& symIds() const {
return m_symIds;
}
private:
typedef std::pair<Identifier32::value_type, uint32_t> IdPair_t;
std::vector<IdPair_t>
initIndices (const std::vector<HWIdentifier>& ids,
const std::vector<HWIdentifier>& symIds) const;
const LArOnlineID* m_onlineID;
const CaloCell_ID* m_caloCellID;
const std::vector<HWIdentifier> m_oflHashtoSymOnl;
const std::vector<HWIdentifier> m_onlHashtoSymOnl;
const std::vector<IdPair_t> m_oflHashtoSymOnl;
const std::vector<IdPair_t> m_onlHashtoSymOnl;
const std::vector<HWIdentifier> m_symIds;
};
......
LArRawConditions/LArMCSym_test
LArMiniFCAL_ID INFO initialize_from_dict - LArCalorimeter dictionary does NOT contain miniFCAL description. Unable to initialize LArMiniFCAL_ID.
test1
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#include "LArRawConditions/LArMCSym.h"
#include <algorithm>
#include <cstdlib>
/**
* @brief Contructor.
* @brief onlId Online ID helper.
* @brief caloId Offline ID helper.
* @brief oflHashtoSymOnl Symmetric HWID corresponding to each offline hash.
* @brief onlHashtoSymOnl Symmetric HWID corresponding to each online hash.
* @brief symIds List of all symmetric HWIDs. MUST BE SORTED.
*/
LArMCSym::LArMCSym(const LArOnlineID* onlId,
const CaloCell_ID* caloId,
std::vector<HWIdentifier>&& oflHashtoSymOnl,
......@@ -12,7 +22,39 @@ LArMCSym::LArMCSym(const LArOnlineID* onlId,
std::vector<HWIdentifier>&& symIds) :
m_onlineID(onlId),
m_caloCellID(caloId),
m_oflHashtoSymOnl(oflHashtoSymOnl),
m_onlHashtoSymOnl(onlHashtoSymOnl),
m_oflHashtoSymOnl (initIndices (oflHashtoSymOnl, symIds)),
m_onlHashtoSymOnl (initIndices (onlHashtoSymOnl, symIds)),
m_symIds(symIds)
{}
{
}
std::vector<LArMCSym::IdPair_t>
LArMCSym::initIndices (const std::vector<HWIdentifier>& ids,
const std::vector<HWIdentifier>& symIds) const
{
std::vector<IdPair_t> out;
out.reserve (ids.size());
HWIdentifier last_id;
size_t idx = NO_INDEX;
for (const HWIdentifier& id : ids) {
if (!id.is_valid()) {
idx = NO_INDEX;
}
else if (id != last_id) {
if (idx < symIds.size()-1 && symIds[idx+1] == id) {
++idx;
}
else {
auto it = std::lower_bound (symIds.begin(), symIds.end(), id);
if (it == symIds.end() || *it != id) std::abort();
idx = it - symIds.begin();
}
}
out.emplace_back (id.get_identifier32().get_compact(), idx);
last_id = id;
}
return out;
}
/*
* Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
*/
/**
* @file LArRawConditions/test/LArMCSym_test.cxx
* @author scott snyder <snyder@bnl.gov>
* @date Feb, 2020
* @brief Unit test for LArMCSym.
*/
#undef NDEBUG
#include "LArRawConditions/LArMCSym.h"
#include "CaloIdentifier/CaloHelpersTest.h"
#include "LArIdentifier/LArOnlineID.h"
#include "IdDictParser/IdDictParser.h"
#include <vector>
#include <algorithm>
#include <unordered_set>
class LArOnlineIDTest
{
public:
LArOnlineIDTest();
~LArOnlineIDTest();
const LArOnlineID& onlineID() const { return m_helper; }
private:
std::unique_ptr<IdDictParser> m_parser;
LArOnlineID m_helper;
};
LArOnlineIDTest::LArOnlineIDTest()
: m_parser (std::make_unique<IdDictParser>())
{
m_parser->register_external_entity("LArCalorimeter", "IdDictLArCalorimeter_DC3-05.xml");
IdDictMgr& idd = m_parser->parse("IdDictParser/ATLAS_IDS.xml");
m_helper.set_quiet (true);
if (m_helper.initialize_from_dictionary(idd) != 0) {
std::abort();
}
}
LArOnlineIDTest::~LArOnlineIDTest()
{
}
void test1 (const CaloHelpersTest& caloHelpers,
const LArOnlineID& onlineID)
{
std::cout << "test1\n";
// Mappings here are completely bogus ... just for testing
// (would have to read the DB to get proper mappings).
const unsigned onlHashMax = onlineID.channelHashMax();
std::vector<HWIdentifier> onlHashtoSymOnl(onlHashMax);
IdentifierHash hwid_max_hash = 0;
std::unordered_set<HWIdentifier> symIds;
for (HWIdentifier hwid : onlineID.channel_range()) {
if (!onlineID.isEMBchannel (hwid)) continue;
IdentifierHash hwid_hash = onlineID.channel_Hash (hwid);
HWIdentifier hwid_sym = onlineID.channel_Id (onlineID.feedthrough_Id(hwid),
1,
onlineID.channel(hwid));
onlHashtoSymOnl[hwid_hash] = hwid_sym;
hwid_max_hash = std::max (hwid_max_hash, hwid_hash);
symIds.insert (hwid_sym);
}
onlHashtoSymOnl.resize (hwid_max_hash+1);
std::vector<HWIdentifier> oflHashtoSymOnl = onlHashtoSymOnl;
std::reverse (oflHashtoSymOnl.begin(), oflHashtoSymOnl.end());
std::vector<HWIdentifier> symVec (symIds.begin(), symIds.end());
std::sort (symVec.begin(), symVec.end());
const CaloCell_ID& calo_id = caloHelpers.caloID();
LArMCSym mcsym (&onlineID, &calo_id,
std::vector<HWIdentifier> (oflHashtoSymOnl),
std::vector<HWIdentifier> (onlHashtoSymOnl),
std::vector<HWIdentifier> (symVec));
assert (mcsym.symIds() == symVec);
for (size_t i = 0; i <= hwid_max_hash; ++i) {
HWIdentifier hwid = onlineID.channel_Id(i);
assert (mcsym.ZPhiSymOnl(i) == onlHashtoSymOnl[i]);
assert (mcsym.ZPhiSymOnl(hwid) == onlHashtoSymOnl[i]);
if (!onlHashtoSymOnl[i].is_valid()) {
assert (mcsym.ZPhiSymOnlIndex(i) == LArMCSym::NO_INDEX);
assert (mcsym.ZPhiSymOnlIndex(hwid) == LArMCSym::NO_INDEX);
}
else {
size_t idx = mcsym.ZPhiSymOnlIndex(i);
assert (idx != LArMCSym::NO_INDEX);
assert (mcsym.ZPhiSymOnlIndex(hwid) == idx);
assert (symVec[idx] == onlHashtoSymOnl[i]);
}
}
for (size_t i = 0; i <= hwid_max_hash; ++i) {
Identifier id = calo_id.cell_id (i);
if (!id.is_valid()) continue;
assert (mcsym.ZPhiSymOfl(i) == oflHashtoSymOnl[i]);
assert (mcsym.ZPhiSymOfl(id) == oflHashtoSymOnl[i]);
if (!oflHashtoSymOnl[i].is_valid()) {
assert (mcsym.ZPhiSymOflIndex(i) == LArMCSym::NO_INDEX);
assert (mcsym.ZPhiSymOflIndex(id) == LArMCSym::NO_INDEX);
}
else {
size_t idx = mcsym.ZPhiSymOflIndex(i);
assert (idx != LArMCSym::NO_INDEX);
assert (mcsym.ZPhiSymOflIndex(id) == idx);
assert (symVec[idx] == oflHashtoSymOnl[i]);
}
}
}
int main()
{
std::cout << "LArRawConditions/LArMCSym_test\n";
CaloHelpersTest helpers;
LArOnlineIDTest larhelpers;
test1 (helpers, larhelpers.onlineID());
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment