ROOT logo
//*-- AUTHOR : Ilse Koenig
//*-- Last modified : 26/04/02 by Ilse Koenig

//_HADES_CLASS_DESCRIPTION 
///////////////////////////////////////////////////////////////////////////////
// HGeomDetPar
//
// Container class for the basic geometry parameters of a detector
//
// This container can hold the information about the sizes and positions of
// volumes forming a geometry tree with 2 levels: modules and components in
// these modules.
// 
// The information is stored in 2 arrays.
// The array "modules" is a linear array of maxSectors*maxModules pointers to
// detector modules (type HModGeomPar) each having a name and a lab
// transformation which describes the position and orientation of the internal
// module coordinate system relative to the cave coordinate system.
// Each module has a pointer to a reference module describing the type of this
// module. These module types (objects of class HGeomCompositeVolume) are
// stored in the second array "refVolumes". (Normally the modules in the six
// sectors are identical and the information has to be stored only once. Only
// their position is different.)
// Each reference module is a volume with a detector dependent number of
// components which are volumes themselves. Each volume has a name, a shape, a
// mother, a shape dependant number of points describing the size and a
// transformation. The transformation of a module describes the detector
// coordinate system (ideal position in a sector) and the transformation of a
// component shows the position and orientation relative to  this detector
// coordinate system. 
//  
// inline functions of class HDetGeomPar:
//
//   Int_t getNumComponents()
//       returns the number of components in a module
//   Int_t getMaxSectors()
//       returns the maximum number of sectors
//   Int_t getMaxModules()
//       returns the maximum number of modules
//   HGeomShapes* getShapes()
//       return the pointer to the shape classes
//
// virtual functions of class HDetGeomPar which have to be implemented by the
// detector classes:
//   virtual Bool_t init(HParIo*,Int_t*)
//       initilizes the container from an input 
//   virtual Int_t write(HParIo*)
//       writes the container to an output
//   virtual Int_t getSecNum(const TString&)
//       retrieves the sector number from the name of a module 
//   virtual Int_t getModNumInMod(const TString&) {return -1;}
//       retrieves the module number from the name of a module 
//   virtual Int_t getModNumInComp(const TString&) {return -1;}
//       retrieves the module number from the name of a component 
//   virtual Int_t getCompNum(const TString&) {return -1;}
//       retrieves the component number from the name of a component
//
// inline functions of class HModGeomPar:
//
//   void setVolume(HGeomCompositeVolume* p)
//       sets the pointer to the reference volume
//   HGeomCompositeVolume* getRefVolume()
//       returns a pointer to the reference volume
//   HGeomTransform& getLabTransform()
//       returns the lab transformation of a module
//   const Text_t* getRefName() const
//       sets the name of the reference volume
//
///////////////////////////////////////////////////////////////////////////////

#include "hdetgeompar.h"
#include "hgeomcompositevolume.h"
#include "hades.h"
#include "hruntimedb.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hpario.h"

ClassImp(HDetGeomPar)
ClassImp(HModGeomPar)

void HModGeomPar::setRefName(const Text_t* s) {
  //sets the name of the reference volume
  refName=s;
  refName.ToUpper();
}

void HModGeomPar::print() {
  // prints the name of the module volume, the name of the reference module
  // volume and the lab transformation
  cout<<fName<<"  "<<refName<<'\n';
  transform.print();
  printf("\n");
}

void HModGeomPar::clear() {
  // clears the module
  refName="";
  refVolume=0;
  transform.clear();
}

HDetGeomPar::HDetGeomPar(const Char_t* name,const Char_t* title,
               const Char_t* context,const Char_t* detectorName)
           : HParSet(name,title,context) {
  // The constructor creates an array of maxSectors*maxModules pointers of
  // type HModGeomPar
  // The pointers to modules, which are not active (taken from the setup),
  // are NULL-pointers.
  // It creates also an array of size maxModules, which is filled which the 
  // reference modules during the first initialisation
  HDetector* setup=0;
  strcpy(detName,detectorName);
  isFirstInit=kTRUE;
  if (gHades && (setup=gHades->getSetup()->getDetector(detName))) {
    shapes=gHades->getSetup()->getShapes();
    maxSectors=setup->getMaxSectors();
    maxModules=setup->getMaxModules();
    numComponents=setup->getMaxComponents();
    if (maxModules>0) {
      refVolumes=new TObjArray(maxModules);
      Int_t* set=setup->getModules();
      Int_t n=0;
      if (maxSectors>0) n=maxSectors*maxModules;
      else n=maxModules;
      modules=new TObjArray(n);
      for (Int_t i=0;i<n;++i) {
        if (set[i]!=0) modules->AddAt(new HModGeomPar(),i);
        else modules->RemoveAt(i);
      }
    }
  } else {
    if (gHades) Error("HDetGeomPar(...)",
                      "Detector %s not found", detName);
    modules=0;
    refVolumes=0;
    shapes=0;
    maxSectors=maxModules=numComponents=0;
  }
}

