-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic geometrical accessors to shapes. #697
Add basic geometrical accessors to shapes. #697
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarkusFrankATcernch - thanks for taking care of it! Just a few points:
- I think, we should avoid the unit conversions. We ought to leave it to a user IMHO.
- I do not care much if the API is close to G4 or ROOT as long as it is well documented.
- Also, I cannot tell if CMS IB checks will be happy with using
size_t
in place ofint
which is the most commonly used type. Perhaps, you could try to runclang-tidy
with a narrowing conversion check?
Thanks!
@@ -829,6 +945,27 @@ namespace dd4hep { | |||
Trap& setDimensions(double z, double theta, double phi, | |||
double h1, double bl1, double tl1, double alpha1, | |||
double h2, double bl2, double tl2, double alpha2); | |||
|
|||
/// Accessor: phi value | |||
double phi() const { return access()->GetPhi()*dd4hep::deg; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarkusFrankATcernch - IMHO we need to avoid double conversion, e.g. converting everything to radians (e.g. G4 definition) and then back to degrees (e.g. ROOT definition). We will definitely see some precision loss.
DDCore/include/DD4hep/Shapes.h
Outdated
@@ -1271,6 +1471,27 @@ namespace dd4hep { | |||
PolyhedraRegular& operator=(PolyhedraRegular&& copy) = default; | |||
/// Copy Assignment operator | |||
PolyhedraRegular& operator=(const PolyhedraRegular& copy) = default; | |||
|
|||
/// Accessor: Number of edges | |||
size_t numEdge() const { return access()->GetNedges(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are converting signed to an unsigned here. I'd add an s
:
int numEdges() const
DDCore/include/DD4hep/Shapes.h
Outdated
double deltaPhi() const { return access()->GetDphi()*dd4hep::deg; } | ||
|
||
/// Accessor: r-min value | ||
double z(size_t which) const { return access()->GetZ(which); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, it should be int
More importantly: |
I'd leave the optimisation for later. Most of the CMSSW code uses a dimensions vector any way... |
The standard has been that DD4hep returns angles as radians. Let's keep that convention. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly comments for the docstrings
DDCore/include/DD4hep/Shapes.h
Outdated
/// Accessor: delta-phi value | ||
double deltaPhi() const { return access()->GetDphi()*dd4hep::deg; } | ||
|
||
/// Accessor: r-min value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Accessor: r-min value | |
/// Accessor: z value |
template <typename SOLID> std::vector<double> _extract_vector(const SOLID* solid, | ||
double (SOLID::*extract)(Int_t) const, | ||
Int_t (SOLID::*len)() const) { | ||
std::vector<double> result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reserve the size (count
)
DDCore/include/DD4hep/Shapes.h
Outdated
|
||
/// Accessor: delta-z value | ||
double dZ() const { return access()->GetDz(); } | ||
/// Accessor: r-min value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Accessor: r-min value | |
/// Accessor: a value |
DDCore/include/DD4hep/Shapes.h
Outdated
double dZ() const { return access()->GetDz(); } | ||
/// Accessor: r-min value | ||
double a() const { return access()->GetA(); } | ||
/// Accessor: r-max value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Accessor: r-max value | |
/// Accessor: b value |
DDCore/include/DD4hep/Shapes.h
Outdated
/// Accessor: delta-phi value | ||
double deltaPhi() const { return access()->GetDphi()*dd4hep::deg; } | ||
|
||
/// Accessor: r-min value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what this is, but different than r-min
/// Accessor: delta-phi value | ||
double deltaPhi() const { return access()->GetDphi()*dd4hep::deg; } | ||
|
||
/// Accessor: r-min value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Accessor: r-min value | |
/// Accessor: z value |
DDCore/include/DD4hep/Shapes.h
Outdated
/// Accessor: delta-phi value | ||
double deltaPhi() const { return access()->GetDphi()*dd4hep::deg; } | ||
|
||
/// Accessor: r-min value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Accessor: r-min value | |
/// Accessor: z value |
DDCore/include/DD4hep/Shapes.h
Outdated
const double* values = access()->GetVertices(); | ||
return detail::_make_vector(values, 8*2); | ||
} | ||
/// Accessor: singlke vertex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Accessor: singlke vertex | |
/// Accessor: single vertex |
Concerning |
DDCore/include/DD4hep/Shapes.h
Outdated
double phi() const { return access()->GetPhi()*dd4hep::deg; } | ||
/// Accessor: theta value | ||
double theta() const { return access()->GetTheta()*dd4hep::deg; } | ||
/// Angle between centers of x edges an y axis at low z |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Angle between centers of x edges an y axis at low z | |
/// Angle between centers of x edges and y axis at low z |
DDCore/include/DD4hep/Shapes.h
Outdated
double theta() const { return access()->GetTheta()*dd4hep::deg; } | ||
/// Angle between centers of x edges an y axis at low z | ||
double alpha1() const { return access()->GetAlpha1()*dd4hep::deg; } | ||
/// Angle between centers of x edges an y axis at low z |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Angle between centers of x edges an y axis at low z | |
/// Angle between centers of x edges and y axis at high z |
@MarkusFrankATcernch - I think, you could introduce a nested namespace for units, for example [119/607] Building CXX object DDCore/CMakeFiles/DDCore.dir/src/Conditions.cpp.o
1232FAILED: DDCore/CMakeFiles/DDCore.dir/src/Conditions.cpp.o
1233/cvmfs/sft.cern.ch/lcg/releases/clang/8.0.0-ed577/x86_64-centos7/bin/clang++ -DBOOST_SPIRIT_USE_PHOENIX_V3 -DDD4HEP_USE_TINYXML -DDDCore_EXPORTS -I../DDCore/include -I../DDParsers/include -ftls-model=global-dynamic -Wheader-hygiene -Wno-c++1z-extensions -Winconsistent-missing-override -fdiagnostics-color=auto -Wshadow -Wdeprecated -Wno-long-long -Wformat-security -Wshadow -pedantic -Wextra -Wall -fdiagnostics-color=always -Werror -pthread -O3 -DNDEBUG -fPIC -std=c++17 -MD -MT DDCore/CMakeFiles/DDCore.dir/src/Conditions.cpp.o -MF DDCore/CMakeFiles/DDCore.dir/src/Conditions.cpp.o.d -o DDCore/CMakeFiles/DDCore.dir/src/Conditions.cpp.o -c ../DDCore/src/Conditions.cpp
1234../DDCore/src/Conditions.cpp:177:23: error: declaration shadows a variable in namespace 'dd4hep' [-Werror,-Wshadow]
1235 const BasicGrammar* g = access()->data.grammar;
1236 ^
1237../DDParsers/include/Evaluator/DD4hepUnits.h:191:29: note: previous declaration is here
1238 static constexpr double g = gram;
1239 ^
1240../DDCore/src/Conditions.cpp:193:12: error: declaration shadows a variable in namespace 'dd4hep' [-Werror,-Wshadow]
1241 KeyMaker m(detector.key(), detail::hash32(value));
1242 ^
1243../DDParsers/include/Evaluator/DD4hepUnits.h:98:29: note: previous declaration is here
1244 static constexpr double m = meter;
1245 ^
1246../DDCore/src/Conditions.cpp:199:12: error: declaration shadows a variable in namespace 'dd4hep' [-Werror,-Wshadow]
1247 KeyMaker m(detector.key(), item_key);
1248 ^
1249../DDParsers/include/Evaluator/DD4hepUnits.h:98:29: note: previous declaration is here
1250 static constexpr double m = meter;
1251 ^
1252../DDCore/src/Conditions.cpp:205:12: error: declaration shadows a variable in namespace 'dd4hep' [-Werror,-Wshadow]
1253 KeyMaker m(det, detail::hash32(value));
1254 ^
1255../DDParsers/include/Evaluator/DD4hepUnits.h:98:29: note: previous declaration is here
1256 static constexpr double m = meter;
1257 ^
12584 errors generated.
1259[121/607] Building CXX object DDCore/C...s/DDCore.dir/src/ConditionsDebug.cpp.o
1260ninja: build stopped: subcommand failed.
1261The command "if [[ "$PYTHON_CHECK" == "yes" ]]; then docker exec -ti CI_container /bin/bash -c "./DD4hep/.dd4hep-ci.d/runPythonChecks.sh"; else docker exec -ti CI_container /bin/bash -c "./DD4hep/.dd4hep-ci.d/compile_and_test.sh"; fi" exited with 1.
1262
1263
1264Done. Your build exited with 1. |
@MarkusFrankATcernch Thanks for the additions. This pull request will be very helpful for us in CMS. |
@cvuosalo Yes, but we first have to discuss in the dd4hep meeting the issue of putting the units into a separate namespace - ideally in a user-transparent way. |
20349c8
to
64af59b
Compare
64af59b
to
99dea9d
Compare
@@ -36,7 +36,7 @@ endmacro(dd4hep_to_parent_scope) | |||
macro(dd4hep_set_compiler_flags) | |||
include(CheckCXXCompilerFlag) | |||
|
|||
SET(COMPILER_FLAGS -Wall -Wextra -pedantic -Wshadow -Wformat-security -Wno-long-long -Wdeprecated -fdiagnostics-color=auto) | |||
SET(COMPILER_FLAGS -Wshadow -Wformat-security -Wno-long-long -Wdeprecated -fdiagnostics-color=auto -Wall -Wextra -pedantic) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this re-shuffling change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently nothing. I had the suspicion that -Wall or -Wextra after -Wshadow disables -Wshadow.
Note that the real order when compiling is inverted.
Net result is that -Wshadow does not work at all for gcc. Only for clang.
BEGINRELEASENOTES
Shapes.h
. As discussed in the thread Add DDExtrudedPolygon, DDPolycone, and DDPolyhedra shapes for reading shape parameters cms-sw/cmssw#30931 it was felt that read-only access to the basic construction parameters of a shape would be highly useful.ENDRELEASENOTES