Skip to content
Snippets Groups Projects
Commit c84081fd authored by Johannes Junggeburth's avatar Johannes Junggeburth :dog2:
Browse files

Factor out the log vol sorter

parent f797b08f
No related branches found
No related tags found
No related merge requests found
Pipeline #6747553 passed
/*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/
#ifndef GEOMODELFUNCSNIPPETS_GEOLOGVOLSORTER_H
#define GEOMODELFUNCSNIPPETS_GEOLOGVOLSORTER_H
#include "GeoModelKernel/GeoLogVol.h"
#include "GeoModelKernel/GeoIntrusivePtr.h"
class GeoLogVolSorter{
public:
template <class LogVolType>
bool operator()(const GeoIntrusivePtr<LogVolType>& a,
const GeoIntrusivePtr<LogVolType>& b) const{
return (*this) (a.get(), b.get());
}
bool operator()(const GeoLogVol* a, const GeoLogVol* b) const;
int compare(const GeoLogVol*a, const GeoLogVol* b) const;
};
#endif
\ No newline at end of file
/*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/
#include "GeoModelFuncSnippets/GeoLogVolSorter.h"
#include "GeoModelFuncSnippets/throwExcept.h"
#include "GeoModelFuncSnippets/GeoShapeSorter.h"
bool GeoLogVolSorter::operator()(const GeoLogVol* a, const GeoLogVol* b) const{
return compare(a, b) < 0;
}
int GeoLogVolSorter::compare(const GeoLogVol*a, const GeoLogVol* b) const{
if (!a || !b) {
THROW_EXCEPTION("Nullptr given to the comparator");
}
if (a->getMaterial() != b->getMaterial()) {
return a->getMaterial()->getName() < b->getMaterial()->getName() ? -1 : 1;
}
static const GeoShapeSorter shapeSorter{};
return shapeSorter.compare(a->getShape(), b->getShape());
}
......@@ -2,22 +2,17 @@
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/
#include "GeoModelFuncSnippets/GeoPhysVolSorter.h"
#include "GeoModelFuncSnippets/TransformSorter.h"
#include "GeoModelFuncSnippets/GeoShapeSorter.h"
#include "GeoModelFuncSnippets/GeoLogVolSorter.h"
#include "GeoModelKernel/GeoVolumeCursor.h"
#include "GeoModelFuncSnippets/getChildNodesWithTrf.h"
int GeoPhysVolSorter::compare(const GeoVPhysVol* a, const GeoVPhysVol* b) const {
const GeoLogVol* logVolA{a->getLogVol()}, *logVolB{b->getLogVol()};
if (logVolA->getMaterial() != logVolA->getMaterial()) {
return logVolA->getMaterial()->getName() <
logVolB->getMaterial()->getName() ? -1 : 1;
}
/// Check whether the shape differ
{
static const GeoShapeSorter sorter{};
const int shapeCmp = sorter.compare(logVolA->getShape(), logVolB->getShape());
static const GeoLogVolSorter sorter{};
const int shapeCmp = sorter.compare(a->getLogVol(), b->getLogVol());
if (shapeCmp) return shapeCmp;
}
......@@ -50,6 +45,5 @@ int GeoPhysVolSorter::compare(const GeoVPhysVol* a, const GeoVPhysVol* b) const
if (cursA.atEnd()) return -1;
return 1;
}
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment