VIVE L’AMOUR!
I am Pepe Le Pew. Zis is my first affair so, please, be kind. I’m shy but, uh, I’m willing…
I’d like to traverse a geometry and perform some actions based on the “name” and “path”.
I’ve tried three approaches, but none of them is really satisfactory to me.
- An iterative function traversing nodes.
void MyNodeIter(TGeoVolume *vol) {
vol->GetGeoManager()->PushPath(); // save the original path
TGeoIterator next(vol);
TGeoNode *node;
TString path;
while ((node = next())) // daughters
{
next.GetPath(path);
vol = node->GetVolume();
vol->GetGeoManager()->cd(path.Data());
// do some “actions” for the current node
std::cout << node->GetName() << " "
<< vol->GetGeoManager()->GetPath() << " "
<< path << std::endl;
}
next.GetTopVolume()->GetGeoManager()->PopPath(); // restore the original path
}
void MyNodeIter(TGeoNode *node) {
MyNodeIter(node->GetVolume());
}
which is then called, for example, as
MyNodeIter(gGeomanager->GetTopVolume());
or as
MyNodeIter(gGeomanager->GetTopNode());
There are two problems here:
a. it does not work for the “starting node” (“actions” are performed for daughters only),
b. the “path” contains “A/B_0/C_0”, while “vol->GetGeoManager()->GetPath()” returns “/A_1/B_0/C_0” and if I do not “cd(path.Data())”, the “vol->GetGeoManager()->GetPath()” is never changing, it always returns “/A_1” (the “path” does change, however).
Can I somehow improve this function to perform my “actions” for the “starting node”, too?
Is the “PushPath” / “PopPath” logic doing what I’m “expecting”?
- A recursive function traversing nodes.
void MyNodeRecur(TGeoNode *node) {
// I need to “CdDown(node)” but HOW?
// do some “actions” for the current node
std::cout << node->GetName() << " "
<< node->GetVolume()->GetGeoManager()->GetPath() << " "
<< std::endl;
// daughters now
for (Int_t i = 0; i < node->GetNdaughters(); i++)
MyNodeRecur(node->GetDaughter(i), name);
// I need to “CdUp()” but HOW?
}
which is then called, for example, as
MyNodeIter(gGeomanager->GetTopNode())
As one can see, my “actions” are performed for every node, including the “starting node”.
The problem with this function is that I do not know how to “CdDown” / “CdUp” and as a result the “GetPath()” always returns “/A_1” (and I do not know how to “GetPath(node)”).
- A recursive function traversing volumes.
void MyVolRecur(TGeoVolume *vol) {
// I need to “CdDown(vol)” but HOW?
// do some “actions” for the current node
std::cout << vol->GetName() << " "
<< vol->GetGeoManager()->GetPath() << " "
<< std::endl;
// daughters now
for (Int_t i = 0; i < vol->GetNdaughters(); i++)
MyVolRecur(vol->GetNode(i)->GetVolume());
// I need to “CdUp()” but HOW?
}
void MyVolRecur(TGeoNode *node) {
MyVolRecur(node->GetVolume());
}
which is then called, for example, as
MyVolRecur(gGeomanager->GetTopVolume());
or as
MyVolRecur(gGeomanager->GetTopNode());
As one can see, my “actions” are performed for every node, including the “starting node”.
The problem with this function is that I do not know how to “CdDown” / “CdUp” and as a result the “GetPath()” always returns “/A_1” (and I do not know how to “GetPath(vol)”).
I am stupid. No?
Pepe Le Pew.