HDetGeomPar::~HDetGeomPar() {
  // destructor deletes the arrays
  if (modules) modules->Delete();
  delete modules;
  if (refVolumes) refVolumes->Delete();
  delete refVolumes;
}

Int_t HDetGeomPar::getNumModules() {
  // returns the maximum number of the modules
  if (modules) return  (modules->GetSize());
    return 0;
}

Int_t HDetGeomPar::getNumRefModules() {
  // returns the maximum number of the reference modules
  if (refVolumes) return  (refVolumes->GetSize());
    return 0;
}

HModGeomPar* HDetGeomPar::getModule(const Int_t s,const Int_t m) {
  // returns a pointer to the module with index m in sector with index s
  if (modules) {
    if (s>=0) return (HModGeomPar*)modules->At(s*maxModules+m);
    else return (HModGeomPar*)modules->At(m);
  }
  return 0;
}

HModGeomPar* HDetGeomPar::getModule(const Int_t n) {
  // returns a pointer to the module at position n in the array
  if (modules && n<modules->GetSize()) return (HModGeomPar*)modules->At(n);
  return 0;
}

void HDetGeomPar::getSector(TObjArray* array,const Int_t s) {
  // fills the given array with the pointers to all modules in the sector with
  // index s
  Int_t l=0;
  if (array && (l=array->GetSize())) {
    Int_t i=s*maxModules;
    for(Int_t n=0;n<l&&n<maxModules;n++) {
      array->AddAt(modules->At(i),n);
      i++;
    }
  }
}

HGeomCompositeVolume* HDetGeomPar::getRefVolume(const Int_t m) {
  // returns a pointer to the reference module with index m
  if (refVolumes && m<refVolumes->GetSize()) return (HGeomCompositeVolume*)refVolumes->At(m);
  return 0;
}

void HDetGeomPar::addRefVolume(HGeomCompositeVolume* v,const Int_t n) {
  // adds the given reference volume at postion n in the array refVolumes
  if (refVolumes==0) refVolumes=new TObjArray(n+1);
  if (n>=refVolumes->GetSize()) refVolumes->Expand(n+1);
  refVolumes->AddAt(v,n);
}

void HDetGeomPar::clear() {
  // clears the parameter container completely as Long_t as it was not
  //   initialized completly
  // otherwise it clears only the module transformation, but not the
  //   reference volume and its inner parts 
  // This function is virtual and could be overloaded in the derived class if needed.
  if (isFirstInit) {
    for(Int_t i=0;i<modules->GetSize();i++) {
      HModGeomPar* p=(HModGeomPar*)modules->At(i);
      if (p) p->clear();
    }
    for(Int_t i=0;i<refVolumes->GetSize();i++) {
      HGeomCompositeVolume* p=(HGeomCompositeVolume*)refVolumes->At(i);
      if (p) p->clear();
    }
  } else {
    for(Int_t i=0;i<modules->GetSize();i++) {
      HModGeomPar* p=(HModGeomPar*)modules->At(i);  
      if (p) p->getLabTransform().clear();
    }
  }
  status=kFALSE;
  resetInputVersions();
}

void HDetGeomPar::printParam() {
  // prints the parameters
  // This function is virtual and could be overloaded in the derived class if
  // needed.
  for(Int_t i=0;i<modules->GetSize();i++) {
    HModGeomPar* p=(HModGeomPar*)modules->At(i);  
    if (p) p->print();
  }
  for(Int_t i=0;i<refVolumes->GetSize();i++) {
    HGeomCompositeVolume* p=(HGeomCompositeVolume*)refVolumes->At(i);  
    if (p) p->print();
  }
}

