forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Geant4 utilities in preparation for g4vg (celeritas-project#…
…1095) * Reuse daughter placer in g4vg * Refactor Geant4 volume visitor to an actual volume visitor * Fix cxx target * Split generic geo test into multiple * Fix build errors * Fix edge case in importer
- Loading branch information
Showing
31 changed files
with
870 additions
and
783 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file celeritas/ext/VisitGeantVolumes.hh | ||
//---------------------------------------------------------------------------// | ||
#pragma once | ||
|
||
#include <unordered_set> | ||
#include <vector> | ||
#include <G4LogicalVolume.hh> | ||
|
||
#include "corecel/Assert.hh" | ||
#include "corecel/cont/Range.hh" | ||
|
||
namespace celeritas | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Do a recursive depth-first listing of Geant4 logical volumes. | ||
* | ||
* This will visit each volume exactly once based on when it's encountered in | ||
* the hierarchy. The visitor function F should have the signature | ||
* \code void(*)(G4LogicalVolume const&) \endcode . | ||
*/ | ||
template<class F> | ||
void visit_geant_volumes(F&& vis, G4LogicalVolume const& parent_vol) | ||
{ | ||
std::unordered_set<G4LogicalVolume const*> visited; | ||
std::vector<G4LogicalVolume const*> stack{&parent_vol}; | ||
|
||
while (!stack.empty()) | ||
{ | ||
G4LogicalVolume const* lv = stack.back(); | ||
stack.pop_back(); | ||
vis(*lv); | ||
for (auto const i : range(lv->GetNoDaughters())) | ||
{ | ||
G4LogicalVolume* daughter = lv->GetDaughter(i)->GetLogicalVolume(); | ||
CELER_ASSERT(daughter); | ||
auto&& [iter, inserted] = visited.insert(daughter); | ||
if (inserted) | ||
{ | ||
stack.push_back(daughter); | ||
} | ||
} | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace celeritas |
Oops, something went wrong.