ROOT logo
//*-- AUTHOR : Ilse Koenig
//*-- Modified : 17/01/2002 by I. Koenig

//_HADES_CLASS_DESCRIPTION 
/////////////////////////////////////////////////////////////
// HMdcGeomStruct
//
// Container class for parameters decribing the geometrical
// tree of an Mdc (sectors,modules,layers with the number of
// cells in each layer.
// This information is needed to create the data tree and to
// create the parameter containers for the Mdc. 
//
/////////////////////////////////////////////////////////////

#include "hmdcgeomstruct.h"
#include "hades.h"
#include "hruntimedb.h"
#include "hspectrometer.h"
#include "hmdcdetector.h"
#include "hpario.h"
#include "hdetpario.h"
#include "hmessagemgr.h"

ClassImp(HMdcGeomModStru)
ClassImp(HMdcGeomSecStru)
ClassImp(HMdcGeomStruct)

HMdcGeomSecStru::HMdcGeomSecStru(Int_t n) {
  // constructor creates an array of pointers of type
  // HMdcGeomModStru each containing an Int_t array[6]
  // to hold the number of the cells in each layer
  array = new TObjArray(n);
  for(Int_t i=0;i<n;i++) array->AddAt(new HMdcGeomModStru(),i);
}

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

HMdcGeomStruct::HMdcGeomStruct(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 HMdcGeomSecStru
  strcpy(detName,"Mdc");
  array = new TObjArray(n);
  for(Int_t i=0;i<n;i++) array->AddAt(new HMdcGeomSecStru(4),i);
  clear();
}

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

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

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

void HMdcGeomStruct::readline(const Char_t *buf, Int_t *set) {
  // decodes one line read from ascii file I/O
  Int_t sec, mod, lay, nwires, pos;
  sscanf(buf,"%i%i%i%i", &sec, &mod, &lay, &nwires);
  pos=sec*4+mod;
  if (!set[pos]) return;
  HMdcGeomStruct &pp = *this;
  pp[sec][mod].fill(lay, nwires);
  set[pos]=999;
}

void HMdcGeomStruct::putAsciiHeader(TString& header) {
  // puts the ascii header to the string used in HMdcParAsciiFileIo
  header=
    "# Parameters describing the geometrical sizes of the MDC\n"
    "# Format:\n"
    "# sector   module   layer   max number of wires\n";
}

Bool_t HMdcGeomStruct::writeline(Char_t *buf, Int_t sec, Int_t mod, Int_t lay) {
  // writes one line to the buffer used by ascii file I/O
  Int_t nCells = (*this)[sec][mod][lay];
  if (nCells<=0) return kFALSE;
  sprintf(buf,"%1i %1i %1i %3i\n", sec, mod, lay, nCells);
  return kTRUE;
}

void HMdcGeomStruct::clear() {
  // clears the container
  for(Int_t i=0;i<6;i++) {
    HMdcGeomSecStru& sec=(*this)[i];
    for(Int_t j=0;j<4;j++) {
      HMdcGeomModStru& mod=sec[j];
      mod.clear();
    }
  }
  resetInputVersions();
  status=kFALSE;
  changed=kFALSE;
}

void HMdcGeomStruct::printParam() {
  // prints the number of the cells
  INFO_msg(10,HMessageMgr::DET_MDC,"Number of Mdc cells:");
  for(Int_t i=0;i<6;i++) {
    for(Int_t j=0;j<4;j++) {
      for(Int_t k=0;k<6;k++) {
        Int_t nCells = (*this)[i][j][k];
        if (nCells>0)
	    gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName()
				   ,"%1i %1i %1i %3i\n",i,j,k,nCells);
      }
    }
  }
}

