66#include " QualityControl/HistoMerger.h"
77
88#include < Framework/DataRefUtils.h>
9+ #include < TObjArray.h>
910
1011namespace o2
1112{
@@ -22,33 +23,42 @@ HistoMerger::HistoMerger(std::string mergerName, double publicationPeriodSeconds
2223 : mMergerName (mergerName), mOutputSpec { header::gDataOriginInvalid , header::gDataDescriptionInvalid }
2324{
2425 mPublicationTimer .reset (static_cast <int >(publicationPeriodSeconds * 1000000 ));
26+ mMergedArray .SetOwner (true );
2527}
2628
2729HistoMerger::~HistoMerger () {}
2830
29- void HistoMerger::init (framework::InitContext& ctx ) { mMonitorObject . reset (); }
31+ void HistoMerger::init (framework::InitContext&) { mMergedArray . Clear (); }
3032
3133void HistoMerger::run (framework::ProcessingContext& ctx)
3234{
3335 for (const auto & input : ctx.inputs ()) {
34- if (input.header != nullptr && input.spec != nullptr &&
35- std::strstr ( DataRefUtils::as<MonitorObject >(input)-> getObject ()-> ClassName (), " TH1 " ) != nullptr ) {
36+ if (input.header != nullptr && input.spec != nullptr ) {
37+ std::unique_ptr<TObjArray> moArray = DataRefUtils::as<TObjArray >(input);
3638
37- if (! mMonitorObject ) {
38- mMonitorObject . reset (DataRefUtils::as<MonitorObject>(input). release () );
39+ if (mMergedArray . IsEmpty () ) {
40+ mMergedArray = *moArray. release ();
3941 } else {
40- TH1 * h = dynamic_cast <TH1 *>(mMonitorObject ->getObject ());
41- const TH1 * hUpdate = dynamic_cast <TH1 *>(DataRefUtils::as<MonitorObject>(input)->getObject ());
42- h->Add (hUpdate);
42+ if (mMergedArray .GetSize () != moArray->GetSize ()) {
43+ LOG (ERROR ) << " array don't match in size, " << mMergedArray .GetSize () << " vs " << moArray->GetSize ();
44+ return ;
45+ }
46+
47+ for (int i = 0 ; i < mMergedArray .GetEntries (); i++) {
48+ MonitorObject* mo = dynamic_cast <MonitorObject*>((*moArray)[i]);
49+ if (mo && std::strstr (mo->getObject ()->ClassName (), " TH1" ) != nullptr ) {
50+ TH1 * h = dynamic_cast <TH1 *>(dynamic_cast <MonitorObject*>(mMergedArray [i])->getObject ());
51+ const TH1 * hUpdate = dynamic_cast <TH1 *>(mo->getObject ());
52+ h->Add (hUpdate);
53+ }
54+ }
4355 }
4456 }
4557 }
4658 if (mPublicationTimer .isTimeout ()) {
47- if (mMonitorObject ) {
48- ctx.outputs ().snapshot <MonitorObject>(Output{ mOutputSpec .origin , mOutputSpec .description , mOutputSpec .subSpec },
49- *mMonitorObject );
59+ if (!mMergedArray .IsEmpty ()) {
60+ ctx.outputs ().snapshot (Output{ mOutputSpec .origin , mOutputSpec .description , mOutputSpec .subSpec }, mMergedArray );
5061 }
51-
5262 // avoid publishing mo many times consecutively because of too long initial waiting time
5363 do {
5464 mPublicationTimer .increment ();
0 commit comments