Skip to content

Commit fb1b397

Browse files
committed
Custom streamer for std::vector<o2::tpc::PadFlags>
* Add support for EXTRA_PATCH in root dictionary generation
1 parent fb08a8e commit fb1b397

File tree

6 files changed

+92
-10
lines changed

6 files changed

+92
-10
lines changed

DataFormats/Detectors/TPC/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ o2_add_library(
4040

4141
o2_target_root_dictionary(
4242
DataFormatsTPC
43+
EXTRA_PATCH src/VectorPadflagsCustomStreamer.cxx
4344
HEADERS include/DataFormatsTPC/ClusterGroupAttribute.h
4445
include/DataFormatsTPC/ClusterNative.h
4546
include/DataFormatsTPC/ClusterNativeHelper.h

DataFormats/Detectors/TPC/src/DataFormatsTPCLinkDef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
#pragma link C++ class o2::tpc::ClusterHardwareContainerFixedSize < 8192> + ;
2323
#pragma link C++ class o2::tpc::ClusterNativeContainer + ;
2424
#pragma link C++ class o2::tpc::Digit + ;
25+
#pragma link C++ enum o2::tpc::PadFlags +; // enum itself
2526
#pragma link C++ class o2::tpc::ZeroSuppressedContainer8kb + ;
2627
#pragma link C++ class std::vector < o2::tpc::ClusterNative> + ;
2728
#pragma link C++ class std::vector < o2::tpc::ClusterNativeContainer> + ;
2829
#pragma link C++ class std::vector < o2::tpc::ClusterHardware> + ;
2930
#pragma link C++ class std::vector < o2::tpc::ClusterHardwareContainerFixedSize < 8192>> + ;
3031
#pragma link C++ class std::vector < o2::tpc::ClusterHardwareContainer8kb> + ;
3132
#pragma link C++ class std::vector < o2::tpc::Digit> + ;
33+
#pragma link C++ class std::vector < o2::tpc::PadFlags> + ;
3234
#pragma link C++ class std::vector < o2::tpc::ZeroSuppressedContainer8kb> + ;
3335
#pragma link C++ class o2::tpc::TrackTPC + ;
3436
#pragma link C++ class o2::tpc::LaserTrack + ;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2019-2025 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
using std::vector;
13+
14+
void VectorPadFlagsStreamer(TBuffer& R__b, void* objp)
15+
{
16+
std::vector<o2::tpc::PadFlags>* obj = static_cast<std::vector<o2::tpc::PadFlags>*>(objp);
17+
if (R__b.IsReading()) {
18+
std::vector<int> R__stl;
19+
R__stl.clear();
20+
int R__n;
21+
R__b >> R__n;
22+
R__stl.reserve(R__n);
23+
for (int R__i = 0; R__i < R__n; R__i++) {
24+
Int_t readtemp;
25+
R__b >> readtemp;
26+
R__stl.push_back(readtemp);
27+
}
28+
auto data = reinterpret_cast<unsigned short*>(R__stl.data());
29+
for (int i = 0; i < R__n; ++i) {
30+
obj->push_back(static_cast<o2::tpc::PadFlags>(data[i]));
31+
}
32+
} else {
33+
// We always save things with the old format.
34+
R__b << (int)obj->size() / 2;
35+
for (size_t i = 0; i < obj->size(); i++) {
36+
R__b << (short)obj->at(i);
37+
}
38+
}
39+
}
40+
41+
#define RootStreamerLocal(name,STREAMER) \
42+
namespace ROOT { \
43+
\
44+
/** \cond HIDDEN_SYMBOLS */ \
45+
static auto _R__UNIQUE_(R__dummyStreamer) = \
46+
[]() { TClass::GetClass<name>()->SetStreamerFunc(STREAMER); return 0; }(); \
47+
/** \endcond */ \
48+
R__UseDummy(_R__UNIQUE_(R__dummyStreamer)); \
49+
}
50+
51+
RootStreamerLocal(vector<o2::tpc::PadFlags>, VectorPadFlagsStreamer);

cmake/AddRootDictionary.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function(add_root_dictionary target)
5151
1
5252
A
5353
""
54-
"LINKDEF"
54+
"LINKDEF;EXTRA_PATCH"
5555
"HEADERS;BASENAME")
5656
if(A_UNPARSED_ARGUMENTS)
5757
message(
@@ -112,7 +112,7 @@ function(add_root_dictionary target)
112112
set(pcmBase ${dictionary}_rdict.pcm)
113113
set(pcmFile ${lib_output_dir}/${pcmBase})
114114
set(rootmapFile ${lib_output_dir}/lib${basename}.rootmap)
115-
115+
116116
set(O2_TARGETPCMMAP_TARGET "${O2_TARGETPCMMAP_TARGET};${target}" CACHE INTERNAL "target/PCM map (target)")
117117
set(O2_TARGETPCMMAP_PCM "${O2_TARGETPCMMAP_PCM};${pcmFile}" CACHE INTERNAL "target/PCM map (pcm)")
118118

@@ -132,6 +132,7 @@ function(add_root_dictionary target)
132132
set(includeDirs $<TARGET_PROPERTY:${target},INCLUDE_DIRECTORIES>)
133133
set(includeDirs $<REMOVE_DUPLICATES:${includeDirs}>)
134134

135+
list(LENGTH A_EXTRA_PATCH hasExtraPatch)
135136
# add a custom command to generate the dictionary using rootcling
136137
# cmake-format: off
137138
add_custom_command(
@@ -146,11 +147,13 @@ function(add_root_dictionary target)
146147
--include_dirs -I$<JOIN:${includeDirs},$<SEMICOLON>-I>
147148
$<$<BOOL:${prop}>:--compile_defs>
148149
$<$<BOOL:${prop}>:-D$<JOIN:${prop},$<SEMICOLON>-D>>
150+
$<$<BOOL:${hasExtraPatch}>:--extra-patch>
151+
$<$<BOOL:${hasExtraPatch}>:${CMAKE_CURRENT_LIST_DIR}/${A_EXTRA_PATCH}>
149152
--pcmdeps "$<REMOVE_DUPLICATES:${list_pcm_deps_${target}}>"
150153
--headers "${headers}"
151154
COMMAND
152155
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${pcmBase} ${pcmFile}
153-
DEPENDS ${headers} "$<REMOVE_DUPLICATES:${list_pcm_deps_${target}}>")
156+
DEPENDS ${headers} "$<REMOVE_DUPLICATES:${list_pcm_deps_${target}}>" ${A_EXTRA_PATCH})
154157
# cmake-format: on
155158

156159
# add dictionary source to the target sources

cmake/O2TargetRootDictionary.cmake

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,9 @@ function(o2_target_root_dictionary baseTargetName)
5555
1
5656
A
5757
""
58-
"LINKDEF"
58+
"LINKDEF;EXTRA_PATCH"
5959
"HEADERS")
6060