void HMdcGeomStruct::getMaxIndices(TArrayI* ind) {
  // return the maximum indices of the sectors, modules, layers,
  // cells in the actual setup
  Int_t  maxSec=-1, maxMod=-1, maxLay=-1,maxCell=-1;
  for(Int_t i=0;i<6;i++) {
    HMdcGeomSecStru& sec=(*this)[i];
    for(Int_t j=0;j<4;j++) {
      HMdcGeomModStru& mod=sec[j];
      for(Int_t k=0;k<6;k++) {
        Int_t n=mod[k]-1;  // index is number of cells -1
        if (n>=0) {
          maxSec=(i>maxSec)?i:maxSec;
          maxMod=(j>maxMod)?j:maxMod;
          maxLay=(k>maxLay)?k:maxLay;
          maxCell=(n>maxCell)?n:maxCell;
        }
      }
    }
  }
  ind->AddAt(maxSec,0);
  ind->AddAt(maxMod,1);
  ind->AddAt(maxLay,2);
  ind->AddAt(maxCell,3);
}

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

   UInt_t R__s, R__c;
   if (R__b.IsReading()) {
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
      if (R__v > 1) {
	HMdcGeomStruct::Class()->ReadBuffer(R__b,this,R__v,R__s,R__c);
      } else {
	HParSet::Streamer(R__b);
	R__b >> array;
	R__b.CheckByteCount(R__s, R__c, HMdcGeomStruct::IsA());
      }
   } else {
     HMdcGeomStruct::Class()->WriteBuffer(R__b,this);
   }
}

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

   UInt_t R__s, R__c;
   if (R__b.IsReading()) {
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c); 
      if (R__v > 1) {
	HMdcGeomSecStru::Class()->ReadBuffer(R__b,this,R__v,R__s,R__c);
      } else {
	TObject::Streamer(R__b);
	R__b >> array;
	R__b.CheckByteCount(R__s, R__c, HMdcGeomSecStru::IsA());
      }
   } else {
     HMdcGeomSecStru::Class()->WriteBuffer(R__b,this);
   }
}

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

   UInt_t R__s, R__c;
   if (R__b.IsReading()) {
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c); 
      if (R__v > 1) {
	HMdcGeomModStru::Class()->ReadBuffer(R__b,this,R__v,R__s,R__c);
      } else { 
	TObject::Streamer(R__b);
	R__b.ReadStaticArray(nCells);
	R__b.CheckByteCount(R__s, R__c, HMdcGeomModStru::IsA());
      }
   } else {
     HMdcGeomModStru::Class()->WriteBuffer(R__b,this);
   }
}
 hmdcgeomstruct.cc:1
 hmdcgeomstruct.cc:2
 hmdcgeomstruct.cc:3
 hmdcgeomstruct.cc:4
 hmdcgeomstruct.cc:5
 hmdcgeomstruct.cc:6
 hmdcgeomstruct.cc:7
 hmdcgeomstruct.cc:8
 hmdcgeomstruct.cc:9
 hmdcgeomstruct.cc:10
 hmdcgeomstruct.cc:11
 hmdcgeomstruct.cc:12
 hmdcgeomstruct.cc:13
 hmdcgeomstruct.cc:14
 hmdcgeomstruct.cc:15
 hmdcgeomstruct.cc:16
 hmdcgeomstruct.cc:17
 hmdcgeomstruct.cc:18
 hmdcgeomstruct.cc:19
 hmdcgeomstruct.cc:20
 hmdcgeomstruct.cc:21
 hmdcgeomstruct.cc:22
 hmdcgeomstruct.cc:23
 hmdcgeomstruct.cc:24
 hmdcgeomstruct.cc:25
 hmdcgeomstruct.cc:26
 hmdcgeomstruct.cc:27
 hmdcgeomstruct.cc:28
 hmdcgeomstruct.cc:29
 hmdcgeomstruct.cc:30
 hmdcgeomstruct.cc:31
 hmdcgeomstruct.cc:32
 hmdcgeomstruct.cc:33
 hmdcgeomstruct.cc:34
 hmdcgeomstruct.cc:35
 hmdcgeomstruct.cc:36
 hmdcgeomstruct.cc:37
 hmdcgeomstruct.cc:38
 hmdcgeomstruct.cc:39
 hmdcgeomstruct.cc:40
 hmdcgeomstruct.cc:41
 hmdcgeomstruct.cc:42
 hmdcgeomstruct.cc:43
 hmdcgeomstruct.cc:44
 hmdcgeomstruct.cc:45
 hmdcgeomstruct.cc:46
 hmdcgeomstruct.cc:47
 hmdcgeomstruct.cc:48
 hmdcgeomstruct.cc:49
 hmdcgeomstruct.cc:50
 hmdcgeomstruct.cc:51
 hmdcgeomstruct.cc:52
 hmdcgeomstruct.cc:53
 hmdcgeomstruct.cc:54
 hmdcgeomstruct.cc:55
 hmdcgeomstruct.cc:56
 hmdcgeomstruct.cc:57
 hmdcgeomstruct.cc:58
 hmdcgeomstruct.cc:59
 hmdcgeomstruct.cc:60
 hmdcgeomstruct.cc:61
 hmdcgeomstruct.cc:62
 hmdcgeomstruct.cc:63
 hmdcgeomstruct.cc:64
 hmdcgeomstruct.cc:65
 hmdcgeomstruct.cc:66
 hmdcgeomstruct.cc:67
 hmdcgeomstruct.cc:68
 hmdcgeomstruct.cc:69
 hmdcgeomstruct.cc:70
 hmdcgeomstruct.cc:71
 hmdcgeomstruct.cc:72
 hmdcgeomstruct.cc:73
 hmdcgeomstruct.cc:74
 hmdcgeomstruct.cc:75
 hmdcgeomstruct.cc:76
 hmdcgeomstruct.cc:77
 hmdcgeomstruct.cc:78
 hmdcgeomstruct.cc:79
 hmdcgeomstruct.cc:80
 hmdcgeomstruct.cc:81
 hmdcgeomstruct.cc:82
 hmdcgeomstruct.cc:83
 hmdcgeomstruct.cc:84
 hmdcgeomstruct.cc:85
 hmdcgeomstruct.cc:86
 hmdcgeomstruct.cc:87
 hmdcgeomstruct.cc:88
 hmdcgeomstruct.cc:89
 hmdcgeomstruct.cc:90
 hmdcgeomstruct.cc:91
 hmdcgeomstruct.cc:92
 hmdcgeomstruct.cc:93
 hmdcgeomstruct.cc:94
 hmdcgeomstruct.cc:95
 hmdcgeomstruct.cc:96
 hmdcgeomstruct.cc:97
 hmdcgeomstruct.cc:98
 hmdcgeomstruct.cc:99
 hmdcgeomstruct.cc:100
 hmdcgeomstruct.cc:101
 hmdcgeomstruct.cc:102
 hmdcgeomstruct.cc:103
 hmdcgeomstruct.cc:104
 hmdcgeomstruct.cc:105
 hmdcgeomstruct.cc:106
 hmdcgeomstruct.cc:107
 hmdcgeomstruct.cc:108
 hmdcgeomstruct.cc:109
 hmdcgeomstruct.cc:110
 hmdcgeomstruct.cc:111
 hmdcgeomstruct.cc:112
 hmdcgeomstruct.cc:113
 hmdcgeomstruct.cc:114
 hmdcgeomstruct.cc:115
 hmdcgeomstruct.cc:116
 hmdcgeomstruct.cc:117
 hmdcgeomstruct.cc:118
 hmdcgeomstruct.cc:119
 hmdcgeomstruct.cc:120
 hmdcgeomstruct.cc:121
 hmdcgeomstruct.cc:122
 hmdcgeomstruct.cc:123
 hmdcgeomstruct.cc:124
 hmdcgeomstruct.cc:125
 hmdcgeomstruct.cc:126
 hmdcgeomstruct.cc:127
 hmdcgeomstruct.cc:128
 hmdcgeomstruct.cc:129
 hmdcgeomstruct.cc:130
 hmdcgeomstruct.cc:131
 hmdcgeomstruct.cc:132
 hmdcgeomstruct.cc:133
 hmdcgeomstruct.cc:134
 hmdcgeomstruct.cc:135
 hmdcgeomstruct.cc:136
 hmdcgeomstruct.cc:137
 hmdcgeomstruct.cc:138
 hmdcgeomstruct.cc:139
 hmdcgeomstruct.cc:140
 hmdcgeomstruct.cc:141
 hmdcgeomstruct.cc:142
 hmdcgeomstruct.cc:143
 hmdcgeomstruct.cc:144
 hmdcgeomstruct.cc:145
 hmdcgeomstruct.cc:146
 hmdcgeomstruct.cc:147
 hmdcgeomstruct.cc:148
 hmdcgeomstruct.cc:149
 hmdcgeomstruct.cc:150
 hmdcgeomstruct.cc:151
 hmdcgeomstruct.cc:152
 hmdcgeomstruct.cc:153
 hmdcgeomstruct.cc:154
 hmdcgeomstruct.cc:155
 hmdcgeomstruct.cc:156
 hmdcgeomstruct.cc:157
 hmdcgeomstruct.cc:158
 hmdcgeomstruct.cc:159
 hmdcgeomstruct.cc:160
 hmdcgeomstruct.cc:161
 hmdcgeomstruct.cc:162
 hmdcgeomstruct.cc:163
 hmdcgeomstruct.cc:164
 hmdcgeomstruct.cc:165
 hmdcgeomstruct.cc:166
 hmdcgeomstruct.cc:167
 hmdcgeomstruct.cc:168
 hmdcgeomstruct.cc:169
 hmdcgeomstruct.cc:170
 hmdcgeomstruct.cc:171
 hmdcgeomstruct.cc:172
 hmdcgeomstruct.cc:173
 hmdcgeomstruct.cc:174
 hmdcgeomstruct.cc:175
 hmdcgeomstruct.cc:176
 hmdcgeomstruct.cc:177
 hmdcgeomstruct.cc:178
 hmdcgeomstruct.cc:179
 hmdcgeomstruct.cc:180
 hmdcgeomstruct.cc:181
 hmdcgeomstruct.cc:182
 hmdcgeomstruct.cc:183
 hmdcgeomstruct.cc:184
 hmdcgeomstruct.cc:185
 hmdcgeomstruct.cc:186
 hmdcgeomstruct.cc:187
 hmdcgeomstruct.cc:188
 hmdcgeomstruct.cc:189
 hmdcgeomstruct.cc:190
 hmdcgeomstruct.cc:191
 hmdcgeomstruct.cc:192
 hmdcgeomstruct.cc:193
 hmdcgeomstruct.cc:194
 hmdcgeomstruct.cc:195
 hmdcgeomstruct.cc:196
 hmdcgeomstruct.cc:197
 hmdcgeomstruct.cc:198
 hmdcgeomstruct.cc:199
 hmdcgeomstruct.cc:200
 hmdcgeomstruct.cc:201
 hmdcgeomstruct.cc:202
 hmdcgeomstruct.cc:203
 hmdcgeomstruct.cc:204
 hmdcgeomstruct.cc:205
 hmdcgeomstruct.cc:206
 hmdcgeomstruct.cc:207
 hmdcgeomstruct.cc:208
 hmdcgeomstruct.cc:209
 hmdcgeomstruct.cc:210
 hmdcgeomstruct.cc:211
 hmdcgeomstruct.cc:212
 hmdcgeomstruct.cc:213
 hmdcgeomstruct.cc:214