Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor MonitorObject and adding Copy capabilities #2450

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions Framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@ configure_file("include/QualityControl/Version.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/include/QualityControl/Version.h"
@ONLY)

# ---- Library for the types ----
# ---- Library for IL ----
add_library(O2QualityControlInfoLogger STATIC
src/QcInfoLogger.cxx
)

target_include_directories(O2QualityControlInfoLogger
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

target_link_libraries(O2QualityControlInfoLogger
PUBLIC
AliceO2::InfoLogger
)

# ---- Library for the types ----
add_library(O2QualityControlTypes
src/MonitorObject.cxx
src/QualityObject.cxx
Expand All @@ -21,11 +35,13 @@ target_include_directories(
)

target_link_libraries(O2QualityControlTypes
PRIVATE
O2QualityControlInfoLogger
PUBLIC
ROOT::Hist
AliceO2::BookkeepingApi
AliceO2::Common
O2::DataFormatsQualityControl
AliceO2::BookkeepingApi
ROOT::Hist
)

add_root_dictionary(O2QualityControlTypes
Expand Down Expand Up @@ -70,7 +86,6 @@ add_library(O2QualityControl
src/AggregatorInterface.cxx
src/DatabaseFactory.cxx
src/CcdbDatabase.cxx
src/QcInfoLogger.cxx
src/TaskFactory.cxx
src/TaskRunner.cxx
src/TaskRunnerFactory.cxx
Expand Down Expand Up @@ -141,7 +156,6 @@ target_link_libraries(O2QualityControl
ROOT::Hist
ROOT::TreePlayer
AliceO2::Common
AliceO2::InfoLogger
AliceO2::Monitoring
AliceO2::Configuration
AliceO2::Occ
Expand All @@ -159,6 +173,7 @@ target_link_libraries(O2QualityControl
${RDKAFKA_LIB}
PRIVATE Boost::system
CURL::libcurl
O2QualityControlInfoLogger
)

add_root_dictionary(O2QualityControl
Expand Down
33 changes: 19 additions & 14 deletions Framework/include/QualityControl/MonitorObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class MonitorObject : public TObject
/// Destructor
~MonitorObject() override;

/// Copy constructor
MonitorObject(const MonitorObject& other) = default;
// /// Copy constructor
MonitorObject(const MonitorObject& other);
/// Move constructor
MonitorObject(MonitorObject&& other) /*noexcept*/ = default;
/// Copy assignment operator
MonitorObject& operator=(const MonitorObject& other) = default;
MonitorObject& operator=(const MonitorObject& other);
/// Move assignment operator
MonitorObject& operator=(MonitorObject&& other) /*noexcept*/ = default;

Expand All @@ -69,19 +69,19 @@ class MonitorObject : public TObject

/// \brief Return joined task name and name of the encapsulated object (if any).
/// @return The name as "{getTaskName()}/{getName())}.
const std::string getFullName() const { return getTaskName() + "/" + getName(); }
std::string getFullName() const;

TObject* getObject() const { return mObject; }
void setObject(TObject* object) { mObject = object; }
TObject* getObject() const;
void setObject(TObject* object);

bool isIsOwner() const { return mIsOwner; }
void setIsOwner(bool isOwner) { mIsOwner = isOwner; }
bool isIsOwner() const;
void setIsOwner(bool isOwner);

const std::string& getTaskName() const { return mTaskName; }
void setTaskName(const std::string& taskName) { mTaskName = taskName; }
const std::string& getTaskName() const;
void setTaskName(const std::string& taskName);

const std::string& getDetectorName() const { return mDetectorName; }
void setDetectorName(const std::string& detectorName) { mDetectorName = detectorName; }
const std::string& getDetectorName() const;
void setDetectorName(const std::string& detectorName);

const std::string& getTaskClass() const;
void setTaskClass(const std::string& taskClass);
Expand Down Expand Up @@ -117,6 +117,8 @@ class MonitorObject : public TObject
void Draw(Option_t* option) override;
TObject* DrawClone(Option_t* option) const override;

void Copy(TObject& object) const override;

/// \brief Build the path to this object.
/// Build the path to this object as it will appear in the GUI.
/// \return A string containing the path.
Expand All @@ -126,7 +128,7 @@ class MonitorObject : public TObject
void setDescription(const std::string& description);

private:
TObject* mObject;
std::unique_ptr<TObject> mObject;
std::string mTaskName;
std::string mTaskClass;
std::string mDetectorName;
Expand All @@ -141,7 +143,10 @@ class MonitorObject : public TObject
// tells Merger to create an object with data from the last cycle only on the side of the complete object
bool mCreateMovingWindow = false;

ClassDefOverride(MonitorObject, 12);
void releaseObject();
void cloneAndSetObject(const MonitorObject&);

ClassDefOverride(MonitorObject, 13);
};

} // namespace o2::quality_control::core
Expand Down
150 changes: 128 additions & 22 deletions Framework/src/MonitorObject.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,92 @@
///

#include "QualityControl/MonitorObject.h"
#include <TObject.h>
#include "QualityControl/RepoPathUtils.h"
#include "QualityControl/QcInfoLogger.h"

#include <iostream>
#include "QualityControl/RepoPathUtils.h"

using namespace std;

namespace o2::quality_control::core
{

MonitorObject::MonitorObject()
: TObject(),
mObject(nullptr),
mTaskName(""),
mDetectorName(""),
mIsOwner(true)
: TObject{},
mIsOwner{ true }
{
mActivity.mProvenance = "qc";
mActivity.mId = 0;
mActivity.mValidity = gInvalidValidityInterval;
}

MonitorObject::MonitorObject(TObject* object, const std::string& taskName, const std::string& taskClass, const std::string& detectorName, int runNumber, const std::string& periodName, const std::string& passName, const std::string& provenance)
: TObject(),
mObject(object),
mTaskName(taskName),
mTaskClass(taskClass),
mDetectorName(detectorName),
mActivity(runNumber, "NONE", periodName, passName, provenance, gInvalidValidityInterval),
mIsOwner(true)
: TObject{},
mObject{ object },
mTaskName{ taskName },
mTaskClass{ taskClass },
mDetectorName{ detectorName },
mActivity{ runNumber, "NONE", periodName, passName, provenance, gInvalidValidityInterval },
mIsOwner{ true }
{
}

MonitorObject::MonitorObject(const MonitorObject& other)
: TObject{ other },
mObject{},
mTaskName{ other.mTaskName },
mTaskClass{ other.mTaskClass },
mDetectorName{ other.mDetectorName },
mUserMetadata{ other.mUserMetadata },
mDescription{ other.mDescription },
mActivity{ other.mActivity },
mCreateMovingWindow{ other.mCreateMovingWindow }
{
cloneAndSetObject(other);
}

MonitorObject& MonitorObject::operator=(const MonitorObject& other)
{
TObject::operator=(other);
mTaskName = other.mTaskName;
mTaskClass = other.mTaskClass;
mDetectorName = other.mDetectorName;
mUserMetadata = other.mUserMetadata;
mDescription = other.mDescription;
mActivity = other.mActivity;
mCreateMovingWindow = other.mCreateMovingWindow;
cloneAndSetObject(other);

return *this;
}

void MonitorObject::Copy(TObject& object) const
{
static_cast<MonitorObject&>(object) = *this;
}

MonitorObject::~MonitorObject()
{
if (mIsOwner) {
delete mObject;
mObject = nullptr;
}
releaseObject();
}

void MonitorObject::Draw(Option_t* option) { mObject->Draw(option); }
void MonitorObject::Draw(Option_t* option)
{
if (mObject) {
mObject->Draw(option);
} else {
ILOG(Error, Devel) << "MonitorObject::Draw() : You are trying to draw MonitorObject with no internal TObject" << ENDM;
}
}

TObject* MonitorObject::DrawClone(Option_t* option) const
{
if (!mObject) {
ILOG(Error, Devel) << "MonitorObject::DrawClone() : You are trying to draw MonitorObject with no internal TObject" << ENDM;
return nullptr;
}

auto* clone = new MonitorObject();
clone->setTaskName(this->getTaskName());
clone->setObject(mObject->DrawClone(option));
Expand All @@ -72,10 +114,9 @@ const std::string MonitorObject::getName() const

const char* MonitorObject::GetName() const
{
if (mObject == nullptr) {
cerr << "MonitorObject::getName() : No object in this MonitorObject, returning empty string" << endl;
static char empty[] = "";
return empty;
if (!mObject) {
ILOG(Error, Ops) << "MonitorObject::getName() : No object in this MonitorObject, returning empty string" << ENDM;
return "";
}
return mObject->GetName();
}
Expand Down Expand Up @@ -160,6 +201,52 @@ void MonitorObject::updateValidity(validity_time_t value)
mActivity.mValidity.update(value);
}

std::string MonitorObject::getFullName() const
{
return getTaskName() + "/" + getName();
}

TObject* MonitorObject::getObject() const
{
return mObject.get();
}

void MonitorObject::setObject(TObject* object)
{
releaseObject();
mObject.reset(object);
}

bool MonitorObject::isIsOwner() const
{
return mIsOwner;
}

void MonitorObject::setIsOwner(bool isOwner)
{
mIsOwner = isOwner;
}

const std::string& MonitorObject::getTaskName() const
{
return mTaskName;
}

void MonitorObject::setTaskName(const std::string& taskName)
{
mTaskName = taskName;
}

const std::string& MonitorObject::getDetectorName() const
{
return mDetectorName;
}

void MonitorObject::setDetectorName(const std::string& detectorName)
{
mDetectorName = detectorName;
}

ValidityInterval MonitorObject::getValidity() const
{
return mActivity.mValidity;
Expand All @@ -185,4 +272,23 @@ bool MonitorObject::getCreateMovingWindow() const
return mCreateMovingWindow;
}

void MonitorObject::releaseObject()
{
if (!mIsOwner) {
void(mObject.release());
}
}

void MonitorObject::cloneAndSetObject(const MonitorObject& other)
{
releaseObject();

if (auto* otherObject = other.getObject(); otherObject != nullptr && other.isIsOwner()) {
mObject.reset(otherObject->Clone());
} else {
mObject.reset(otherObject);
}
mIsOwner = other.isIsOwner();
}

} // namespace o2::quality_control::core
Loading
Loading