Add helper class to abstract the difference between DetDesc DE* and DD4hep handles
During adaptation of code to transparently work with DetDesc and DD4hep, I had to keep a pointer/reference to a DetectorElement in a derived condition.
This is highly non transparent because in DetDesc we have to use bare pointers and in DD4hep we have handles:
struct MyCond {
MyCond() = default; // must be default constructible, see lhcb/LHCb!3544
MyCond& operator=(MyCond&&) = default; // must be default (at least) move assignable, see lhcb/LHCb!3544
MyCond(const DetElement& det_):
#ifdef USE_DD4HEP
det(det_)
#else
det(&det_)
#endif
{}
#ifdef USE_DD4HEP
DetElement det; // we must make a copy as handles are temporary
#else
const DetElement* det = nullptr; // we must make have a pointer do be default constructible
#endif
};
void userCode(const MyCond& cond) {
#ifdef USE_DD4HEP
cond.det.method();
#else
cond.det->method();
#endif
}
With the new helper one can write:
struct MyCond {
MyCond() = default; // must be default constructible, see lhcb/LHCb!3544
MyCond& operator=(MyCond&&) = default; // must be default (at least) move assignable, see lhcb/LHCb!3544
MyCond(const DetElement& det_): det(det_) {}
LHCb::DetDesc::DetElementRef<DetElement> det; // alias pointing to the right version
};
void userCode(const MyCond& cond) {
cond.det->method();
}
/cc @sponce