ROOT logo
//*-- AUTHOR : Rainer Schicker
//*-- modified : 20/07/2003 by T.Wojcik
//*-- modified : 18/12/2001 by I.Koenig
//*-- modified : 02/03/2000 by I.Koenig

//_HADES_CLASS_DESCRIPTION
//////////////////////////////////////////////////////////////////
//
//  HStart2Detector
//
//  Class for detector "Start2" using the TRB for readout
//  stores the setup in a linear array of maximum number
//  of modules defined in the hstartdef.h definition file.
//  At the moment:
//    - 1st module: start detector
//    - 2nd module: veto detector ????
//    - 3rd module: halo detector ????
//////////////////////////////////////////////////////////////////

#include "TClass.h"

#include "hades.h"
#include "hcategory.h"
#include "hdetpario.h"
#include "hevent.h"
#include "hlinearcategory.h"
#include "hmatrixcategory.h"
#include "hparasciifileio.h"
#include "hpario.h"
#include "hparrootfileio.h"
#include "hstart2detector.h"
#include "hstartparasciifileio.h"
#include "hstartparrootfileio.h"

using namespace std;

ClassImp(HStart2Detector)

HStart2Detector::HStart2Detector()
{
   // constructor
   fName         = "Start";
   maxSectors    = START2_MAX_SECTORS;
   maxModules    = START2_MAX_MODULES;
   maxComponents = START2_MAX_COMPONENTS;
   modules       = new TArrayI(maxModules);

   for (Int_t i = 0; i < maxModules; i++) {
      modules->AddAt(0, i);
   }
}


HStart2Detector::~HStart2Detector()
{
   // destructor
   if (NULL != modules) {
      delete modules;
      modules = NULL;
   }
}


Bool_t HStart2Detector::init(void)
{
   // nothing to be done
   return kTRUE;
}


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


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


HCategory* HStart2Detector::buildMatrixCategory(const Text_t* className, Float_t fillRate)
{
   Int_t maxMod = getMaxModInSetup();
   if (maxMod == 0) return 0;
   Int_t* sizes = new Int_t[2]; // 2 levels
   sizes[0] = maxMod;
   sizes[1] = maxComponents;
   HMatrixCategory* category = new HMatrixCategory(className, 2, sizes, fillRate);
   delete [] sizes;
   return category;
}


HCategory* HStart2Detector::buildLinearCategory(const Text_t* className)
{
   Int_t size = getMaxModInSetup() * maxComponents;
   if (size) {
      HLinearCategory* category = new HLinearCategory(className, size);
      return category;
   }
   return 0;
}


HCategory* HStart2Detector::buildCategory(Cat_t cat)
{
   // gets the category if existing
   // builts and adds if not existing
   // returns the pointer to the category or zero
   HCategory *pcat;
   pcat = gHades->getCurrentEvent()->getCategory(cat);
   if (pcat) return(pcat);  // already existing
   switch (cat) {
      case catStart2Raw:
         pcat = buildMatrixCategory("HStart2Raw", 0.5);
         break;
      case catStart2Cal:
         pcat = buildMatrixCategory("HStart2Cal", 0.5);
         break;
      case catStart2Hit:
         pcat = buildLinearCategory("HStart2Hit");
         break;
      default:
         return NULL;
   }
   if (pcat) gHades->getCurrentEvent()->addCategory(cat, pcat, "Start");
   return(pcat);
}


