[WIP] Accumulator for cloned Algs
see GAUDI-1194
this provides a mechanism for cloned Algorithms to perform some accumulation/merging across all instances. The user must have their Algorithm inherit from IAccumulator, which defines an operator +=
function. Just before finalization, the AlgorithmManager loops over all Algorithms that inherit from IAccumulator, and calls +=
on them, adding Algorithm::index >0 to Algorithm::index=0, ie the accumulated values will show up in the instance of the Algorithm where Algorithm::index() == 0
During Algorithm::finalize(), the user should test for (index()==0), and perform any required special actions.
an example of user code:
class MyAlg : public Algorithm, public IAccumulator {
public:
...
int val() const { return m_val; }
IAccumulator& operator +=(const IAccumulator& other);
...
private:
int m_val; // value to be accumulated
}
IAccumulator& MyAlg::operator+=(const IAccumulator& other) {
auto oth = dynamic_cast<const MyAlg*>(&other);
if (oth != 0) { /// in reality this should never fail
m_val += oth->val();
}
}
StatusCode MyAlg::finalize() {
if (index() == 0) {
// accumulated value is in primary instance, ie Algorithm::index() == 0
info() << "accumulated value is: " << val() << endmsg;
}
}