00001 #ifndef _H_P__HISTO_1D_H_
00002
00003 #if 1
00004
00005 #define _H_P__HISTO_1D_H_ 1
00006 #include "HTL/P_I_Histo_1D.h"
00007 #else
00008
00009 #define _H_T__HISTO_1D_H_ 1
00010 #include "HTL/T_I_Histo_1D.h"
00011 #endif
00012 #include "HTL/Histo_op.h"
00013
00017 template< class T_Life, class T_Bin, class T_Partition >
00018 class P_Histo_1D: public P_I_Histo_1D
00019 {
00020 public:
00022 H_IID_IMPLEMENT( P_Histo_1D );
00023 typedef P_Histo_1D<T_Life, T_Bin, T_Partition> Like_Current;
00024 typedef H_P_REF( Like_Current ) Ref_Like_Current;
00025 typedef T_Bin Bin_Type;
00026 typedef T_Partition Partition_Type;
00027
00028 #if defined __sun && __SUNPRO_CC < 0x500
00029 typedef T_Partition::Mapped_Point Mapped_Point;
00030 #else
00031 typedef typename T_Partition::Mapped_Point Mapped_Point;
00032 #endif
00033
00034 protected:
00035 P_Histo_1D() {}
00036
00037 public:
00038 virtual ~P_Histo_1D() {}
00039
00044 P_Histo_1D( const char *a_name, const T_Partition &a_partition );
00045
00055 P_Histo_1D( I_Histo &a_histo, int copy_data = 1 );
00056
00059 P_Histo_1D( const I_Histo &a_histo, int copy_data = 1 );
00060
00061 public:
00063 virtual const char *name() const { return P_HTL_STR_CONV(name_);}
00064
00066 virtual void set_name(const char *a_name ){update_(); name_ = a_name;}
00067
00070 virtual I_Bin & i_bin( I_Bin_Location &a_location );
00071
00074 virtual I_Bin & i_bin ( I_Bin_Location &a_location ) const;
00075
00079 virtual I_Bin & i_extra_bin( I_Extra_Bin_Location &a_location );
00080
00084 virtual I_Bin & i_extra_bin ( I_Extra_Bin_Location &a_location ) const;
00085
00088 virtual Size bin_count() const { return Size(partition().bin_count()); }
00089
00091 virtual I_Partition & i_partition( Index p = 0 );
00092
00094 virtual I_Partition & i_partition( Index p = 0 ) const ;
00095
00097 virtual I_Bin & i_bin( Index i )
00098 {
00099 if (i>=0 && i<Index(bin_count()+extra_bin_count())) {
00100 return (I_Bin &) bins_[i];
00101 } else {
00102 HTL_ERR("Invalid index in i_bin( Index i )");
00103 return (I_Bin &) bins_[0];
00104 }
00105 }
00107 virtual I_Bin & i_bin( Index i ) const ;
00109 virtual void reset();
00115 virtual I_Bin & i_any_bin ( I_Bin_Location &a_location ) const;
00116
00117 public:
00120 T_Partition & partition() { return (T_Partition &) partition_; }
00121
00124 T_Partition & partition() const { return (T_Partition &) partition_; }
00125
00130 T_Bin & mapped_bin( Mapped_Point x );
00131
00134 T_Bin & bin( Index i , int updateBin = 1)
00135 {
00136 if ((i >= 0) && (i < Index(bin_count()))) {
00137 if (updateBin) {H_BIN_UPDATE}
00138 return (T_Bin &) bins_[ i ];
00139 } else {
00140 HTL_ERR("Invalid bin index in bin(..)");
00141 return (T_Bin &) bins_[ 0 ];
00142 }
00143 }
00144
00147 T_Bin & bin( Index i ) const;
00148
00152 T_Bin & extra_bin( Extra_Index an_extra_i , int updateBin = 1)
00153 {
00154 if(EXTRA_VALID(an_extra_i)) {
00155 if (updateBin) {H_BIN_UPDATE}
00156 return (T_Bin &) bins_[ bin_count() + EXTRA_VALUE(an_extra_i)];
00157 } else {
00158 HTL_ERR("Invalid index in extra_bin(..)");
00159 return (T_Bin &) bins_[ bin_count()];
00160 }
00161 }
00162
00166 T_Bin & extra_bin( Extra_Index an_extra_i ) const ;
00167
00170 bool is_in_range( Extra_Index an_extra_i ) const
00171 { return EXTRA_IN_RANGE( an_extra_i ); }
00172
00173
00174 public:
00175
00177 T_Bin & _bin( Index i ) { H_BIN_UPDATE return (T_Bin &) bins_[i]; }
00178
00179 public:
00184 Ref_Like_Current clone( int copy_data = 1 )
00185 {
00186 Ref_Like_Current h =
00187 H_P_NEW_CLUSTER0 Like_Current( *this, copy_data );
00188 return h;
00189 }
00190
00192 Ref_Like_Current clone( H_P_CLUSTER1(a_place), int copy_data = 1 )
00193 { return H_P_NEW_CLUSTER1(a_place) Like_Current(*this, copy_data); }
00194
00195 protected:
00196 virtual P_REF_I_Histo clone_( int copy_data = 1 )
00197 { return (P_REF_I_Histo) clone( copy_data ); }
00198
00199 virtual P_REF_I_Histo clone_( H_P_CLUSTER1(a_place),
00200 int copy_data = 1 )
00201 { return (P_REF_I_Histo) clone( a_place, copy_data ); }
00202
00204 public:
00207 Ref_Like_Current add( const Ref_Like_Current &other )
00208 {
00209 Ref_Like_Current h = (Ref_Like_Current &) other;
00210
00211 if (partition().is_compatible_with( h->partition() )) {
00212 H_BIN_UPDATE
00213 for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00214 bins_[i].add( h->_bin(i) );
00215 } else {
00216 HTL_ERR("Incompatible partitions in add(..)");
00217 }
00218 return H_P_THIS;
00219 }
00220
00222 void add( const I_Histo &other ) { add_( other ); }
00223
00226 Ref_Like_Current sub( const Ref_Like_Current &other )
00227 {
00228 Ref_Like_Current h = (Ref_Like_Current &) other;
00229 if ( partition().is_compatible_with( h->partition() )) {
00230 H_BIN_UPDATE
00231 for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00232 bins_[i].sub( h->_bin(i) );
00233 } else {
00234 HTL_ERR("Incompatible partitions in sub(..)");
00235 }
00236 return H_P_THIS;
00237 }
00238
00240 void sub( const I_Histo &other ) { sub_( other ); }
00241
00244 Ref_Like_Current mul( const Ref_Like_Current &other )
00245 {
00246 Ref_Like_Current h = (Ref_Like_Current &) other;
00247 if ( partition().is_compatible_with( h->partition() )) {
00248 H_BIN_UPDATE
00249 for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00250 bins_[i].mul( h->_bin(i) );
00251 } else {
00252 HTL_ERR("Incompatible partitions in mul(..)");
00253 }
00254 return H_P_THIS;
00255 }
00256
00258 void mul( const I_Histo &other ) { mul_( other ); }
00259
00262 Ref_Like_Current div( const Ref_Like_Current &other )
00263 {
00264 Ref_Like_Current h = (Ref_Like_Current &) other;
00265 if ( partition().is_compatible_with( h->partition() )) {
00266 H_BIN_UPDATE
00267 for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00268 bins_[i].div( h->_bin(i) );
00269 } else {
00270 HTL_ERR("Incompatible partitions in div(..)" );
00271 }
00272 return H_P_THIS;
00273 }
00274
00276 void div( const I_Histo &other ) { div_( other ); }
00277
00280 Ref_Like_Current binomial_div( const Ref_Like_Current &other )
00281 {
00282 Ref_Like_Current h = (Ref_Like_Current &) other;
00283 if ( partition().is_compatible_with( h->partition() )) {
00284 H_BIN_UPDATE
00285 for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00286 bins_[i].binomial_div( h->_bin(i) );
00287 } else {
00288 HTL_ERR("Incompatible partitions in binomial_div(..)" );
00289 }
00290 return H_P_THIS;
00291 }
00292
00294 void binomial_div( const I_Histo &other ) { binomial_div_( other ); }
00296 void add( double x ) { add_( x ); }
00298 void sub( double x ) { sub_( x ); }
00300 void mul( double x ) { mul_( x ); }
00302 void div( double x ) { div_( x ); }
00303
00304 protected:
00305 virtual void add_( const I_Histo &other );
00306 virtual P_REF_I_Histo add1_( const I_Histo &other );
00307
00308 virtual void sub_( const I_Histo &other );
00309 virtual P_REF_I_Histo sub1_( const I_Histo &other );
00310
00311 virtual void mul_( const I_Histo &other );
00312 virtual P_REF_I_Histo mul1_( const I_Histo &other );
00313
00314 virtual void div_( const I_Histo &other );
00315 virtual P_REF_I_Histo div1_( const I_Histo &other );
00316
00317 virtual void binomial_div_( const I_Histo &other );
00318 virtual P_REF_I_Histo binomial_div1_(const I_Histo &other);
00319
00320 virtual void add_( double x );
00321 virtual void sub_( double x );
00322 virtual void mul_( double x );
00323 virtual void div_( double x );
00324 bool compatiblePartitions (const I_Histo &other, const char *oper);
00325 void compute_( const I_Histo &other , binHistoOp &oper) ;
00326 void compute_( double value , binScalarOp &oper) ;
00327
00328 #if 1
00329 public:
00330 virtual void start_update() { bins_.update(); }
00331
00332 protected:
00333 void update_()
00334 { if( ooUpdate() != oocSuccess) HTL_ERR("Cant open for update" ); }
00335 #else
00336 public:
00337 virtual void start_update() {}
00338 protected:
00339 void update_() {}
00340 #endif
00341
00342
00344 protected:
00345 #if defined __sun && __SUNPRO_CC < 0x500
00346 T_Life::S_String name_;
00347 #else
00348 typename T_Life::S_String name_;
00349 #endif
00350
00351 T_Partition partition_;
00352
00353 #if defined __sun && __SUNPRO_CC < 0x500
00354 T_Life::P_Bin_Container bins_;
00355 #else
00356 typename T_Life::P_Bin_Container bins_;
00357 #endif
00358
00359 Extra_Index extra_index_;
00360
00361 };
00362
00363 #endif // _HISTO_1D_H_
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402