Anaphe Home Page Reference Documentation

Main Page     Namespaces     Classes     Source Code    

H_HistoTable.h

Go to the documentation of this file.
00001 #ifndef _H_HISTOTABLE_H_
00002 #define _H_HISTOTABLE_H_ 1
00003 
00004 #include "HTL/HTL_std.h"
00005 #include "HTL/I_Histo.h"
00006 #include "HTL/H_Bin_Helper.h"
00007 
00008 
00012 class HistoTable1D
00013 {
00014 public:
00016   HistoTable1D(const char *fn): os(*new HTL_STREAM_STD::ofstream(fn,HTL_STREAM_STD::ios::out)) {}
00018   virtual ~HistoTable1D() { delete &os;}
00020   int write( const I_Histo &a_histo )
00021     {
00022       I_Histo &hp = (I_Histo &) a_histo;
00023       if (hp.dim() == 1) {
00024       for( Size i=0; i<hp.bin_count(); i++ ) {
00025         os << H_Bin_Helper::bin_center(hp, i) << " " 
00026            << hp.i_bin(i).value() << " " 
00027            << hp.i_bin(i).error() << HTL_STREAM_STD::endl;
00028       }
00029       os << HTL_STREAM_STD::endl;
00030       } else
00031         HTL_ERR("Can't write to file: not a 1D histo");
00032       return !os.fail();
00033     }
00034 private:
00035   HTL_STREAM_STD::ofstream &os;
00036 };
00037 
00038 
00042 class HistoTable2D
00043 {
00044 public:
00046   HistoTable2D(const char *fn): os(*new HTL_STREAM_STD::ofstream(fn,HTL_STREAM_STD::ios::out)) {}
00048   virtual ~HistoTable2D() { delete &os;}
00050   int write( const I_Histo &a_histo )
00051     {
00052       I_Histo &hp = (I_Histo &) a_histo;
00053       if (hp.dim() == 2) {
00054       I_Histo::I_Bin_Location l(2);
00055       for( Size i=0; i<hp.i_partition(0).bin_count(); i++ ) {
00056         for( Size j=0; j<hp.i_partition(1).bin_count(); j++ ) {
00057           l[0] = i; l[1] = j;
00058           os << H_Bin_Helper::bin_center(hp, 0, l) << " " 
00059              << H_Bin_Helper::bin_center(hp, 1, l) << " " 
00060              << hp.i_bin(l).value() << HTL_STREAM_STD::endl;
00061         }
00062       }
00063       os << HTL_STREAM_STD::endl;
00064       } else
00065         HTL_ERR("Can't write to file: not a 2D histo");
00066       return !os.fail();
00067     }
00068 private:
00069   HTL_STREAM_STD::ofstream &os;
00070 };
00071 
00075 class HistoTable3D
00076 {
00077 public:
00079   HistoTable3D(const char *fn): os(*new HTL_STREAM_STD::ofstream(fn,HTL_STREAM_STD::ios::out)) {}
00081   virtual ~HistoTable3D() { delete &os;}
00083   int write( const I_Histo &a_histo )
00084     {
00085       I_Histo &hp = (I_Histo &) a_histo;
00086       if (hp.dim() == 3) {
00087       I_Histo::I_Bin_Location l(3);
00088       for( Size i=0; i<hp.i_partition(0).bin_count(); i++ ) {
00089         for( Size j=0; j<hp.i_partition(1).bin_count(); j++ ) {
00090           for( Size k=0; k<hp.i_partition(2).bin_count(); k++ ) {
00091             l[0] = i; l[1] = j;l[2] = k;
00092             os << H_Bin_Helper::bin_center(hp, 0, l) << " " 
00093                << H_Bin_Helper::bin_center(hp, 1, l) << " " 
00094                << H_Bin_Helper::bin_center(hp, 2, l) << " " 
00095                << hp.i_bin(l).value() << HTL_STREAM_STD::endl;
00096           }
00097         }
00098       }
00099       os << HTL_STREAM_STD::endl;
00100       } else
00101         HTL_ERR("Can't write to file: not a 3D histo");
00102       return !os.fail();
00103     }
00104 private:
00105   HTL_STREAM_STD::ofstream &os;
00106 };
00107 
00108 #endif
00109 


Anaphe documentation generated by Doxygen (www.doxygen.org)