ROOT logo
using namespace std;
#include "htofdetector.h"
#include "hcategory.h"
#include "hmatrixcategory.h"
#include "tofdef.h"
#include "htofcalibrater.h"
#include "htofhitf.h"
#include "htaskset.h"
#include "hades.h"
#include "hpario.h"
#include "hparrootfileio.h"
#include "hdetpario.h"
#include "htofparrootfileio.h"
#include "hparasciifileio.h"
#include "htofparasciifileio.h"
#include <iostream> 
#include <iomanip>
#include "TClass.h"

HTofDetector::HTofDetector(void) : HDetector("Tof","The TOF detector") {
  maxModules=22;
  maxComponents=8;
  modules=new TArrayI(getMaxSectors()*maxModules);
}


HTofDetector::~HTofDetector(void) {
}


HTask *HTofDetector::buildTask(const Text_t *name,const Option_t *opt) {
  HTask *r=NULL;
  /*  if (strcmp(name,"digitize")==0) {
    r=new TofDigitizer("tof.digitizer","tof.digitizer");
  } else */
  if (strcmp(name,"calibrate")==0) {
    r=new HTofCalibrater("tof.calibrater","calibrater");
    /*if (strcmp(opt,"digi")==0) {
      HTaskSet *ts=new HTaskSet("tof.calibrater","calibrater");
      ts->connect(new HTofDigitizer("tof.digitizer","digitizer"));
      ts->connect(r,"tof.digitizer");
      ts->connect(NULL,r);
      r=ts;
    }*/
  } else if (strcmp(name,"hitF")==0) {
    r=new HTofHitF("tof.hitF","Hit finder");
    if (strcmp(opt,"raw")==0) {
      HTaskSet *ts=new HTaskSet("tof.hitF","Hit finder");
      ts->connect(new HTofCalibrater("tof.calibrater","tof.calibrater"));
      if (!ts->connect(r,"tof.calibrater")) 
	Error("buildTask","connection failed");
      ts->connect(NULL,r);
      r=ts;
    } /*else if (strcmp(opt,"digi")==0) {
      HTaskSet *ts=new HTaskSet("tof.hitF","Hit finder");
      ts->connect(new HTofDigitizer("tof.digitizer","digitizer"));
      ts->connect(new HTofCalibrater("tof.calibrater","calibrater"),
		  "tof.digitizer");
      ts->connect(r,"tof.calibrater");
      ts->connect(NULL,r);
      r=ts;
    }*/
  }
  return r;
} 

HCategory *HTofDetector::buildMatrixCategory(const Text_t *classname,Float_t fillRate) {
  Int_t maxSector=0, mod=0;
  Int_t sec=0;
  Int_t i, sizes[3];
  HMatrixCategory *category=NULL;

  for (i=0;i<modules->fN;i++) {
    mod=modules->At(i)-1;
    if (mod > -1) {
      sec=i/maxModules;
      maxSector=((sec)>maxSector)?(sec):maxSector;
    }
  }
  maxSector++;
  sizes[0]=maxSector;
  sizes[1]=maxModules;
  sizes[2]=maxComponents;
  category=new HMatrixCategory(classname,3,sizes,fillRate);
  return category;
}

HCategory *HTofDetector::buildCategory(Cat_t cat) {
  switch (cat) {
  case catTofRaw : return buildMatrixCategory("HTofRaw",0.5);
  case catTofCal : return buildMatrixCategory("HTofCal",0.5);
  case catTofHit : return buildMatrixCategory("HTofHit",0.5);
  case catTofCluster : return buildMatrixCategory("HTofCluster",0.5);
  case catTofGeantRaw : return buildMatrixCategory("HGeantTof",0.1);
  default : return NULL;
  }
}

void HTofDetector::activateParIo(HParIo* io) {
  // activates the input/output class for the parameters
  // needed by the Tof
  if (strcmp(io->IsA()->GetName(),"HParOraIo")==0) {
    io->setDetParIo("HTofParIo");
    return;
  }
  if (strcmp(io->IsA()->GetName(),"HParRootFileIo")==0) {
    HTofParRootFileIo* p=new HTofParRootFileIo(((HParRootFileIo*)io)->getParRootFile());
    io->setDetParIo(p);
  }
  if (strcmp(io->IsA()->GetName(),"HParAsciiFileIo")==0) {
    HTofParAsciiFileIo* p=new HTofParAsciiFileIo(((HParAsciiFileIo*)io)->getFile());
    io->setDetParIo(p);
  }
}

