|
| 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 | + |
| 12 | +/// \file DebugStreamer.h |
| 13 | +/// \brief Definition of class for writing debug informations |
| 14 | +/// \author Matthias Kleiner <mkleiner@ikf.uni-frankfurt.de> |
| 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) |
| 21 | +#include "CommonUtils/ConfigurableParamHelper.h" |
| 22 | +#if defined(DEBUG_STREAMER) |
| 23 | +#include "CommonUtils/TreeStreamRedirector.h" |
| 24 | +#endif |
| 25 | +#endif |
| 26 | + |
| 27 | +namespace o2::utils |
| 28 | +{ |
| 29 | + |
| 30 | +/// struct defining the flags which can be used to check if a certain debug streamer is used |
| 31 | +enum StreamFlags { |
| 32 | + streamdEdx = 1 << 0, ///< stream corrections and cluster properties used for the dE/dx |
| 33 | +}; |
| 34 | + |
| 35 | +#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) |
| 36 | + |
| 37 | +inline StreamFlags operator|(StreamFlags a, StreamFlags b) |
| 38 | +{ |
| 39 | + return static_cast<StreamFlags>(static_cast<int>(a) | static_cast<int>(b)); |
| 40 | +} |
| 41 | +inline StreamFlags operator&(StreamFlags a, StreamFlags b) { return static_cast<StreamFlags>(static_cast<int>(a) & static_cast<int>(b)); } |
| 42 | +inline StreamFlags operator~(StreamFlags a) { return static_cast<StreamFlags>(~static_cast<int>(a)); } |
| 43 | + |
| 44 | +/// struct for setting and storing the streamer level |
| 45 | +struct ParameterDebugStreamer : public o2::conf::ConfigurableParamHelper<ParameterDebugStreamer> { |
| 46 | + StreamFlags StreamLevel{}; /// flag to store what will be streamed |
| 47 | + O2ParamDef(ParameterDebugStreamer, "DebugStreamerParam"); |
| 48 | +}; |
| 49 | + |
| 50 | +#endif |
| 51 | + |
| 52 | +/// class to enable streaming debug information to root files |
| 53 | +class DebugStreamer |
| 54 | +{ |
| 55 | + |
| 56 | +// CPU implementation of the class |
| 57 | +#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) && defined(DEBUG_STREAMER) |
| 58 | + public: |
| 59 | + /// set the streamer i.e. create the output file and set up the streamer |
| 60 | + /// \param outFile output file name without .root suffix |
| 61 | + /// \param option RECREATE or UPDATE |
| 62 | + void setStreamer(const char* outFile, const char* option); |
| 63 | + |
| 64 | + /// \return returns if the streamer is set |
| 65 | + bool isStreamerSet() const { return mTreeStreamer ? true : false; } |
| 66 | + |
| 67 | + /// \return returns streamer object |
| 68 | + o2::utils::TreeStreamRedirector& getStreamer() { return *mTreeStreamer; } |
| 69 | + |
| 70 | + /// \return returns streamer level i.e. what will be written to file |
| 71 | + static StreamFlags getStreamFlags() { return ParameterDebugStreamer::Instance().StreamLevel; } |
| 72 | + |
| 73 | + ///< return returns unique ID for each CPU thread to give each thread an own output file |
| 74 | + static size_t getCPUID(); |
| 75 | + |
| 76 | + /// \return returns number of trees in the streamer |
| 77 | + int getNTrees() const; |
| 78 | + |
| 79 | + /// \return returns an unique branch name which is not already written in the file |
| 80 | + /// \param tree name of the tree for which to get a unique tree name |
| 81 | + std::string getUniqueTreeName(const char* tree) const; |
| 82 | + |
| 83 | + /// set directly the debug level |
| 84 | + static void setStreamFlags(const StreamFlags streamFlags) { o2::conf::ConfigurableParam::setValue("DebugStreamerParam", "StreamLevel", static_cast<int>(streamFlags)); } |
| 85 | + |
| 86 | + /// enable specific streamer flag |
| 87 | + static void enableStream(const StreamFlags streamFlag); |
| 88 | + |
| 89 | + /// disable a specific streamer flag |
| 90 | + static void disableStream(const StreamFlags streamFlag); |
| 91 | + |
| 92 | + /// check if streamer for specific flag is enabled |
| 93 | + static bool checkStream(const StreamFlags streamFlag) { return ((getStreamFlags() & streamFlag) == streamFlag); } |
| 94 | + |
| 95 | + /// merge trees with the same content structure, but different naming |
| 96 | + /// \param inpFile input file containing several trees with the same content |
| 97 | + /// \param outFile contains the merged tree from the input file in one branch |
| 98 | + /// \param option setting which is used for the merging |
| 99 | + static void mergeTrees(const char* inpFile, const char* outFile, const char* option = "fast"); |
| 100 | + |
| 101 | + private: |
| 102 | + std::unique_ptr<o2::utils::TreeStreamRedirector> mTreeStreamer; ///< streamer which is used for the debugging |
| 103 | +#else |
| 104 | + |
| 105 | + // empty implementation of the class for GPU or when the debug streamer is not build for CPU |
| 106 | + public: |
| 107 | + /// empty for GPU |
| 108 | + template <typename... Args> |
| 109 | + GPUd() void setStreamer(Args... args){}; |
| 110 | + |
| 111 | + /// always false for GPU |
| 112 | + GPUd() static bool checkStream(const StreamFlags) { return false; } |
| 113 | + |
| 114 | + class StreamerDummy |
| 115 | + { |
| 116 | + public: |
| 117 | + GPUd() int data() const { return 0; }; |
| 118 | + |
| 119 | + template <typename Type> |
| 120 | + GPUd() StreamerDummy& operator<<(Type) |
| 121 | + { |
| 122 | + return *this; |
| 123 | + } |
| 124 | + }; |
| 125 | + |
| 126 | + GPUd() StreamerDummy getStreamer() const { return StreamerDummy{}; }; |
| 127 | + |
| 128 | + template <typename Type> |
| 129 | + GPUd() StreamerDummy getUniqueTreeName(Type) const |
| 130 | + { |
| 131 | + return StreamerDummy{}; |
| 132 | + } |
| 133 | + |
| 134 | +#endif |
| 135 | +}; |
| 136 | + |
| 137 | +} // namespace o2::utils |
| 138 | + |
| 139 | +#endif |
0 commit comments