Skip to content

Commit 47f932a

Browse files
committed
Do not keep physical nodes when aligning the o2-sim geometry
This lowers the memory of o2-sim by deleting each TGeo physical node right after its alignment. - Applying the alignment created one TGeoPhysicalNode per alignable volume (29582), kept for the whole job. - GeometryManager::applyAlignment and Aligner::applyAlignment get an option keepPhysicalNodes, true by default. - o2-sim sets it to false, since it needs no original matrices; reconstruction and alignment are unchanged.
1 parent f611478 commit 47f932a

5 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎Detectors/Base/include/DetectorsBase/Aligner.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Aligner : public o2::conf::ConfigurableParamHelper<Aligner>
3333
o2::detectors::DetID::mask_t getDetectorsMask() const;
3434

3535
bool isAlignmentRequested() const { return getDetectorsMask().any(); }
36-
void applyAlignment(long timestamp = 0, o2::detectors::DetID::mask_t addMask = o2::detectors::DetID::FullMask) const;
36+
void applyAlignment(long timestamp = 0, o2::detectors::DetID::mask_t addMask = o2::detectors::DetID::FullMask, bool keepPhysicalNodes = true) const;
3737

3838
private:
3939
std::string mDetectors = "all"; // comma-separated list of modules to align, "all" or "none"

‎Detectors/Base/include/DetectorsBase/GeometryManager.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ class GeometryManager : public TObject
8484
~GeometryManager() override = default;
8585

8686
/// misalign geometry with alignment objects from the array, optionaly check overlaps
87-
static bool applyAlignment(const std::vector<o2::detectors::AlignParam>& algPars);
87+
/// with keepPhysicalNodes false, each physical node is deleted after its alignment (no original matrices are kept)
88+
static bool applyAlignment(const std::vector<o2::detectors::AlignParam>& algPars, bool keepPhysicalNodes = true);
8889
static bool applyAlignment(const std::vector<const std::vector<o2::detectors::AlignParam>*> algPars);
8990

9091
struct MatBudgetExt {

‎Detectors/Base/src/Aligner.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ DetID::mask_t Aligner::getDetectorsMask() const
2727
return DetID::getMask(mDetectors) & (~DetID::getMask(DetID::CTP));
2828
}
2929

30-
void Aligner::applyAlignment(long timestamp, DetID::mask_t addMask) const
30+
void Aligner::applyAlignment(long timestamp, DetID::mask_t addMask, bool keepPhysicalNodes) const
3131
{
3232
DetID::mask_t msk = getDetectorsMask() & addMask;
3333
if (msk.none()) {
@@ -59,7 +59,7 @@ void Aligner::applyAlignment(long timestamp, DetID::mask_t addMask) const
5959
}
6060
if (!algV->empty()) {
6161
done.set(id);
62-
o2::base::GeometryManager::applyAlignment(*algV);
62+
o2::base::GeometryManager::applyAlignment(*algV, keepPhysicalNodes);
6363
} else {
6464
skipped.set(id);
6565
}

‎Detectors/Base/src/GeometryManager.cxx‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ bool GeometryManager::applyAlignment(const std::vector<const std::vector<o2::det
277277
}
278278

279279
//______________________________________________________________________
280-
bool GeometryManager::applyAlignment(const std::vector<o2::detectors::AlignParam>& algPars)
280+
bool GeometryManager::applyAlignment(const std::vector<o2::detectors::AlignParam>& algPars, bool keepPhysicalNodes)
281281
{
282282
/// misalign geometry with alignment objects from the array, optionaly check overlaps
283283
int nvols = algPars.size();
@@ -286,11 +286,23 @@ bool GeometryManager::applyAlignment(const std::vector<o2::detectors::AlignParam
286286
std::sort(std::begin(ord), std::end(ord), [&algPars](int a, int b) { return algPars[a].getLevel() < algPars[b].getLevel(); });
287287

288288
bool res = true;
289+
auto pns = gGeoManager->GetListOfPhysicalNodes();
289290
for (int i = 0; i < nvols; i++) {
291+
int npn = pns->GetEntriesFast();
290292
if (!algPars[ord[i]].applyToGeometry(GeometryManagerParam::Instance().printLevel)) {
291293
res = false;
292294
LOG(error) << "Error applying alignment object for volume" << algPars[ord[i]].getSymName();
293295
}
296+
if (!keepPhysicalNodes) { // delete the nodes this alignment created, so their memory is reused by the next one
297+
for (int k = pns->GetEntriesFast() - 1; k >= npn; k--) {
298+
auto pn = static_cast<TGeoPhysicalNode*>(pns->RemoveAt(k));
299+
if (auto pne = gGeoManager->GetAlignableEntry(algPars[ord[i]].getSymName().c_str()); pne && pne->GetPhysicalNode() == pn) {
300+
pne->SetPhysicalNode(nullptr);
301+
}
302+
delete pn;
303+
}
304+
pns->Compress();
305+
}
294306
}
295307
return res;
296308
}

‎Steer/src/O2MCApplication.cxx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ bool O2MCApplicationBase::MisalignGeometry()
330330

331331
// apply alignment for included detectors AFTER exporting ideal geometry
332332
auto& aligner = o2::base::Aligner::Instance();
333-
aligner.applyAlignment(confref.getTimestamp());
333+
// the simulation needs no original matrices, so the physical nodes are not kept
334+
aligner.applyAlignment(confref.getTimestamp(), o2::detectors::DetID::FullMask, false);
334335

335336
// export aligned geometry into different file
336337
auto alignedgeomfile = o2::base::NameConf::getAlignedGeomFileName(confref.getOutPrefix());

0 commit comments

Comments
 (0)