Int_t HStart2Detector::getMaxModInSetup(void)
{
   Int_t maxMod = -1;
   for (Int_t i = 0; i < maxModules; i++) {
      if (modules->At(i)) maxMod = (i > maxMod) ? i : maxMod;
   }
   maxMod++;
   return maxMod;
}





 hstart2detector.cc:1
 hstart2detector.cc:2
 hstart2detector.cc:3
 hstart2detector.cc:4
 hstart2detector.cc:5
 hstart2detector.cc:6
 hstart2detector.cc:7
 hstart2detector.cc:8
 hstart2detector.cc:9
 hstart2detector.cc:10
 hstart2detector.cc:11
 hstart2detector.cc:12
 hstart2detector.cc:13
 hstart2detector.cc:14
 hstart2detector.cc:15
 hstart2detector.cc:16
 hstart2detector.cc:17
 hstart2detector.cc:18
 hstart2detector.cc:19
 hstart2detector.cc:20
 hstart2detector.cc:21
 hstart2detector.cc:22
 hstart2detector.cc:23
 hstart2detector.cc:24
 hstart2detector.cc:25
 hstart2detector.cc:26
 hstart2detector.cc:27
 hstart2detector.cc:28
 hstart2detector.cc:29
 hstart2detector.cc:30
 hstart2detector.cc:31
 hstart2detector.cc:32
 hstart2detector.cc:33
 hstart2detector.cc:34
 hstart2detector.cc:35
 hstart2detector.cc:36
 hstart2detector.cc:37
 hstart2detector.cc:38
 hstart2detector.cc:39
 hstart2detector.cc:40
 hstart2detector.cc:41
 hstart2detector.cc:42
 hstart2detector.cc:43
 hstart2detector.cc:44
 hstart2detector.cc:45
 hstart2detector.cc:46
 hstart2detector.cc:47
 hstart2detector.cc:48
 hstart2detector.cc:49
 hstart2detector.cc:50
 hstart2detector.cc:51
 hstart2detector.cc:52
 hstart2detector.cc:53
 hstart2detector.cc:54
 hstart2detector.cc:55
 hstart2detector.cc:56
 hstart2detector.cc:57
 hstart2detector.cc:58
 hstart2detector.cc:59
 hstart2detector.cc:60
 hstart2detector.cc:61
 hstart2detector.cc:62
 hstart2detector.cc:63
 hstart2detector.cc:64
 hstart2detector.cc:65
 hstart2detector.cc:66
 hstart2detector.cc:67
 hstart2detector.cc:68
 hstart2detector.cc:69
 hstart2detector.cc:70
 hstart2detector.cc:71
 hstart2detector.cc:72
 hstart2detector.cc:73
 hstart2detector.cc:74
 hstart2detector.cc:75
 hstart2detector.cc:76
 hstart2detector.cc:77
 hstart2detector.cc:78
 hstart2detector.cc:79
 hstart2detector.cc:80
 hstart2detector.cc:81
 hstart2detector.cc:82
 hstart2detector.cc:83
 hstart2detector.cc:84
 hstart2detector.cc:85
 hstart2detector.cc:86
 hstart2detector.cc:87
 hstart2detector.cc:88
 hstart2detector.cc:89
 hstart2detector.cc:90
 hstart2detector.cc:91
 hstart2detector.cc:92
 hstart2detector.cc:93
 hstart2detector.cc:94
 hstart2detector.cc:95
 hstart2detector.cc:96
 hstart2detector.cc:97
 hstart2detector.cc:98
 hstart2detector.cc:99
 hstart2detector.cc:100
 hstart2detector.cc:101
 hstart2detector.cc:102
 hstart2detector.cc:103
 hstart2detector.cc:104
 hstart2detector.cc:105
 hstart2detector.cc:106
 hstart2detector.cc:107
 hstart2detector.cc:108
 hstart2detector.cc:109
 hstart2detector.cc:110
 hstart2detector.cc:111
 hstart2detector.cc:112
 hstart2detector.cc:113
 hstart2detector.cc:114
 hstart2detector.cc:115
 hstart2detector.cc:116
 hstart2detector.cc:117
 hstart2detector.cc:118
 hstart2detector.cc:119
 hstart2detector.cc:120
 hstart2detector.cc:121
 hstart2detector.cc:122
 hstart2detector.cc:123
 hstart2detector.cc:124
 hstart2detector.cc:125
 hstart2detector.cc:126
 hstart2detector.cc:127
 hstart2detector.cc:128
 hstart2detector.cc:129
 hstart2detector.cc:130
 hstart2detector.cc:131
 hstart2detector.cc:132
 hstart2detector.cc:133
 hstart2detector.cc:134
 hstart2detector.cc:135
 hstart2detector.cc:136
 hstart2detector.cc:137
 hstart2detector.cc:138
 hstart2detector.cc:139
 hstart2detector.cc:140
 hstart2detector.cc:141
 hstart2detector.cc:142
 hstart2detector.cc:143
 hstart2detector.cc:144
 hstart2detector.cc:145
 hstart2detector.cc:146
 hstart2detector.cc:147
 hstart2detector.cc:148
 hstart2detector.cc:149
 hstart2detector.cc:150
 hstart2detector.cc:151
 hstart2detector.cc:152
 hstart2detector.cc:153
 hstart2detector.cc:154
 hstart2detector.cc:155
 hstart2detector.cc:156
 hstart2detector.cc:157
 hstart2detector.cc:158
 hstart2detector.cc:159
 hstart2detector.cc:160
 hstart2detector.cc:161
 hstart2detector.cc:162