Skip to content

Commit b0ae952

Browse files
authored
Set proper ownership of MO collection after deserialization (#798)
1 parent d6dd132 commit b0ae952

4 files changed

Lines changed: 28 additions & 5 deletions

File tree

Framework/include/QualityControl/MonitorObjectCollection.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class MonitorObjectCollection : public TObjArray, public mergers::MergeInterface
3030
~MonitorObjectCollection() = default;
3131

3232
void merge(mergers::MergeInterface* const other) override;
33+
34+
void postDeserialization() override;
35+
3336
ClassDefOverride(MonitorObjectCollection, 0);
3437
};
3538

Framework/src/CheckRunner.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,12 @@ void CheckRunner::prepareCacheData(framework::InputRecord& inputRecord)
243243

244244
// We don't know what we receive, so we test for an array and then try a tobject.
245245
// If we received a tobject, it gets encapsulated in the tobjarray.
246-
shared_ptr<const TObjArray> array = nullptr;
247-
shared_ptr<const TObject> tobj = inputRecord.get<TObject*>(input.binding.c_str());
246+
shared_ptr<TObjArray> array = nullptr;
247+
auto tobj = DataRefUtils::as<TObject>(dataRef);
248248
// if the object has not been found, it will raise an exception that we just let go.
249249
if (tobj->InheritsFrom("TObjArray")) {
250-
array = dynamic_pointer_cast<const TObjArray>(tobj);
250+
array.reset(dynamic_cast<TObjArray*>(tobj.release()));
251+
array->SetOwner(false);
251252
mLogger << AliceO2::InfoLogger::InfoLogger::Info << "CheckRunner " << mDeviceName
252253
<< " received an array with " << array->GetEntries()
253254
<< " entries from " << input.binding << ENDM;

Framework/src/MonitorObjectCollection.cxx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
///
1616

1717
#include "QualityControl/MonitorObjectCollection.h"
18-
1918
#include "QualityControl/MonitorObject.h"
19+
#include "QualityControl/QcInfoLogger.h"
2020

2121
#include <Mergers/MergerAlgorithm.h>
2222

@@ -51,4 +51,23 @@ void MonitorObjectCollection::merge(mergers::MergeInterface* const other)
5151
delete otherIterator;
5252
}
5353

54+
void MonitorObjectCollection::postDeserialization()
55+
{
56+
auto it = this->MakeIterator();
57+
while (auto obj = it->Next()) {
58+
auto mo = dynamic_cast<MonitorObject*>(obj);
59+
if (mo == nullptr) {
60+
ILOG(Warning) << "Could not cast an object of type '" << obj->ClassName() << "' in MonitorObjectCollection to MonitorObject, skipping." << ENDM;
61+
continue;
62+
}
63+
mo->setIsOwner(true);
64+
if (mo->getObject() != nullptr && mo->getObject()->InheritsFrom(TCollection::Class())) {
65+
auto collection = dynamic_cast<TCollection*>(mo->getObject());
66+
collection->SetOwner(true);
67+
}
68+
}
69+
this->SetOwner(true);
70+
delete it;
71+
}
72+
5473
} // namespace o2::quality_control::core

Framework/src/ObjectsManager.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ObjectsManager::~ObjectsManager() = default;
5353

5454
void ObjectsManager::startPublishing(TObject* object)
5555
{
56-
if (mMonitorObjects->FindObject(object->GetName()) != 0) {
56+
if (mMonitorObjects->FindObject(object->GetName()) != nullptr) {
5757
ILOG(Warning, Support) << "Object is already being published (" << object->GetName() << ")" << ENDM;
5858
BOOST_THROW_EXCEPTION(DuplicateObjectError() << errinfo_object_name(object->GetName()));
5959
}

0 commit comments

Comments
 (0)