convert radiator pointer into shared_ptr instead of constructing new one
When trying to do simulations with non-default radiator parameters I noticed that the parameters I set where always overwritten by the defaults.
For example if I set a radiator with 100 transitions in the run_digi.C
:
CbmDigitization run;
CbmTrdRadiator* radiator = new CbmTrdRadiator(true,100, 0.0012, 0.09, "pefoam20", "Kapton");
CbmTrdDigitizer *trddigitizer = new CbmTrdDigitizer(radiator);
run.SetDigitizer(ECbmModuleId::kTrd, trddigitizer);
the number of transitions in the actual digitization run were always reset to the default value of 337.
This seems to happen because the CbmTrdDigitizer
expects a shared_ptr<CbmTrdRadiator>
and when provided with a normal pointer it will create a new shared one (Line 85f):
CbmTrdDigitizer::CbmTrdDigitizer(CbmTrdRadiator* radiator)
: CbmTrdDigitizer(std::make_shared<CbmTrdRadiator>(radiator)) {};
The problem is that std::make_shared
will invoke the default constructor of CbmTrdRadiator
since no parameters are provided, thus overwriting any custom parameters set previously. I think instead of creating a new shared pointer one should convert the normal pointer into a shared pointer to keep the parameters.
I am not sure if this should be done by using std::shared_ptr
directly or using a static_cast
(or some other way?):
//option 1
CbmTrdDigitizer::CbmTrdDigitizer(CbmTrdRadiator* radiator)
: CbmTrdDigitizer(std::shared_ptr<CbmTrdRadiator>(radiator)) {};
//option 2
CbmTrdDigitizer::CbmTrdDigitizer(CbmTrdRadiator* radiator)
: CbmTrdDigitizer(static_cast<std::shared_ptr<CbmTrdRadiator>>(radiator)) {};
Both options seem to work in my case, I commited option 1 as it is a bit simpler to read in my opinion.
Merge request reports
Activity
added 4 commits
-
a8870c47...f3e1f0b8 - 3 commits from branch
computing:master
- 2858141b - convert radiator pointer into shared_ptr instead of constructing new one
-
a8870c47...f3e1f0b8 - 3 commits from branch
Dear @a.bercuci, @p.kaehler,
you have been identified as code owner of at least one file which was changed with this merge request.
Please check the changes and approve them or request changes.
added CodeOwners label
added 10 commits
-
f8d79a40...687fd53a - 8 commits from branch
computing:master
- bab7d519 - convert radiator pointer into shared_ptr instead of constructing new one
- 0fce088d - apply format
-
f8d79a40...687fd53a - 8 commits from branch
@f.uhlig do you have any preferences here? If not, we are in principle ready to merge
- Resolved by Adrian Meyer-Ahrens
the change is fine with me. I will rebase and merge.
enabled an automatic merge when the pipeline for eb9c374e succeeds
added 7 commits
-
eb9c374e...d3c3818a - 5 commits from branch
computing:master
- f8a2c436 - convert radiator pointer into shared_ptr instead of constructing new one
- 00a413e2 - apply format
-
eb9c374e...d3c3818a - 5 commits from branch
added 4 commits
-
00a413e2...78e1f39a - 2 commits from branch
computing:master
- d46f384e - convert radiator pointer into shared_ptr instead of constructing new one
- 17ab3df0 - apply format
-
00a413e2...78e1f39a - 2 commits from branch
enabled an automatic merge when the pipeline for 17ab3df0 succeeds