All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HistoXML.cpp
Go to the documentation of this file.
1 // $Id: HistoXML.cpp,v 1.1.1.1 2009-10-22 09:17:02 ibelyaev Exp $
2 // ============================================================================
3 // Include files
4 // ============================================================================
5 // STD&STL
6 // ============================================================================
7 #include <memory>
8 // ============================================================================
9 // ROOT
10 // ============================================================================
11 #include "TH1.h"
12 #include "TH1D.h"
13 #include "TH2D.h"
14 #include "TH3D.h"
15 #include "TH1F.h"
16 #include "TH2F.h"
17 #include "TH3F.h"
18 #include "TProfile.h"
19 #include "TProfile2D.h"
20 #include "TBufferXML.h"
21 // ============================================================================
22 // AIDA
23 // ============================================================================
24 #include "AIDA/IHistogram1D.h"
25 #include "AIDA/IHistogram2D.h"
26 #include "AIDA/IHistogram3D.h"
27 #include "AIDA/IProfile1D.h"
28 #include "AIDA/IProfile2D.h"
29 // ============================================================================
30 // local
31 // ============================================================================
32 #include "GaudiUtils/Aida2ROOT.h"
33 #include "GaudiUtils/HistoXML.h"
34 // ============================================================================
40 // ============================================================================
41 namespace
42 {
43  // ==========================================================================
45  template <class TYPE>
46  struct _Xml
47  {
48  typedef std::auto_ptr<TYPE> H ;
49  //
50  H operator() ( const std::string& input ) const
51  {
52  // 1) use XML-parser
53  std::auto_ptr<TObject> obj ( TBufferXML::ConvertFromXML ( input.c_str() ) ) ;
54  if ( 0 == obj.get() ) { return H() ; } // RETURN
55  H histo ( dynamic_cast<TYPE*>( obj.get() ) ) ;
56  if ( 0 != histo.get() ) { obj.release() ; }
57  return histo ;
58  }
59  //
60  } ;
61  // ==========================================================================
62 } // end of anonymous namespace
63 // ============================================================================
64 /* stream the ROOT histogram into output stream as XML
65  * @param histo (INPUT) the histogram to be streamed
66  * @param stream (OUTPUT) the stream
67  */
68 // ============================================================================
69 std::ostream& Gaudi::Utils::Histos::toXml
70 ( const TH1D& histo ,
71  std::ostream& stream )
72 {
73  //
74  const TObject* obj = &histo ;
75  //
76  TString s = TBufferXML::ConvertToXML ( const_cast<TObject*> ( obj ) ) ;
77  //
78  return stream << s ;
79 }
80 // ============================================================================
81 /* stream the ROOT histogram into output stream as XML
82  * @param histo (INPUT) the histogram to be streamed
83  * @param stream (OUTPUT) the stream
84  */
85 // ============================================================================
86 std::ostream& Gaudi::Utils::Histos::toXml
87 ( const TH2D& histo ,
88  std::ostream& stream )
89 {
90  //
91  const TObject* obj = &histo ;
92  //
93  TString s = TBufferXML::ConvertToXML ( const_cast<TObject*> ( obj ) ) ;
94  //
95  return stream << s ;
96 }
97 // ============================================================================
98 /* stream the ROOT histogram into output stream as XML
99  * @param histo (INPUT) the histogram to be streamed
100  * @param stream (OUTPUT) the stream
101  */
102 // ============================================================================
103 std::ostream& Gaudi::Utils::Histos::toXml
104 ( const TH3D& histo ,
105  std::ostream& stream )
106 {
107  //
108  const TObject* obj = &histo ;
109  //
110  TString s = TBufferXML::ConvertToXML ( const_cast<TObject*> ( obj ) ) ;
111  //
112  return stream << s ;
113 }
114 // ============================================================================
115 /* stream the ROOT histogram into output stream as XML
116  * @param histo (INPUT) the histogram to be streamed
117  * @param stream (OUTPUT) the stream
118  */
119 // ============================================================================
120 std::ostream& Gaudi::Utils::Histos::toXml
121 ( const TH1F& histo ,
122  std::ostream& stream )
123 {
124  //
125  const TObject* obj = &histo ;
126  //
127  TString s = TBufferXML::ConvertToXML ( const_cast<TObject*> ( obj ) ) ;
128  //
129  return stream << s ;
130 }
131 // ============================================================================
132 /* stream the ROOT histogram into output stream as XML
133  * @param histo (INPUT) the histogram to be streamed
134  * @param stream (OUTPUT) the stream
135  */
136 // ============================================================================
137 std::ostream& Gaudi::Utils::Histos::toXml
138 ( const TH2F& histo ,
139  std::ostream& stream )
140 {
141  //
142  const TObject* obj = &histo ;
143  //
144  TString s = TBufferXML::ConvertToXML ( const_cast<TObject*> ( obj ) ) ;
145  //
146  return stream << s ;
147 }
148 // ============================================================================
149 /* stream the ROOT histogram into output stream as XML
150  * @param histo (INPUT) the histogram to be streamed
151  * @param stream (OUTPUT) the stream
152  */
153 // ============================================================================
154 std::ostream& Gaudi::Utils::Histos::toXml
155 ( const TH3F& histo ,
156  std::ostream& stream )
157 {
158  //
159  const TObject* obj = &histo ;
160  //
161  TString s = TBufferXML::ConvertToXML ( const_cast<TObject*> ( obj ) ) ;
162  //
163  return stream << s ;
164 }
165 // ============================================================================
166 /* stream the ROOT histogram into output stream as XML
167  * @param histo (INPUT) the histogram to be streamed
168  * @param stream (OUTPUT) the stream
169  */
170 // ============================================================================
171 std::ostream& Gaudi::Utils::Histos::toXml
172 ( const TProfile& histo ,
173  std::ostream& stream )
174 {
175  //
176  const TObject* obj = &histo ;
177  //
178  TString s = TBufferXML::ConvertToXML ( const_cast<TObject*> ( obj ) ) ;
179  //
180  return stream << s ;
181 }
182 // ============================================================================
183 /* stream the ROOT histogram into output stream as XML
184  * @param histo (INPUT) the histogram to be streamed
185  * @param stream (OUTPUT) the stream
186  */
187 // ============================================================================
188 std::ostream& Gaudi::Utils::Histos::toXml
189 ( const TProfile2D& histo ,
190  std::ostream& stream )
191 {
192  //
193  const TObject* obj = &histo ;
194  //
195  TString s = TBufferXML::ConvertToXML ( const_cast<TObject*> ( obj ) ) ;
196  //
197  return stream << s ;
198 }
199 // ============================================================================
200 /* stream the ROOT histogram into the output stream as XML
201  * @param histo (INPUT) the histogram to be streamed
202  * @param stream (OUTPUT) the stream
203  */
204 // ============================================================================
205 std::ostream& Gaudi::Utils::Histos::toXml
206 ( const AIDA::IHistogram1D& histo ,
207  std::ostream& stream )
208 {
209  //
210  AIDA::IHistogram1D* aida = const_cast<AIDA::IHistogram1D*> ( &histo ) ;
211  //
212  const TH1D* root = Gaudi::Utils::Aida2ROOT::aida2root ( aida ) ;
213  if ( 0 == root ) { return stream ; } // RETURN
214  //
215  return toXml ( *root , stream ) ;
216 }
217 // ============================================================================
218 /* stream the ROOT histogram into the output stream as XML
219  * @param histo (INPUT) the histogram to be streamed
220  * @param stream (OUTPUT) the stream
221  */
222 // ============================================================================
223 std::ostream& Gaudi::Utils::Histos::toXml
224 ( const AIDA::IHistogram2D& histo ,
225  std::ostream& stream )
226 {
227  //
228  AIDA::IHistogram2D* aida = const_cast<AIDA::IHistogram2D*> ( &histo ) ;
229  //
230  const TH2D* root = Gaudi::Utils::Aida2ROOT::aida2root ( aida ) ;
231  if ( 0 == root ) { return stream ; } // RETURN
232  //
233  return toXml ( *root , stream ) ;
234 }
235 // ============================================================================
236 /* stream the ROOT histogram into the output stream as XML
237  * @param histo (INPUT) the histogram to be streamed
238  * @param stream (OUTPUT) the stream
239  */
240 // ============================================================================
241 std::ostream& Gaudi::Utils::Histos::toXml
242 ( const AIDA::IHistogram3D& histo ,
243  std::ostream& stream )
244 {
245  //
246  AIDA::IHistogram3D* aida = const_cast<AIDA::IHistogram3D*> ( &histo ) ;
247  //
248  const TH3D* root = Gaudi::Utils::Aida2ROOT::aida2root ( aida ) ;
249  if ( 0 == root ) { return stream ; } // RETURN
250  //
251  return toXml ( *root , stream ) ;
252 }
253 // ============================================================================
254 /* stream the ROOT histogram into the output stream as XML
255  * @param histo (INPUT) the histogram to be streamed
256  * @param stream (OUTPUT) the stream
257  */
258 // ============================================================================
259 std::ostream& Gaudi::Utils::Histos::toXml
260 ( const AIDA::IProfile1D& histo ,
261  std::ostream& stream )
262 {
263  //
264  AIDA::IProfile1D* aida = const_cast<AIDA::IProfile1D*> ( &histo ) ;
265  //
266  const TProfile* root = Gaudi::Utils::Aida2ROOT::aida2root ( aida ) ;
267  if ( 0 == root ) { return stream ; } // RETURN
268  //
269  return toXml ( *root , stream ) ;
270 }
271 // ============================================================================
272 /* stream the ROOT histogram into the output stream as XML
273  * @param histo (INPUT) the histogram to be streamed
274  * @param stream (OUTPUT) the stream
275  */
276 // ============================================================================
277 std::ostream& Gaudi::Utils::Histos::toXml
278 ( const AIDA::IProfile2D& histo ,
279  std::ostream& stream )
280 {
281  //
282  AIDA::IProfile2D* aida = const_cast<AIDA::IProfile2D*> ( &histo ) ;
283  //
284  const TProfile2D* root = Gaudi::Utils::Aida2ROOT::aida2root ( aida ) ;
285  if ( 0 == root ) { return stream ; } // RETURN
286  //
287  return toXml ( *root , stream ) ;
288 }
289 // ============================================================================
290 /* parse the histogram from standard ROOT XML
291  * @param result (OUTPUT) the parsed histogram
292  * @param input (INPUT) the input XML string
293  * @return status code
294  */
295 // ============================================================================
297 ( TH1D& result , const std::string& input )
298 {
299  //
300  result.Reset() ; // RESET old histogram
301  //
302  _Xml<TH1D> _xml ;
303  std::auto_ptr<TH1D> histo = _xml ( input ) ;
304  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
305  //
306  result.Reset() ;
307  histo->Copy ( result ) ;
308  //
309  return StatusCode::SUCCESS ;
310 }
311 // ============================================================================
312 /* parse the histogram from standard ROOT XML
313  * @param result (OUTPUT) the parsed histogram
314  * @param input (INPUT) the input XML string
315  * @return status code
316  */
317 // ============================================================================
319 ( TH2D& result , const std::string& input )
320 {
321  //
322  result.Reset() ; // RESET old histogram
323  //
324  _Xml<TH2D> _xml ;
325  std::auto_ptr<TH2D> histo = _xml ( input ) ;
326  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
327  //
328  result.Reset() ;
329  histo->Copy ( result ) ;
330  //
331  return StatusCode::SUCCESS ;
332 }
333 // ============================================================================
334 /* parse the histogram from standard ROOT XML
335  * @param result (OUTPUT) the parsed histogram
336  * @param input (INPUT) the input XML string
337  * @return status code
338  */
339 // ============================================================================
341 ( TH3D& result , const std::string& input )
342 {
343  //
344  result.Reset() ; // RESET old histogram
345  //
346  _Xml<TH3D> _xml ;
347  std::auto_ptr<TH3D> histo = _xml ( input ) ;
348  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
349  //
350  result.Reset() ;
351  histo->Copy ( result ) ;
352  //
353  return StatusCode::SUCCESS ;
354 }
355 // ============================================================================
356 /* parse the histogram from standard ROOT XML
357  * @param result (OUTPUT) the parsed histogram
358  * @param input (INPUT) the input XML string
359  * @return status code
360  */
361 // ============================================================================
363 ( TH1F& result , const std::string& input )
364 {
365  //
366  result.Reset() ; // RESET old histogram
367  //
368  _Xml<TH1F> _xml ;
369  std::auto_ptr<TH1F> histo = _xml ( input ) ;
370  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
371  //
372  result.Reset() ;
373  histo->Copy ( result ) ;
374  //
375  return StatusCode::SUCCESS ;
376 }
377 // ============================================================================
378 /* parse the histogram from standard ROOT XML
379  * @param result (OUTPUT) the parsed histogram
380  * @param input (INPUT) the input XML string
381  * @return status code
382  */
383 // ============================================================================
385 ( TH2F& result , const std::string& input )
386 {
387  //
388  result.Reset() ; // RESET old histogram
389  //
390  _Xml<TH2F> _xml ;
391  std::auto_ptr<TH2F> histo = _xml ( input ) ;
392  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
393  //
394  result.Reset() ;
395  histo->Copy ( result ) ;
396  //
397  return StatusCode::SUCCESS ;
398 }
399 // ============================================================================
400 /* parse the histogram from standard ROOT XML
401  * @param result (OUTPUT) the parsed histogram
402  * @param input (INPUT) the input XML string
403  * @return status code
404  */
405 // ============================================================================
407 ( TH3F& result , const std::string& input )
408 {
409  //
410  result.Reset() ; // RESET old histogram
411  //
412  _Xml<TH3F> _xml ;
413  std::auto_ptr<TH3F> histo = _xml ( input ) ;
414  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
415  //
416  result.Reset() ;
417  histo->Copy ( result ) ;
418  //
419  return StatusCode::SUCCESS ;
420 }
421 // ============================================================================
422 /* parse the histogram from standard ROOT XML
423  * @param result (OUTPUT) the parsed histogram
424  * @param input (INPUT) the input XML string
425  * @return status code
426  */
427 // ============================================================================
429 ( TProfile& result , const std::string& input )
430 {
431  //
432  result.Reset() ; // RESET old histogram
433  //
434  _Xml<TProfile> _xml ;
435  std::auto_ptr<TProfile> histo = _xml ( input ) ;
436  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
437  //
438  result.Reset() ;
439  histo->Copy ( result ) ;
440  //
441  return StatusCode::SUCCESS ;
442 }
443 // ============================================================================
444 /* parse the histogram from standard ROOT XML
445  * @param result (OUTPUT) the parsed histogram
446  * @param input (INPUT) the input XML string
447  * @return status code
448  */
449 // ============================================================================
451 ( TProfile2D& result , const std::string& input )
452 {
453  //
454  result.Reset() ; // RESET old histogram
455  //
456  _Xml<TProfile2D> _xml ;
457  std::auto_ptr<TProfile2D> histo = _xml ( input ) ;
458  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
459  //
460  result.Reset() ;
461  histo->Copy ( result ) ;
462  //
463  return StatusCode::SUCCESS ;
464 }
465 
466 
467 // ============================================================================
468 /* parse the histogram from standard ROOT XML
469  * @param result (OUTPUT) the parsed histogram
470  * @param input (INPUT) the input XML string
471  * @return status code
472  */
473 // ============================================================================
475 ( TH1D*& result , const std::string& input )
476 {
477  if ( 0 != result ) { return fromXml ( *result , input ) ; }
478  //
479  _Xml<TH1D> _xml ;
480  std::auto_ptr<TH1D> histo = _xml ( input ) ;
481  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
482  //
483  result = histo.release() ; // ASSIGN
484  //
485  return StatusCode::SUCCESS ;
486 }
487 // ============================================================================
488 /* parse the histogram from standard ROOT XML
489  * @param result (OUTPUT) the parsed histogram
490  * @param input (INPUT) the input XML string
491  * @return status code
492  */
493 // ============================================================================
495 ( TH2D*& result , const std::string& input )
496 {
497  if ( 0 != result ) { return fromXml ( *result , input ) ; }
498  //
499  _Xml<TH2D> _xml ;
500  std::auto_ptr<TH2D> histo = _xml ( input ) ;
501  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
502  //
503  result = histo.release() ; // ASSIGN
504  //
505  return StatusCode::SUCCESS ;
506 }
507 // ============================================================================
508 /* parse the histogram from standard ROOT XML
509  * @param result (OUTPUT) the parsed histogram
510  * @param input (INPUT) the input XML string
511  * @return status code
512  */
513 // ============================================================================
515 ( TH3D*& result , const std::string& input )
516 {
517  if ( 0 != result ) { return fromXml ( *result , input ) ; }
518  //
519  _Xml<TH3D> _xml ;
520  std::auto_ptr<TH3D> histo = _xml ( input ) ;
521  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
522  //
523  result = histo.release() ; // ASSIGN
524  //
525  return StatusCode::SUCCESS ;
526 }
527 
528 // ============================================================================
529 /* parse the histogram from standard ROOT XML
530  * @param result (OUTPUT) the parsed histogram
531  * @param input (INPUT) the input XML string
532  * @return status code
533  */
534 // ============================================================================
536 ( TProfile*& result , const std::string& input )
537 {
538  if ( 0 != result ) { return fromXml ( *result , input ) ; }
539  //
540  _Xml<TProfile> _xml ;
541  std::auto_ptr<TProfile> histo = _xml ( input ) ;
542  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
543  //
544  result = histo.release() ; // ASSIGN
545  //
546  return StatusCode::SUCCESS ;
547 }
548 // ============================================================================
549 /* parse the histogram from standard ROOT XML
550  * @param result (OUTPUT) the parsed histogram
551  * @param input (INPUT) the input XML string
552  * @return status code
553  */
554 // ============================================================================
556 ( TProfile2D*& result , const std::string& input )
557 {
558  if ( 0 != result ) { return fromXml ( *result , input ) ; }
559  //
560  _Xml<TProfile2D> _xml ;
561  std::auto_ptr<TProfile2D> histo = _xml ( input ) ;
562  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN
563  //
564  result = histo.release() ; // ASSIGN
565  //
566  return StatusCode::SUCCESS ;
567 }
568 // ============================================================================
569 /* parse the histogram from standard ROOT XML
570  * @param result (OUTPUT) the parsed histogram
571  * @param input (INPUT) the input XML string
572  * @return status code
573  */
574 // ============================================================================
576 ( AIDA::IHistogram1D& result , const std::string& input )
577 {
578  TH1D* root = Gaudi::Utils::Aida2ROOT::aida2root ( &result ) ;
579  if ( 0 == root ) { return StatusCode::FAILURE ; } // RETURN
580  //
581  return fromXml ( *root , input ) ; // RETURN
582 }
583 // ============================================================================
584 /* parse the histogram from standard ROOT XML
585  * @param result (OUTPUT) the parsed histogram
586  * @param input (INPUT) the input XML string
587  * @return status code
588  */
589 // ============================================================================
591 ( AIDA::IHistogram2D& result , const std::string& input )
592 {
593  TH2D* root = Gaudi::Utils::Aida2ROOT::aida2root ( &result ) ;
594  if ( 0 == root ) { return StatusCode::FAILURE ; } // RETURN
595  //
596  return fromXml ( *root , input ) ; // RETURN
597 }
598 // ============================================================================
599 /* parse the histogram from standard ROOT XML
600  * @param result (OUTPUT) the parsed histogram
601  * @param input (INPUT) the input XML string
602  * @return status code
603  */
604 // ============================================================================
606 ( AIDA::IHistogram3D& result , const std::string& input )
607 {
608  TH3D* root = Gaudi::Utils::Aida2ROOT::aida2root ( &result ) ;
609  if ( 0 == root ) { return StatusCode::FAILURE ; } // RETURN
610  //
611  return fromXml ( *root , input ) ; // RETURN
612 }
613 // ============================================================================
614 /* parse the histogram from standard ROOT XML
615  * @param result (OUTPUT) the parsed histogram
616  * @param input (INPUT) the input XML string
617  * @return status code
618  */
619 // ============================================================================
621 ( AIDA::IProfile1D& result , const std::string& input )
622 {
623  TProfile* root = Gaudi::Utils::Aida2ROOT::aida2root ( &result ) ;
624  if ( 0 == root ) { return StatusCode::FAILURE ; } // RETURN
625  //
626  return fromXml ( *root , input ) ; // RETURN
627 }
628 // ============================================================================
629 /* parse the histogram from standard ROOT XML
630  * @param result (OUTPUT) the parsed histogram
631  * @param input (INPUT) the input XML string
632  * @return status code
633  */
634 // ============================================================================
636 ( AIDA::IProfile2D& result , const std::string& input )
637 {
638  TProfile2D* root = Gaudi::Utils::Aida2ROOT::aida2root ( &result ) ;
639  if ( 0 == root ) { return StatusCode::FAILURE ; } // RETURN
640  //
641  return fromXml ( *root , input ) ; // RETURN
642 }
643 // ============================================================================
644 // The END
645 // ============================================================================
GAUDI_API StatusCode fromXml(TH1D &result, const std::string &input)
parse the histogram from standard ROOT XML
Definition: HistoXML.cpp:297
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
static TH1D * aida2root(AIDA::IHistogram1D *aida)
get the underlying pointer for 1D-histogram
Definition: Aida2ROOT.cpp:55
GAUDI_API std::ostream & toXml(const TH1D &histo, std::ostream &stream)
stream the ROOT histogram into output stream as XML
Definition: HistoXML.cpp:70
string s
Definition: gaudirun.py:210
tuple root
Definition: IOTest.py:42