Skip to content

Commit

Permalink
Add CCDB integration tester (#3540)
Browse files Browse the repository at this point in the history
* Add CCDB integration tester

* Please consider the following formatting changes (#173)

---------

Co-authored-by: David Dobrigkeit Chinellato <david.dobrigkeit.chinellato.cern.ch>
Co-authored-by: ALICE Builder <[email protected]>
  • Loading branch information
ddobrigk and alibuild authored Oct 3, 2023
1 parent 3bd0163 commit 0071844
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Common/Tasks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
123 changes: 123 additions & 0 deletions Common/Tasks/integrationTestCCDB.cxx
Original file line number Diff line number Diff line change
@@ -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<o2::ccdb::BasicCCDBManager> ccdb;

Configurable<bool> loadMatLut{"loadMatLut", true, "load material look-up table"};

// CCDB paths for access
Configurable<std::string> ccdburl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<std::string> grpPath{"grpPath", "GLO/GRP/GRP", "Path of the grp file"};
Configurable<std::string> grpmagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"};
Configurable<std::string> lutPath{"lutPath", "GLO/Param/MatLUT", "Path of the Lut parametrization"};
Configurable<std::string> 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<o2::parameters::GRPObject>(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<o2::parameters::GRPMagField>(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<o2::base::MatLayerCylSet>(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<integrationTestCCDB>(cfgc)};
}

0 comments on commit 0071844

Please sign in to comment.