ROOT logo
//*-- AUTHOR : Ilse Koenig
//*-- Modified : 26/04/02 by Ilse Koenig
//*-- Modified : 10/12/01 by Ilse Koenig
//*-- Modified : 30/06/99
//*-- Modified : 10/05/01 by Dan Magestro
//*-- Modified : 13/01/05 by Ilse Koenig

//_HADES_CLASS_DESCRIPTION 
///////////////////////////////////////////////////////////////////////////////
//
// HSpecGeomPar
//
// Parameter container for the geometry of the cave, the sector(s) and the 
// target(s)
//
///////////////////////////////////////////////////////////////////////////////
using namespace std;
#include "hspecgeompar.h"
#include "hgeomshapes.h"
#include "hgeomvolume.h"
#include "hades.h"
#include "hruntimedb.h"
#include "hspectrometer.h"
#include "hpario.h"
#include "hdetpario.h"
#include <iostream> 
#include <iomanip>

ClassImp(HSpecGeomPar)

HSpecGeomPar::HSpecGeomPar(const Char_t* name,const Char_t* title,
              const Char_t* context,const Int_t maxSec)
            : HParSet(name,title,context) {
  // constructor takes a pointer to the shape classes
  // creates an empty array 'sectors' of size maxSec (default 0)
  strcpy(detName,"Spectrom");  // max 10 char!
  isFirstInit=kTRUE;
  if (maxSec>0) sectors=new TObjArray(maxSec);
  else sectors=0;
  cave=0;
  targets=0; 
  if (gHades) shapes=gHades->getSetup()->getShapes();
  else shapes=0;
}


HSpecGeomPar::~HSpecGeomPar() {
  // destructor deletes the arrays
  if (cave) delete cave;
  if (sectors) {
    sectors->Delete();
    delete sectors;
  }
  if (targets) {
    targets->Delete();
    delete targets;
  }
}


Int_t HSpecGeomPar::getNumSectors() {
  // returns the maximum index of the sectors
  if (sectors) return  (sectors->GetSize());
  return 0;
}


Int_t HSpecGeomPar::getNumTargets() {
  // returns the number the targets
  if (targets) return  (targets->GetEntries());
  return 0;
}


HGeomVolume* HSpecGeomPar::getSector(const Int_t n) {
  // returns a pointer to the sector volume with index n
  if (sectors) return (HGeomVolume*)sectors->At(n);
  return 0;
}


HGeomVolume* HSpecGeomPar::getTarget(const Int_t n) {
  // returns a pointer to the target volume with index n
  if (targets) return (HGeomVolume*)targets->At(n);
  return 0;
}


void HSpecGeomPar::createTargets(const Int_t n) {
  // creates an empty array 'targets' of size n
  // if n==0 the array is deleted
  if (targets) {
    targets->Delete();
    delete targets;
    targets=0;
  }
  if (n>0) targets=new TObjArray(n);
}


void HSpecGeomPar::addCave(HGeomVolume* v) {
  if (!v) return;
  if (cave) delete cave;
  cave=new HGeomVolume(*v);
  cave->setMother("");
}


void HSpecGeomPar::addSector(HGeomVolume* v) {
  // Adds the given sector volume in the array 'sectors'.
  // The position in the array is retrieved from the name.
  // If the array does not exist it is created.
  // If the array it too small it is expanded.
  if (!v) return;
  Int_t n=getSectorIndex(v->GetName());
  if (sectors==0) sectors=new TObjArray(n+1);
  else {
    if (n>=sectors->GetSize()) sectors->Expand(n+1);
    else {
      HGeomVolume* s=(HGeomVolume*)sectors->At(n);
      if (s) delete s;
      s=0;
    }
  }
  sectors->AddAt(new HGeomVolume(*v),n);
}


