ROOT logo
//*-- AUTHOR Ilse Koenig
//*-- created : 08/12/2000 by Ilse Koenig
//_HADES_CLASS_DESCRIPTION 
////////////////////////////////////////////////////////////////////
// HTofLookup
//
// Container class for mapping Crate/TdcAdc/Channel to Module/Paddle
//   needed by the TOF unpacker
//
////////////////////////////////////////////////////////////////////
using namespace std;
#include "htoflookup.h"
#include "hpario.h"
#include "hdetpario.h"
#include <iostream> 
#include <iomanip>

ClassImp(HTofLookupChan)
ClassImp(HTofLookupSlot)
ClassImp(HTofLookupCrate)
ClassImp(HTofLookup)

HTofLookupSlot::HTofLookupSlot(Int_t nChan) {
  // constructor creates an array of nChan pointers of type HTofLookupChan
  array = new TObjArray(nChan);
  for(Int_t i=0;i<nChan;i++) array->AddAt(new HTofLookupChan(),i);
  nChannels=32;
  maxChannel=nChan-1;
  clear();
}

HTofLookupSlot::~HTofLookupSlot() {
  // destructor
  array->Delete();
  delete array;
}

void HTofLookupSlot::clear() {
  // sets the module type to 'U' (unknown) and clears the array
  modType='U';
  for(Int_t i=0;i<=maxChannel;i++) (*this)[i].clear();
}

void HTofLookupSlot::fill(Char_t dcType, Int_t channel, 
        Int_t sector, Int_t module, Int_t cell, Char_t side) {
  // Sets the module type and fills the HLookupChan objects with index channel
  // The array is automatically expanded to 32 channels. 
  modType=dcType;
  if (channel>maxChannel) {
    array->Expand(nChannels);
    for(Int_t i=maxChannel+1;i<nChannels;i++) array->AddAt(new HTofLookupChan(),i);
    maxChannel=nChannels-1;
  }
  (*this)[channel].fill(sector,module,cell,side);
}

HTofLookupCrate::HTofLookupCrate(Int_t numSlots) {
  // constructor creates an array of pointers of type HTofLookupSlot
  nSlots=21;
  maxSlot=numSlots-1;
  array = new TObjArray(numSlots);
  for(Int_t i=0;i<numSlots;i++) array->AddAt(new HTofLookupSlot(),i);
}

HTofLookupCrate::~HTofLookupCrate() {
  // destructor
  array->Delete();
  delete array;
}

void HTofLookupCrate::fill(Int_t slot, Char_t modType,
        Int_t channel, Int_t sector, Int_t module, Int_t cell, Char_t side) {
  // Expands the array, if necessary, creates the objects of type HTofLookupSlot,
  // and then calls the fill function of the objects with index slot. 
  if (slot>maxSlot) {
    array->Expand(slot+1);
    for(Int_t i=maxSlot+1;i<=slot;i++) array->AddAt(new HTofLookupSlot(),i);
    maxSlot=slot;
  }
  (*this)[slot].fill(modType,channel,sector,module,cell,side);
}

HTofLookup::HTofLookup(const Char_t* name,const Char_t* title,
                       const Char_t* context,
                       Int_t nCrates, Int_t nSlots)
           : HParSet(name,title,context) {
  // The constructor creates an array of pointers of type HTofLookupCrate of
  // size nSlots
  // The container name is set to "TofLookup".
  strcpy(detName,"Tof");
  maxCrate=nCrates-1;
  array = new TObjArray(nCrates);
  for (Int_t i=0;i<nCrates;i++) array->AddAt(new HTofLookupCrate(nSlots),i);
}

HTofLookup::~HTofLookup() {
  // destructor
  array->Delete();
  delete array;
}

Bool_t HTofLookup::init(HParIo* inp,Int_t* set) {
  // intitializes the container from an input
  HDetParIo* input=inp->getDetParIo("HTofParIo");
  if (input) return (input->init(this,set));
  return kFALSE;
}

Int_t HTofLookup::write(HParIo* output) {
  // writes the container to an output
  HDetParIo* out=output->getDetParIo("HTofParIo");
  if (out) return out->write(this);
  return -1;
}

void HTofLookup::clear() {
  // clears the container
  for(Int_t c=0;c<=maxCrate;c++) {
    for(Int_t s=0;s<(*this)[c].getSize();s++) (*this)[c][s].clear();
  }
  status=kFALSE;
  resetInputVersions();
}

void HTofLookup::printParam() {
  // prints the lookup table
  printf("Lookup table for the TOF unpacker\n");
  printf("crate  slot  type  channel  sector  module  cell  side\n");
  for(Int_t c=0;c<getSize();c++) {
    for(Int_t s=0;s<(*this)[c].getSize();s++) {
      HTofLookupSlot& slot=(*this)[c][s];
      for(Int_t r=0;r<slot.getSize();r++) {
        HTofLookupChan& chan=slot[r];
        if (chan.getSector()>=0) printf("%4i%4i   %c%4i%4i%4i%4i   %c\n",
               c,s,slot.getType(),r,chan.getSector(),chan.getModule(),
               chan.getCell(),chan.getSide());
      }
    }
  }
}

void HTofLookup::fill(Int_t crate, Int_t slot, Char_t modType,
        Int_t channel, Int_t sector, Int_t module, Int_t cell, Char_t side) {
  // Expands the array, if necessary, creates the objects of type HTofLookupCrate,
  // and then calls the fill function of the objects with index slot. 
  if (crate>maxCrate) {
    array->Expand(crate+1);
    for(Int_t i=maxCrate+1;i<=crate;i++) array->AddAt(new HTofLookupCrate(),i);
    maxCrate=crate;
  }
  (*this)[crate].fill(slot,modType,channel,sector,module,cell,side);
}

void HTofLookup::readline(const Char_t *buf, Int_t *set) {
  // decodes one line read from ascii file I/O
  Int_t crate, slot, chan, sec, mod, cell;
  Char_t dcType[2], side[2];
  sscanf(buf,"%i%i%s%i%i%i%i%s",&crate,&slot,dcType,&chan,&sec,&mod,&cell,side);
  Int_t pos=sec*22+mod;
  if (set[pos]) {
    fill(crate,slot,dcType[0],chan,sec,mod,cell,side[0]);
    set[pos]=999;
  }
}

void HTofLookup::putAsciiHeader(TString& header) {
  // puts the ascii header to the string used in HTofParAsciiFileIo
  header=
    "# Lookup table for the TOF unpacker\n"
    "# Format:\n"
    "# crate  slot  type  channel  sector  module  rod  side\n";
}

Bool_t HTofLookup::writeline(Char_t *buf, Int_t crate, Int_t slot, Int_t chan) {
  // writes one line to the buffer used by ascii file I/O
  HTofLookupSlot& s=(*this)[crate][slot];
  HTofLookupChan& c=s[chan];
  if (c.getSector()>=0) {
    sprintf(buf,"%4i%4i   %c%4i%4i%4i%4i   %c\n",
          crate,slot,s.getType(),chan,c.getSector(),c.getModule(),c.getCell(),
          c.getSide());
    return kTRUE;
  }
  return kFALSE;
}
 htoflookup.cc:1
 htoflookup.cc:2
 htoflookup.cc:3
 htoflookup.cc:4
 htoflookup.cc:5
 htoflookup.cc:6
 htoflookup.cc:7
 htoflookup.cc:8
 htoflookup.cc:9
 htoflookup.cc:10
 htoflookup.cc:11
 htoflookup.cc:12
 htoflookup.cc:13
 htoflookup.cc:14
 htoflookup.cc:15
 htoflookup.cc:16
 htoflookup.cc:17
 htoflookup.cc:18
 htoflookup.cc:19
 htoflookup.cc:20
 htoflookup.cc:21
 htoflookup.cc:22
 htoflookup.cc:23
 htoflookup.cc:24
 htoflookup.cc:25
 htoflookup.cc:26
 htoflookup.cc:27
 htoflookup.cc:28
 htoflookup.cc:29
 htoflookup.cc:30
 htoflookup.cc:31
 htoflookup.cc:32
 htoflookup.cc:33
 htoflookup.cc:34
 htoflookup.cc:35
 htoflookup.cc:36
 htoflookup.cc:37
 htoflookup.cc:38
 htoflookup.cc:39
 htoflookup.cc:40
 htoflookup.cc:41
 htoflookup.cc:42
 htoflookup.cc:43
 htoflookup.cc:44
 htoflookup.cc:45
 htoflookup.cc:46
 htoflookup.cc:47
 htoflookup.cc:48
 htoflookup.cc:49
 htoflookup.cc:50
 htoflookup.cc:51
 htoflookup.cc:52
 htoflookup.cc:53
 htoflookup.cc:54
 htoflookup.cc:55
 htoflookup.cc:56
 htoflookup.cc:57
 htoflookup.cc:58
 htoflookup.cc:59
 htoflookup.cc:60
 htoflookup.cc:61
 htoflookup.cc:62
 htoflookup.cc:63
 htoflookup.cc:64
 htoflookup.cc:65
 htoflookup.cc:66
 htoflookup.cc:67
 htoflookup.cc:68
 htoflookup.cc:69
 htoflookup.cc:70
 htoflookup.cc:71
 htoflookup.cc:72
 htoflookup.cc:73
 htoflookup.cc:74
 htoflookup.cc:75
 htoflookup.cc:76
 htoflookup.cc:77
 htoflookup.cc:78
 htoflookup.cc:79
 htoflookup.cc:80
 htoflookup.cc:81
 htoflookup.cc:82
 htoflookup.cc:83
 htoflookup.cc:84
 htoflookup.cc:85
 htoflookup.cc:86
 htoflookup.cc:87
 htoflookup.cc:88
 htoflookup.cc:89
 htoflookup.cc:90
 htoflookup.cc:91
 htoflookup.cc:92
 htoflookup.cc:93
 htoflookup.cc:94
 htoflookup.cc:95
 htoflookup.cc:96
 htoflookup.cc:97
 htoflookup.cc:98
 htoflookup.cc:99
 htoflookup.cc:100
 htoflookup.cc:101
 htoflookup.cc:102
 htoflookup.cc:103
 htoflookup.cc:104
 htoflookup.cc:105
 htoflookup.cc:106
 htoflookup.cc:107
 htoflookup.cc:108
 htoflookup.cc:109
 htoflookup.cc:110
 htoflookup.cc:111
 htoflookup.cc:112
 htoflookup.cc:113
 htoflookup.cc:114
 htoflookup.cc:115
 htoflookup.cc:116
 htoflookup.cc:117
 htoflookup.cc:118
 htoflookup.cc:119
 htoflookup.cc:120
 htoflookup.cc:121
 htoflookup.cc:122
 htoflookup.cc:123
 htoflookup.cc:124
 htoflookup.cc:125
 htoflookup.cc:126
 htoflookup.cc:127
 htoflookup.cc:128
 htoflookup.cc:129
 htoflookup.cc:130
 htoflookup.cc:131
 htoflookup.cc:132
 htoflookup.cc:133
 htoflookup.cc:134
 htoflookup.cc:135
 htoflookup.cc:136
 htoflookup.cc:137
 htoflookup.cc:138
 htoflookup.cc:139
 htoflookup.cc:140
 htoflookup.cc:141
 htoflookup.cc:142
 htoflookup.cc:143
 htoflookup.cc:144
 htoflookup.cc:145
 htoflookup.cc:146
 htoflookup.cc:147
 htoflookup.cc:148
 htoflookup.cc:149
 htoflookup.cc:150
 htoflookup.cc:151
 htoflookup.cc:152
 htoflookup.cc:153
 htoflookup.cc:154
 htoflookup.cc:155
 htoflookup.cc:156
 htoflookup.cc:157
 htoflookup.cc:158
 htoflookup.cc:159
 htoflookup.cc:160
 htoflookup.cc:161
 htoflookup.cc:162
 htoflookup.cc:163
 htoflookup.cc:164
 htoflookup.cc:165
 htoflookup.cc:166
 htoflookup.cc:167
 htoflookup.cc:168
 htoflookup.cc:169
 htoflookup.cc:170
 htoflookup.cc:171
 htoflookup.cc:172
 htoflookup.cc:173
 htoflookup.cc:174
 htoflookup.cc:175
 htoflookup.cc:176
 htoflookup.cc:177
 htoflookup.cc:178
 htoflookup.cc:179
 htoflookup.cc:180
 htoflookup.cc:181
 htoflookup.cc:182
 htoflookup.cc:183
 htoflookup.cc:184
 htoflookup.cc:185