The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
HistoStrings.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 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// ============================================================================
12// Include files
13// ============================================================================
14// STD & STL
15// ============================================================================
16#include <sstream>
17// ============================================================================
18// local
19// ============================================================================
23#include <GaudiUtils/HistoXML.h>
24// ============================================================================
30// ============================================================================
31/* convert the histogram into the string
32 * @param histo (INPUT) the histogram to be streamed
33 * @param asXML (INPUT) use XML-format
34 * @return the string representation of the histogram
35 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
36 * @date 2009-09-26
37 */
38// ============================================================================
39std::string Gaudi::Utils::Histos::HistoStrings::toString( const TH1D& histo, const bool asXML ) {
40 return Gaudi::Utils::toString( histo, asXML );
41}
42// ============================================================================
43/* convert the histogram into the string
44 * @param histo (INPUT) the histogram to be streamed
45 * @param asXML (INPUT) use XML-format
46 * @return the string representation of the histogram
47 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
48 * @date 2009-09-26
49 */
50// ============================================================================
51std::string Gaudi::Utils::Histos::HistoStrings::toString( const TH2D& histo, const bool asXML ) {
52 return Gaudi::Utils::toString( histo, asXML );
53}
54// ============================================================================
55/* convert the histogram into the string
56 * @param histo (INPUT) the histogram to be streamed
57 * @param asXML (INPUT) use XML-format
58 * @return the string representation of the histogram
59 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
60 * @date 2009-09-26
61 */
62// ============================================================================
63std::string Gaudi::Utils::Histos::HistoStrings::toString( const AIDA::IHistogram1D& histo, const bool asXML ) {
64 return Gaudi::Utils::toString( histo, asXML );
65}
66// ============================================================================
67/* convert the histogram into the string
68 * @param histo (INPUT) the histogram to be streamed
69 * @param asXML (INPUT) use XML-format
70 * @return the string representation of the histogram
71 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
72 * @date 2009-09-26
73 */
74// ============================================================================
75std::string Gaudi::Utils::Histos::HistoStrings::toString( const AIDA::IHistogram2D& histo, const bool asXML ) {
76 return Gaudi::Utils::toString( histo, asXML );
77}
78// ============================================================================
79/* parse the histogram from string
80 * @param result (OUTPUT) the parsed histogram
81 * @param input (INPUT) the input string
82 * @return status code
83 */
84// ============================================================================
85StatusCode Gaudi::Utils::Histos::HistoStrings::fromString( TH1D& result, const std::string& input ) {
86 return Gaudi::Parsers::parse( result, input );
87}
88// ============================================================================
89/* parse the histogram from string
90 * @param result (OUTPUT) the parsed histogram
91 * @param input (INPUT) the input string
92 * @return status code
93 */
94// ============================================================================
95StatusCode Gaudi::Utils::Histos::HistoStrings::fromString( TH2D& result, const std::string& input ) {
96 return Gaudi::Parsers::parse( result, input );
97}
98// ============================================================================
99/* parse the histogram from string
100 * @param result (OUTPUT) the parsed histogram
101 * @param input (INPUT) the input XML string
102 * @return status code
103 */
104// ============================================================================
105StatusCode Gaudi::Utils::Histos::HistoStrings::fromString( AIDA::IHistogram1D& result, const std::string& input ) {
106 return Gaudi::Parsers::parse( result, input );
107}
108// ============================================================================
109/* parse the histogram from string
110 * @param result (OUTPUT) the parsed histogram
111 * @param input (INPUT) the input XML string
112 * @return status code
113 */
114// ============================================================================
115StatusCode Gaudi::Utils::Histos::HistoStrings::fromString( AIDA::IHistogram2D& result, const std::string& input ) {
116 return Gaudi::Parsers::parse( result, input );
117}
118// ============================================================================
119namespace {
120 // ==========================================================================
121 template <class TYPE>
122 std::string _toXml( const TYPE& object ) {
123 std::ostringstream s;
124 Gaudi::Utils::Histos::toXml( object, s );
125 return s.str();
126 }
127 // ==========================================================================
128 template <class TYPE>
129 StatusCode _fromXml( TYPE& object, const std::string& input ) {
130 return Gaudi::Utils::Histos::fromXml( object, input );
131 }
132 // ==========================================================================
133} // end of anonymous namespace
134// ============================================================================
135std::string Gaudi::Utils::Histos::HistoStrings::toXml( const TH1D& histo ) { return _toXml( histo ); }
136std::string Gaudi::Utils::Histos::HistoStrings::toXml( const TH2D& histo ) { return _toXml( histo ); }
137std::string Gaudi::Utils::Histos::HistoStrings::toXml( const TH3D& histo ) { return _toXml( histo ); }
138std::string Gaudi::Utils::Histos::HistoStrings::toXml( const TProfile& histo ) { return _toXml( histo ); }
139std::string Gaudi::Utils::Histos::HistoStrings::toXml( const TProfile2D& histo ) { return _toXml( histo ); }
140// ============================================================================
141std::string Gaudi::Utils::Histos::HistoStrings::toXml( const AIDA::IHistogram1D& histo ) { return _toXml( histo ); }
142std::string Gaudi::Utils::Histos::HistoStrings::toXml( const AIDA::IHistogram2D& histo ) { return _toXml( histo ); }
143std::string Gaudi::Utils::Histos::HistoStrings::toXml( const AIDA::IHistogram3D& histo ) { return _toXml( histo ); }
144std::string Gaudi::Utils::Histos::HistoStrings::toXml( const AIDA::IProfile1D& histo ) { return _toXml( histo ); }
145std::string Gaudi::Utils::Histos::HistoStrings::toXml( const AIDA::IProfile2D& histo ) { return _toXml( histo ); }
146// ============================================================================
147StatusCode Gaudi::Utils::Histos::HistoStrings::fromXml( TH1D& result, const std::string& input ) {
148 return _fromXml( result, input );
149}
150StatusCode Gaudi::Utils::Histos::HistoStrings::fromXml( TH2D& result, const std::string& input ) {
151 return _fromXml( result, input );
152}
153StatusCode Gaudi::Utils::Histos::HistoStrings::fromXml( TH3D& result, const std::string& input ) {
154 return _fromXml( result, input );
155}
156StatusCode Gaudi::Utils::Histos::HistoStrings::fromXml( TProfile& result, const std::string& input ) {
157 return _fromXml( result, input );
158}
159StatusCode Gaudi::Utils::Histos::HistoStrings::fromXml( TProfile2D& result, const std::string& input ) {
160 return _fromXml( result, input );
161}
162// ============================================================================
163StatusCode Gaudi::Utils::Histos::HistoStrings::fromXml( AIDA::IHistogram1D& result, const std::string& input ) {
164 return _fromXml( result, input );
165}
166StatusCode Gaudi::Utils::Histos::HistoStrings::fromXml( AIDA::IHistogram2D& result, const std::string& input ) {
167 return _fromXml( result, input );
168}
169StatusCode Gaudi::Utils::Histos::HistoStrings::fromXml( AIDA::IHistogram3D& result, const std::string& input ) {
170 return _fromXml( result, input );
171}
172StatusCode Gaudi::Utils::Histos::HistoStrings::fromXml( AIDA::IProfile1D& result, const std::string& input ) {
173 return _fromXml( result, input );
174}
175StatusCode Gaudi::Utils::Histos::HistoStrings::fromXml( AIDA::IProfile2D& result, const std::string& input ) {
176 return _fromXml( result, input );
177}
178// ============================================================================
179
180// ============================================================================
181// The END
182// ============================================================================
static StatusCode fromString(TH1D &result, const std::string &input)
parse the histogram from string
static std::string toString(const TH1D &histo, const bool asXML=false)
convert the histogram into the string
static StatusCode fromXml(TH1D &result, const std::string &input)
static std::string toXml(const TH1D &histo)
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
StatusCode parse(GaudiUtils::HashMap< K, V > &result, std::string_view input)
Basic parser for the types of HashMap used in DODBasicMapper.
GAUDI_API StatusCode fromXml(TH1D &result, std::string_view input)
parse the histogram from standard ROOT XML
Definition HistoXML.cpp:199
GAUDI_API std::ostream & toXml(const TH1D &histo, std::ostream &stream)
stream the ROOT histogram into output stream as XML
Definition HistoXML.cpp:76
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition ToStream.h:326