ROOT logo
//*-- AUTHOR : Ilse Koenig
//*-- Modified : 05/09/2002 by P. Zumbruch
//*-- Modified : 11/12/2001 by I. Koenig
//*-- Modified : 21/02/2000 by R. Holzmann
//*-- Modified : 27/05/99   by I. Koenig

//_HADES_CLASS_DESCRIPTION
/////////////////////////////////////////////////////////////
//HMdcDetector
//
//  class for detector Mdc
//  stores the actual setup in a linear array of 24 modules;
//
/////////////////////////////////////////////////////////////

#include <stdio.h>
#include "hmdcdetector.h"
#include "hmdcdef.h"
#include "hades.h"
#include "hruntimedb.h"
#include "hpario.h"
#include "hparrootfileio.h"
#include "hdetpario.h"
#include "hmdcparrootfileio.h"
#include "hparasciifileio.h"
#include "hmdcparasciifileio.h"
#include "hmdcrawstruct.h"
#include "hmdcgeomstruct.h"
#include "hcategory.h"
#include "hlinearcategory.h"
#include "hmatrixcategory.h"
#include "hmessagemgr.h"
#include "TClass.h"

ClassImp(HMdcDetector)

HMdcDetector::HMdcDetector() {
  // constructor
  fName="Mdc";
  maxModules=4;
  maxComponents=6;
  modules= new TArrayI(24);
}

HMdcDetector::~HMdcDetector() {
  // destructor
  delete modules;
  modules=0;
}

Bool_t HMdcDetector::init(void) {
  HRuntimeDb* rtdb=gHades->getRuntimeDb();
  HParSet* pg =rtdb->getContainer("MdcGeomStruct");
  HParSet* pg2=rtdb->getContainer("MdcRawStruct");

  if (!pg->init()|| !pg2->init()) return kFALSE;
  return kTRUE;
}

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


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


HCategory* HMdcDetector::buildLinearCategory(const Text_t* className) {
		HLinearCategory* category;
  if (strcmp(className,"HMdcRawEventHeader")==0) {
    Int_t size=6*4*5*2; //sector*module*roc*10
    category = new HLinearCategory(className,size);
    if (!category) return NULL;
  } else
	if(strcmp(className,"HMdcOepStatusData")==0) {
		Int_t size = 6*4*16;  // sector * module * mbo
		category = new HLinearCategory(className,size);
		if(!category) return NULL;
		} else {
    gHades->getMsg()->warning(10,HMessageMgr::DET_MDC,GetName()
			,"buildLinearCategory for %s not implemented"
			,className);
    return 0;
  }
  if ((strcmp(className,"HMdcRawEventHeader")==0) || (strcmp(className,"HMdcOepStatusData") == 0))
	{
		category->setPersistency(kFALSE);
	}
	return category;

}


