Aida2ROOT.cpp
Go to the documentation of this file.
1 #ifdef __ICC
2 // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits
3 // TODO: To be removed, since it comes from ROOT TMathBase.h
4 #pragma warning(disable:2259)
5 #endif
6 #ifdef WIN32
7 // Disable warning
8 // warning C4996: 'sprintf': This function or variable may be unsafe.
9 // coming from TString.h
10 #pragma warning(disable:4996)
11 #endif
12 // ============================================================================
13 // Include files
14 // ============================================================================
15 #include <type_traits>
16 // ============================================================================
17 // AIDA
18 // ============================================================================
19 #include "GaudiKernel/Kernel.h"
20 //-- to avoid that the class macro trick affects them
22 #define class class GAUDI_API
23 #include "AIDA/IHistogram1D.h"
24 #include "AIDA/IHistogram2D.h"
25 #include "AIDA/IHistogram3D.h"
26 #include "AIDA/IProfile1D.h"
27 #include "AIDA/IProfile2D.h"
28 #undef class
29 // ============================================================================
30 // ROOT
31 // ============================================================================
32 #include "TH1D.h"
33 #include "TH2D.h"
34 #include "TH3D.h"
35 #include "TProfile.h"
36 #include "TProfile2D.h"
37 // ============================================================================
38 // GaudiKernel
39 // ============================================================================
40 #include "GaudiKernel/HistogramBase.h"
41 // ============================================================================
42 // GaudiAlg
43 // ============================================================================
44 #include "GaudiUtils/Aida2ROOT.h"
45 // ============================================================================
52 namespace {
53  template <typename Out, typename In>
54  Out *a2r_cast(In* aida) {
55  using Base = typename std::conditional<std::is_const<Out>::value,
57  Gaudi::HistogramBase>::type;
58  auto base = dynamic_cast<Base*>( aida );
59  return base ? dynamic_cast<Out*>( base->representation() ) : nullptr;
60  }
61 }
62 // ============================================================================
63 // get the underlying pointer for 1D-histogram
64 // ============================================================================
65 TH1D* Gaudi::Utils::Aida2ROOT::aida2root ( AIDA::IHistogram1D* aida )
66 {
67  return a2r_cast<TH1D>( aida );
68 }
69 const TH1D* Gaudi::Utils::Aida2ROOT::aida2root ( const AIDA::IHistogram1D* aida )
70 {
71  return a2r_cast<const TH1D>( aida );
72 }
73 // ============================================================================
74 // get the underlying pointer for 2D-histogram
75 // ============================================================================
76 TH2D* Gaudi::Utils::Aida2ROOT::aida2root ( AIDA::IHistogram2D* aida )
77 {
78  return a2r_cast<TH2D>( aida );
79 }
80 const TH2D* Gaudi::Utils::Aida2ROOT::aida2root ( const AIDA::IHistogram2D* aida )
81 {
82  return a2r_cast<const TH2D>( aida );
83 }
84 // ============================================================================
85 // get the underlying pointer for 3D-histogram
86 // ============================================================================
87 TH3D* Gaudi::Utils::Aida2ROOT::aida2root ( AIDA::IHistogram3D* aida )
88 {
89  return a2r_cast<TH3D>( aida );
90 }
91 const TH3D* Gaudi::Utils::Aida2ROOT::aida2root (const AIDA::IHistogram3D* aida )
92 {
93  return a2r_cast<const TH3D>( aida );
94 }
95 // ============================================================================
96 // get the underlying pointer for 1D-profile
97 // ============================================================================
98 TProfile* Gaudi::Utils::Aida2ROOT::aida2root ( AIDA::IProfile1D* aida )
99 {
100  return a2r_cast<TProfile>( aida );
101 }
102 const TProfile* Gaudi::Utils::Aida2ROOT::aida2root ( const AIDA::IProfile1D* aida )
103 {
104  return a2r_cast<const TProfile>( aida );
105 }
106 // ============================================================================
107 // get the underlying pointer for 2D-profile
108 // ============================================================================
109 TProfile2D* Gaudi::Utils::Aida2ROOT::aida2root ( AIDA::IProfile2D* aida )
110 {
111  return a2r_cast<TProfile2D>( aida );
112 }
113 const TProfile2D* Gaudi::Utils::Aida2ROOT::aida2root ( const AIDA::IProfile2D* aida )
114 {
115  return a2r_cast<const TProfile2D>( aida );
116 }
117 // ============================================================================
118 // get root representation for other cases
119 // ============================================================================
120 TObject* Gaudi::Utils::Aida2ROOT::aida2root ( AIDA::IHistogram* aida )
121 {
122  return a2r_cast<TObject>(aida);
123 }
124 const TObject* Gaudi::Utils::Aida2ROOT::aida2root ( const AIDA::IHistogram* aida )
125 {
126  return a2r_cast<const TObject>(aida);
127 }
128 // ============================================================================
129 // The END
130 // ============================================================================
static TH1D * aida2root(AIDA::IHistogram1D *aida)
get the underlying pointer for 1D-histogram
Definition: Aida2ROOT.cpp:65
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
Definition: HistogramBase.h:22
string type
Definition: gaudirun.py:151