From 016f8a0d4630a251d9ddb2124c55afa56b4bdd3b Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 21 Mar 2017 16:49:21 +0100 Subject: [PATCH] ItemType renamed type --- papas/datatypes/IdCoder.h | 16 +++++----- papas/datatypes/src/Cluster.cpp | 6 ++-- papas/datatypes/src/Event.cpp | 8 ++--- papas/datatypes/src/HistoryHelper.cpp | 2 +- papas/datatypes/src/IdCoder.cpp | 30 +++++++++---------- papas/graphtools/src/EventRuler.cpp | 4 +-- .../src/MergedClusterBuilder.cpp | 2 +- papas/reconstruction/src/PFBlock.cpp | 4 +-- papas/simulation/src/Simulator.cpp | 2 +- tests/unittest.cpp | 2 +- 10 files changed, 38 insertions(+), 38 deletions(-) diff --git a/papas/datatypes/IdCoder.h b/papas/datatypes/IdCoder.h index 6922a13..d99c3af 100644 --- a/papas/datatypes/IdCoder.h +++ b/papas/datatypes/IdCoder.h @@ -62,7 +62,7 @@ class IdCoder { @param[in] id: the identifier @return an enum IdCoder::ItemType */ - static ItemType itemType(Identifier id); ///< Returns encoded ItemType eg kParticle etc; + static ItemType type(Identifier id); ///< Returns encoded ItemType eg kParticle etc; /** returns the subtype of the identifier eg 'm' Some possible existing uses @@ -103,12 +103,12 @@ class IdCoder { /** boolean test of whether identifier is from an ecal cluster @param ident: identifier */ - static bool isEcal(Identifier id) { return (IdCoder::itemType(id) == kEcalCluster); } + static bool isEcal(Identifier id) { return (IdCoder::type(id) == kEcalCluster); } /** boolean test of whether identifier is from an hcal cluster @param ident: identifier */ - static bool isHcal(Identifier id) { return (IdCoder::itemType(id) == kHcalCluster); } + static bool isHcal(Identifier id) { return (IdCoder::type(id) == kHcalCluster); } /** boolean test of whether identifier is from a cluster @param ident: identifier @@ -118,24 +118,24 @@ class IdCoder { /** boolean test of whether identifier is from an track @param ident: identifier */ - static bool isTrack(Identifier id) { return (IdCoder::itemType(id) == kTrack); } + static bool isTrack(Identifier id) { return (IdCoder::type(id) == kTrack); } /** boolean test of whether identifier is from a particle @param ident: identifier */ - static bool isParticle(Identifier id) { return (IdCoder::itemType(id) == kParticle); } + static bool isParticle(Identifier id) { return (IdCoder::type(id) == kParticle); } /** boolean test of whether identifier is from a block @param ident: identifier */ - static bool isBlock(Identifier id) { return (IdCoder::itemType(id) == kBlock); } + static bool isBlock(Identifier id) { return (IdCoder::type(id) == kBlock); } /** Uses detector layer to work out what itemType is appropriate @param layer: detector layer as an enumeration eg kEcal @return ItemType enumeration value eg kEcalCluster */ - static ItemType itemType(papas::Layer layer); ///< Uses detector layer to work out itemType - static ItemType itemType(char s); + static ItemType type(papas::Layer layer); ///< Uses detector layer to work out itemType + static ItemType type(char s); /** Uses identifier type to work out what detector layer the item belongs to, may be kNone @param id: identifier diff --git a/papas/datatypes/src/Cluster.cpp b/papas/datatypes/src/Cluster.cpp index 8949368..b2844a8 100644 --- a/papas/datatypes/src/Cluster.cpp +++ b/papas/datatypes/src/Cluster.cpp @@ -14,8 +14,8 @@ namespace papas { double Cluster::s_maxEnergy = 0; -Cluster::Cluster(double energy, const TVector3& position, double size_m, unsigned int index, IdCoder::ItemType idtype, char subtype) - : m_id(IdCoder::makeId(index, idtype, subtype, fmax(0, energy))), m_p3(position), m_subClusters() { +Cluster::Cluster(double energy, const TVector3& position, double size_m, unsigned int index, IdCoder::ItemType type, char subtype) + : m_id(IdCoder::makeId(index, type, subtype, fmax(0, energy))), m_p3(position), m_subClusters() { setSize(size_m); setEnergy(energy); m_subClusters.push_back(this); @@ -78,7 +78,7 @@ void Cluster::setEnergy(double energy) { } Cluster& Cluster::operator+=(const Cluster& rhs) { - if (IdCoder::itemType(m_id) != IdCoder::itemType(rhs.id())) { + if (IdCoder::type(m_id) != IdCoder::type(rhs.id())) { throw "can only add a cluster from the same layer"; } m_p3 = m_p3 * m_energy + rhs.position() * rhs.energy(); diff --git a/papas/datatypes/src/Event.cpp b/papas/datatypes/src/Event.cpp index 00319c8..c7b5c34 100644 --- a/papas/datatypes/src/Event.cpp +++ b/papas/datatypes/src/Event.cpp @@ -46,12 +46,12 @@ const Clusters& Event::clusters(IdCoder::ItemType type, const IdCoder::SubType s const Clusters& Event::clusters(Identifier id) const { // return the corresponding collection with the same type and subtype as this id - return clusters(IdCoder::itemType(id), IdCoder::subtype(id)); + return clusters(IdCoder::type(id), IdCoder::subtype(id)); }; const Clusters& Event::clusters(const std::string& typeAndSubtype) const { // return the corresponding collection with this type and subtype - return clusters(IdCoder::itemType(typeAndSubtype[0]), typeAndSubtype[1]); + return clusters(IdCoder::type(typeAndSubtype[0]), typeAndSubtype[1]); } const Tracks& Event::tracks(const IdCoder::SubType subtype) const { @@ -93,13 +93,13 @@ bool Event::hasCollection(IdCoder::ItemType type, const IdCoder::SubType subtype }; bool Event::hasCollection(Identifier id) const { - return hasCollection(IdCoder::itemType(id), IdCoder::subtype(id)); + return hasCollection(IdCoder::type(id), IdCoder::subtype(id)); }; bool Event::hasObject(Identifier id) const { // check if this object id is present auto found = false; - auto type = IdCoder::itemType(id); + auto type = IdCoder::type(id); if (hasCollection(id)) { switch (type) { case IdCoder::kEcalCluster: diff --git a/papas/datatypes/src/HistoryHelper.cpp b/papas/datatypes/src/HistoryHelper.cpp index 32f791a..d56746d 100644 --- a/papas/datatypes/src/HistoryHelper.cpp +++ b/papas/datatypes/src/HistoryHelper.cpp @@ -28,7 +28,7 @@ Ids HistoryHelper::linkedIds(Identifier id, const std::string& typeAndSubtype, D Ids HistoryHelper::filteredIds(Ids ids, const IdCoder::ItemType type, const IdCoder::SubType subtype) const { Ids matchedIds; for (auto id : ids) { - if (IdCoder::itemType(id) == type && IdCoder::subtype(id) == subtype) { + if (IdCoder::type(id) == type && IdCoder::subtype(id) == subtype) { matchedIds.push_back(id); } } diff --git a/papas/datatypes/src/IdCoder.cpp b/papas/datatypes/src/IdCoder.cpp index 0a1fca8..3d95be2 100644 --- a/papas/datatypes/src/IdCoder.cpp +++ b/papas/datatypes/src/IdCoder.cpp @@ -29,7 +29,7 @@ Identifier IdCoder::makeId(unsigned int index, ItemType type, char subt, float v // if the m_bitshift is 32 or more the shift is undefined and can return 0 Identifier typeShift = (uint64_t)type << m_bitshift1; - Identifier valueShift = (uint64_t)IdCoder::floatToBits(val) << m_bitshift; + Identifier valueShift = (uint64_t)floatToBits(val) << m_bitshift; Identifier subtypeShift = (uint64_t) static_cast(tolower(subt)) << m_bitshift2; Identifier uid = (uint64_t)subtypeShift | (uint64_t)valueShift | (uint64_t)typeShift | index; @@ -37,7 +37,7 @@ Identifier IdCoder::makeId(unsigned int index, ItemType type, char subt, float v return uid; } -IdCoder::ItemType IdCoder::itemType(Identifier id) { +IdCoder::ItemType IdCoder::type(Identifier id) { return static_cast((id >> m_bitshift1) & (uint64_t)(pow(2, 3) - 1)); } @@ -58,10 +58,10 @@ unsigned int IdCoder::uniqueId(Identifier id) { //For some purposes we want a smaller uniqueid without the value information //here we consruct a 32 bit uniqueid out of the index and the type and subtype unsigned int bitshift = m_bitshift + m_bitshift1 - m_bitshift2; - Identifier typeShift = (uint32_t)IdCoder::itemType(id) << bitshift; - Identifier subtypeShift = (uint32_t) static_cast(tolower(IdCoder::subtype(id))) << m_bitshift; + Identifier typeShift = (uint32_t)type(id) << bitshift; + Identifier subtypeShift = (uint32_t) static_cast(tolower(subtype(id))) << m_bitshift; //binary printout std::cout <<"Index" << std::bitset<32>(IdCoder::index(id)) <= fabs(val) * 10e-6) | (itemType(uid) != type) | (subtype(uid) != subt)) return false; + if ((fabs(value(uid) - val) >= fabs(val) * 10e-6) | (type(uid) != itype) | (subtype(uid) != subt)) return false; } return true; } @@ -135,7 +135,7 @@ bool IdCoder::checkValid(Identifier uid, ItemType type, char subt, float val, un ItemType it = static_cast((uniqueid >> bitshift) & (uint32_t)(pow(2, 3) - 1)); char st = static_cast((uniqueid >> m_bitshift) & (uint64_t)(pow(2,bitshift - m_bitshift) - 1)); unsigned idx = ((uniqueid) & (uint32_t)(pow(2, m_bitshift) - 1)); - if (it != itemType(id) || st != subtype(id) || idx != index(id)) + if (it != type(id) || st != subtype(id) || idx != index(id)) return false; return true; } diff --git a/papas/graphtools/src/EventRuler.cpp b/papas/graphtools/src/EventRuler.cpp index 019ad1c..5952824 100644 --- a/papas/graphtools/src/EventRuler.cpp +++ b/papas/graphtools/src/EventRuler.cpp @@ -11,7 +11,7 @@ EventRuler::EventRuler(const Event& papasevent) : m_ruler(), m_event(papasevent) Distance EventRuler::distance(Identifier id1, Identifier id2) const { //figure out the object types and then call ClusterCluster or ClusterTrack distance measures if (IdCoder::isCluster(id1) && IdCoder::isCluster(id2)) - if (IdCoder::itemType(id1) == IdCoder::itemType(id2)) + if (IdCoder::type(id1) == IdCoder::type(id2)) return std::move(clusterClusterDistance(id1, id2)); else // hcal ecal not linked return Distance(); @@ -21,7 +21,7 @@ Distance EventRuler::distance(Identifier id1, Identifier id2) const { return std::move(clusterTrackDistance(id2, id1)); else if (IdCoder::isTrack(id1) && IdCoder::isTrack(id2)) return std::move(Distance()); - std::cout << IdCoder::itemType(id1) << ":" << IdCoder::itemType(id2) << std::endl; + std::cout << IdCoder::type(id1) << ":" << IdCoder::type(id2) << std::endl; throw "Distance between ids could not be computed"; return std::move(Distance()); } diff --git a/papas/reconstruction/src/MergedClusterBuilder.cpp b/papas/reconstruction/src/MergedClusterBuilder.cpp index aa82688..fefa2aa 100644 --- a/papas/reconstruction/src/MergedClusterBuilder.cpp +++ b/papas/reconstruction/src/MergedClusterBuilder.cpp @@ -57,7 +57,7 @@ MergedClusterBuilder::MergedClusterBuilder(const Event& event, // Note we could try to do this in one shot as in the latest Python version... but its a little complicated //for several reasons so this is probably more straightforward auto mergedCluster = - Cluster(clusters.at(id), merged.size(), IdCoder::itemType(id), 'm', totalenergy); // create a new cluster based on old one + Cluster(clusters.at(id), merged.size(), IdCoder::type(id), 'm', totalenergy); // create a new cluster based on old one if (id == mergedCluster.id()) { throw "MergedCluster has same id as existing cluster"; } diff --git a/papas/reconstruction/src/PFBlock.cpp b/papas/reconstruction/src/PFBlock.cpp index cd51170..72a9853 100644 --- a/papas/reconstruction/src/PFBlock.cpp +++ b/papas/reconstruction/src/PFBlock.cpp @@ -18,10 +18,10 @@ namespace papas { int PFBlock::tempBlockCount = 0; bool blockIdComparer (Identifier id1, Identifier id2) { - if (IdCoder::itemType(id1) ==IdCoder::itemType(id2)) + if (IdCoder::type(id1) ==IdCoder::type(id2)) return id1>id2; else - return IdCoder::itemType(id1) < IdCoder::itemType(id2);} + return IdCoder::type(id1) < IdCoder::type(id2);} PFBlock::PFBlock(const Ids& element_ids, Edges& edges, unsigned int index, char subtype) : m_id(IdCoder::makeId(index, IdCoder::kBlock, subtype, element_ids.size())), diff --git a/papas/simulation/src/Simulator.cpp b/papas/simulation/src/Simulator.cpp index f8d8c1a..b3c2e8d 100644 --- a/papas/simulation/src/Simulator.cpp +++ b/papas/simulation/src/Simulator.cpp @@ -303,7 +303,7 @@ Cluster Simulator::smearCluster(const Cluster& parent, papas::Layer detectorLaye else counter = m_smearedHcalClusters.size(); // energy = fmax(0., energy); // energy always positive - auto cluster = Cluster(energy, parent.position(), parent.size(), counter, IdCoder::itemType(parent.id()), 's'); + auto cluster = Cluster(energy, parent.position(), parent.size(), counter, IdCoder::type(parent.id()), 's'); PDebug::write("Made Smeared{}", cluster); return cluster; } diff --git a/tests/unittest.cpp b/tests/unittest.cpp index 137efbf..9847c22 100644 --- a/tests/unittest.cpp +++ b/tests/unittest.cpp @@ -70,7 +70,7 @@ TEST_CASE("IdCoder") { REQUIRE(IdCoder::value(idvec[3]) == 0.25); auto id = IdCoder::makeId(1, IdCoder::ItemType::kEcalCluster, 'g', 3.1); - REQUIRE(IdCoder::itemType('e') == IdCoder::kEcalCluster); + REQUIRE(IdCoder::type('e') == IdCoder::kEcalCluster); for (int j = 0; j < 6; j++) { IdCoder::ItemType e = IdCoder::ItemType::kEcalCluster;