#ifndef HBARRAY_H
#define HBARRAY_H
#include "TObject.h"
#include "hlocateddataobject.h"
#include "hlocation.h"
#include <stddef.h>
 typedef size_t                  elem_t;
 typedef UChar_t           bit;
class HBArray : public TObject {
private:
  
  static Int_t nWords;      
  static Int_t nSplit;      
  static UInt_t** data;     
  static Int_t *modules;    
  static Int_t nDimensions; 
  static Int_t *lSizes;     
  
  UInt_t mBits;                  
  static UInt_t bitPerWord;      
  UInt_t* dataCurrent;           
  Int_t offset;                  
  static Int_t *indexes;         
  static Bool_t caching;         
  static Int_t init_count;       
  static Bool_t S_setup;         
  inline UInt_t maxBytes(void) const; 
  inline UInt_t maxWords(void) const; 
 
public:
   HBArray(void);	
   HBArray( UInt_t mlenght);				        
   virtual ~HBArray(void);
   void set( UInt_t pos);
   void setDimensions(Int_t nDim,Int_t *sizes); 
   Int_t* getDimensions(){ return lSizes;} 
   Int_t getNDim() {return nDimensions;} 
   void clear( UInt_t pos); 
   void set(void); 
   void clear(void); 
   Int_t operator[](UInt_t pos); 
   UInt_t lenght(void){return mBits;} 
   void dump(void);
   UInt_t  bcount(const size_t nsize );
   inline UInt_t  bcount2(const size_t nsize );
   Int_t getNBitSet ( size_t  upto);
   UInt_t** getData(){ return data;}
   void  setCapacity( Int_t nword,Int_t nsplit); 
   void release(); 
   Int_t getEntries(void) { return  nWords*bitPerWord;}     
   inline Int_t getSubLocation(  HLocation *aLoc );
   inline Int_t getSubLocation( Int_t *aLoc, Int_t dim );
   inline Int_t getSubLocation( HLocatedDataObject* data );
   inline Int_t getPosition( HLocation &aLoc);
   inline void set ( HLocation &aLoc );
   inline void setMod( Int_t loc, Int_t i);
   void complement(const size_t nsize );
   void Streamer_sparse(TBuffer & R__b); 
  ClassDef(HBArray,1) 
}; 
   
 inline Int_t HBArray::getSubLocation(  HLocation *aLoc ) {
     Int_t linear=aLoc->operator[](0);  
           for(Int_t i=1;i<nDimensions-1;i++) 
                         linear = linear*lSizes[i]+
                                  aLoc->operator[](i);
    #if DEBUG_LEVEL>2
	   aLoc->Dump(); 
           Warning(" linear:%i nDImens:%i \n",linear, nDimensions);
    #endif
	 return linear;
  }
 inline Int_t HBArray::getSubLocation( HLocatedDataObject* data ) {
    Int_t linear=data->getLocationIndex(0);
    #if DEBUG_LEVEL>2  
    Warning(" linear:%i nDImens:%i \n",linear, nDimensions);
    #endif  
    for(Int_t i=1;i<nDimensions-1;i++) {
               linear = linear*lSizes[i]+
                        data->getLocationIndex(i);
    #if DEBUG_LEVEL>2
	 Warning(" iter:%i sizes[]:%i index:%i \n",i,lSizes[i],data->getLocationIndex(i));
    #endif
     }
    #if DEBUG_LEVEL>2
       Warning(" linear:%i \n",linear);
    #endif
 
	 return linear;
  }
 inline Int_t HBArray::getSubLocation( Int_t *aLoc, Int_t dim ) {
    #if DEBUG_LEVEL>2 
     Warning(" aLoc:%i \n",aLoc->operator[](0));
    #endif
    Int_t linear=aLoc[0];
    #if DEBUG_LEVEL>2  
    Warning(" getSubLocation linear:%i nDImens:%i \n",linear, nDimensions);
    #endif
  
           for(Int_t i=1;i<dim-1;i++) 
               linear = linear*lSizes[i]+
                         aLoc[i];
	 return linear;
  }
 inline Int_t HBArray::getPosition( HLocation &aLoc){ 
     
     
     
     
     
     
     Int_t linear= getSubLocation( &aLoc );  
            dataCurrent = data[linear];
            Int_t pos = modules[linear];
     
    #if DEBUG_LEVEL>2
        Warning("linear:%i module pos : %i  \
                 dataCurrent:%i operat[]: %i \n",linear, 
	        pos, dataCurrent, operator[](aLoc[nDimensions-1]) 
               );
     #endif   
           if((pos != -1) && dataCurrent && 
              (operator[](aLoc[nDimensions-1]) == 1) ){ 
	          pos+= bcount2( ((int) aLoc[nDimensions-1]) );
 
     #if DEBUG_LEVEL>2
        Warning(" bitcount()=> cell: %i position : %i \n", 
		  pos,aLoc[nDimensions-1]); 
     #endif 
                 return ( pos );
	   } 
          else return -1; 
  }
 inline void HBArray::set ( HLocation &aLoc ){
    Int_t linear= getSubLocation( &aLoc );  
    dataCurrent = data[linear];
 
     #if DEBUG_LEVEL>2
      Warning("sub linear:%i cell loc:%i \n",linear,aLoc[nDimensions-1]);
     #endif     
    set ( aLoc[nDimensions-1] ); 
  } 
 
 inline void HBArray::setMod( Int_t loc, Int_t i){
           modules[loc] = i; 
 }
  
 inline UInt_t HBArray::maxBytes(void) const{
   return (UInt_t) (( maxWords()* sizeof(*data) )/nSplit + 1 ) ; 
 }
 inline UInt_t HBArray::maxWords(void) const{
   UInt_t res = mBits / bitPerWord; 
   if(mBits % bitPerWord) ++res;
   return res;  
 }
 inline UInt_t  HBArray::bcount2(const size_t nsize )
 {
  
  
  
  
  
  
  
  
  register     UInt_t count; 
  register     size_t        i;     
  size_t       nchar = (nsize  / 8);       
  size_t       mask_index = (nsize  % 8);  
  UChar_t *iter = (UChar_t*) dataCurrent; 
  
  static const UInt_t bitcount[256] = {0, 1, 1, 2, 1, 2, 2, 3, 1,
        2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3,
        4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2,
        3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2,
        3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3,
        4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4,
        5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1,
        2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3,
        4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3,
        4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5,
        6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3,
        4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4,
        5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5,
        6, 6, 7, 6, 7, 7, 8};
    static UInt_t  bmask[8]={      0x0 ,
				   0x1,       
				   0x3,
				   0x7, 
				   0xf, 
				   0x1f, 
				   0x3f, 
				   0x7f};       
     
      for (count = 0, i = 0; i < nchar; i++) {
        count += bitcount[*(iter)];
        iter++; 
     }  
     #if DEBUG_LEVEL>2
      Warning(" counting nchar gives: %i  + adding: %i  iter:%i  \n", count,
                bitcount[( *(iter) & bmask[mask_index]) ], *iter  ) ; 
     #endif 
     count+=bitcount[( *(iter) & bmask[mask_index]) ];  
   return (count);
} 
#endif /* !HBARRAY_H */
Last change: Sat May 22 12:53:39 2010
Last generated: 2010-05-22 12:53
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.