Skip to content
Snippets Groups Projects
Commit 080bc329 authored by Wouter Deconinck's avatar Wouter Deconinck
Browse files

Modifications for podio-0.14 (mainly CollectionsBase)

parent 435b50d3
No related branches found
No related tags found
1 merge request!342Modifications for podio-0.14 (mainly CollectionsBase)
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.19)
# CMP0074: find_package() uses <PackageName>_ROOT variables # CMP0074: find_package() uses <PackageName>_ROOT variables
cmake_policy(SET CMP0074 NEW) cmake_policy(SET CMP0074 NEW)
...@@ -9,7 +9,12 @@ set(CMAKE_CXX_STANDARD 17) ...@@ -9,7 +9,12 @@ set(CMAKE_CXX_STANDARD 17)
find_package(EICD REQUIRED) find_package(EICD REQUIRED)
find_package(NPDet REQUIRED) find_package(NPDet REQUIRED)
find_package(podio 0.11.0 REQUIRED)
find_package(podio 0.11...0.14 REQUIRED)
add_definitions("-Dpodio_VERSION_MAJOR=${podio_VERSION_MAJOR}")
add_definitions("-Dpodio_VERSION_MINOR=${podio_VERSION_MINOR}")
add_definitions("-Dpodio_VERSION_PATCH=${podio_VERSION_PATCH}")
find_package(ROOT COMPONENTS Core RIO Tree MathCore GenVector Geom REQUIRED) find_package(ROOT COMPONENTS Core RIO Tree MathCore GenVector Geom REQUIRED)
find_package(DD4hep COMPONENTS DDG4 DDG4IO DDRec REQUIRED) find_package(DD4hep COMPONENTS DDG4 DDG4IO DDRec REQUIRED)
find_package(Acts REQUIRED COMPONENTS Core PluginIdentification PluginTGeo PluginDD4hep PluginJson) find_package(Acts REQUIRED COMPONENTS Core PluginIdentification PluginTGeo PluginDD4hep PluginJson)
......
#include "PodioOutput.h" #include "PodioOutput.h"
#include "podio/podioVersion.h"
#include "GaudiKernel/ISvcLocator.h" #include "GaudiKernel/ISvcLocator.h"
#include "JugBase/PodioDataSvc.h" #include "JugBase/PodioDataSvc.h"
#include "TFile.h" #include "TFile.h"
...@@ -32,10 +33,21 @@ StatusCode PodioOutput::initialize() { ...@@ -32,10 +33,21 @@ StatusCode PodioOutput::initialize() {
void PodioOutput::resetBranches(const std::vector<std::pair<std::string, podio::CollectionBase*>>& collections) { void PodioOutput::resetBranches(const std::vector<std::pair<std::string, podio::CollectionBase*>>& collections) {
for (auto& [collName, collBuffers] : collections) { for (auto& [collName, collBuffers] : collections) {
#if podio_VERSION_MAJOR == 0 && podio_VERSION_MINOR < 14
auto data = collBuffers->getBufferAddress();
auto references = collBuffers->referenceCollections();
auto vecmembers = collBuffers->vectorMembers();
#else
auto buffers = collBuffers->getBuffers();
auto data = buffers.data;
auto references = buffers.references;
auto vecmembers = buffers.vectorMembers;
#endif
if (m_switch.isOn(collName)) { if (m_switch.isOn(collName)) {
// Reconnect branches and collections // Reconnect branches and collections
m_datatree->SetBranchAddress(collName.c_str(), collBuffers->getBufferAddress()); m_datatree->SetBranchAddress(collName.c_str(), data);
auto colls = collBuffers->referenceCollections(); auto colls = references;
if (colls) { if (colls) {
int j = 0; int j = 0;
for (auto& c : (*colls)) { for (auto& c : (*colls)) {
...@@ -44,7 +56,7 @@ void PodioOutput::resetBranches(const std::vector<std::pair<std::string, podio:: ...@@ -44,7 +56,7 @@ void PodioOutput::resetBranches(const std::vector<std::pair<std::string, podio::
++j; ++j;
} }
} }
auto colls_v = collBuffers->vectorMembers(); auto colls_v = vecmembers;
if (colls_v) { if (colls_v) {
int j = 0; int j = 0;
for (auto& [dataType, add] : (*colls_v)) { for (auto& [dataType, add] : (*colls_v)) {
...@@ -60,15 +72,26 @@ void PodioOutput::resetBranches(const std::vector<std::pair<std::string, podio:: ...@@ -60,15 +72,26 @@ void PodioOutput::resetBranches(const std::vector<std::pair<std::string, podio::
void PodioOutput::createBranches(const std::vector<std::pair<std::string, podio::CollectionBase*>>& collections) { void PodioOutput::createBranches(const std::vector<std::pair<std::string, podio::CollectionBase*>>& collections) {
for (auto& [collName, collBuffers] : collections) { for (auto& [collName, collBuffers] : collections) {
#if podio_VERSION_MAJOR == 0 && podio_VERSION_MINOR < 14
auto data = collBuffers->getBufferAddress();
auto references = collBuffers->referenceCollections();
auto vecmembers = collBuffers->vectorMembers();
#else
auto buffers = collBuffers->getBuffers();
auto data = buffers.data;
auto references = buffers.references;
auto vecmembers = buffers.vectorMembers;
#endif
const std::string className = collBuffers->getValueTypeName(); const std::string className = collBuffers->getValueTypeName();
const std::string collClassName = "vector<" + className + "Data>"; const std::string collClassName = "vector<" + className + "Data>";
int isOn = 0; int isOn = 0;
if (m_switch.isOn(collName)) { if (m_switch.isOn(collName)) {
isOn = 1; isOn = 1;
m_datatree->Branch(collName.c_str(), collClassName.c_str(), collBuffers->getBufferAddress()); m_datatree->Branch(collName.c_str(), collClassName.c_str(), data);
// Create branches for collections holding relations // Create branches for collections holding relations
if (auto refColls = collBuffers->referenceCollections()) { if (auto refColls = references) {
int j = 0; int j = 0;
for (auto& c : (*refColls)) { for (auto& c : (*refColls)) {
const auto brName = podio::root_utils::refBranch(collName, j); const auto brName = podio::root_utils::refBranch(collName, j);
...@@ -77,7 +100,7 @@ void PodioOutput::createBranches(const std::vector<std::pair<std::string, podio: ...@@ -77,7 +100,7 @@ void PodioOutput::createBranches(const std::vector<std::pair<std::string, podio:
} }
} }
// vector members // vector members
if (auto vminfo = collBuffers->vectorMembers()) { if (auto vminfo = vecmembers) {
int j = 0; int j = 0;
for (auto& [dataType, add] : (*vminfo)) { for (auto& [dataType, add] : (*vminfo)) {
const std::string typeName = "vector<" + dataType + ">"; const std::string typeName = "vector<" + dataType + ">";
......
#ifndef PODIO_ROOT_UTILS_H #ifndef PODIO_ROOT_UTILS_H
#define PODIO_ROOT_UTILS_H #define PODIO_ROOT_UTILS_H
#include "podio/podioVersion.h"
#include "podio/CollectionBase.h" #include "podio/CollectionBase.h"
#include "podio/CollectionBranches.h" #include "podio/CollectionBranches.h"
...@@ -28,19 +29,30 @@ inline std::string vecBranch(const std::string& name, size_t index) { ...@@ -28,19 +29,30 @@ inline std::string vecBranch(const std::string& name, size_t index) {
inline void setCollectionAddresses(podio::CollectionBase* collection, const CollectionBranches& branches) { inline void setCollectionAddresses(podio::CollectionBase* collection, const CollectionBranches& branches) {
if (auto buffer = collection->getBufferAddress()) { #if podio_VERSION_MAJOR == 0 && podio_VERSION_MINOR < 14
branches.data->SetAddress(buffer); auto data = collection->getBufferAddress();
auto references = collection->referenceCollections();
auto vecmembers = collection->vectorMembers();
#else
auto buffers = collection->getBuffers();
auto data = buffers.data;
auto references = buffers.references;
auto vecmembers = buffers.vectorMembers;
#endif
if (data) {
branches.data->SetAddress(data);
} }
if (auto refCollections = collection->referenceCollections()) { if (references) {
for (size_t i = 0; i < refCollections->size(); ++i) { for (size_t i = 0; i < references->size(); ++i) {
branches.refs[i]->SetAddress(&(*refCollections)[i]); branches.refs[i]->SetAddress(&(*references)[i]);
} }
} }
if (auto vecMembers = collection->vectorMembers()) { if (vecmembers) {
for (size_t i = 0; i < vecMembers->size(); ++i) { for (size_t i = 0; i < vecmembers->size(); ++i) {
branches.vecs[i]->SetAddress((*vecMembers)[i].second); branches.vecs[i]->SetAddress((*vecmembers)[i].second);
} }
} }
} }
...@@ -48,3 +60,4 @@ inline void setCollectionAddresses(podio::CollectionBase* collection, const Coll ...@@ -48,3 +60,4 @@ inline void setCollectionAddresses(podio::CollectionBase* collection, const Coll
} }
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment