diff --git a/Analysis/Core/CMakeLists.txt b/Analysis/Core/CMakeLists.txt index bc4a674b231b7..6feb7d1ec9a73 100644 --- a/Analysis/Core/CMakeLists.txt +++ b/Analysis/Core/CMakeLists.txt @@ -13,6 +13,8 @@ o2_add_library(AnalysisCore SOURCES src/CorrelationContainer.cxx src/TrackSelection.cxx src/TriggerAliases.cxx + src/HFConfigurables.cxx + src/BasicPDGManager.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisDataModel) o2_target_root_dictionary(AnalysisCore @@ -21,6 +23,8 @@ o2_target_root_dictionary(AnalysisCore include/AnalysisCore/TrackSelectionDefaults.h include/AnalysisCore/TriggerAliases.h include/AnalysisCore/MC.h + include/AnalysisCore/HFConfigurables.h + include/AnalysisCore/BasicPDGManager.h LINKDEF src/AnalysisCoreLinkDef.h) o2_add_executable(merger diff --git a/Analysis/Core/include/AnalysisCore/BasicPDGManager.h b/Analysis/Core/include/AnalysisCore/BasicPDGManager.h new file mode 100644 index 0000000000000..0c979a4dfb6be --- /dev/null +++ b/Analysis/Core/include/AnalysisCore/BasicPDGManager.h @@ -0,0 +1,46 @@ +// 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. + +#ifndef O2_BASICPDGMANAGER_H +#define O2_BASICPDGMANAGER_H +#include "TDatabasePDG.h" + +namespace o2::pdg +{ +class PDGManagerInstance +{ + public: + PDGManagerInstance(const char* path = ""); + ~PDGManagerInstance(); + void setDatabasePath(const char* path); + void reReadDatabase(); + TParticlePDG* GetParticle(int pdgcode); + + private: + std::string dbPath; + TDatabasePDG* db; +}; + +class BasicPDGManager : public PDGManagerInstance +{ + public: + static BasicPDGManager& instance() + { + static BasicPDGManager inst{}; + return inst; + } + + private: + using PDGManagerInstance::PDGManagerInstance; +}; +} // namespace o2::pdg + +#endif // O2_BASICPDGMANAGER_H diff --git a/Analysis/Core/src/BasicPDGManager.cxx b/Analysis/Core/src/BasicPDGManager.cxx new file mode 100644 index 0000000000000..baec438a34dfb --- /dev/null +++ b/Analysis/Core/src/BasicPDGManager.cxx @@ -0,0 +1,44 @@ +// 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. + +#include "AnalysisCore/BasicPDGManager.h" + +namespace o2::pdg +{ +PDGManagerInstance::PDGManagerInstance(const char* path) + : dbPath{path} +{ + db = new TDatabasePDG(); + db->ReadPDGTable(path); +} + +PDGManagerInstance::~PDGManagerInstance() +{ + db->Delete(); +} + +void PDGManagerInstance::setDatabasePath(const char* path) +{ + dbPath = path; +} + +void PDGManagerInstance::reReadDatabase() +{ + if (db != nullptr) { + db->ReadPDGTable(dbPath.c_str()); + } +} + +TParticlePDG* PDGManagerInstance::GetParticle(int pdgcode) +{ + return db->GetParticle(pdgcode); +} +} // namespace o2::pdg diff --git a/Analysis/Tutorials/CMakeLists.txt b/Analysis/Tutorials/CMakeLists.txt index 3bc60f6219bdc..28be5a8f46bc8 100644 --- a/Analysis/Tutorials/CMakeLists.txt +++ b/Analysis/Tutorials/CMakeLists.txt @@ -228,3 +228,9 @@ o2_add_dpl_workflow(multiprocess-example JOB_POOL analysis PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisCore O2::AnalysisDataModel COMPONENT_NAME AnalysisTutorial) + +o2_add_dpl_workflow(using-pdg + SOURCES src/usingPDGService.cxx + JOB_POOL analysis + PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisCore O2::AnalysisDataModel + COMPONENT_NAME AnalysisTutorial) diff --git a/Analysis/Tutorials/src/usingPDGService.cxx b/Analysis/Tutorials/src/usingPDGService.cxx new file mode 100644 index 0000000000000..10243597ecc7a --- /dev/null +++ b/Analysis/Tutorials/src/usingPDGService.cxx @@ -0,0 +1,41 @@ +// 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. + +#include "Framework/runDataProcessing.h" +#include "Framework/AnalysisTask.h" +#include "AnalysisCore/MC.h" +#include "AnalysisCore/BasicPDGManager.h" + +using namespace o2; +using namespace o2::framework; + +struct UsePdgDatabase { + Service pdg; + OutputObj particleCharges{TH1F("charges", ";charge;entries", 201, -10.1, 10.1)}; + + void process(aod::McCollision const&, aod::McParticles const& particles) + { + for (auto& particle : particles) { + auto pdgInfo = pdg->GetParticle(particle.pdgCode()); + if (pdgInfo != nullptr) { + particleCharges->Fill(pdgInfo->Charge()); + } else { + LOGF(warn, "[%d] unknown particle with PDG code %d", particle.globalIndex(), particle.pdgCode()); + } + } + } +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + return WorkflowSpec{ + adaptAnalysisTask(cfgc)}; +}