Skip to content
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

Fix "Called C++ object pointer is null" in DDCoreToDDXMLOutput::position #46075

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions DetectorDescription/OfflineDBLoader/src/DDCoreToDDXMLOutput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -784,25 +784,27 @@ void DDCoreToDDXMLOutput::position(const TGeoVolume& parent,
xos << "<rChild name=\"" << childVolName << "\"/>" << std::endl;

const auto matrix = child.GetMatrix();
if (matrix != nullptr && !matrix->IsIdentity()) {
Copy link
Contributor

@civanch civanch Sep 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iarspider, if (matrix != nullptr && !matrix->IsIdentity()) is a valid construction. If the first check 'false' the second does not checked. This is used in many places, no reason to change this place. The fix should be done in place where position is called - matrix should not be nullptr. With the current change of indentation I cannot understand where and how - better to avoid such big modification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A rotation matrix may or may not be present in a transformation matrix. Sometimes a child is placed in a mother with no translation and no rotation. In Geant4 one needs to provide a translation vector with a default 3-vector for the translation matrix while in DD4hep one may specify the placement dropping reference to both translation and rotation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bsunanda , should we review this code or accept this fix?

auto rot = matrix->GetRotationMatrix();
if (cms::rotation_utils::rotHash(rot) != cms::rotation_utils::identityHash) {
std::string rotNameStr = cms::rotation_utils::rotName(rot, context);
if (rotNameStr == "NULL") {
rotNameStr = child.GetName(); // Phys vol name
rotNameStr += parent.GetName();
cms::DDNamespace nameSpace(context);
cms::rotation_utils::addRotWithNewName(nameSpace, rotNameStr, rot);
if (matrix != nullptr) {
if (!matrix->IsIdentity()) {
auto rot = matrix->GetRotationMatrix();
if (cms::rotation_utils::rotHash(rot) != cms::rotation_utils::identityHash) {
std::string rotNameStr = cms::rotation_utils::rotName(rot, context);
if (rotNameStr == "NULL") {
rotNameStr = child.GetName(); // Phys vol name
rotNameStr += parent.GetName();
cms::DDNamespace nameSpace(context);
cms::rotation_utils::addRotWithNewName(nameSpace, rotNameStr, rot);
}
xos << "<rRotation name=\"" << rotNameStr << "\"/>" << std::endl;
}
xos << "<rRotation name=\"" << rotNameStr << "\"/>" << std::endl;
}
auto trans = matrix->GetTranslation();
using namespace cms_rounding;
xos << "<Translation x=\"" << roundIfNear0(trans[0]) << "*mm\"";
xos << " y=\"" << roundIfNear0(trans[1]) << "*mm\"";
xos << " z=\"" << roundIfNear0(trans[2]) << "*mm\"";
xos << "/>" << std::endl;
}
auto trans = matrix->GetTranslation();
using namespace cms_rounding;
xos << "<Translation x=\"" << roundIfNear0(trans[0]) << "*mm\"";
xos << " y=\"" << roundIfNear0(trans[1]) << "*mm\"";
xos << " z=\"" << roundIfNear0(trans[2]) << "*mm\"";
xos << "/>" << std::endl;
xos << "</PosPart>" << std::endl;
}

Expand Down