Bool_t HTofDetector::write(HParIo* output) {
  // writes the Tof setup to output
  HDetParIo* out=output->getDetParIo("HTofParIo");
  if (out) return out->write(this);
  return kFALSE;
}

ClassImp(HTofDetector) // TOF detector class
 htofdetector.cc:1
 htofdetector.cc:2
 htofdetector.cc:3
 htofdetector.cc:4
 htofdetector.cc:5
 htofdetector.cc:6
 htofdetector.cc:7
 htofdetector.cc:8
 htofdetector.cc:9
 htofdetector.cc:10
 htofdetector.cc:11
 htofdetector.cc:12
 htofdetector.cc:13
 htofdetector.cc:14
 htofdetector.cc:15
 htofdetector.cc:16
 htofdetector.cc:17
 htofdetector.cc:18
 htofdetector.cc:19
 htofdetector.cc:20
 htofdetector.cc:21
 htofdetector.cc:22
 htofdetector.cc:23
 htofdetector.cc:24
 htofdetector.cc:25
 htofdetector.cc:26
 htofdetector.cc:27
 htofdetector.cc:28
 htofdetector.cc:29
 htofdetector.cc:30
 htofdetector.cc:31
 htofdetector.cc:32
 htofdetector.cc:33
 htofdetector.cc:34
 htofdetector.cc:35
 htofdetector.cc:36
 htofdetector.cc:37
 htofdetector.cc:38
 htofdetector.cc:39
 htofdetector.cc:40
 htofdetector.cc:41
 htofdetector.cc:42
 htofdetector.cc:43
 htofdetector.cc:44
 htofdetector.cc:45
 htofdetector.cc:46
 htofdetector.cc:47
 htofdetector.cc:48
 htofdetector.cc:49
 htofdetector.cc:50
 htofdetector.cc:51
 htofdetector.cc:52
 htofdetector.cc:53
 htofdetector.cc:54
 htofdetector.cc:55
 htofdetector.cc:56
 htofdetector.cc:57
 htofdetector.cc:58
 htofdetector.cc:59
 htofdetector.cc:60
 htofdetector.cc:61
 htofdetector.cc:62
 htofdetector.cc:63
 htofdetector.cc:64
 htofdetector.cc:65
 htofdetector.cc:66
 htofdetector.cc:67
 htofdetector.cc:68
 htofdetector.cc:69
 htofdetector.cc:70
 htofdetector.cc:71
 htofdetector.cc:72
 htofdetector.cc:73
 htofdetector.cc:74
 htofdetector.cc:75
 htofdetector.cc:76
 htofdetector.cc:77
 htofdetector.cc:78
 htofdetector.cc:79
 htofdetector.cc:80
 htofdetector.cc:81
 htofdetector.cc:82
 htofdetector.cc:83
 htofdetector.cc:84
 htofdetector.cc:85
 htofdetector.cc:86
 htofdetector.cc:87
 htofdetector.cc:88
 htofdetector.cc:89
 htofdetector.cc:90
 htofdetector.cc:91
 htofdetector.cc:92
 htofdetector.cc:93
 htofdetector.cc:94
 htofdetector.cc:95
 htofdetector.cc:96
 htofdetector.cc:97
 htofdetector.cc:98
 htofdetector.cc:99
 htofdetector.cc:100
 htofdetector.cc:101
 htofdetector.cc:102
 htofdetector.cc:103
 htofdetector.cc:104
 htofdetector.cc:105
 htofdetector.cc:106
 htofdetector.cc:107
 htofdetector.cc:108
 htofdetector.cc:109
 htofdetector.cc:110
 htofdetector.cc:111
 htofdetector.cc:112
 htofdetector.cc:113
 htofdetector.cc:114
 htofdetector.cc:115
 htofdetector.cc:116
 htofdetector.cc:117
 htofdetector.cc:118
 htofdetector.cc:119
 htofdetector.cc:120
 htofdetector.cc:121
 htofdetector.cc:122
 htofdetector.cc:123