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) {
strcpy(detName,"Spectrometer");
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() {
if (cave) delete cave;
if (sectors) {
sectors->Delete();
delete sectors;
}
if (targets) {
targets->Delete();
delete targets;
}
}
Int_t HSpecGeomPar::getNumSectors() {
if (sectors) return (sectors->GetSize());
return 0;
}
Int_t HSpecGeomPar::getNumTargets() {
if (targets) return (targets->GetEntries());
return 0;
}
HGeomVolume* HSpecGeomPar::getSector(const Int_t n) {
if (sectors) return (HGeomVolume*)sectors->At(n);
return 0;
}
HGeomVolume* HSpecGeomPar::getTarget(const Int_t n) {
if (targets) return (HGeomVolume*)targets->At(n);
return 0;
}
void HSpecGeomPar::createTargets(const Int_t n) {
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) {
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) {
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) {
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) {
HDetParIo* input=inp->getDetParIo("HSpecParIo");
if (input) return (input->init(this,set));
return kFALSE;
}
Int_t HSpecGeomPar::write(HParIo* output) {
HDetParIo* out=output->getDetParIo("HSpecParIo");
if (out) return out->write(this);
return -1;
}
void HSpecGeomPar::clear() {
if (targets) {
targets->Delete();
delete targets;
targets=0;
}
status=kFALSE;
resetInputVersions();
}
void HSpecGeomPar::printParam() {
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) {
return (Int_t)(name[3]-'0')-1;
}
Int_t HSpecGeomPar::getTargetIndex(const Text_t* name) {
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;
}
Last change: Sat May 22 13:14:23 2010
Last generated: 2010-05-22 13:14
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.