Skip to content

Commit

Permalink
[QC-885] Modify reference check to also accept a TH1 … (#2358)
Browse files Browse the repository at this point in the history
* [QC-885] Modify ReferenceComparatorCheck to also accept a TH1 instead of a Canvas

- also pass the database object from CheckRunner to CheckInterface and use it to implement a new method `retrieveReference`.

* format

* add beautify and doc

* Format

* Format

* cout

* Update ReferenceComparatorCheck.cxx

* Update Advanced.md

* Update Advanced.md

* Update DevelopersTips.md

* Update Framework/include/QualityControl/ReferenceUtils.h

Co-authored-by: Piotr Konopka <piotr.jan.konopka@cern.ch>

* Update Modules/Common/src/ReferenceComparatorCheck.cxx

Co-authored-by: Piotr Konopka <piotr.jan.konopka@cern.ch>

* Update doc/Advanced.md

Co-authored-by: Piotr Konopka <piotr.jan.konopka@cern.ch>

* Update doc/Advanced.md

Co-authored-by: Piotr Konopka <piotr.jan.konopka@cern.ch>

* Update ReferenceComparatorCheck.cxx

* Update ReferenceComparatorCheck.cxx

* - use int for the run
- update the namespaces

* format

* return a tuple

* format

* return null quality if no reference run number is provided.

* extraction

* - Keep the activity parameter but document it
- use size_t for the run number
- use Timestamp::Latest

* Use extended parameters.

* pass only 1 activity for reference and not the reference run + the current activity

---------

Co-authored-by: Piotr Konopka <piotr.jan.konopka@cern.ch>
  • Loading branch information
Barthelemy and knopers8 authored Jul 8, 2024
1 parent 37b7d68 commit 90c35b1
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 102 deletions.
7 changes: 7 additions & 0 deletions Framework/include/QualityControl/Check.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
// O2
#include <Framework/DataProcessorSpec.h>
// QC
#include "QualityControl/DatabaseInterface.h"
#include "QualityControl/QualityObject.h"
#include "QualityControl/CheckConfig.h"
#include "QualityControl/CheckInterface.h"

namespace o2::quality_control::core
{
Expand Down Expand Up @@ -92,6 +94,11 @@ class Check
static CheckConfig extractConfig(const core::CommonSpec&, const CheckSpec&);
static framework::OutputSpec createOutputSpec(const std::string& detector, const std::string& checkName);

void setDatabase(std::shared_ptr<o2::quality_control::repository::DatabaseInterface> database)
{
mCheckInterface->setDatabase(database);
}

private:
void beautify(std::map<std::string, std::shared_ptr<core::MonitorObject>>& moMap, const core::Quality& quality);

Expand Down
17 changes: 17 additions & 0 deletions Framework/include/QualityControl/CheckInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef QC_CHECKER_CHECKINTERFACE_H
#define QC_CHECKER_CHECKINTERFACE_H

#include "QualityControl/DatabaseInterface.h"
#include "QualityControl/Quality.h"
#include "QualityControl/UserCodeInterface.h"
#include "QualityControl/Activity.h"
Expand Down Expand Up @@ -82,10 +83,26 @@ class CheckInterface : public core::UserCodeInterface
virtual void startOfActivity(const core::Activity& activity); // not fully abstract because we don't want to change all the existing subclasses
virtual void endOfActivity(const core::Activity& activity); // not fully abstract because we don't want to change all the existing subclasses

void setDatabase(std::shared_ptr<o2::quality_control::repository::DatabaseInterface> database)
{
mDatabase = database;
}

protected:
/// \brief Called each time mCustomParameters is updated.
virtual void configure() override;

/// \brief Retrieve a reference plot at the provided path, matching the give activity and for the provided run.
/// the activity is the current one, while the run number is the reference run.
///
/// \param path path to the object (no provenance)
/// \param referenceActivity Reference activity (usually a copy of the current activity with a different run number)
/// \return
std::shared_ptr<MonitorObject> retrieveReference(std::string path, Activity referenceActivity);

private:
std::shared_ptr<o2::quality_control::repository::DatabaseInterface> mDatabase;

ClassDef(CheckInterface, 6)
};

Expand Down
47 changes: 47 additions & 0 deletions Framework/include/QualityControl/ReferenceUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file ReferenceComparatorUtils.h
/// \author Andrea Ferrero and Barthelemy von Haller
///

#ifndef QUALITYCONTROL_ReferenceUtils_H
#define QUALITYCONTROL_ReferenceUtils_H

#include <memory>
#include "QualityControl/MonitorObject.h"
#include "QualityControl/DatabaseInterface.h"
#include "QualityControl/Activity.h"
#include "QualityControl/ActivityHelpers.h"
#include "QualityControl/QcInfoLogger.h"
#include "QualityControl/RepoPathUtils.h"

namespace o2::quality_control::checker
{

//_________________________________________________________________________________________
//
// Get the reference plot for a given MonitorObject path

static std::shared_ptr<quality_control::core::MonitorObject> getReferencePlot(quality_control::repository::DatabaseInterface* qcdb, std::string& fullPath,
core::Activity referenceActivity)
{
auto [success, path, name] = o2::quality_control::core::RepoPathUtils::splitObjectPath(fullPath);
if (!success) {
return nullptr;
}
return qcdb->retrieveMO(path, name, repository::DatabaseInterface::Timestamp::Latest, referenceActivity);
}

} // namespace o2::quality_control::checker

#endif // QUALITYCONTROL_ReferenceUtils_H
30 changes: 30 additions & 0 deletions Framework/include/QualityControl/RepoPathUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,36 @@ class RepoPathUtils

static constexpr auto allowedProvenancesMessage = R"(Allowed provenances are "qc" (real data processed synchronously), "qc_async" (real data processed asynchronously) and "qc_mc" (simulated data).)";
static bool isProvenanceAllowed(const std::string& provenance);

/**
* Splits the provided path and returns both the base path and the object name.
* @param fullPath
* @return A tuple with 1. a boolean to specify if we succeeded (i.e. whether we found a `/`)
* 2. the path
* 3. the object name
*/
static std::tuple<bool, std::string, std::string> splitObjectPath(const std::string& fullPath)
{
std::string delimiter = "/";
std::string det;
size_t pos = fullPath.rfind(delimiter);
if (pos == std::string::npos) {
return { false, "", "" };
}
std::string path = fullPath.substr(0, pos);
std::string name = fullPath.substr(pos + 1);
return { true, path, name };
}

static std::string getPathNoProvenance(std::shared_ptr<MonitorObject> mo)
{
std::string path = mo->getPath();
size_t pos = path.find('/');
if (pos != std::string::npos) {
path = path.substr(pos + 1);
}
return path;
}
};
} // namespace o2::quality_control::core