61-
if(A_UNPARSED_ARGUMENTS)
62-
message(
63-
FATAL_ERROR "Unexpected unparsed arguments: ${A_UNPARSED_ARGUMENTS}")
64-
endif()
65-
6661
if(${ARGC} LESS 1)
6762
message(
6863
FATAL_ERROR
@@ -96,6 +91,13 @@ function(o2_target_root_dictionary baseTargetName)
9691

9792
# now that we have the O2 specific stuff computed, delegate the actual work to
9893
# the add_root_dictionary function
99-
add_root_dictionary(${target} HEADERS ${A_HEADERS} LINKDEF ${A_LINKDEF})
94+
if(NOT A_EXTRA_PATCH)
95+
add_root_dictionary(${target} HEADERS ${A_HEADERS} LINKDEF ${A_LINKDEF})
96+
else()
97+
add_root_dictionary(${target}
98+
EXTRA_PATCH ${A_EXTRA_PATCH}
99+
HEADERS ${A_HEADERS}
100+
LINKDEF ${A_LINKDEF})
101+
endif()
100102

101103
endfunction()

cmake/rootcling_wrapper.sh.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ while [[ $# -gt 0 ]]; do
4141
PCMDEPS="$2"
4242
shift 2
4343
;;
44+
--extra-patch)
45+
EXTRA_PATCH="$2"
46+
shift 2
47+
;;
4448
*)
4549
if [[ -z "$1" ]]; then
4650
shift
@@ -82,6 +86,18 @@ esac
8286

8387
LOGFILE=${DICTIONARY_FILE}.log
8488

89+
echo @CMAKE_COMMAND@ -E env "LD_LIBRARY_PATH=$libpath" @ROOT_rootcling_CMD@ \
90+
-f $DICTIONARY_FILE \
91+
-inlineInputHeader \
92+
-noGlobalUsingStd \
93+
-rmf ${ROOTMAP_FILE} \
94+
-rml ${ROOTMAP_LIBRARY_NAME} \
95+
${INCLUDE_DIRS//;/ } \
96+
${COMPILE_DEFINITIONS//;/ } \
97+
${PCMDEPS:+-m }${PCMDEPS//;/ -m } \
98+
${HEADERS//;/ } \
99+
> ${LOGFILE} 2>&1 || ROOTCLINGRETVAL=$?
100+
85101
@CMAKE_COMMAND@ -E env "LD_LIBRARY_PATH=$libpath" @ROOT_rootcling_CMD@ \
86102
-f $DICTIONARY_FILE \
87103
-inlineInputHeader \
@@ -94,6 +110,13 @@ LOGFILE=${DICTIONARY_FILE}.log
94110
${HEADERS//;/ } \
95111
> ${LOGFILE} 2>&1 || ROOTCLINGRETVAL=$?
96112

113+
# Add the extra patch file at the end of the generated dictionary.
114+
# This is needed to inject custom streamers (e.g. for std::vector<PadFlags>)
115+
# to our dictionary.
116+
if [ ! X"${EXTRA_PATCH}" = X ]; then
117+
cat $EXTRA_PATCH >> ${DICTIONARY_FILE}
118+
fi
119+
97120
if [[ ${ROOTCLINGRETVAL:-0} != "0" ]]; then
98121
cat ${LOGFILE} >&2
99122
rm -f $DICTIONARY_FILE

0 commit comments

Comments
 (0)