HCategory* HMdcDetector::buildMatrixCategory(const Text_t* className,Float_t fillRate) {
  TArrayI* ind=0;
  Int_t nSizes;
  Int_t* sizes=0;
  HRuntimeDb *rtdb = gHades->getRuntimeDb();
  if (!rtdb) return NULL;

  if (strcmp(className,"HMdcRaw")==0 ||
      strcmp(className,"HMdcRawCor")==0 ||
      strcmp(className,"HMdcSlopes")==0
     )
    {
      ind=new TArrayI(4);
      HMdcRawStruct* p;
      if (!(p = (HMdcRawStruct*) rtdb->getContainer("MdcRawStruct"))) return NULL;
      p->getMaxIndices(ind);
      nSizes=ind->GetSize();
      sizes=new Int_t[nSizes];
      for (Int_t i=0;i<nSizes;i++) sizes[i]=ind->At(i)+1;
    }
  else if (strcmp(className,"HMdcDataword")==0)
    {
      ind=new TArrayI(4);
      HMdcRawStruct* p;
      if (!(p = (HMdcRawStruct*) rtdb->getContainer("MdcRawStruct"))) return NULL;
      p->getMaxIndices(ind);
      nSizes=ind->GetSize();
      sizes=new Int_t[nSizes+1];
      for (Int_t i=0;i<nSizes-1;i++) sizes[i]=ind->At(i)+1;
      sizes[nSizes-1]=8;
      nSizes++;
    }
    else if(strcmp(className,"HMdcOepStatusData")==0)
		{
			ind=new TArrayI(4);
			HMdcRawStruct* p;
      if (!(p = (HMdcRawStruct*) rtdb->getContainer("MdcRawStruct"))) return NULL;
      p->getMaxIndices(ind);
      nSizes=ind->GetSize()-1;
      sizes=new Int_t[nSizes];
			for (Int_t i=0;i<nSizes;i++) sizes[i]=ind->At(i)+1;
		}
		else
		{
      ind=new TArrayI(4);
      HMdcGeomStruct* p;
      if (!(p = (HMdcGeomStruct*) rtdb->getContainer("MdcGeomStruct"))) return NULL;
      p->getMaxIndices(ind);

      if (strcmp(className,"HMdcCal1")==0 ||
	  strcmp(className,"HMdcCal2")==0 ||
	  strcmp(className,"HMdcGeantCell")==0 ||
	  strcmp(className,"HMdcCal1Sim")==0 ||
	  strcmp(className,"HMdcCal2Sim")==0)
        {
	    nSizes=ind->GetSize();
	    sizes=new Int_t[nSizes];
	    for (Int_t i=0;i<nSizes;i++) sizes[i]=ind->At(i)+1;
        }
      else if (strcmp(className, "HMdcTrkCand")==0 ||
	       strcmp(className, "HMdcTrkCandIdeal")==0)
        {
          nSizes=2;
          sizes=new Int_t[nSizes];
          sizes[0] = ind->At(0) + 1;
          sizes[1] = 8000;
        }
     else
       {
	   nSizes=ind->GetSize()-1;
	   sizes=new Int_t[nSizes];
	   sizes[nSizes-1] = 8000;

	   if (strcmp(className, "HMdcSeg")==0 ||
	       strcmp(className, "HMdcSegSim")==0 ||
	       strcmp(className, "HMdcSegIdeal")==0 )
	     {
		 sizes[0] = ind->At(0) + 1;
		 sizes[1] = (ind->At(1) / 2) + 1;
	     }
	   else if (strcmp(className, "HMdcHit")==0 ||
		    strcmp(className, "HMdcHitSim")==0 ||
		    strcmp(className, "HMdcHitIdeal")==0)
	     {
		 for (Int_t i=0;i<nSizes-1;i++) sizes[i]=ind->At(i)+1;
	     }
	   else
	     {
		 Error("buildMatrixCategory","Class %s not supported",className);
		 return NULL;
	     }
       }
    }

  HMatrixCategory* category = new HMatrixCategory(className,nSizes,sizes,fillRate);

  if (ind) delete ind;
  delete [] sizes;

  if ((strcmp(className,"HMdcDataword")==0) || (strcmp(className,"HMdcOepStatusData")==0))
    {
      category->setPersistency(kFALSE);
    }

  return category;
}

