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

//_HADES_CLASS_DESCRIPTION 
/////////////////////////////////////////////////////////////
// HMdcRawStruct
//
// Container class for parameters decribing the hardware
// tree of an Mdc (sectors,modules,motherboards with the
// maximum number of TDCs on each motherboards.
// This information is needed to create the data tree and to
// create the lookup table for the Mdc. 
//
/////////////////////////////////////////////////////////////

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

ClassImp(HMdcRawMothStru)
ClassImp(HMdcRawModStru)
ClassImp(HMdcRawSecStru)
ClassImp(HMdcRawStruct)

HMdcRawModStru::HMdcRawModStru(Int_t n) {
  // constructor creates an array of pointers of type
  // HMdcRawMothStru
  array = new TObjArray(n);
  for(Int_t i=0;i<n;i++) array->AddAt(new HMdcRawMothStru(),i);
}


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


Int_t HMdcRawModStru::getMboIndex(const Text_t* mbo) {
  // returns the index of the MBO given by its logical position
  for(Int_t i=0;i<getNMotherboards();i++) {
    const Text_t* name=array->At(i)->GetName();
    if (strcmp(name,mbo)==0) return i;
  }
  return -1;
}


HMdcRawSecStru::HMdcRawSecStru(Int_t n) {
  // constructor creates an array of pointers of type
  // HMdcRawModStru
  array = new TObjArray(n);
  for(Int_t i=0;i<n;i++) array->AddAt(new HMdcRawModStru(16),i);
}


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


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


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


Bool_t HMdcRawStruct::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 HMdcRawStruct::write(HParIo* output) {
  // writes the container to an output
  HDetParIo* out=output->getDetParIo("HMdcParIo");
  if (out) return out->write(this);
  return -1;
}

void HMdcRawStruct::clear() {
  // clears the container
  for(Int_t i=0;i<6;i++) {
    HMdcRawSecStru& sec=(*this)[i];
    for(Int_t j=0;j<4;j++) {
      HMdcRawModStru& mod=sec[j];
      for(Int_t k=0;k<16;k++) {
        HMdcRawMothStru& moth=mod[k];
        moth.clear();
      }
    }
  }
  status=kFALSE;
  resetInputVersions();
}


void HMdcRawStruct::printParam() {
  // prints the names (characterizes the position on the chamber) of the
  // motherboards and the number of TDCs on each of them;
  Char_t buf[255];
  SEPERATOR_msg("-",60);
  INFO_msg(10,HMessageMgr::DET_MDC,"Position identifier of motherboards");
  INFO_msg(10,HMessageMgr::DET_MDC,"number of TDCs");

  HMdcDetector* set=(HMdcDetector*)(((HSpectrometer*)(gHades->getSetup()))->getDetector("Mdc"));
  if (set) {
    for(Int_t i=0;i<6;i++) {
      HMdcRawSecStru& sec=(*this)[i];
      for(Int_t j=0;j<4;j++) {
        HMdcRawModStru& mod=sec[j];
        if (set->getModule(i,j)) {
	    gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName()
				   ,"sector: %i  module: %i",i,j);
          for(Int_t k=0;k<16;k++) {
	    sprintf(buf,"%s %s",buf,mod[k].GetName());
          }
	  INFO_msg(10,HMessageMgr::DET_MDC,buf);
					strcpy(buf,"");
          for(Int_t k=0;k<16;k++) {
            Int_t nt=mod[k].getNTdcs();
	    gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),"%3i ",nt);
          }
        }
      }
    }
    SEPERATOR_msg("-",60);
  }
}
          

void HMdcRawStruct::getMaxIndices(TArrayI* ind) {
  // returns the maximum indices of the sectors, modules, motherborads,
  // tdc channels in the actual setup
  Int_t maxSec=-1, maxMod=-1, maxMbo=-1, maxTdc=-1;
  for(Int_t i=0;i<6;i++) {
    HMdcRawSecStru& sec=(*this)[i];
    for(Int_t j=0;j<4;j++) {
      HMdcRawModStru& mod=sec[j];
      for(Int_t k=0;k<16;k++) {
        Int_t nt=mod[k].getNTdcs()-1; // index is number of tds -1
        if (nt>=0) {
          maxSec=(i>maxSec)?i:maxSec;
          maxMod=(j>maxMod)?j:maxMod;
          maxMbo=(k>maxMbo)?k:maxMbo;
          maxTdc=(nt>maxTdc)?nt:maxTdc;
        }
      }
    }
  }
  ind->AddAt(maxSec,0);
  ind->AddAt(maxMod,1);
  ind->AddAt(maxMbo,2);
  ind->AddAt(maxTdc,3);
}

