Anaphe Home Page Reference Documentation

Main Page     Namespaces     Classes     Source Code    

P_Histo_1D.cpp

Go to the documentation of this file.
00001 #if 1
00002         #include "HTL/P_Histo_1D.h"
00003 #else
00004         #include "HTL/T_Histo_1D.h"
00005 #endif
00006 
00007 //
00008 // Let's get lazy and use the preprocessor:
00009 //
00010 #define TEMPLATE___     \
00011         template< class T_Life, class T_Bin, class T_Partition >
00012 
00013 #define CLASS___        \
00014         P_Histo_1D < T_Life, T_Bin, T_Partition >
00015 
00016 //
00017 // *************************************************************************** 
00018 //
00019 
00020 TEMPLATE___
00021 CLASS___::P_Histo_1D( const char *a_name
00022         , const T_Partition &a_partition )
00023         : P_I_Histo_1D()
00024         , name_(a_name)
00025         , partition_( a_partition )
00026         , bins_( a_partition.bin_count()+a_partition.extra_bin_count() )
00027 {
00028         // Note: The extra 1 bin is the extra bin with extra index H_IN_RANGE.
00029         // It is used only to simplify the retrieving of extra bins.
00030         //
00031         // Bins are stored linearly according to the following order:
00032         //      * 0 .. bin_count()-1 ==> H_IN_RANGE bins
00033         //      * H_UNDERFLOW H_IN_RANGE H_OVERFLOW
00034 }
00035 
00036 TEMPLATE___
00037 CLASS___::P_Histo_1D( I_Histo &a_histo, int copy_data )
00038         : name_( a_histo.name() )
00039         , partition_( a_histo.i_partition(0) )
00040         , bins_( a_histo.bin_count() + a_histo.extra_bin_count() )
00041 {
00042   if(a_histo.dim() == 1) {
00043     if( copy_data ) {
00044       // Copy the bin contents:
00045       //
00046       for( Index i=0; i<Index(bin_count()+extra_bin_count()); i++ )
00047         bins_[i].make( a_histo.i_bin(i) );
00048     }
00049   } else {
00050     HTL_ERR("1st argument is not a 1D-histo interface");
00051   }
00052 }
00053 
00054 TEMPLATE___
00055 CLASS___::P_Histo_1D( const I_Histo &a_histo, int copy_data )
00056         : name_( a_histo.name() )
00057         , partition_( a_histo.i_partition(0) )
00058         , bins_( a_histo.bin_count() + a_histo.extra_bin_count() )
00059 {
00060   if(a_histo.dim() == 1) {
00061     if( copy_data ) {
00062       // Copy the bin contents:
00063       //
00064       for( Index i=0; i<Index(bin_count()+extra_bin_count()); i++ )
00065         bins_[i].make( a_histo.i_bin(i) );
00066     }
00067   } else {
00068     HTL_ERR("1st argument is not a 1D-histo interface");
00069   }
00070 }
00071 
00072 
00073 TEMPLATE___
00074 I_Bin & CLASS___::i_bin( I_Bin_Location &a_location )
00075 {
00076   if (a_location.size() >= (unsigned long) dim()) {
00077     return (I_Bin &) bin( a_location[0],0 );
00078   } else {
00079     HTL_ERR("1st argument is not a 1D-histo interface.");
00080     return (I_Bin &) bin( 1,0 );
00081   }     
00082 }
00083 
00084 TEMPLATE___
00085 I_Bin & CLASS___::i_bin( Index i ) const
00086 {
00087   if (i>=0 && i<Index(bin_count()+extra_bin_count())) {
00088     return (I_Bin &) bins_[i];
00089   } else {
00090     HTL_ERR("Invalid index in i_bin( Index i )");
00091     return (I_Bin &) bins_[0];
00092   }
00093 }
00094 
00095 TEMPLATE___
00096 I_Bin & CLASS___::i_bin( I_Bin_Location &a_location ) const
00097 {
00098   if (a_location.size() >= (unsigned long) dim()) {
00099     return (I_Bin &) bin( a_location[0] );
00100   } else {
00101     HTL_ERR("1st argument is not a 1D-histo interface.");
00102     return (I_Bin &) bin( 1 );
00103   }     
00104 }
00105 
00106 TEMPLATE___
00107 I_Bin & CLASS___::i_extra_bin( I_Extra_Bin_Location &a_location )
00108 {
00109   if (a_location.size() >= (unsigned long) dim()) {
00110     return (I_Bin &) extra_bin( a_location[0],0);
00111   } else {
00112     HTL_ERR("Invalid dimension for location in i_extra_bin(..)");
00113     return (I_Bin &) bin( 1, 0);
00114   }     
00115 }
00116 
00117 TEMPLATE___
00118 I_Bin & CLASS___::i_extra_bin( I_Extra_Bin_Location &a_location ) const
00119 {
00120   if (a_location.size() >= (unsigned long) dim()) {
00121     return (I_Bin &) extra_bin( a_location[0] );
00122   } else {
00123     HTL_ERR("Invalid dimension for location in i_extra_bin(..)");
00124     return (I_Bin &) bin( 1);
00125   }     
00126 }
00127 
00128 TEMPLATE___
00129 I_Partition & CLASS___::i_partition( Index p )
00130 {
00131   if (p == 0) {
00132     return (I_Partition &) partition_;
00133   } else {
00134     HTL_ERR("Invalid partition index in i_partition(..)");
00135     return (I_Partition &) partition_;
00136   }     
00137 }
00138 
00139 TEMPLATE___
00140 I_Partition & CLASS___::i_partition( Index p ) const
00141 {
00142   if (p == 0) {
00143     return (I_Partition &) partition_;
00144   } else {
00145     HTL_ERR("Invalid partition index in i_partition(..)");
00146     return (I_Partition &) partition_;
00147   }     
00148 }
00149 
00150 TEMPLATE___
00151 T_Bin & CLASS___::bin( Index i ) const
00152 {
00153   if ((i >= 0) && (i < Index(bin_count()))) {
00154     return (T_Bin &) bins_[ i ];
00155   } else {
00156     HTL_ERR("Invalid bin index in bin(..)");
00157     return (T_Bin &) bins_[ 0 ];
00158   }
00159 }
00160 
00161 TEMPLATE___
00162 T_Bin & CLASS___::extra_bin( Extra_Index an_extra_i ) const
00163 {
00164   if(EXTRA_VALID(an_extra_i)) {
00165     return (T_Bin &) bins_[ bin_count() + EXTRA_VALUE(an_extra_i)];
00166   } else {
00167     HTL_ERR("Invalid index in extra_bin(..)");
00168     return (T_Bin &) bins_[ bin_count()];
00169   }
00170 }
00171 
00172 TEMPLATE___
00173 void CLASS___::reset()
00174 {
00175   for( Index i=0; i<Index(bin_count()+extra_bin_count()); i++ )
00176     bins_[i] .reset();
00177 }
00178 
00179 
00180 TEMPLATE___
00181 T_Bin & CLASS___::mapped_bin( Mapped_Point x )
00182 {
00183         Index an_index;
00184 
00185         // Map the point `x' to an index:
00186         //
00187         partition().map_index( x, an_index, extra_index_ );
00188         // Return mapped bin:
00189         //
00190         if( is_in_range( extra_index_ ) )
00191           return bin( an_index );
00192         else
00193           return extra_bin( extra_index_ );
00194 }
00195 
00196 TEMPLATE___
00197 void CLASS___::compute_(const I_Histo &other, binHistoOp &oper)
00198 {
00199   H_BIN_UPDATE;
00200   for( Index i=0; i<Index(bin_count()+extra_bin_count()); i++ )
00201     oper.eval(i_bin(i), other.i_bin(i) );
00202 }
00203 
00204 TEMPLATE___
00205 void CLASS___::compute_(double value, binScalarOp &oper)
00206 {
00207   H_BIN_UPDATE;
00208   for( Index i=0; i<Index(bin_count()+extra_bin_count()); i++ )
00209     oper.eval(i_bin(i), value );
00210 }
00211 
00212 TEMPLATE___
00213 void CLASS___::add_( const I_Histo &other )
00214 {
00215   if (compatiblePartitions(other,"add_(..)")) {
00216     binHistoAdd operation;
00217     compute_ (other, operation);
00218   }
00219 }
00220 
00221 TEMPLATE___
00222 P_REF_I_Histo CLASS___::add1_( const I_Histo &other )
00223 {
00224   add_( other );
00225   return H_P_THIS;
00226 }
00227 
00228 
00229 TEMPLATE___
00230 void CLASS___::sub_( const I_Histo &other )
00231 {
00232   if (compatiblePartitions(other,"sub_(..)")) {
00233     binHistoSub operation;
00234     compute_ (other, operation);
00235   } 
00236 }
00237 
00238 TEMPLATE___
00239 P_REF_I_Histo CLASS___::sub1_( const I_Histo &other )
00240 {
00241   sub_( other );
00242   return H_P_THIS;
00243 }
00244 
00245 
00246 TEMPLATE___
00247 void CLASS___::mul_( const I_Histo &other )
00248 {
00249   if (compatiblePartitions(other,"mul_(..)")) {
00250     binHistoMul operation;
00251     compute_ (other, operation);
00252   }
00253 }
00254 
00255 TEMPLATE___
00256 P_REF_I_Histo CLASS___::mul1_( const I_Histo &other )
00257 {
00258   mul_( other );
00259   return H_P_THIS;
00260 }
00261 
00262 
00263 TEMPLATE___
00264 void CLASS___::div_( const I_Histo &other )
00265 {
00266   if (compatiblePartitions(other,"div_(..)")) {
00267     binHistoDiv operation;
00268     compute_ (other, operation);
00269   } 
00270 }
00271 
00272 TEMPLATE___
00273 P_REF_I_Histo CLASS___::div1_( const I_Histo &other )
00274 {
00275   div_( other );
00276   return H_P_THIS;
00277 }
00278 
00279 
00280 TEMPLATE___
00281 void CLASS___::binomial_div_( const I_Histo &other )
00282 {
00283   if (compatiblePartitions(other,"div_(..)")) {
00284     binHistoBinDiv operation;
00285     compute_ (other, operation);
00286   }
00287 }
00288 
00289 TEMPLATE___
00290 P_REF_I_Histo CLASS___::binomial_div1_( const I_Histo &other )
00291 {
00292   binomial_div_( other );
00293   return H_P_THIS;
00294 }
00295 
00296 TEMPLATE___
00297 void CLASS___::add_( double x )
00298 {
00299   binScalarAdd operation;
00300   compute_ (x,operation );
00301 }
00302 
00303 TEMPLATE___
00304 void CLASS___::sub_( double x )
00305 {
00306   binScalarSub operation;
00307   compute_ (x, operation);
00308 }
00309 
00310 TEMPLATE___
00311 void CLASS___::mul_( double x )
00312 {
00313   binScalarMul operation;
00314   compute_ (x, operation);
00315 }
00316 
00317 TEMPLATE___
00318 void CLASS___::div_( double x )
00319 {
00320   binScalarDiv operation;
00321   compute_ (x, operation);
00322 }
00323 
00324 TEMPLATE___
00325 bool CLASS___::compatiblePartitions (const I_Histo &other, const char *oper) {
00326   if(partition().is_compatible_with(((I_Histo &) other).i_partition(0))){
00327     return true;
00328   } else {
00329     char msg [128];
00330     strcpy (msg, "Incompatible partitions in (..)");
00331     strcat (msg,oper);
00332     HTL_ERR(msg );    
00333     return false;
00334   }
00335 }
00336 
00337 TEMPLATE___
00338 I_Bin & CLASS___::i_any_bin ( I_Bin_Location &a_loc ) const {
00339   if (a_loc.size() >= (unsigned long) dim()) {
00340     if (a_loc[0] >= 0)
00341       return i_bin( a_loc );
00342     else {
00343       if (a_loc[0] == I_Histo::UNDERFLOW_BIN)
00344         return (I_Bin &) extra_bin(H_UNDERFLOW);
00345       else
00346         return (I_Bin &) extra_bin(H_OVERFLOW);
00347     }
00348   } else {
00349     HTL_ERR("1st argument is not a 1D-histo interface.");
00350     return (I_Bin &) bin(0);
00351   }     
00352 }
00353 
00354 
00355 #undef CLASS___
00356 #undef TEMPLATE___
00357 
00358 


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