The Gaudi Framework  master (37c0b60a)
P2D.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifdef __ICC
12 // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits
13 // TODO: To be removed, since it comes from ROOT TMathBase.h
14 # pragma warning( disable : 2259 )
15 #endif
16 #ifdef WIN32
17 // Disable warning
18 // warning C4996: 'sprintf': This function or variable may be unsafe.
19 // coming from TString.h
20 # pragma warning( disable : 4996 )
21 #endif
22 #include "GaudiPI.h"
23 #include <Gaudi/MonitoringHub.h>
25 #include <GaudiCommonSvc/P2D.h>
26 #include <GaudiKernel/DataObject.h>
28 
29 #include <TH2D.h>
30 #include <TProfile2D.h>
31 
32 namespace Gaudi {
33  template <>
35  return className == "AIDA::IProfile2D"
36  ? const_cast<AIDA::IProfile2D*>( static_cast<const AIDA::IProfile2D*>( this ) )
37  : className == "AIDA::IProfile" ? const_cast<AIDA::IProfile*>( static_cast<const AIDA::IProfile*>( this ) )
38  : className == "AIDA::IBaseHistogram"
39  ? const_cast<AIDA::IBaseHistogram*>( static_cast<const AIDA::IBaseHistogram*>( this ) )
40  : nullptr;
41  }
42 
43  template <>
45  int rBin = m_rep->GetBin( rIndexX( idX ), rIndexY( idY ) );
46  return int( m_rep->GetBinEntries( rBin ) + 0.5 );
47  }
48 
49  template <>
51  TProfile2D* imp = dynamic_cast<TProfile2D*>( rep );
52  if ( !imp ) throw std::runtime_error( "Cannot adopt native histogram representation." );
53  m_rep.reset( imp );
54  m_xAxis.initialize( m_rep->GetXaxis(), true );
55  m_yAxis.initialize( m_rep->GetYaxis(), true );
56  setTitle( m_rep->GetTitle() );
57  }
58 } // namespace Gaudi
59 
61  const std::string& title, const Edges& eX,
62  const Edges& eY, double /* zlow */, double /* zup */ ) {
63  // Not implemented in ROOT! Can only use TProfile2D with no z-limits
64  auto p = new Profile2D( new TProfile2D( title.c_str(), title.c_str(), eX.size() - 1, &eX.front(), eY.size() - 1,
65  &eY.front() /*,zlow,zup */ ) );
66  svcLocator->monitoringHub().registerEntity( "", path, "histogram:ProfileHistogram:double", *p );
67  return { p, p };
68 }
69 
71  const std::string& title, int binsX, double xlow,
72  double xup, int binsY, double ylow, double yup,
73  double zlow, double zup ) {
74  auto p =
75  new Profile2D( new TProfile2D( title.c_str(), title.c_str(), binsX, xlow, xup, binsY, ylow, yup, zlow, zup ) );
76  svcLocator->monitoringHub().registerEntity( "", path, "histogram:ProfileHistogram:double", *p );
77  return { p, p };
78 }
79 
81  const AIDA::IProfile2D& hist ) {
82  auto h = getRepresentation<AIDA::IProfile2D, TProfile2D>( hist );
83  auto n = ( h ? new Profile2D( new TProfile2D( *h ) ) : nullptr );
84  if ( n ) { svcLocator->monitoringHub().registerEntity( "", path, "histogram:ProfileHistogram:double", *n ); }
85  return { n, n };
86 }
87 
88 Gaudi::Profile2D::Profile2D( TProfile2D* rep ) {
89  m_classType = "IProfile2D";
90  rep->SetDirectory( nullptr );
91  adoptRepresentation( rep );
92  m_sumEntries = 0;
93 }
ISvcLocator::monitoringHub
Gaudi::Monitoring::Hub & monitoringHub()
Definition: ISvcLocator.cpp:25
std::string
STL class.
AtlasMCRecoFullPrecedenceDump.path
path
Definition: AtlasMCRecoFullPrecedenceDump.py:49
MonitoringHub.h
std::pair
ISvcLocator
Definition: ISvcLocator.h:46
P2D.h
ObjectFactory.h
Gaudi::Generic2D::cast
void * cast(const std::string &className) const override
Introspection method.
HistogramUtility.h
Gaudi::Profile2D::Profile2D
Profile2D()
Default Constructor.
Definition: P2D.h:34
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
Gaudi::Generic2D< AIDA::IProfile2D, TProfile2D >::adoptRepresentation
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
std::string::c_str
T c_str(T... args)
AlgSequencer.h
h
Definition: AlgSequencer.py:31
Gaudi::Generic2D< AIDA::IProfile2D, TProfile2D >::m_classType
std::string m_classType
class type
Definition: Generic2D.h:164
GaudiPython.Bindings.nullptr
nullptr
Definition: Bindings.py:87
Gaudi::Monitoring::Hub::registerEntity
void registerEntity(std::string c, std::string n, std::string t, T &ent)
Definition: MonitoringHub.h:140
std::runtime_error
STL class.
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
cpluginsvc.n
n
Definition: cpluginsvc.py:234
DataObject.h
GaudiPI.h
Gaudi::Generic2D< AIDA::IProfile2D, TProfile2D >::m_sumEntries
int m_sumEntries
cache sumEntries (allEntries) when setting contents since Root can't compute by himself
Definition: Generic2D.h:166
Gaudi::Generic2D
Definition: Generic2D.h:46
Gaudi::createProf2D
std::pair< DataObject *, AIDA::IProfile2D * > createProf2D(ISvcLocator *svcLocator, const std::string &path, const AIDA::IProfile2D &hist)
Copy constructor.