void HMdcRawStruct::readline(const Char_t *buf, Int_t *set) {
  // decodes one line read from ascii file I/O
  Int_t sec, mod, mboInd, num;
  Char_t mboName[155];
  sscanf(buf,"%i%i%i%s%i", &sec, &mod, &mboInd, mboName, &num);
  Int_t n=sec*4+mod;
  if (!set[n]) return;
  HMdcRawMothStru& r=(*this)[sec][mod][mboInd];
  r.SetName(mboName);
  r.setNTdcs(num);
  set[n]=999;
}

void HMdcRawStruct::putAsciiHeader(TString& header) {
  // puts the ascii header to the string used in HMdcParAsciiFileIo
  header=
    "# Parameters describing the hardware of the MDC\n"
    "# Format:\n"
    "# sector   module   motherboard index   motherboard name\n"
    "#    number of TDC channels on the board\n";
}

Bool_t HMdcRawStruct::writeline(Char_t *buf, Int_t sec, Int_t mod, Int_t mbo) {
  // writes one line to the buffer used by ascii file I/O
  HMdcRawMothStru &moth=(*this)[sec][mod][mbo];
  Int_t nTdcs=moth.getNTdcs();
  if (nTdcs<=0) return kFALSE;
  sprintf(buf,"%1i %1i %2i %s %2i\n",sec,mod,mbo,moth.GetName(),nTdcs);
  return kTRUE;
}
 hmdcrawstruct.cc:1
 hmdcrawstruct.cc:2
 hmdcrawstruct.cc:3
 hmdcrawstruct.cc:4
 hmdcrawstruct.cc:5
 hmdcrawstruct.cc:6
 hmdcrawstruct.cc:7
 hmdcrawstruct.cc:8
 hmdcrawstruct.cc:9
 hmdcrawstruct.cc:10
 hmdcrawstruct.cc:11
 hmdcrawstruct.cc:12
 hmdcrawstruct.cc:13
 hmdcrawstruct.cc:14
 hmdcrawstruct.cc:15
 hmdcrawstruct.cc:16
 hmdcrawstruct.cc:17
 hmdcrawstruct.cc:18
 hmdcrawstruct.cc:19
 hmdcrawstruct.cc:20
 hmdcrawstruct.cc:21
 hmdcrawstruct.cc:22
 hmdcrawstruct.cc:23
 hmdcrawstruct.cc:24
 hmdcrawstruct.cc:25
 hmdcrawstruct.cc:26
 hmdcrawstruct.cc:27
 hmdcrawstruct.cc:28
 hmdcrawstruct.cc:29
 hmdcrawstruct.cc:30
 hmdcrawstruct.cc:31
 hmdcrawstruct.cc:32
 hmdcrawstruct.cc:33
 hmdcrawstruct.cc:34
 hmdcrawstruct.cc:35
 hmdcrawstruct.cc:36
 hmdcrawstruct.cc:37
 hmdcrawstruct.cc:38
 hmdcrawstruct.cc:39
 hmdcrawstruct.cc:40
 hmdcrawstruct.cc:41
 hmdcrawstruct.cc:42
 hmdcrawstruct.cc:43
 hmdcrawstruct.cc:44
 hmdcrawstruct.cc:45
 hmdcrawstruct.cc:46
 hmdcrawstruct.cc:47
 hmdcrawstruct.cc:48
 hmdcrawstruct.cc:49
 hmdcrawstruct.cc:50
 hmdcrawstruct.cc:51
 hmdcrawstruct.cc:52
 hmdcrawstruct.cc:53
 hmdcrawstruct.cc:54
 hmdcrawstruct.cc:55
 hmdcrawstruct.cc:56
 hmdcrawstruct.cc:57
 hmdcrawstruct.cc:58
 hmdcrawstruct.cc:59
 hmdcrawstruct.cc:60
 hmdcrawstruct.cc:61
 hmdcrawstruct.cc:62
 hmdcrawstruct.cc:63
 hmdcrawstruct.cc:64
 hmdcrawstruct.cc:65
 hmdcrawstruct.cc:66
 hmdcrawstruct.cc:67
 hmdcrawstruct.cc:68
 hmdcrawstruct.cc:69
 hmdcrawstruct.cc:70
 hmdcrawstruct.cc:71
 hmdcrawstruct.cc:72
 hmdcrawstruct.cc:73
 hmdcrawstruct.cc:74
 hmdcrawstruct.cc:75
 hmdcrawstruct.cc:76
 hmdcrawstruct.cc:77
 hmdcrawstruct.cc:78
 hmdcrawstruct.cc:79
 hmdcrawstruct.cc:80
 hmdcrawstruct.cc:81
 hmdcrawstruct.cc:82
 hmdcrawstruct.cc:83
 hmdcrawstruct.cc:84
 hmdcrawstruct.cc:85
 hmdcrawstruct.cc:86
 hmdcrawstruct.cc:87
 hmdcrawstruct.cc:88
 hmdcrawstruct.cc:89
 hmdcrawstruct.cc:90
 hmdcrawstruct.cc:91
 hmdcrawstruct.cc:92
 hmdcrawstruct.cc:93
 hmdcrawstruct.cc:94
 hmdcrawstruct.cc:95
 hmdcrawstruct.cc:96
 hmdcrawstruct.cc:97
 hmdcrawstruct.cc:98
 hmdcrawstruct.cc:99
 hmdcrawstruct.cc:100
 hmdcrawstruct.cc:101
 hmdcrawstruct.cc:102
 hmdcrawstruct.cc:103
 hmdcrawstruct.cc:104
 hmdcrawstruct.cc:105
 hmdcrawstruct.cc:106
 hmdcrawstruct.cc:107
 hmdcrawstruct.cc:108
 hmdcrawstruct.cc:109
 hmdcrawstruct.cc:110
 hmdcrawstruct.cc:111
 hmdcrawstruct.cc:112
 hmdcrawstruct.cc:113
 hmdcrawstruct.cc:114
 hmdcrawstruct.cc:115
 hmdcrawstruct.cc:116
 hmdcrawstruct.cc:117
 hmdcrawstruct.cc:118
 hmdcrawstruct.cc:119
 hmdcrawstruct.cc:120
 hmdcrawstruct.cc:121
 hmdcrawstruct.cc:122
 hmdcrawstruct.cc:123
 hmdcrawstruct.cc:124
 hmdcrawstruct.cc:125
 hmdcrawstruct.cc:126
 hmdcrawstruct.cc:127
 hmdcrawstruct.cc:128
 hmdcrawstruct.cc:129
 hmdcrawstruct.cc:130
 hmdcrawstruct.cc:131
 hmdcrawstruct.cc:132
 hmdcrawstruct.cc:133
 hmdcrawstruct.cc:134
 hmdcrawstruct.cc:135
 hmdcrawstruct.cc:136
 hmdcrawstruct.cc:137
 hmdcrawstruct.cc:138
 hmdcrawstruct.cc:139
 hmdcrawstruct.cc:140
 hmdcrawstruct.cc:141
 hmdcrawstruct.cc:142
 hmdcrawstruct.cc:143
 hmdcrawstruct.cc:144
 hmdcrawstruct.cc:145
 hmdcrawstruct.cc:146
 hmdcrawstruct.cc:147
 hmdcrawstruct.cc:148
 hmdcrawstruct.cc:149
 hmdcrawstruct.cc:150
 hmdcrawstruct.cc:151
 hmdcrawstruct.cc:152
 hmdcrawstruct.cc:153
 hmdcrawstruct.cc:154
 hmdcrawstruct.cc:155
 hmdcrawstruct.cc:156
 hmdcrawstruct.cc:157
 hmdcrawstruct.cc:158
 hmdcrawstruct.cc:159
 hmdcrawstruct.cc:160
 hmdcrawstruct.cc:161
 hmdcrawstruct.cc:162
 hmdcrawstruct.cc:163
 hmdcrawstruct.cc:164
 hmdcrawstruct.cc:165
 hmdcrawstruct.cc:166
 hmdcrawstruct.cc:167
 hmdcrawstruct.cc:168
 hmdcrawstruct.cc:169
 hmdcrawstruct.cc:170
 hmdcrawstruct.cc:171
 hmdcrawstruct.cc:172
 hmdcrawstruct.cc:173
 hmdcrawstruct.cc:174
 hmdcrawstruct.cc:175
 hmdcrawstruct.cc:176
 hmdcrawstruct.cc:177
 hmdcrawstruct.cc:178
 hmdcrawstruct.cc:179
 hmdcrawstruct.cc:180
 hmdcrawstruct.cc:181
 hmdcrawstruct.cc:182
 hmdcrawstruct.cc:183
 hmdcrawstruct.cc:184
 hmdcrawstruct.cc:185
 hmdcrawstruct.cc:186
 hmdcrawstruct.cc:187
 hmdcrawstruct.cc:188
 hmdcrawstruct.cc:189
 hmdcrawstruct.cc:190
 hmdcrawstruct.cc:191
 hmdcrawstruct.cc:192
 hmdcrawstruct.cc:193
 hmdcrawstruct.cc:194
 hmdcrawstruct.cc:195
 hmdcrawstruct.cc:196
 hmdcrawstruct.cc:197
 hmdcrawstruct.cc:198
 hmdcrawstruct.cc:199
 hmdcrawstruct.cc:200
 hmdcrawstruct.cc:201
 hmdcrawstruct.cc:202
 hmdcrawstruct.cc:203
 hmdcrawstruct.cc:204
 hmdcrawstruct.cc:205
 hmdcrawstruct.cc:206
 hmdcrawstruct.cc:207
 hmdcrawstruct.cc:208
 hmdcrawstruct.cc:209
 hmdcrawstruct.cc:210
 hmdcrawstruct.cc:211