void HSpecGeomPar::addTarget(HGeomVolume* v) {
  // Adds the given target volume in the array 'target'.
  // The position in the array is retrieved from the name.
  // If the array does not exist it is created.
  // If the array it too small it is expanded.
  if (!v) return;
  Int_t n=getTargetIndex(v->GetName());
  if (targets==0) targets=new TObjArray(n+1);
  else {
    if (n>=targets->GetSize()) targets->Expand(n+1);
    else {
      HGeomVolume* t=(HGeomVolume*)targets->At(n);
      if (t) delete t;
      t=0;
    }
  }
  targets->AddAt(new HGeomVolume(*v),n);
}


Bool_t HSpecGeomPar::init(HParIo* io) {
  // Initializes the container from the input(s) in the runtime database.
  // The sector or target informations have to be initialized completely from
  // one input. It is possible to take the sector informations from the first
  // input and the target informations from the second input, but it is not
  // possible to take the sector informations from two inputs. 
  if (versions[1]!=-1 && versions[2]!=-1) clear();
  Int_t set[3]={1,1,1};
  Bool_t allFound=kFALSE;
  if (io) {
    allFound=init(io,set);
  } else {
    HRuntimeDb* rtdb=gHades->getRuntimeDb();
    io=rtdb->getFirstInput();
    if (io) allFound=init(io,set);
    if (!allFound) {
      io=rtdb->getSecondInput();
      if (io) allFound=init(io,set);
    } else setInputVersion(-1,2);
  }
  if (allFound) return kTRUE;
  cerr<<"********  "<<GetName()<<"  not initialized  ********"<<endl;
  return kFALSE;
}


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


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


void HSpecGeomPar::clear() {
  // deletes the targets, but does not change cave and sectors
  if (targets) {
    targets->Delete();
    delete targets;
    targets=0;
  }
  status=kFALSE;
  resetInputVersions();
}


void HSpecGeomPar::printParam() {
  // prints the parameters
  if (cave) cave->print();
  if (sectors) {
    for(Int_t i=0;i<sectors->GetSize();i++) {
      HGeomVolume* p=(HGeomVolume*)sectors->At(i);  
      if (p) p->print();
    }
  }
  if (targets) {
    for(Int_t i=0;i<targets->GetSize();i++) {
      HGeomVolume* p=(HGeomVolume*)targets->At(i);  
      if (p) p->print();
    }
  }
}


Int_t HSpecGeomPar::getSectorIndex(const Text_t* name) {
  // returns the module index retrieved from the module name SECx
  return (Int_t)(name[3]-'0')-1;
}


