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
PPS: code to copy-without-children moved from copy constructor to a named method #31492
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -53,15 +53,17 @@ class DetGeomDesc { | |||||||||||||||||||||||||||||
using RotationMatrix = ROOT::Math::Rotation3D; | ||||||||||||||||||||||||||||||
using Translation = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double>>; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
DetGeomDesc() = default; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// Constructor from old DD DDFilteredView | ||||||||||||||||||||||||||||||
DetGeomDesc(const DDFilteredView& fv); | ||||||||||||||||||||||||||||||
// Constructor from DD4Hep DDFilteredView | ||||||||||||||||||||||||||||||
DetGeomDesc(const cms::DDFilteredView& fv); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
DetGeomDesc(const DetGeomDesc&); | ||||||||||||||||||||||||||||||
DetGeomDesc& operator=(const DetGeomDesc&); | ||||||||||||||||||||||||||||||
virtual ~DetGeomDesc(); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
DetGeomDesc* makeCopyWithoutChildren() const; | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be made to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a return by value would work as well. If so, that is better than returning by pointer or unique_ptr. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current code works with pointers:
thus I proposed a function returning a pointer. Switching to unique_ptr is trivial. Let me know what your suggestion is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One option would be to add a (private) constructor that takes all cmssw/Geometry/VeryForwardGeometryBuilder/src/DetGeomDesc.cc Lines 65 to 76 in 0e26c4a
as parameters. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking it might be better to remove DetGeomDesc* alignedDetRoot = new DetGeomDesc(idealDetRoot, DetGeomDesc::noChildren); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Dr15Jones Yes exactly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many thanks for all the suggestions! I also like this one. I will give it a try tomorrow. |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// general info | ||||||||||||||||||||||||||||||
const std::string& name() const { return m_name; } | ||||||||||||||||||||||||||||||
int copyno() const { return m_copy; } | ||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,21 +58,24 @@ DetGeomDesc::DetGeomDesc(const cms::DDFilteredView& fv) | |
m_z(geant_units::operators::convertCmToMm(fv.translation().z())) // converted from cm (DD4hep) to mm | ||
{} | ||
|
||
DetGeomDesc::DetGeomDesc(const DetGeomDesc& ref) { (*this) = ref; } | ||
|
||
DetGeomDesc& DetGeomDesc::operator=(const DetGeomDesc& ref) { | ||
m_name = ref.m_name; | ||
m_copy = ref.m_copy; | ||
m_isDD4hep = ref.m_isDD4hep; | ||
m_trans = ref.m_trans; | ||
m_rot = ref.m_rot; | ||
m_params = ref.m_params; | ||
m_isABox = ref.m_isABox; | ||
m_diamondBoxParams = ref.m_diamondBoxParams; | ||
m_sensorType = ref.m_sensorType; | ||
m_geographicalID = ref.m_geographicalID; | ||
m_z = ref.m_z; | ||
return (*this); | ||
DetGeomDesc* DetGeomDesc::makeCopyWithoutChildren() const { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes the renaming is a good idea |
||
DetGeomDesc* output = new DetGeomDesc; | ||
|
||
// copy all data members except children (m_container) | ||
output->m_name = m_name; | ||
output->m_copy = m_copy; | ||
output->m_isDD4hep = m_isDD4hep; | ||
output->m_trans = m_trans; | ||
output->m_rot = m_rot; | ||
output->m_params = m_params; | ||
output->m_isABox = m_isABox; | ||
output->m_diamondBoxParams = m_diamondBoxParams; | ||
output->m_sensorType = m_sensorType; | ||
output->m_geographicalID = m_geographicalID; | ||
|
||
output->m_z = m_z; | ||
|
||
return output; | ||
} | ||
|
||
DetGeomDesc::~DetGeomDesc() { deepDeleteComponents(); } | ||
|
@@ -116,8 +119,7 @@ void DetGeomDesc::deleteComponents() { m_container.erase(m_container.begin(), m_ | |
|
||
void DetGeomDesc::deepDeleteComponents() { | ||
for (auto& it : m_container) { | ||
it->deepDeleteComponents(); | ||
delete it; | ||
delete it; // the destructor calls deepDeleteComponents | ||
} | ||
clearComponents(); | ||
} | ||
|
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.
Why adding the default constructor?
A DetGeomDesc built with this, will not have interesting data members, and no way of setting them.
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.
A way of creating an "empty" object is needed here:
https://github.com/cms-sw/cmssw/pull/31492/files/0e26c4a0f7658a37176349a8e446492503cdf81c#diff-cae30eec6c3de96aa4e668edf94cf7a8R62
Would you have a better suggestion?
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.
Make it private?
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 there should just be a custom copy constructor.
This in a sense is just 'trying to have' a constructor, with settings done in makeCopyWithoutChildren()