/*
void HDetGeomPar::Streamer(TBuffer &R__b)
{
   // Stream an object of class HDetGeomPar.

   UInt_t R__s, R__c;
   if (R__b.IsReading()) {
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
      if (R__v > 1) {
	HDetGeomPar::Class()->ReadBuffer(R__b,this,R__v,R__s,R__c);
      } else {
	HParSet::Streamer(R__b);
	R__b >> modules;
	R__b >> refVolumes;
	R__b >> maxSectors;
	R__b >> maxModules;
	R__b >> numComponents;
	R__b.CheckByteCount(R__s, R__c, HDetGeomPar::IsA());
      }
   } else {
     HDetGeomPar::Class()->WriteBuffer(R__b,this);
   }
}
*/
 hdetgeompar.cc:1
 hdetgeompar.cc:2
 hdetgeompar.cc:3
 hdetgeompar.cc:4
 hdetgeompar.cc:5
 hdetgeompar.cc:6
 hdetgeompar.cc:7
 hdetgeompar.cc:8
 hdetgeompar.cc:9
 hdetgeompar.cc:10
 hdetgeompar.cc:11
 hdetgeompar.cc:12
 hdetgeompar.cc:13
 hdetgeompar.cc:14
 hdetgeompar.cc:15
 hdetgeompar.cc:16
 hdetgeompar.cc:17
 hdetgeompar.cc:18
 hdetgeompar.cc:19
 hdetgeompar.cc:20
 hdetgeompar.cc:21
 hdetgeompar.cc:22
 hdetgeompar.cc:23
 hdetgeompar.cc:24
 hdetgeompar.cc:25
 hdetgeompar.cc:26
 hdetgeompar.cc:27
 hdetgeompar.cc:28
 hdetgeompar.cc:29
 hdetgeompar.cc:30
 hdetgeompar.cc:31
 hdetgeompar.cc:32
 hdetgeompar.cc:33
 hdetgeompar.cc:34
 hdetgeompar.cc:35
 hdetgeompar.cc:36
 hdetgeompar.cc:37
 hdetgeompar.cc:38
 hdetgeompar.cc:39
 hdetgeompar.cc:40
 hdetgeompar.cc:41
 hdetgeompar.cc:42
 hdetgeompar.cc:43
 hdetgeompar.cc:44
 hdetgeompar.cc:45
 hdetgeompar.cc:46
 hdetgeompar.cc:47
 hdetgeompar.cc:48
 hdetgeompar.cc:49
 hdetgeompar.cc:50
 hdetgeompar.cc:51
 hdetgeompar.cc:52
 hdetgeompar.cc:53
 hdetgeompar.cc:54
 hdetgeompar.cc:55
 hdetgeompar.cc:56
 hdetgeompar.cc:57
 hdetgeompar.cc:58
 hdetgeompar.cc:59
 hdetgeompar.cc:60
 hdetgeompar.cc:61
 hdetgeompar.cc:62
 hdetgeompar.cc:63
 hdetgeompar.cc:64
 hdetgeompar.cc:65
 hdetgeompar.cc:66
 hdetgeompar.cc:67
 hdetgeompar.cc:68
 hdetgeompar.cc:69
 hdetgeompar.cc:70
 hdetgeompar.cc:71
 hdetgeompar.cc:72
 hdetgeompar.cc:73
 hdetgeompar.cc:74
 hdetgeompar.cc:75
 hdetgeompar.cc:76
 hdetgeompar.cc:77
 hdetgeompar.cc:78
 hdetgeompar.cc:79
 hdetgeompar.cc:80
 hdetgeompar.cc:81
 hdetgeompar.cc:82
 hdetgeompar.cc:83
 hdetgeompar.cc:84
 hdetgeompar.cc:85
 hdetgeompar.cc:86
 hdetgeompar.cc:87
 hdetgeompar.cc:88
 hdetgeompar.cc:89
 hdetgeompar.cc:90
 hdetgeompar.cc:91
 hdetgeompar.cc:92
 hdetgeompar.cc:93
 hdetgeompar.cc:94
 hdetgeompar.cc:95
 hdetgeompar.cc:96
 hdetgeompar.cc:97
 hdetgeompar.cc:98
 hdetgeompar.cc:99
 hdetgeompar.cc:100
 hdetgeompar.cc:101
 hdetgeompar.cc:102
 hdetgeompar.cc:103
 hdetgeompar.cc:104
 hdetgeompar.cc:105
 hdetgeompar.cc:106
 hdetgeompar.cc:107
 hdetgeompar.cc:108
 hdetgeompar.cc:109
 hdetgeompar.cc:110
 hdetgeompar.cc:111
 hdetgeompar.cc:112
 hdetgeompar.cc:113
 hdetgeompar.cc:114
 hdetgeompar.cc:115
 hdetgeompar.cc:116
 hdetgeompar.cc:117
 hdetgeompar.cc:118
 hdetgeompar.cc:119
 hdetgeompar.cc:120
 hdetgeompar.cc:121
 hdetgeompar.cc:122
 hdetgeompar.cc:123
 hdetgeompar.cc:124
 hdetgeompar.cc:125
 hdetgeompar.cc:126
 hdetgeompar.cc:127
 hdetgeompar.cc:128
 hdetgeompar.cc:129
 hdetgeompar.cc:130
 hdetgeompar.cc:131
 hdetgeompar.cc:132
 hdetgeompar.cc:133
 hdetgeompar.cc:134
 hdetgeompar.cc:135
 hdetgeompar.cc:136
 hdetgeompar.cc:137
 hdetgeompar.cc:138
 hdetgeompar.cc:139
 hdetgeompar.cc:140
 hdetgeompar.cc:141
 hdetgeompar.cc:142
 hdetgeompar.cc:143
 hdetgeompar.cc:144
 hdetgeompar.cc:145
 hdetgeompar.cc:146
 hdetgeompar.cc:147
 hdetgeompar.cc:148
 hdetgeompar.cc:149
 hdetgeompar.cc:150
 hdetgeompar.cc:151
 hdetgeompar.cc:152
 hdetgeompar.cc:153
 hdetgeompar.cc:154
 hdetgeompar.cc:155
 hdetgeompar.cc:156
 hdetgeompar.cc:157
 hdetgeompar.cc:158
 hdetgeompar.cc:159
 hdetgeompar.cc:160
 hdetgeompar.cc:161
 hdetgeompar.cc:162
 hdetgeompar.cc:163
 hdetgeompar.cc:164
 hdetgeompar.cc:165
 hdetgeompar.cc:166
 hdetgeompar.cc:167
 hdetgeompar.cc:168
 hdetgeompar.cc:169
 hdetgeompar.cc:170
 hdetgeompar.cc:171
 hdetgeompar.cc:172
 hdetgeompar.cc:173
 hdetgeompar.cc:174
 hdetgeompar.cc:175
 hdetgeompar.cc:176
 hdetgeompar.cc:177
 hdetgeompar.cc:178
 hdetgeompar.cc:179
 hdetgeompar.cc:180
 hdetgeompar.cc:181
 hdetgeompar.cc:182
 hdetgeompar.cc:183
 hdetgeompar.cc:184
 hdetgeompar.cc:185
 hdetgeompar.cc:186
 hdetgeompar.cc:187
 hdetgeompar.cc:188
 hdetgeompar.cc:189
 hdetgeompar.cc:190
 hdetgeompar.cc:191
 hdetgeompar.cc:192
 hdetgeompar.cc:193
 hdetgeompar.cc:194
 hdetgeompar.cc:195
 hdetgeompar.cc:196
 hdetgeompar.cc:197
 hdetgeompar.cc:198
 hdetgeompar.cc:199
 hdetgeompar.cc:200
 hdetgeompar.cc:201
 hdetgeompar.cc:202
 hdetgeompar.cc:203
 hdetgeompar.cc:204
 hdetgeompar.cc:205
 hdetgeompar.cc:206
 hdetgeompar.cc:207
 hdetgeompar.cc:208
 hdetgeompar.cc:209
 hdetgeompar.cc:210
 hdetgeompar.cc:211
 hdetgeompar.cc:212
 hdetgeompar.cc:213
 hdetgeompar.cc:214
 hdetgeompar.cc:215
 hdetgeompar.cc:216
 hdetgeompar.cc:217
 hdetgeompar.cc:218
 hdetgeompar.cc:219
 hdetgeompar.cc:220
 hdetgeompar.cc:221
 hdetgeompar.cc:222
 hdetgeompar.cc:223
 hdetgeompar.cc:224
 hdetgeompar.cc:225
 hdetgeompar.cc:226
 hdetgeompar.cc:227
 hdetgeompar.cc:228
 hdetgeompar.cc:229
 hdetgeompar.cc:230
 hdetgeompar.cc:231
 hdetgeompar.cc:232
 hdetgeompar.cc:233
 hdetgeompar.cc:234
 hdetgeompar.cc:235
 hdetgeompar.cc:236
 hdetgeompar.cc:237
 hdetgeompar.cc:238
 hdetgeompar.cc:239
 hdetgeompar.cc:240
 hdetgeompar.cc:241
 hdetgeompar.cc:242
 hdetgeompar.cc:243
 hdetgeompar.cc:244
 hdetgeompar.cc:245
 hdetgeompar.cc:246
 hdetgeompar.cc:247
 hdetgeompar.cc:248
 hdetgeompar.cc:249
 hdetgeompar.cc:250
 hdetgeompar.cc:251
 hdetgeompar.cc:252
 hdetgeompar.cc:253
 hdetgeompar.cc:254
 hdetgeompar.cc:255
 hdetgeompar.cc:256
 hdetgeompar.cc:257
 hdetgeompar.cc:258
 hdetgeompar.cc:259
 hdetgeompar.cc:260
 hdetgeompar.cc:261
 hdetgeompar.cc:262
 hdetgeompar.cc:263
 hdetgeompar.cc:264
 hdetgeompar.cc:265