Commit 080bc329 authored by Wouter Deconinck's avatar Wouter Deconinck
Browse files

Modifications for podio-0.14 (mainly CollectionsBase)

parent 435b50d3
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.19)
# CMP0074: find_package() uses <PackageName>_ROOT variables
cmake_policy(SET CMP0074 NEW)
......@@ -9,7 +9,12 @@ set(CMAKE_CXX_STANDARD 17)
find_package(EICD 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(DD4hep COMPONENTS DDG4 DDG4IO DDRec REQUIRED)
find_package(Acts REQUIRED COMPONENTS Core PluginIdentification PluginTGeo PluginDD4hep PluginJson)
......
#include "PodioOutput.h"
#include "podio/podioVersion.h"
#include "GaudiKernel/ISvcLocator.h"
#include "JugBase/PodioDataSvc.h"
#include "TFile.h"
......@@ -32,10 +33,21 @@ StatusCode PodioOutput::initialize() {
void PodioOutput::resetBranches(const std::vector<std::pair<std::string, podio::CollectionBase*>>& 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)) {
// Reconnect branches and collections
m_datatree->SetBranchAddress(collName.c_str(), collBuffers->getBufferAddress());
auto colls = collBuffers->referenceCollections();
m_datatree->SetBranchAddress(collName.c_str(), data);
auto colls = references;
if (colls) {
int j = 0;
for (auto& c : (*colls)) {
......@@ -44,7 +56,7 @@ void PodioOutput::resetBranches(const std::vector<std::pair<std::string, podio::
++j;
}
}
auto colls_v = collBuffers->vectorMembers();
auto colls_v = vecmembers;
if (colls_v) {
int j = 0;
for (auto& [dataType, add] : (*colls_v)) {
......@@ -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) {
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 collClassName = "vector<" + className + "Data>";
int isOn = 0;
if (m_switch.isOn(collName)) {
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
if (auto refColls = collBuffers->referenceCollections()) {
if (auto refColls = references) {
int j = 0;
for (auto& c : (*refColls)) {
const auto brName = podio::root_utils::refBranch(collName, j);
......@@ -77,7 +100,7 @@ void PodioOutput::createBranches(const std::vector<std::pair<std::string, podio:
}
}
// vector members
if (auto vminfo = collBuffers->vectorMembers()) {
if (auto vminfo = vecmembers) {
int j = 0;
for (auto& [dataType, add] : (*vminfo)) {
const std::string typeName = "vector<" + dataType + ">";
......
#ifndef PODIO_ROOT_UTILS_H
#define PODIO_ROOT_UTILS_H
#include "podio/podioVersion.h"
#include "podio/CollectionBase.h"
#include "podio/CollectionBranches.h"
......@@ -28,19 +29,30 @@ inline std::string vecBranch(const std::string& name, size_t index) {
inline void setCollectionAddresses(podio::CollectionBase* collection, const CollectionBranches& branches) {
if (auto buffer = collection->getBufferAddress()) {
branches.data->SetAddress(buffer);
#if podio_VERSION_MAJOR == 0 && podio_VERSION_MINOR < 14
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()) {
for (size_t i = 0; i < refCollections->size(); ++i) {
branches.refs[i]->SetAddress(&(*refCollections)[i]);
if (references) {
for (size_t i = 0; i < references->size(); ++i) {
branches.refs[i]->SetAddress(&(*references)[i]);
}
}
if (auto vecMembers = collection->vectorMembers()) {
for (size_t i = 0; i < vecMembers->size(); ++i) {
branches.vecs[i]->SetAddress((*vecMembers)[i].second);
if (vecmembers) {
for (size_t i = 0; i < vecmembers->size(); ++i) {
branches.vecs[i]->SetAddress((*vecmembers)[i].second);
}
}
}
......@@ -48,3 +60,4 @@ inline void setCollectionAddresses(podio::CollectionBase* collection, const Coll
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment