ROOT logo
//*-- AUTHOR : Ilse Koenig
//*-- Modified : 25/08/2009 by I. Koenig

//_HADES_CLASS_DESCRIPTION 
/////////////////////////////////////////////////////////////
//  HMdcLookupRaw
//
//  Container class for lookup parameters to map the
//  geometrical tree of the Mdc (sectors, modules, layers,
//  cells) to the hardware tree of the Mdc (sectors, modules,
//  motherboards, TDC channels).
//  This information is needed for data mapping from cal1
//  level to raw level.
//  This container has no read functions in the I/O classes,
//  but is initialized from the lookup table HMdcLookupGeom,
//  which contains the same information but accesssible with
//  hardware addresses. This garanties the consistency when
//  both containers are needed.
//  A write function is only provided for an ASCII I/O.
//
/////////////////////////////////////////////////////////////

#include "hmdclookupraw.h"
#include "hmdclookupgeom.h"
#include "hades.h"
#include "hruntimedb.h"
#include "hspectrometer.h"
#include "hmdcdetector.h"
#include "hmdcgeomstruct.h"
#include "hpario.h"
#include "hdetpario.h"
#include "TClass.h"

ClassImp(HMdcLookupCell)
ClassImp(HMdcLookupLayer)
ClassImp(HMdcLookupRMod)
ClassImp(HMdcLookupRSec)
ClassImp(HMdcLookupRaw)

void HMdcLookupCell::Streamer(TBuffer &R__b) {
  // Stream an object of class HMdcLookupCell.
  UInt_t R__s, R__c;
  if (R__b.IsReading()) {
    Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
    TObject::Streamer(R__b);
    R__b >> nMoth;
    R__b >> nChan;
    if (R__v>1) {
      R__b >> readoutSide;
    } else {
      readoutSide='0';
    }
    R__b.CheckByteCount(R__s, R__c, HMdcLookupCell::IsA());
  } else {
    R__c = R__b.WriteVersion(HMdcLookupCell::IsA(), kTRUE);
    TObject::Streamer(R__b);
    R__b << nMoth;
    R__b << nChan;
    R__b << readoutSide;
    R__b.SetByteCount(R__c, kTRUE);
  }
}

HMdcLookupLayer::HMdcLookupLayer(Int_t n) {
  // constructor creates an array of pointers of type
  // HMdcLookupCell (array of all cells in a layer)
  array = new TObjArray(n);
//printf("results :n:%i \n",n);
  for (Int_t i = 0; i < n; i++) {
    array->AddAt(new HMdcLookupCell(),i);
  }
}

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

HMdcLookupRMod::HMdcLookupRMod(Int_t n) {
  // constructor creates an array for each layer
  // the array objects of type HMdcLookupLayer are created in the init function
  array = new TObjArray(n);
}

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

void HMdcLookupRMod::createLayer(Int_t layer, Int_t nCells) {
  // creates the array objects of type HMdcLookupLayer
  if (layer<array->GetSize()&&array->At(layer)==NULL) {
    array->AddAt(new HMdcLookupLayer(nCells),layer);
  }
}

HMdcLookupRSec::HMdcLookupRSec(Int_t n) {
  // constructor creates an array of pointers of type HMdcLookupRMod
  array = new TObjArray(n);
  for(Int_t i=0;i<n;i++) array->AddAt(new HMdcLookupRMod(),i);
}

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

HMdcLookupRaw::HMdcLookupRaw(const Char_t* name,const Char_t* title,
                             const Char_t* context,Int_t n)
              : HParSet(name,title,context) {
  // constructor creates an array of pointers of type HMdcLookupRSec
  // creates the container "MdcLookupGeom"
  strcpy(detName,"Mdc");
  array = new TObjArray(n);
  for(Int_t i=0;i<n;i++) array->AddAt(new HMdcLookupRSec(),i);
  gHades->getRuntimeDb()->getContainer("MdcGeomStruct");
  gHades->getRuntimeDb()->getContainer("MdcLookupGeom");
}

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

Bool_t HMdcLookupRaw::init(HParIo*) {
  // creates the array objects of type HMdcLookupLayer using the data in the parameter container
  // MdcGeomStruct and initializes the parameter container from the container MdcLookupGeom
  HMdcLookupGeom* p=
     (HMdcLookupGeom*)gHades->getRuntimeDb()->findContainer("MdcLookupGeom");
  if (p==NULL) {
    Error("HMdcLookupRaw::init()","MdcLookupRaw not initialized, container MdcLookupGeom not found");
    return kFALSE;
  }
  Int_t v1=p->getInputVersion(1);
  Int_t v2=p->getInputVersion(2);
  if (v1==-1 && v2==-1) return kFALSE;  // not initialized
  if (v1==versions[1] && v2==versions[2]) return kTRUE;  // no change
  // needs reinitialization
  clear();
  HMdcGeomStruct* pGeomStruct=
       (HMdcGeomStruct*)gHades->getRuntimeDb()->findContainer("MdcGeomStruct");
  if (pGeomStruct==NULL) {
    Error("HMdcLookupRaw::init()","HMdcLookupRaw not initialized, container MdcGeomStruct not found");
    return kFALSE;
  }
  Int_t lay, cell;
  for(Int_t s=0;s<p->getSize();s++) {
    HMdcGeomSecStru& secStruct= (*pGeomStruct)[s];
    HMdcLookupGSec& secG=(*p)[s];
    for(Int_t m=0;m<secG.getSize();m++) {
      HMdcGeomModStru& modStruct=secStruct[m];
      HMdcLookupGMod& modG=secG[m];
      HMdcLookupRMod& modR=(*this)[s][m];
      for(Int_t l=0;l<modStruct.getSize();l++) {
        modR.createLayer(l,modStruct[l]);
      }
      for(Int_t l=0;l<modG.getSize();l++) {
        HMdcLookupMoth& moth=modG[l];
        for(Int_t c=0;c<moth.getSize();c++) {
          HMdcLookupChan& chan=moth[c];
          lay=chan.getNLayer();
          cell=chan.getNCell();
          if (lay>=0) {
            modR[lay][cell].setNMoth(l);
            modR[lay][cell].setNChan(c);
            modR[lay][cell].setReadoutSide(chan.getReadoutSide());
          }
        }
      }
    }
  }
  versions[1]=v1;
  versions[2]=v2;
  changed=kTRUE;                          
  return kTRUE;
}

Int_t HMdcLookupRaw::write(HParIo* output) {
  // writes the container to an output if the output is an ascii file
  if (strcmp(output->IsA()->GetName(),"HParAsciiFileIo")==0) {
    HDetParIo* out=output->getDetParIo("HMdcParIo");
    if (out) return out->write(this);
  }
  changed=kFALSE;
  return 0;
}

void HMdcLookupRaw::putAsciiHeader(TString& header) {
  // puts the ascii header to the string used in HMdcParAsciiFileIo
  header=
    "# Mdc lookup table (geometry->hardware)\n"
    "# Format:\n"
    "# sector  module  layer  cell  motherboard index  TDC channel  readout side\n";
}

Bool_t HMdcLookupRaw::writeline(Char_t *buf, Int_t sec, Int_t mod, Int_t mbo,
                                           Int_t tdc) {
  // writes one line to the buffer used by ascii file I/O
    HMdcLookupCell &cell=(*this)[sec][mod][mbo][tdc];
    Int_t nTdc=cell.getNChan();
    if (nTdc==-1) return kFALSE;
    sprintf(buf,"%1i %1i %1i %3i %2i %2i %c\n",
            sec, mod, mbo, tdc, cell.getNMoth(), nTdc, cell.getReadoutSide());
    return kTRUE;
}

void HMdcLookupRaw::clear() {
  // clears the container
   for(Int_t s=0;s<6;s++) {
    HMdcLookupRSec& sec=(*this)[s];
    for(Int_t m=0;m<4;m++) {
      HMdcLookupRMod& mod=sec[m];
      Int_t nl=mod.getSize();
      for(Int_t l=0;l<nl;l++) {
        HMdcLookupLayer& lay=mod[l];
        Int_t nc=lay.getSize();
        for(Int_t c=0;c<nc;c++) {
          HMdcLookupCell& cell=lay[c];
          cell.clear();
        }
      }
    }
  }
  status=kFALSE;
  resetInputVersions();
}
 hmdclookupraw.cc:1
 hmdclookupraw.cc:2
 hmdclookupraw.cc:3
 hmdclookupraw.cc:4
 hmdclookupraw.cc:5
 hmdclookupraw.cc:6
 hmdclookupraw.cc:7
 hmdclookupraw.cc:8
 hmdclookupraw.cc:9
 hmdclookupraw.cc:10
 hmdclookupraw.cc:11
 hmdclookupraw.cc:12
 hmdclookupraw.cc:13
 hmdclookupraw.cc:14
 hmdclookupraw.cc:15
 hmdclookupraw.cc:16
 hmdclookupraw.cc:17
 hmdclookupraw.cc:18
 hmdclookupraw.cc:19
 hmdclookupraw.cc:20
 hmdclookupraw.cc:21
 hmdclookupraw.cc:22
 hmdclookupraw.cc:23
 hmdclookupraw.cc:24
 hmdclookupraw.cc:25
 hmdclookupraw.cc:26
 hmdclookupraw.cc:27
 hmdclookupraw.cc:28
 hmdclookupraw.cc:29
 hmdclookupraw.cc:30
 hmdclookupraw.cc:31
 hmdclookupraw.cc:32
 hmdclookupraw.cc:33
 hmdclookupraw.cc:34
 hmdclookupraw.cc:35
 hmdclookupraw.cc:36
 hmdclookupraw.cc:37
 hmdclookupraw.cc:38
 hmdclookupraw.cc:39
 hmdclookupraw.cc:40
 hmdclookupraw.cc:41
 hmdclookupraw.cc:42
 hmdclookupraw.cc:43
 hmdclookupraw.cc:44
 hmdclookupraw.cc:45
 hmdclookupraw.cc:46
 hmdclookupraw.cc:47
 hmdclookupraw.cc:48
 hmdclookupraw.cc:49
 hmdclookupraw.cc:50
 hmdclookupraw.cc:51
 hmdclookupraw.cc:52
 hmdclookupraw.cc:53
 hmdclookupraw.cc:54
 hmdclookupraw.cc:55
 hmdclookupraw.cc:56
 hmdclookupraw.cc:57
 hmdclookupraw.cc:58
 hmdclookupraw.cc:59
 hmdclookupraw.cc:60
 hmdclookupraw.cc:61
 hmdclookupraw.cc:62
 hmdclookupraw.cc:63
 hmdclookupraw.cc:64
 hmdclookupraw.cc:65
 hmdclookupraw.cc:66
 hmdclookupraw.cc:67
 hmdclookupraw.cc:68
 hmdclookupraw.cc:69
 hmdclookupraw.cc:70
 hmdclookupraw.cc:71
 hmdclookupraw.cc:72
 hmdclookupraw.cc:73
 hmdclookupraw.cc:74
 hmdclookupraw.cc:75
 hmdclookupraw.cc:76
 hmdclookupraw.cc:77
 hmdclookupraw.cc:78
 hmdclookupraw.cc:79
 hmdclookupraw.cc:80
 hmdclookupraw.cc:81
 hmdclookupraw.cc:82
 hmdclookupraw.cc:83
 hmdclookupraw.cc:84
 hmdclookupraw.cc:85
 hmdclookupraw.cc:86
 hmdclookupraw.cc:87
 hmdclookupraw.cc:88
 hmdclookupraw.cc:89
 hmdclookupraw.cc:90
 hmdclookupraw.cc:91
 hmdclookupraw.cc:92
 hmdclookupraw.cc:93
 hmdclookupraw.cc:94
 hmdclookupraw.cc:95
 hmdclookupraw.cc:96
 hmdclookupraw.cc:97
 hmdclookupraw.cc:98
 hmdclookupraw.cc:99
 hmdclookupraw.cc:100
 hmdclookupraw.cc:101
 hmdclookupraw.cc:102
 hmdclookupraw.cc:103
 hmdclookupraw.cc:104
 hmdclookupraw.cc:105
 hmdclookupraw.cc:106
 hmdclookupraw.cc:107
 hmdclookupraw.cc:108
 hmdclookupraw.cc:109
 hmdclookupraw.cc:110
 hmdclookupraw.cc:111
 hmdclookupraw.cc:112
 hmdclookupraw.cc:113
 hmdclookupraw.cc:114
 hmdclookupraw.cc:115
 hmdclookupraw.cc:116
 hmdclookupraw.cc:117
 hmdclookupraw.cc:118
 hmdclookupraw.cc:119
 hmdclookupraw.cc:120
 hmdclookupraw.cc:121
 hmdclookupraw.cc:122
 hmdclookupraw.cc:123
 hmdclookupraw.cc:124
 hmdclookupraw.cc:125
 hmdclookupraw.cc:126
 hmdclookupraw.cc:127
 hmdclookupraw.cc:128
 hmdclookupraw.cc:129
 hmdclookupraw.cc:130
 hmdclookupraw.cc:131
 hmdclookupraw.cc:132
 hmdclookupraw.cc:133
 hmdclookupraw.cc:134
 hmdclookupraw.cc:135
 hmdclookupraw.cc:136
 hmdclookupraw.cc:137
 hmdclookupraw.cc:138
 hmdclookupraw.cc:139
 hmdclookupraw.cc:140
 hmdclookupraw.cc:141
 hmdclookupraw.cc:142
 hmdclookupraw.cc:143
 hmdclookupraw.cc:144
 hmdclookupraw.cc:145
 hmdclookupraw.cc:146
 hmdclookupraw.cc:147
 hmdclookupraw.cc:148
 hmdclookupraw.cc:149
 hmdclookupraw.cc:150
 hmdclookupraw.cc:151
 hmdclookupraw.cc:152
 hmdclookupraw.cc:153
 hmdclookupraw.cc:154
 hmdclookupraw.cc:155
 hmdclookupraw.cc:156
 hmdclookupraw.cc:157
 hmdclookupraw.cc:158
 hmdclookupraw.cc:159
 hmdclookupraw.cc:160
 hmdclookupraw.cc:161
 hmdclookupraw.cc:162
 hmdclookupraw.cc:163
 hmdclookupraw.cc:164
 hmdclookupraw.cc:165
 hmdclookupraw.cc:166
 hmdclookupraw.cc:167
 hmdclookupraw.cc:168
 hmdclookupraw.cc:169
 hmdclookupraw.cc:170
 hmdclookupraw.cc:171
 hmdclookupraw.cc:172
 hmdclookupraw.cc:173
 hmdclookupraw.cc:174
 hmdclookupraw.cc:175
 hmdclookupraw.cc:176
 hmdclookupraw.cc:177
 hmdclookupraw.cc:178
 hmdclookupraw.cc:179
 hmdclookupraw.cc:180
 hmdclookupraw.cc:181
 hmdclookupraw.cc:182
 hmdclookupraw.cc:183
 hmdclookupraw.cc:184
 hmdclookupraw.cc:185
 hmdclookupraw.cc:186
 hmdclookupraw.cc:187
 hmdclookupraw.cc:188
 hmdclookupraw.cc:189
 hmdclookupraw.cc:190
 hmdclookupraw.cc:191
 hmdclookupraw.cc:192
 hmdclookupraw.cc:193
 hmdclookupraw.cc:194
 hmdclookupraw.cc:195
 hmdclookupraw.cc:196
 hmdclookupraw.cc:197
 hmdclookupraw.cc:198
 hmdclookupraw.cc:199
 hmdclookupraw.cc:200
 hmdclookupraw.cc:201
 hmdclookupraw.cc:202
 hmdclookupraw.cc:203
 hmdclookupraw.cc:204
 hmdclookupraw.cc:205
 hmdclookupraw.cc:206
 hmdclookupraw.cc:207
 hmdclookupraw.cc:208
 hmdclookupraw.cc:209
 hmdclookupraw.cc:210
 hmdclookupraw.cc:211
 hmdclookupraw.cc:212
 hmdclookupraw.cc:213
 hmdclookupraw.cc:214
 hmdclookupraw.cc:215
 hmdclookupraw.cc:216
 hmdclookupraw.cc:217
 hmdclookupraw.cc:218
 hmdclookupraw.cc:219
 hmdclookupraw.cc:220
 hmdclookupraw.cc:221
 hmdclookupraw.cc:222
 hmdclookupraw.cc:223
 hmdclookupraw.cc:224
 hmdclookupraw.cc:225
 hmdclookupraw.cc:226
 hmdclookupraw.cc:227
 hmdclookupraw.cc:228
 hmdclookupraw.cc:229
 hmdclookupraw.cc:230