From 0071844663e66dd0f34b33188e32aea77a3765ad Mon Sep 17 00:00:00 2001 From: ddobrigk Date: Tue, 3 Oct 2023 21:45:50 +0200 Subject: [PATCH] Add CCDB integration tester (#3540) * Add CCDB integration tester * Please consider the following formatting changes (#173) --------- Co-authored-by: David Dobrigkeit Chinellato Co-authored-by: ALICE Builder --- Common/Tasks/CMakeLists.txt | 5 ++ Common/Tasks/integrationTestCCDB.cxx | 123 +++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 Common/Tasks/integrationTestCCDB.cxx diff --git a/Common/Tasks/CMakeLists.txt b/Common/Tasks/CMakeLists.txt index 6937ccc42af..8ec7f39ef6d 100644 --- a/Common/Tasks/CMakeLists.txt +++ b/Common/Tasks/CMakeLists.txt @@ -24,6 +24,11 @@ o2physics_add_dpl_workflow(integrationtest PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore COMPONENT_NAME Analysis) +o2physics_add_dpl_workflow(integrationtestccdb + SOURCES integrationTestCCDB.cxx + PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore + COMPONENT_NAME Analysis) + o2physics_add_dpl_workflow(validation SOURCES validation.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsBase diff --git a/Common/Tasks/integrationTestCCDB.cxx b/Common/Tasks/integrationTestCCDB.cxx new file mode 100644 index 00000000000..5127d2c8e3f --- /dev/null +++ b/Common/Tasks/integrationTestCCDB.cxx @@ -0,0 +1,123 @@ +// 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. + +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// Integration tester for CCDB access +// This task is meant to attempt accessing typical CCDB objects +// but to do no actual analysis. It will then allow for systematic +// studies of CCDB access performance for the various objects it queries. +// +// The task allows for some basic configuration of which CCDB objects +// are to be queried (from B field to material LUT and others). +// For now: magnetic field is required, matlut is optional +// +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +#include "Framework/AnalysisDataModel.h" +#include "Framework/AnalysisTask.h" +#include "Framework/HistogramRegistry.h" +#include "Common/DataModel/TrackSelectionTables.h" +#include "Common/Core/TrackSelection.h" +#include "Common/Core/TrackSelectionDefaults.h" +#include "ReconstructionDataFormats/Track.h" +#include "Common/Core/trackUtilities.h" +#include "CCDB/BasicCCDBManager.h" +#include "DataFormatsParameters/GRPObject.h" +#include "DataFormatsParameters/GRPMagField.h" +#include "DetectorsBase/Propagator.h" +#include "DetectorsBase/GeometryManager.h" + +using namespace o2; +using namespace o2::framework; +using namespace o2::framework::expressions; + +#include "Framework/runDataProcessing.h" + +struct integrationTestCCDB { + // this is anyway what this is all about + Service ccdb; + + Configurable loadMatLut{"loadMatLut", true, "load material look-up table"}; + + // CCDB paths for access + Configurable ccdburl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; + Configurable grpPath{"grpPath", "GLO/GRP/GRP", "Path of the grp file"}; + Configurable grpmagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"}; + Configurable lutPath{"lutPath", "GLO/Param/MatLUT", "Path of the Lut parametrization"}; + Configurable geoPath{"geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"}; + + int mRunNumber; + + void initMagneticFieldCCDB(aod::BCsWithTimestamps::iterator const& bc) + { + if (mRunNumber == bc.runNumber()) { + return; + } + LOG(info) << "Starting MagField initialization..."; + + float d_bz = 0.0f; // to store value for printouts only, unused + auto run3grp_timestamp = bc.timestamp(); + o2::parameters::GRPObject* grpo = 0x0; + o2::parameters::GRPMagField* grpmag = 0x0; + grpo = ccdb->getForTimeStamp(grpPath, run3grp_timestamp); + if (grpo) { + o2::base::Propagator::initFieldFromGRP(grpo); + // Fetch magnetic field from ccdb for current collision + d_bz = grpo->getNominalL3Field(); + LOG(info) << "Retrieved GRP for timestamp " << run3grp_timestamp << " with magnetic field of " << d_bz << " kZG"; + } else { + grpmag = ccdb->getForTimeStamp(grpmagPath, run3grp_timestamp); + if (!grpmag) { + LOG(fatal) << "Got nullptr from CCDB for path " << grpmagPath << " of object GRPMagField and " << grpPath << " of object GRPObject for timestamp " << run3grp_timestamp; + } + o2::base::Propagator::initFieldFromGRP(grpmag); + // Fetch magnetic field from ccdb for current collision + d_bz = std::lround(5.f * grpmag->getL3Current() / 30000.f); + LOG(info) << "Retrieved GRP for timestamp " << run3grp_timestamp << " with magnetic field of " << d_bz << " kZG"; + } + mRunNumber = bc.runNumber(); + + // Known magnetic field + float magneticField = o2::base::Propagator::Instance()->getNominalBz(); + LOG(info) << "Finished MagField init! Magnetic field set in Propagator Instance for inspection: " << magneticField; + } + + void init(InitContext& context) + { + // Empty for the time being + } + + void process(aod::BCsWithTimestamps const& bcs) + { + mRunNumber = 0; + + auto bc = bcs.begin(); // first element + + ccdb->setURL(ccdburl); + ccdb->setCaching(true); + ccdb->setLocalObjectValidityChecking(); + ccdb->setFatalWhenNull(false); + if (loadMatLut) { + LOG(info) << "Loading material LUT..."; + o2::base::MatLayerCylSet* lut = o2::base::MatLayerCylSet::rectifyPtrFromFile(ccdb->get(lutPath)); + LOG(info) << "Material LUT successfully loaded!"; + LOG(info) << "Material LUT min R: " << lut->getRMin() << " max R: " << lut->getRMax(); + } + initMagneticFieldCCDB(bc); + } +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + return WorkflowSpec{ + adaptAnalysisTask(cfgc)}; +}