HCategory* HMdcDetector::buildCategory(Cat_t cat) {
  // builds the default categories (here MatrixCategories)
  switch (cat)
    {
    case catMdcRaw :            return buildMatrixCategory("HMdcRaw",0.5);
    case catMdcRawCor :         return buildMatrixCategory("HMdcRawCor",0.5);
    case catMdcCal1 :           return buildMatrixCategory("HMdcCal1",0.5);
    case catMdcCal2 :           return buildMatrixCategory("HMdcCal2",0.5);
    case catMdcGeantCell :      return buildMatrixCategory("HMdcGeantCell",0.5);
    case catMdcHit :            return buildMatrixCategory("HMdcHit",0.5);
    case catMdcSeg :            return buildMatrixCategory("HMdcSeg",0.5);
    case catMdcTrkCand :        return buildMatrixCategory("HMdcTrkCand",0.5);
    case catMdcHitIdeal :       return buildMatrixCategory("HMdcHitIdeal",0.5);
    case catMdcSegIdeal :       return buildMatrixCategory("HMdcSegIdeal",0.5);
    case catMdcTrkCandIdeal :   return buildMatrixCategory("HMdcTrkCandIdeal",0.5);
    case catMdcRawEventHeader : return buildLinearCategory("HMdcRawEventHeader");
    case catMdcDataWord:        return buildMatrixCategory("HMdcDataword",0.1);
    case catMdcSlope :          return buildMatrixCategory("HMdcSlopes",0.5);
    case catMdcOepStatus :      return buildMatrixCategory("HMdcOepStatusData",0.5);
    default : return NULL;
    }
}
 hmdcdetector.cc:1
 hmdcdetector.cc:2
 hmdcdetector.cc:3
 hmdcdetector.cc:4
 hmdcdetector.cc:5
 hmdcdetector.cc:6
 hmdcdetector.cc:7
 hmdcdetector.cc:8
 hmdcdetector.cc:9
 hmdcdetector.cc:10
 hmdcdetector.cc:11
 hmdcdetector.cc:12
 hmdcdetector.cc:13
 hmdcdetector.cc:14
 hmdcdetector.cc:15
 hmdcdetector.cc:16
 hmdcdetector.cc:17
 hmdcdetector.cc:18
 hmdcdetector.cc:19
 hmdcdetector.cc:20
 hmdcdetector.cc:21
 hmdcdetector.cc:22
 hmdcdetector.cc:23
 hmdcdetector.cc:24
 hmdcdetector.cc:25
 hmdcdetector.cc:26
 hmdcdetector.cc:27
 hmdcdetector.cc:28
 hmdcdetector.cc:29
 hmdcdetector.cc:30
 hmdcdetector.cc:31
 hmdcdetector.cc:32
 hmdcdetector.cc:33
 hmdcdetector.cc:34
 hmdcdetector.cc:35
 hmdcdetector.cc:36
 hmdcdetector.cc:37
 hmdcdetector.cc:38
 hmdcdetector.cc:39
 hmdcdetector.cc:40
 hmdcdetector.cc:41
 hmdcdetector.cc:42
 hmdcdetector.cc:43
 hmdcdetector.cc:44
 hmdcdetector.cc:45
 hmdcdetector.cc:46
 hmdcdetector.cc:47
 hmdcdetector.cc:48
 hmdcdetector.cc:49
 hmdcdetector.cc:50
 hmdcdetector.cc:51
 hmdcdetector.cc:52
 hmdcdetector.cc:53
 hmdcdetector.cc:54
 hmdcdetector.cc:55
 hmdcdetector.cc:56
 hmdcdetector.cc:57
 hmdcdetector.cc:58
 hmdcdetector.cc:59
 hmdcdetector.cc:60
 hmdcdetector.cc:61
 hmdcdetector.cc:62
 hmdcdetector.cc:63
 hmdcdetector.cc:64
 hmdcdetector.cc:65
 hmdcdetector.cc:66
 hmdcdetector.cc:67
 hmdcdetector.cc:68
 hmdcdetector.cc:69
 hmdcdetector.cc:70
 hmdcdetector.cc:71
 hmdcdetector.cc:72
 hmdcdetector.cc:73
 hmdcdetector.cc:74
 hmdcdetector.cc:75
 hmdcdetector.cc:76
 hmdcdetector.cc:77
 hmdcdetector.cc:78
 hmdcdetector.cc:79
 hmdcdetector.cc:80
 hmdcdetector.cc:81
 hmdcdetector.cc:82
 hmdcdetector.cc:83
 hmdcdetector.cc:84
 hmdcdetector.cc:85
 hmdcdetector.cc:86
 hmdcdetector.cc:87
 hmdcdetector.cc:88
 hmdcdetector.cc:89
 hmdcdetector.cc:90
 hmdcdetector.cc:91
 hmdcdetector.cc:92
 hmdcdetector.cc:93
 hmdcdetector.cc:94
 hmdcdetector.cc:95
 hmdcdetector.cc:96
 hmdcdetector.cc:97
 hmdcdetector.cc:98
 hmdcdetector.cc:99
 hmdcdetector.cc:100
 hmdcdetector.cc:101
 hmdcdetector.cc:102
 hmdcdetector.cc:103
 hmdcdetector.cc:104
 hmdcdetector.cc:105
 hmdcdetector.cc:106
 hmdcdetector.cc:107
 hmdcdetector.cc:108
 hmdcdetector.cc:109
 hmdcdetector.cc:110
 hmdcdetector.cc:111
 hmdcdetector.cc:112
 hmdcdetector.cc:113
 hmdcdetector.cc:114
 hmdcdetector.cc:115
 hmdcdetector.cc:116
 hmdcdetector.cc:117
 hmdcdetector.cc:118
 hmdcdetector.cc:119
 hmdcdetector.cc:120
 hmdcdetector.cc:121
 hmdcdetector.cc:122
 hmdcdetector.cc:123
 hmdcdetector.cc:124
 hmdcdetector.cc:125
 hmdcdetector.cc:126
 hmdcdetector.cc:127
 hmdcdetector.cc:128
 hmdcdetector.cc:129
 hmdcdetector.cc:130
 hmdcdetector.cc:131
 hmdcdetector.cc:132
 hmdcdetector.cc:133
 hmdcdetector.cc:134
 hmdcdetector.cc:135
 hmdcdetector.cc:136
 hmdcdetector.cc:137
 hmdcdetector.cc:138
 hmdcdetector.cc:139
 hmdcdetector.cc:140
 hmdcdetector.cc:141
 hmdcdetector.cc:142
 hmdcdetector.cc:143
 hmdcdetector.cc:144
 hmdcdetector.cc:145
 hmdcdetector.cc:146
 hmdcdetector.cc:147
 hmdcdetector.cc:148
 hmdcdetector.cc:149
 hmdcdetector.cc:150
 hmdcdetector.cc:151
 hmdcdetector.cc:152
 hmdcdetector.cc:153
 hmdcdetector.cc:154
 hmdcdetector.cc:155
 hmdcdetector.cc:156
 hmdcdetector.cc:157
 hmdcdetector.cc:158
 hmdcdetector.cc:159
 hmdcdetector.cc:160
 hmdcdetector.cc:161
 hmdcdetector.cc:162
 hmdcdetector.cc:163
 hmdcdetector.cc:164
 hmdcdetector.cc:165
 hmdcdetector.cc:166
 hmdcdetector.cc:167
 hmdcdetector.cc:168
 hmdcdetector.cc:169
 hmdcdetector.cc:170
 hmdcdetector.cc:171
 hmdcdetector.cc:172
 hmdcdetector.cc:173
 hmdcdetector.cc:174
 hmdcdetector.cc:175
 hmdcdetector.cc:176
 hmdcdetector.cc:177
 hmdcdetector.cc:178
 hmdcdetector.cc:179
 hmdcdetector.cc:180
 hmdcdetector.cc:181
 hmdcdetector.cc:182
 hmdcdetector.cc:183
 hmdcdetector.cc:184
 hmdcdetector.cc:185
 hmdcdetector.cc:186
 hmdcdetector.cc:187
 hmdcdetector.cc:188
 hmdcdetector.cc:189
 hmdcdetector.cc:190
 hmdcdetector.cc:191
 hmdcdetector.cc:192
 hmdcdetector.cc:193
 hmdcdetector.cc:194
 hmdcdetector.cc:195
 hmdcdetector.cc:196
 hmdcdetector.cc:197
 hmdcdetector.cc:198
 hmdcdetector.cc:199
 hmdcdetector.cc:200
 hmdcdetector.cc:201
 hmdcdetector.cc:202
 hmdcdetector.cc:203
 hmdcdetector.cc:204
 hmdcdetector.cc:205
 hmdcdetector.cc:206
 hmdcdetector.cc:207
 hmdcdetector.cc:208
 hmdcdetector.cc:209
 hmdcdetector.cc:210
 hmdcdetector.cc:211
 hmdcdetector.cc:212
 hmdcdetector.cc:213
 hmdcdetector.cc:214
 hmdcdetector.cc:215
 hmdcdetector.cc:216
 hmdcdetector.cc:217
 hmdcdetector.cc:218
 hmdcdetector.cc:219
 hmdcdetector.cc:220
 hmdcdetector.cc:221
 hmdcdetector.cc:222
 hmdcdetector.cc:223
 hmdcdetector.cc:224
 hmdcdetector.cc:225
 hmdcdetector.cc:226
 hmdcdetector.cc:227
 hmdcdetector.cc:228
 hmdcdetector.cc:229
 hmdcdetector.cc:230
 hmdcdetector.cc:231
 hmdcdetector.cc:232
 hmdcdetector.cc:233
 hmdcdetector.cc:234
 hmdcdetector.cc:235
 hmdcdetector.cc:236
 hmdcdetector.cc:237
 hmdcdetector.cc:238
 hmdcdetector.cc:239
 hmdcdetector.cc:240