Skip to content

Commit

Permalink
Use strongly-typed enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
ianna committed Apr 22, 2015
1 parent e09086f commit 2681e03
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 73 deletions.
16 changes: 5 additions & 11 deletions DetectorDescription/Core/interface/DDAxes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,26 @@
#include <map>

//! analagous to geant4/source/global/HEPGeometry/include/geomdefs.hh
namespace DDI
{
enum DDAxes {x, y, z, rho, radial3D, phi, undefined};
};

enum class DDAxes {x, y, z, rho, radial3D, phi, undefined};

class AxesNames
{
public:
AxesNames();
~AxesNames();

const std::string name( const DDI::DDAxes& s );

DDI::DDAxes index(const std::string & s);
const std::string name( const DDAxes& s );

private:
std::map<std::string, DDI::DDAxes> axesmap_;
std::map<std::string, DDAxes> axesmap_;
};

class DDAxesNames : public DDI::Singleton<AxesNames>
{
public:

static const std::string name( const DDI::DDAxes& s );

static DDI::DDAxes index( const std::string & s );
static const std::string name( const DDAxes& s );
};

#endif // DDAxes_h
8 changes: 4 additions & 4 deletions DetectorDescription/Core/interface/DDDivision.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class DDDivision : public DDBase<DDName, DDI::Division*>
*/
DDDivision(const DDName & name,
const DDLogicalPart & parent,
const DDI::DDAxes axis,
const DDAxes axis,
const int nReplicas,
const double width,
const double offset );
Expand All @@ -96,7 +96,7 @@ class DDDivision : public DDBase<DDName, DDI::Division*>
*/
DDDivision(const DDName & name,
const DDLogicalPart & parent,
const DDI::DDAxes axis,
const DDAxes axis,
const int nReplicas,
const double offset );

Expand All @@ -105,13 +105,13 @@ class DDDivision : public DDBase<DDName, DDI::Division*>
*/
DDDivision(const DDName & name,
const DDLogicalPart & parent,
const DDI::DDAxes axis,
const DDAxes axis,
const double width,
const double offset );

// virtual ~G4PVDivision();

DDI::DDAxes axis() const;
DDAxes axis() const;
int nReplicas() const;
double width() const;
double offset() const;
Expand Down
26 changes: 5 additions & 21 deletions DetectorDescription/Core/src/DDAxes.cc
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
#include "DetectorDescription/Core/interface/DDAxes.h"

using namespace DDI;

AxesNames::AxesNames()
: axesmap_{{"x", x }, {"y", y}, {"z", z}, {"rho", rho}, {"radial3D", radial3D}, {"phi", phi}, {"undefined", undefined }}
: axesmap_{{"x", DDAxes::x }, {"y", DDAxes::y}, {"z", DDAxes::z}, {"rho", DDAxes::rho}, {"radial3D", DDAxes::radial3D}, {"phi", DDAxes::phi}, {"undefined", DDAxes::undefined }}
{}

AxesNames::~AxesNames() { }

const std::string
AxesNames::name(const DDAxes& s)
{
std::map<std::string, DDAxes>::const_iterator it;

for(it = axesmap_.begin(); it != axesmap_.end(); ++it)
for( const auto& it : axesmap_ )
{
if(it->second == s)
break;
if( it.second == s )
return it.first;
}
return it->first;
}

DDAxes
AxesNames::index(const std::string & s)
{
return axesmap_[s];
return "undefined";
}

const std::string
DDAxesNames::name(const DDAxes& s)
{
return instance().name(s);
}

DDAxes
DDAxesNames::index(const std::string & s)
{
return instance().index(s);
}
8 changes: 4 additions & 4 deletions DetectorDescription/Core/src/DDDivision.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ DDDivision::DDDivision( const DDName & name) : DDBase<DDName,DDI::Division*>()