Expand Down
6 changes: 6 additions & 0 deletions Framework/src/CheckInterface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
///

#include "QualityControl/CheckInterface.h"
#include "QualityControl/ReferenceUtils.h"
#include "QualityControl/MonitorObject.h"

#include <TClass.h>
Expand Down Expand Up @@ -59,4 +60,9 @@ void CheckInterface::endOfActivity(const Activity& activity)
// noop, override it if you want.
}

shared_ptr<MonitorObject> CheckInterface::retrieveReference(std::string path, Activity referenceActivity)
{
return o2::quality_control::checker::getReferencePlot(mDatabase.get(), path, referenceActivity);
}

} // namespace o2::quality_control::checker
1 change: 1 addition & 0 deletions Framework/src/CheckRunner.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ void CheckRunner::init(framework::InitContext& iCtx)
updatePolicyManager.reset();
for (auto& [checkName, check] : mChecks) {
check.init();
check.setDatabase(mDatabase);
updatePolicyManager.addPolicy(check.getName(), check.getUpdatePolicyType(), check.getObjectsNames(), check.getAllObjectsOption(), false);
}
} catch (...) {
Expand Down
4 changes: 4 additions & 0 deletions Modules/Common/include/Common/ReferenceComparatorCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ class ReferenceComparatorCheck : public o2::quality_control::checker::CheckInter
void endOfActivity(const Activity& activity) override;

private:
Quality getSinglePlotQuality(std::shared_ptr<MonitorObject> mo, std::string& message);

std::unique_ptr<ObjectComparatorInterface> mComparator;
std::map<std::string, Quality> mQualityFlags;
std::map<std::string, std::shared_ptr<TPaveText>> mQualityLabels;
quality_control::core::Activity mActivity /*current*/, mReferenceActivity;
size_t mReferenceRun;
};

} // namespace o2::quality_control_modules::common
Expand Down
5 changes: 0 additions & 5 deletions Modules/Common/include/Common/ReferenceComparatorTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
#define QUALITYCONTROL_REFERENCECOMPARATORTASK_H

#include "Common/ReferenceComparatorTaskConfig.h"
#include "Common/BigScreenCanvas.h"
#include "QualityControl/PostProcessingInterface.h"
#include "QualityControl/DatabaseInterface.h"
#include "QualityControl/Quality.h"
#include <TH1.h>
#include <TPad.h>
#include <TCanvas.h>
#include <TPaveText.h>
#include <TText.h>
#include <string>
#include <map>
Expand Down Expand Up @@ -63,8 +60,6 @@ class ReferenceComparatorTask : public quality_control::postprocessing::PostProc
};

private:
std::shared_ptr<o2::quality_control::core::MonitorObject> getReferencePlot(o2::quality_control::repository::DatabaseInterface& qcdb, std::string fullPath, o2::quality_control::core::Activity activity);

int mReferenceRun{ 0 };
int mNotOlderThan{ 120 };

Expand Down
Loading

0 comments on commit 90c35b1

Please sign in to comment.