Project
Loading...
Searching...
No Matches
DebugStreamer.h
Go to the documentation of this file.
1// Copyright 2019-2020 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
15
16#ifndef ALICEO2_TPC_DEBUGSTREAMER_H_
17#define ALICEO2_TPC_DEBUGSTREAMER_H_
18
19#include "GPUCommonDef.h"
20#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
22#include <boost/property_tree/ptree.hpp>
23#if defined(DEBUG_STREAMER)
25#include <tbb/concurrent_unordered_map.h>
26#endif
27#endif
28
29namespace o2::utils
30{
31
46
55
56#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
57
59{
60 return static_cast<StreamFlags>(static_cast<int>(a) | static_cast<int>(b));
61}
62inline StreamFlags operator&(StreamFlags a, StreamFlags b) { return static_cast<StreamFlags>(static_cast<int>(a) & static_cast<int>(b)); }
63inline StreamFlags operator~(StreamFlags a) { return static_cast<StreamFlags>(~static_cast<int>(a)); }
64
73
74#endif
75
78{
79
80// CPU implementation of the class
81#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) && defined(DEBUG_STREAMER)
82 public:
85
86 static DebugStreamer* instance()
87 {
88 static DebugStreamer streamer;
89 return &streamer;
90 }
91
96 void setStreamer(const char* outFile, const char* option, const size_t id = getCPUID());
97
100 bool isStreamerSet(const size_t id = getCPUID()) const { return getStreamerPtr(id); }
101
104 void flush(const size_t id);
105
107 void flush();
108
111 o2::utils::TreeStreamRedirector& getStreamer(const size_t id = getCPUID()) { return *(mTreeStreamer[id]); }
112
117 o2::utils::TreeStreamRedirector& getStreamer(const char* outFile, const char* option, const size_t id = getCPUID());
118
121 o2::utils::TreeStreamRedirector* getStreamerPtr(const size_t id = getCPUID()) const;
122
124 static StreamFlags getStreamFlags() { return static_cast<StreamFlags>(ParameterDebugStreamer::Instance().streamLevel); }
125
127 static std::pair<SamplingTypes, float> getSamplingTypeFrequency(const StreamFlags streamFlag);
128
130 static float getSamplingFrequency(const StreamFlags streamFlag) { return getSamplingTypeFrequency(streamFlag).second; }
131
133 static size_t getCPUID();
134
137 int getNTrees(const size_t id = getCPUID()) const;
138
142 std::string getUniqueTreeName(const char* tree, const size_t id = getCPUID()) const;
143
145 static void setStreamFlags(const StreamFlags streamFlags) { o2::conf::ConfigurableParam::setValue<int>("DebugStreamerParam", "streamLevel", static_cast<int>(streamFlags)); }
146
148 static void enableStream(const StreamFlags streamFlag);
149
151 static void disableStream(const StreamFlags streamFlag);
152
156 static bool checkStream(const StreamFlags streamFlag, const size_t samplingID = -1, const float weight = 1);
157
162 static void mergeTrees(const char* inpFile, const char* outFile, const char* option = "fast");
163
165 static int getIndex(const StreamFlags streamFlag);
166
168 static float getRandom(float min = 0, float max = 1);
169
170 private:
171 using StreamersPerFlag = tbb::concurrent_unordered_map<size_t, std::unique_ptr<o2::utils::TreeStreamRedirector>>;
172 StreamersPerFlag mTreeStreamer;
173#else
174
175 // empty implementation of the class for GPU or when the debug streamer is not build for CPU
176 public:
178 template <typename... Args>
179 GPUd() void setStreamer(Args... args){};
180
182 GPUd() static bool checkStream(const StreamFlags, const int samplingID = 0) { return false; }
183
184 GPUd() static DebugStreamer* instance() { return nullptr; }
185
186 class StreamerDummy
187 {
188 public:
189 GPUd() int data() const { return 0; };
190
191 template <typename Type>
192 GPUd() StreamerDummy& operator<<(Type)
193 {
194 return *this;
195 }
196 };
197
198 GPUd() StreamerDummy getStreamer(const int id = 0) const { return StreamerDummy{}; };
199
201 template <typename... Args>
202 GPUd() StreamerDummy getStreamer(Args... args) const
203 {
204 return StreamerDummy{};
205 };
206
207 template <typename Type>
208 GPUd() StreamerDummy getUniqueTreeName(Type, const int id = 0) const
209 {
210 return StreamerDummy{};
211 }
212
213 GPUd() void flush() const {};
214
215#endif
216};
217
218} // namespace o2::utils
219
220#endif
#define GPUd()
class to enable streaming debug information to root files
GPUd() StreamerDummy getStreamer(Args... args) const
empty for GPU
GPUd() StreamerDummy getUniqueTreeName(Type
GPUd() static bool checkStream(const StreamFlags
always false for GPU
GPUd() void setStreamer(Args... args)
empty for GPU
GPUd() StreamerDummy getStreamer(const int id=0) const
GLuint GLuint GLfloat weight
Definition glcorearb.h:5477
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean * data
Definition glcorearb.h:298
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
StreamFlags operator|(StreamFlags a, StreamFlags b)
@ sampleIDGlobal
in case different streamers have access to the same IDs use this gloabl ID
@ sampleTsallis
perform sampling on tsallis pdf
@ sampleAll
use all data (default)
@ sampleID
sample every n IDs (per example track)
@ sampleWeights
perform sampling on weights, defined where the streamer is called
@ sampleRandom
sample randomly every n points
StreamFlags operator~(StreamFlags a)
StreamFlags
struct defining the flags which can be used to check if a certain debug streamer is used
@ streamdEdx
stream corrections and cluster properties used for the dE/dx
@ streamDigits
stream digit information
@ streamFastTransform
stream tpc fast transform
@ streamMergeBorderTracksBest
stream MergeBorderTracks best track
@ streamFlagsCount
total number of streamers
@ streamRejectCluster
stream cluster rejection informations
@ streamMergeBorderTracksAll
stream MergeBorderTracks all tracks
@ streamITCorr
stream ion tail correction information
@ streamDigitFolding
stream ion tail and saturatio information
@ streamDistortionsSC
stream distortions applied in the TPC space-charge class (used for example in the tpc digitizer)
@ streamUpdateTrack
stream update track informations
StreamFlags operator&(StreamFlags a, StreamFlags b)
struct for setting and storing the streamer level
int sampleIDGlobal[StreamFlags::streamFlagsCount]
storage of reference streamer used for sampleIDFromOtherStreamer
float samplingFrequency[StreamFlags::streamFlagsCount]
frequency which is used for the sampling (0.1 -> 10% is written if sampling is used)
O2ParamDef(ParameterDebugStreamer, "DebugStreamerParam")
SamplingTypes samplingType[StreamFlags::streamFlagsCount]
flag to store what will be streamed
constexpr size_t min
constexpr size_t max
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))