ROOT logo
#pragma implementation
//*-- Author : Manuel Sanchez Garcia
//*-- Modified : 27/05/98
//*-- Copyright : GENP (Univ. Santiago de Compostela)

//_HADES_CLASS_DESCRIPTION 
/////////////////////////////////////////////////////////
//HIndexTable
//
//  This class handles an index table with an entry per 
//  possible HLocation. In such a way that, given a HLocation,it returns
//  an index.
//
//  You can also iterate on the index table (on the locations) using the
// functions gotoBegin(),gotoLocation() and next().
//
//  You can also access the indexes as if they were lineally distributed,
//
//////////////////////////////////////////////////////////
using namespace std;
#include "hindextable.h"
#include "hlocation.h"
#include "hdebug.h"
#include "Rtypes.h"
#include <iostream> 
#include <iomanip>

ClassImp(HIndexTable)

HIndexTable::HIndexTable(void) {
  //Default constructor
}

HIndexTable::~HIndexTable(void) {
  //Destructor
}

void HIndexTable::setDimensions(Int_t nDim,Int_t *sizes) {
  //Sets the number of dimensions of the table and its corresponding
  //sizes.
  //
  //Input:
  // nDim ---> number of indexes to define an entry
  // sizes --> max values of those indexes.
#if DEBUG_LEVEL>2
  gDebuger->enterFunc("HIndexTable::setDimensions");
  gDebuger->message("nDim= %i",nDim);
#endif
  Int_t prod=1,i=0;
  fSizes.Set(nDim,sizes);
  for (i=0;i<nDim;i++) { prod*=sizes[i];}
#if DEBUG_LEVEL>2
  gDebuger->message("Setting index array");
#endif
  fCompactTable.setCapacity(prod);
  fIndexArray.Set(prod);
  for (Int_t i=0;i<prod;i++) fIndexArray.fArray[i]=-1;
#if DEBUG_LEVEL > 2
  gDebuger->leaveFunc("HIndexTable::setDimensions");
#endif
}


void HIndexTable::Clear(Option_t *) {
  //Resets all the indexes in the table.
  //Int_t i;
 // for (i=0;i<fIndexArray.fN;i++) fIndexArray.fArray[i]=-1;
  register Int_t i=0;
  for (i=0;i<fCompactTable.getN();i++) {
    fIndexArray.fArray[fCompactTable.getIndex1(i)]=-1;
  }
  fCompactTable.clear();
}


Bool_t HIndexTable::checkLocation(HLocation &aLoc) {
  //Checks if there is an entry in the index table for this location
  Int_t i;
  for (i=0;i<fSizes.fN;i++) {
    if (aLoc[i]>=fSizes.fArray[i]) return kFALSE;
  }
  return kTRUE;
}

Int_t HIndexTable::gotoLocation(HLocation &aLoc) {
  //This function along with HIndexTable::next allows iteration on the index
  //table through all the indexes corresponding to the location aLoc
  //
  //gotoLocation positions a cursor at the index given by aLoc. It should be called
  //before any call to HIndexTable::next()
  //
  //Return value:
  //  The number of positions corresponding to the given location.
  Int_t n=1,i=0;
  if (aLoc.getNIndex()==fSizes.fN) 
    n=1;
  else {
    n=1;
    for(i=aLoc.getNIndex();i<fSizes.fN;i++) 
      n*=fSizes[i];
  }
  fCurrentPos=aLoc.getLinearIndex(&fSizes);
  return n;
}

Int_t HIndexTable::gotoBegin(void) {
  //This function positions the cursor for iterating on the HIndexTable at its
  // very beggining.
  fCurrentPos=0;
  return fIndexArray.fN;
}

Int_t HIndexTable::next(void) {
  //This function along with HIndexTable::gotoLocation allows iteration on the index
  //table.
  //
  //next advances to the next location by incrementing a cursor. It returns
  //the index associated to the current location (the location before advancing)
  Int_t idx;
  idx=fIndexArray[fCurrentPos];
  if (fCurrentPos<fIndexArray.fN-1) fCurrentPos++;
  return idx;
}