Int_t HSpecGeomPar::getTargetIndex(const Text_t* name) {
  // returns 0 if the target name has only 4 characters (only 1 target)
  // returns the index retrieved from the target name TARGxx or TXxx
  Int_t l=strlen(name);
  Int_t idx=-1;
  if (strncmp(name,"TARG",4)==0) {
    if (l==4) {
      idx=0;
    } else if (l==5) {
      idx= (Int_t)(name[4]-'0')-1;
    } else if (l==6) {
      idx=(Int_t)(name[4]-'0')*10+(Int_t)(name[5]-'0')-1; 
    }
  } else if (l==4 && strncmp(name,"TX",2)==0) {
    idx=(Int_t)(name[2]-'0')*10+(Int_t)(name[3]-'0')-1;
  }
  return idx;  
}
 hspecgeompar.cc:1
 hspecgeompar.cc:2
 hspecgeompar.cc:3
 hspecgeompar.cc:4
 hspecgeompar.cc:5
 hspecgeompar.cc:6
 hspecgeompar.cc:7
 hspecgeompar.cc:8
 hspecgeompar.cc:9
 hspecgeompar.cc:10
 hspecgeompar.cc:11
 hspecgeompar.cc:12
 hspecgeompar.cc:13
 hspecgeompar.cc:14
 hspecgeompar.cc:15
 hspecgeompar.cc:16
 hspecgeompar.cc:17
 hspecgeompar.cc:18
 hspecgeompar.cc:19
 hspecgeompar.cc:20
 hspecgeompar.cc:21
 hspecgeompar.cc:22
 hspecgeompar.cc:23
 hspecgeompar.cc:24
 hspecgeompar.cc:25
 hspecgeompar.cc:26
 hspecgeompar.cc:27
 hspecgeompar.cc:28
 hspecgeompar.cc:29
 hspecgeompar.cc:30
 hspecgeompar.cc:31
 hspecgeompar.cc:32
 hspecgeompar.cc:33
 hspecgeompar.cc:34
 hspecgeompar.cc:35
 hspecgeompar.cc:36
 hspecgeompar.cc:37
 hspecgeompar.cc:38
 hspecgeompar.cc:39
 hspecgeompar.cc:40
 hspecgeompar.cc:41
 hspecgeompar.cc:42
 hspecgeompar.cc:43
 hspecgeompar.cc:44
 hspecgeompar.cc:45
 hspecgeompar.cc:46
 hspecgeompar.cc:47
 hspecgeompar.cc:48
 hspecgeompar.cc:49
 hspecgeompar.cc:50
 hspecgeompar.cc:51
 hspecgeompar.cc:52
 hspecgeompar.cc:53
 hspecgeompar.cc:54
 hspecgeompar.cc:55
 hspecgeompar.cc:56
 hspecgeompar.cc:57
 hspecgeompar.cc:58
 hspecgeompar.cc:59
 hspecgeompar.cc:60
 hspecgeompar.cc:61
 hspecgeompar.cc:62
 hspecgeompar.cc:63
 hspecgeompar.cc:64
 hspecgeompar.cc:65
 hspecgeompar.cc:66
 hspecgeompar.cc:67
 hspecgeompar.cc:68
 hspecgeompar.cc:69
 hspecgeompar.cc:70
 hspecgeompar.cc:71
 hspecgeompar.cc:72
 hspecgeompar.cc:73
 hspecgeompar.cc:74
 hspecgeompar.cc:75
 hspecgeompar.cc:76
 hspecgeompar.cc:77
 hspecgeompar.cc:78
 hspecgeompar.cc:79
 hspecgeompar.cc:80
 hspecgeompar.cc:81
 hspecgeompar.cc:82
 hspecgeompar.cc:83
 hspecgeompar.cc:84
 hspecgeompar.cc:85
 hspecgeompar.cc:86
 hspecgeompar.cc:87
 hspecgeompar.cc:88
 hspecgeompar.cc:89
 hspecgeompar.cc:90
 hspecgeompar.cc:91
 hspecgeompar.cc:92
 hspecgeompar.cc:93
 hspecgeompar.cc:94
 hspecgeompar.cc:95
 hspecgeompar.cc:96
 hspecgeompar.cc:97
 hspecgeompar.cc:98
 hspecgeompar.cc:99
 hspecgeompar.cc:100
 hspecgeompar.cc:101
 hspecgeompar.cc:102
 hspecgeompar.cc:103
 hspecgeompar.cc:104
 hspecgeompar.cc:105
 hspecgeompar.cc:106
 hspecgeompar.cc:107
 hspecgeompar.cc:108
 hspecgeompar.cc:109
 hspecgeompar.cc:110
 hspecgeompar.cc:111
 hspecgeompar.cc:112
 hspecgeompar.cc:113
 hspecgeompar.cc:114
 hspecgeompar.cc:115
 hspecgeompar.cc:116
 hspecgeompar.cc:117
 hspecgeompar.cc:118
 hspecgeompar.cc:119
 hspecgeompar.cc:120
 hspecgeompar.cc:121
 hspecgeompar.cc:122
 hspecgeompar.cc:123
 hspecgeompar.cc:124
 hspecgeompar.cc:125
 hspecgeompar.cc:126
 hspecgeompar.cc:127
 hspecgeompar.cc:128
 hspecgeompar.cc:129
 hspecgeompar.cc:130
 hspecgeompar.cc:131
 hspecgeompar.cc:132
 hspecgeompar.cc:133
 hspecgeompar.cc:134
 hspecgeompar.cc:135
 hspecgeompar.cc:136
 hspecgeompar.cc:137
 hspecgeompar.cc:138
 hspecgeompar.cc:139
 hspecgeompar.cc:140
 hspecgeompar.cc:141
 hspecgeompar.cc:142
 hspecgeompar.cc:143
 hspecgeompar.cc:144
 hspecgeompar.cc:145
 hspecgeompar.cc:146
 hspecgeompar.cc:147
 hspecgeompar.cc:148
 hspecgeompar.cc:149
 hspecgeompar.cc:150
 hspecgeompar.cc:151
 hspecgeompar.cc:152
 hspecgeompar.cc:153
 hspecgeompar.cc:154
 hspecgeompar.cc:155
 hspecgeompar.cc:156
 hspecgeompar.cc:157
 hspecgeompar.cc:158
 hspecgeompar.cc:159
 hspecgeompar.cc:160
 hspecgeompar.cc:161
 hspecgeompar.cc:162
 hspecgeompar.cc:163
 hspecgeompar.cc:164
 hspecgeompar.cc:165
 hspecgeompar.cc:166
 hspecgeompar.cc:167
 hspecgeompar.cc:168
 hspecgeompar.cc:169
 hspecgeompar.cc:170
 hspecgeompar.cc:171
 hspecgeompar.cc:172
 hspecgeompar.cc:173
 hspecgeompar.cc:174
 hspecgeompar.cc:175
 hspecgeompar.cc:176
 hspecgeompar.cc:177
 hspecgeompar.cc:178
 hspecgeompar.cc:179
 hspecgeompar.cc:180
 hspecgeompar.cc:181
 hspecgeompar.cc:182
 hspecgeompar.cc:183
 hspecgeompar.cc:184
 hspecgeompar.cc:185
 hspecgeompar.cc:186
 hspecgeompar.cc:187
 hspecgeompar.cc:188
 hspecgeompar.cc:189
 hspecgeompar.cc:190
 hspecgeompar.cc:191
 hspecgeompar.cc:192
 hspecgeompar.cc:193
 hspecgeompar.cc:194
 hspecgeompar.cc:195
 hspecgeompar.cc:196
 hspecgeompar.cc:197
 hspecgeompar.cc:198
 hspecgeompar.cc:199
 hspecgeompar.cc:200
 hspecgeompar.cc:201
 hspecgeompar.cc:202
 hspecgeompar.cc:203
 hspecgeompar.cc:204
 hspecgeompar.cc:205
 hspecgeompar.cc:206
 hspecgeompar.cc:207
 hspecgeompar.cc:208
 hspecgeompar.cc:209
 hspecgeompar.cc:210
 hspecgeompar.cc:211
 hspecgeompar.cc:212
 hspecgeompar.cc:213
 hspecgeompar.cc:214
 hspecgeompar.cc:215
 hspecgeompar.cc:216
 hspecgeompar.cc:217
 hspecgeompar.cc:218
 hspecgeompar.cc:219
 hspecgeompar.cc:220
 hspecgeompar.cc:221
 hspecgeompar.cc:222
 hspecgeompar.cc:223
 hspecgeompar.cc:224
 hspecgeompar.cc:225
 hspecgeompar.cc:226
 hspecgeompar.cc:227
 hspecgeompar.cc:228
 hspecgeompar.cc:229
 hspecgeompar.cc:230
 hspecgeompar.cc:231
 hspecgeompar.cc:232
 hspecgeompar.cc:233
 hspecgeompar.cc:234
 hspecgeompar.cc:235
 hspecgeompar.cc:236
 hspecgeompar.cc:237
 hspecgeompar.cc:238
 hspecgeompar.cc:239
 hspecgeompar.cc:240
 hspecgeompar.cc:241
 hspecgeompar.cc:242
 hspecgeompar.cc:243
 hspecgeompar.cc:244