Skip to content

Commit

Permalink
ItemType renamed type
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice committed Mar 21, 2017
1 parent 7033211 commit 016f8a0
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 38 deletions.
16 changes: 8 additions & 8 deletions papas/datatypes/IdCoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions papas/datatypes/src/Cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions papas/datatypes/src/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion papas/datatypes/src/HistoryHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
30 changes: 15 additions & 15 deletions papas/datatypes/src/IdCoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ 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<int>(tolower(subt)) << m_bitshift2;
Identifier uid = (uint64_t)subtypeShift | (uint64_t)valueShift | (uint64_t)typeShift | index;

if (!checkValid(uid, type, subt, val, index)) throw "Error occured constructing identifier";
return uid;
}

IdCoder::ItemType IdCoder::itemType(Identifier id) {
IdCoder::ItemType IdCoder::type(Identifier id) {
return static_cast<ItemType>((id >> m_bitshift1) & (uint64_t)(pow(2, 3) - 1));
}

Expand All @@ -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<int>(tolower(IdCoder::subtype(id))) << m_bitshift;
Identifier typeShift = (uint32_t)type(id) << bitshift;
Identifier subtypeShift = (uint32_t) static_cast<int>(tolower(subtype(id))) << m_bitshift;
//binary printout std::cout <<"Index" << std::bitset<32>(IdCoder::index(id)) <<std::endl;
uint32_t uniqueid = (uint32_t)subtypeShift | (uint32_t)typeShift | (uint32_t)IdCoder::index(id);
uint32_t uniqueid = (uint32_t)subtypeShift | (uint32_t)typeShift | (uint32_t)index(id);
if (!checkUIDValid(id, uniqueid))
throw "unique id part of identifier not valid";
return uniqueid;
Expand All @@ -72,14 +72,14 @@ char IdCoder::typeLetter(Identifier id) {
// converts from the identifier type enumeration such as kEcalCluster into a single letter decriptor eg 'e'
std::string typelist = ".ehtpb....";

auto index = (unsigned int)IdCoder::itemType(id);
auto index = (unsigned int)type(id);
if (index < 6)
return typelist[(unsigned int)IdCoder::itemType(id)];
return typelist[(unsigned int)type(id)];
else
throw "Error in identifier typeLetter";
}

IdCoder::ItemType IdCoder::itemType(char s) {
IdCoder::ItemType IdCoder::type(char s) {
// converts from the a single letter decriptor eg 'e' into the type enumeration such as kEcalCluster
std::string typelist = ".ehtpb";
auto found = typelist.find(s);
Expand All @@ -99,17 +99,17 @@ std::string IdCoder::pretty(Identifier id) {
}

papas::Layer IdCoder::layer(Identifier id) {
if (IdCoder::isEcal(id))
if (isEcal(id))
return papas::Layer::kEcal;
else if (IdCoder::isHcal(id))
else if (isHcal(id))
return papas::Layer::kHcal;
else if (IdCoder::isTrack(id))
else if (isTrack(id))
return papas::Layer::kTracker;
else
return papas::Layer::kNone;
}

IdCoder::ItemType IdCoder::itemType(papas::Layer layer) {
IdCoder::ItemType IdCoder::type(papas::Layer layer) {
if (layer == papas::Layer::kEcal)
return ItemType::kEcalCluster;
else if (layer == papas::Layer::kHcal)
Expand All @@ -120,11 +120,11 @@ IdCoder::ItemType IdCoder::itemType(papas::Layer layer) {
return ItemType::kNone;
}

bool IdCoder::checkValid(Identifier uid, ItemType type, char subt, float val, unsigned int indx) {
bool IdCoder::checkValid(Identifier uid, ItemType itype, char subt, float val, unsigned int indx) {
// verify that it all works, the id should match the items from which it was constructed
if (index(uid) != indx) return false;
if (val != 0) {
if ((fabs(value(uid) - val) >= 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;
}
Expand All @@ -135,7 +135,7 @@ bool IdCoder::checkValid(Identifier uid, ItemType type, char subt, float val, un
ItemType it = static_cast<ItemType>((uniqueid >> bitshift) & (uint32_t)(pow(2, 3) - 1));
char st = static_cast<char>((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;
}
Expand Down
4 changes: 2 additions & 2 deletions papas/graphtools/src/EventRuler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion papas/reconstruction/src/MergedClusterBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
4 changes: 2 additions & 2 deletions papas/reconstruction/src/PFBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down
2 changes: 1 addition & 1 deletion papas/simulation/src/Simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 016f8a0

Please sign in to comment.