DDDivision::DDDivision( const DDName & name,
const DDLogicalPart & parent,
const DDI::DDAxes axis,
const DDAxes axis,
const int nReplicas,
const double width,
const double offset ) : DDBase<DDName,DDI::Division*>()
Expand All @@ -62,7 +62,7 @@ DDDivision::DDDivision( const DDName & name,

DDDivision::DDDivision( const DDName & name,
const DDLogicalPart & parent,
const DDI::DDAxes axis,
const DDAxes axis,
const int nReplicas,
const double offset )
{
Expand All @@ -73,7 +73,7 @@ DDDivision::DDDivision( const DDName & name,

DDDivision::DDDivision( const DDName & name,
const DDLogicalPart & parent,
const DDI::DDAxes axis,
const DDAxes axis,
const double width,
const double offset )
{
Expand All @@ -82,7 +82,7 @@ DDDivision::DDDivision( const DDName & name,
// DD_NDC(name);
}

DDI::DDAxes DDDivision::axis() const
DDAxes DDDivision::axis() const
{
return rep().axis();
}
Expand Down
3 changes: 1 addition & 2 deletions DetectorDescription/Core/src/Division.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <algorithm>

using DDI::Division;
using namespace DDI;

Division::Division(const DDLogicalPart & parent,
const DDAxes axis,
Expand Down Expand Up @@ -40,7 +39,7 @@ void Division::stream(std::ostream & os)
os << std::endl;
os << " LogicalPart: " << parent_ << std::endl;
os << " Solid: " << parent_.solid() << std::endl;
os << " axis: " << axis() << " nReplicas: " << nReplicas()
os << " axis: " << DDAxesNames::name( axis()) << " nReplicas: " << nReplicas()
<< " width: " << width() << " offset: " << offset() << std::endl;
}

Expand Down
2 changes: 0 additions & 2 deletions DetectorDescription/Parser/src/DDDividedBox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#include <iomanip>

using namespace DDI;

DDDividedBoxX::DDDividedBoxX( const DDDivision& div, DDCompactView* cpv)
: DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
{
Expand Down
2 changes: 0 additions & 2 deletions DetectorDescription/Parser/src/DDDividedCons.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include "CLHEP/Units/GlobalSystemOfUnits.h"

using namespace DDI;

DDDividedConsRho::DDDividedConsRho( const DDDivision& div, DDCompactView* cpv )
: DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
{
Expand Down
8 changes: 3 additions & 5 deletions DetectorDescription/Parser/src/DDDividedTrd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include <cmath>
#include <cstdlib>

using namespace DDI;

DDDividedTrdX::DDDividedTrdX( const DDDivision& div, DDCompactView* cpv )
: DDDividedGeometryObject(div,cpv)
{
Expand Down Expand Up @@ -62,7 +60,7 @@ DDDividedTrdX::makeDDTranslation( const int copyNo ) const

DCOUT_V ('P', " DDDividedTrdX: " << copyNo << "\n Position: x=" << posi << " Axis= " << DDAxesNames::name(div_.axis()) << "\n");

if( div_.axis() == x )
if( div_.axis() == DDAxes::x )
{
return DDTranslation(posi, 0.0, 0.0);
}
Expand Down Expand Up @@ -215,7 +213,7 @@ DDDividedTrdY::makeDDTranslation( const int copyNo ) const

DCOUT_V ('P', " DDDividedTrdY: " << copyNo << "\n Position: y=" << posi << " Axis= " << DDAxesNames::name(div_.axis()) << "\n");

if( div_.axis() == y )
if( div_.axis() == DDAxes::y )
{
return DDTranslation(0.0, posi, 0.0);
}
Expand Down Expand Up @@ -352,7 +350,7 @@ DDDividedTrdZ::makeDDTranslation( const int copyNo ) const

DCOUT_V ('P', " DDDividedTrdZ: " << copyNo << "\n Position: z=" << posi << " Axis= " << DDAxesNames::name(div_.axis()) << "\n");

if( div_.axis() == z )
if( div_.axis() == DDAxes::z )
{
return DDTranslation(0.0, 0.0, posi);
}
Expand Down
2 changes: 0 additions & 2 deletions DetectorDescription/Parser/src/DDDividedTubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include "CLHEP/Units/GlobalSystemOfUnits.h"

using namespace DDI;

DDDividedTubsRho::DDDividedTubsRho( const DDDivision& div, DDCompactView* cpv )
: DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
{
Expand Down
38 changes: 18 additions & 20 deletions DetectorDescription/Parser/src/DDLDivision.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include "DetectorDescription/ExprAlgo/interface/ClhepEvaluator.h"

using namespace DDI;

DDLDivision::DDLDivision( DDLElementRegistry* myreg )
: DDXMLElement( myreg )
{}
Expand Down Expand Up @@ -120,11 +118,11 @@ DDLDivision::makeDivider( const DDDivision& div, DDCompactView* cpv )
switch (div.parent().solid().shape())
{
case ddbox:
if (div.axis() == x)
if (div.axis() == DDAxes::x)
dg = new DDDividedBoxX(div,cpv);
else if (div.axis() == y)
else if (div.axis() == DDAxes::y)
dg = new DDDividedBoxY(div,cpv);
else if (div.axis() == z)
else if (div.axis() == DDAxes::z)
dg = new DDDividedBoxZ(div,cpv);
else {
std::string s = "DDLDivision can not divide a ";
Expand All @@ -138,11 +136,11 @@ DDLDivision::makeDivider( const DDDivision& div, DDCompactView* cpv )
break;

case ddtubs:
if (div.axis() == rho)
if (div.axis() == DDAxes::rho)
dg = new DDDividedTubsRho(div,cpv);
else if (div.axis() == phi)
else if (div.axis() == DDAxes::phi)
dg = new DDDividedTubsPhi(div,cpv);
else if (div.axis() == z)
else if (div.axis() == DDAxes::z)
dg = new DDDividedTubsZ(div,cpv);
else {
std::string s = "DDLDivision can not divide a ";
Expand All @@ -156,11 +154,11 @@ DDLDivision::makeDivider( const DDDivision& div, DDCompactView* cpv )
break;

case ddtrap:
if (div.axis() == x)
if (div.axis() == DDAxes::x)
dg = new DDDividedTrdX(div,cpv);
else if (div.axis() == y )
else if (div.axis() == DDAxes::y )
dg = new DDDividedTrdY(div,cpv);
else if (div.axis() == z )
else if (div.axis() == DDAxes::z )
dg = new DDDividedTrdZ(div,cpv);
else {
std::string s = "DDLDivision can not divide a ";
Expand All @@ -175,11 +173,11 @@ DDLDivision::makeDivider( const DDDivision& div, DDCompactView* cpv )
break;

case ddcons:
if (div.axis() == rho)
if (div.axis() == DDAxes::rho)
dg = new DDDividedConsRho(div,cpv);
else if (div.axis() == phi)
else if (div.axis() == DDAxes::phi)
dg = new DDDividedConsPhi(div,cpv);
else if (div.axis() == z)
else if (div.axis() == DDAxes::z)
dg = new DDDividedConsZ(div,cpv);
else {
std::string s = "DDLDivision can not divide a ";
Expand All @@ -193,11 +191,11 @@ DDLDivision::makeDivider( const DDDivision& div, DDCompactView* cpv )
break;

case ddpolycone_rrz:
if (div.axis() == rho)
if (div.axis() == DDAxes::rho)
dg = new DDDividedPolyconeRho(div,cpv);
else if (div.axis() == phi)
else if (div.axis() == DDAxes::phi)
dg = new DDDividedPolyconePhi(div,cpv);
else if (div.axis() == z)
else if (div.axis() == DDAxes::z)
dg = new DDDividedPolyconeZ(div,cpv);
else {
std::string s = "DDLDivision can not divide a ";
Expand All @@ -212,11 +210,11 @@ DDLDivision::makeDivider( const DDDivision& div, DDCompactView* cpv )
break;

case ddpolyhedra_rrz:
if (div.axis() == rho)
if (div.axis() == DDAxes::rho)
dg = new DDDividedPolyhedraRho(div,cpv);
else if (div.axis() == phi)
else if (div.axis() == DDAxes::phi)
dg = new DDDividedPolyhedraPhi(div,cpv);
else if (div.axis() == z)
else if (div.axis() == DDAxes::z)
dg = new DDDividedPolyhedraZ(div,cpv);
else {
std::string s = "DDLDivision can not divide a ";
Expand Down

0 comments on commit 2681e03

Please sign in to comment.