void HIndexTable::Streamer(TBuffer &R__b)
{
   // Stream an object of class HIndexTable.
   if (R__b.IsReading()) {
     Int_t prod=1;
     Version_t R__v = R__b.ReadVersion(); if (R__v) { }
     TObject::Streamer(R__b);
     fSizes.Streamer(R__b);
     if (R__v==1) {
       fIndexArray.Streamer(R__b);
       for (Int_t i=0;i<fSizes.fN;i++) { prod*=fSizes.fArray[i];}
       fCompactTable.setCapacity(prod);
       fCompactTable.clear();
       for (Int_t i=0;i<fIndexArray.fN;i++) {
	 if (fIndexArray.fArray[i]!=-1) {
	   fCompactTable.add(i,fIndexArray.fArray[i]);
	 }
       }
     } else if (R__v==2) {
       for (Int_t i=0;i<fSizes.fN;i++) { prod*=fSizes.fArray[i];}
       fIndexArray.Set(prod);
       for (Int_t i=0;i<prod;i++) fIndexArray.fArray[i]=-1;
       fCompactTable.Streamer(R__b);
       
       for (Int_t i=0;i<fCompactTable.getN();i++) {
	 fIndexArray.fArray[fCompactTable.getIndex1(i)]=
	   (fCompactTable.getIndex2(i) == kMaxUInt)?-1:fCompactTable.getIndex2(i);
       }
     } else {
       Error("Streamer","Object version not known");
     }
   } else {
      R__b.WriteVersion(HIndexTable::IsA());
      TObject::Streamer(R__b);
      fSizes.Streamer(R__b);
      fCompactTable.Streamer(R__b);
   }
}

/********************** HPairListI ********************************/
ClassImp(HPairListI)

void HPairListI::setCapacity(Int_t n) {
  if (fCapacity!=n) {
    fCapacity=n;
    delete[] fArray[0];
    delete[] fArray[1];
    if (fCapacity>0) {
      fArray[0]=new UInt_t[n];
      fArray[1]=new UInt_t[n];
    }
  }
  clear();
}

void HPairListI::Streamer(TBuffer & b) {

  if (b.IsReading()) {
    Int_t cap;
    b >> cap;
    setCapacity(cap);
    b >> fN;
    if (fN>0) {
      b.ReadFastArray(fArray[0],fN);
      b.ReadFastArray(fArray[1],fN);
    }
  } else {
    b << fCapacity;
    b << fN;
    if (fN>0) {
      b.WriteFastArray(fArray[0],fN);
      b.WriteFastArray(fArray[1],fN);
    }
  }
}

void HPairListI::remove(Int_t idx) {
  //warning "HPairListI::remove not yet implemented"
}
 hindextable.cc:1
 hindextable.cc:2
 hindextable.cc:3
 hindextable.cc:4
 hindextable.cc:5
 hindextable.cc:6
 hindextable.cc:7
 hindextable.cc:8
 hindextable.cc:9
 hindextable.cc:10
 hindextable.cc:11
 hindextable.cc:12
 hindextable.cc:13
 hindextable.cc:14
 hindextable.cc:15
 hindextable.cc:16
 hindextable.cc:17
 hindextable.cc:18
 hindextable.cc:19
 hindextable.cc:20
 hindextable.cc:21
 hindextable.cc:22
 hindextable.cc:23
 hindextable.cc:24
 hindextable.cc:25
 hindextable.cc:26
 hindextable.cc:27
 hindextable.cc:28
 hindextable.cc:29
 hindextable.cc:30
 hindextable.cc:31
 hindextable.cc:32
 hindextable.cc:33
 hindextable.cc:34
 hindextable.cc:35
 hindextable.cc:36
 hindextable.cc:37
 hindextable.cc:38
 hindextable.cc:39
 hindextable.cc:40
 hindextable.cc:41
 hindextable.cc:42
 hindextable.cc:43
 hindextable.cc:44
 hindextable.cc:45
 hindextable.cc:46
 hindextable.cc:47
 hindextable.cc:48
 hindextable.cc:49
 hindextable.cc:50
 hindextable.cc:51
 hindextable.cc:52
 hindextable.cc:53
 hindextable.cc:54
 hindextable.cc:55
 hindextable.cc:56
 hindextable.cc:57
 hindextable.cc:58
 hindextable.cc:59
 hindextable.cc:60
 hindextable.cc:61
 hindextable.cc:62
 hindextable.cc:63
 hindextable.cc:64
 hindextable.cc:65
 hindextable.cc:66
 hindextable.cc:67
 hindextable.cc:68
 hindextable.cc:69
 hindextable.cc:70
 hindextable.cc:71
 hindextable.cc:72
 hindextable.cc:73
 hindextable.cc:74
 hindextable.cc:75
 hindextable.cc:76
 hindextable.cc:77
 hindextable.cc:78
 hindextable.cc:79
 hindextable.cc:80
 hindextable.cc:81
 hindextable.cc:82
 hindextable.cc:83
 hindextable.cc:84
 hindextable.cc:85
 hindextable.cc:86
 hindextable.cc:87
 hindextable.cc:88
 hindextable.cc:89
 hindextable.cc:90
 hindextable.cc:91
 hindextable.cc:92
 hindextable.cc:93
 hindextable.cc:94
 hindextable.cc:95
 hindextable.cc:96
 hindextable.cc:97
 hindextable.cc:98
 hindextable.cc:99
 hindextable.cc:100
 hindextable.cc:101
 hindextable.cc:102
 hindextable.cc:103
 hindextable.cc:104
 hindextable.cc:105
 hindextable.cc:106
 hindextable.cc:107
 hindextable.cc:108
 hindextable.cc:109
 hindextable.cc:110
 hindextable.cc:111
 hindextable.cc:112
 hindextable.cc:113
 hindextable.cc:114
 hindextable.cc:115
 hindextable.cc:116
 hindextable.cc:117
 hindextable.cc:118
 hindextable.cc:119
 hindextable.cc:120
 hindextable.cc:121
 hindextable.cc:122
 hindextable.cc:123
 hindextable.cc:124
 hindextable.cc:125
 hindextable.cc:126
 hindextable.cc:127
 hindextable.cc:128
 hindextable.cc:129
 hindextable.cc:130
 hindextable.cc:131
 hindextable.cc:132
 hindextable.cc:133
 hindextable.cc:134
 hindextable.cc:135
 hindextable.cc:136
 hindextable.cc:137
 hindextable.cc:138
 hindextable.cc:139
 hindextable.cc:140
 hindextable.cc:141
 hindextable.cc:142
 hindextable.cc:143
 hindextable.cc:144
 hindextable.cc:145
 hindextable.cc:146
 hindextable.cc:147
 hindextable.cc:148
 hindextable.cc:149
 hindextable.cc:150
 hindextable.cc:151
 hindextable.cc:152
 hindextable.cc:153
 hindextable.cc:154
 hindextable.cc:155
 hindextable.cc:156
 hindextable.cc:157
 hindextable.cc:158
 hindextable.cc:159
 hindextable.cc:160
 hindextable.cc:161
 hindextable.cc:162
 hindextable.cc:163
 hindextable.cc:164
 hindextable.cc:165
 hindextable.cc:166
 hindextable.cc:167
 hindextable.cc:168
 hindextable.cc:169
 hindextable.cc:170
 hindextable.cc:171
 hindextable.cc:172
 hindextable.cc:173
 hindextable.cc:174
 hindextable.cc:175
 hindextable.cc:176
 hindextable.cc:177
 hindextable.cc:178
 hindextable.cc:179
 hindextable.cc:180
 hindextable.cc:181
 hindextable.cc:182
 hindextable.cc:183
 hindextable.cc:184
 hindextable.cc:185
 hindextable.cc:186
 hindextable.cc:187
 hindextable.cc:188
 hindextable.cc:189
 hindextable.cc:190
 hindextable.cc:191
 hindextable.cc:192
 hindextable.cc:193
 hindextable.cc:194
 hindextable.cc:195
 hindextable.cc:196
 hindextable.cc:197
 hindextable.cc:198
 hindextable.cc:199
 hindextable.cc:200
 hindextable.cc:201
 hindextable.cc:202
 hindextable.cc:203