#include "htofcalibrater.h"
#include "hcategory.h"
#include "hlocation.h"
#include  "htofraw.h"
#include "htofcal.h"
#include "hdebug.h"
#include "hades.h"
#include "hiterator.h"
#include "htofcalpar.h"
#include "tofdef.h"
#include "hruntimedb.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hevent.h"
ClassImp(HTofCalibrater)
void HTofCalibrater::initParContainer() {
  fCalPar=(HTofCalPar *)gHades->getRuntimeDb()->getContainer("TofCalPar");
}
Bool_t HTofCalibrater::init(void) {
  fRawCat=gHades->getCurrentEvent()->getCategory(catTofRaw);
  if (!fRawCat) {
    fRawCat=gHades->getSetup()->getDetector("Tof")->buildCategory(catTofRaw);
    if (!fRawCat) return kFALSE;
    else gHades->getCurrentEvent()->addCategory(catTofRaw,fRawCat,"Tof");
  }
  fCalCat=gHades->getCurrentEvent()->getCategory(catTofCal);
  if (!fCalCat) {
    fCalCat=gHades->getSetup()->getDetector("Tof")->buildCategory(catTofCal);
    if (!fCalCat) return kFALSE;
    else gHades->getCurrentEvent()->addCategory(catTofCal,fCalCat,"Tof");
  }
  fIter=(HIterator *)fRawCat->MakeIterator();
  fLoc.set(3,0,0,0);
  fActive=kTRUE;
  initParContainer();
  return kTRUE;
}
HTofCalibrater::HTofCalibrater(void) {
  fCalPar=NULL;
  fRawCat=fCalCat=NULL;
  fIter=NULL;
}
HTofCalibrater::HTofCalibrater(const Text_t *name,const Text_t *title) :
  HReconstructor(name,title)
{
  fCalPar=NULL;
  fRawCat=fCalCat=NULL;
  fIter=NULL;  
}
HTofCalibrater::~HTofCalibrater(void) {
  if (fCalPar) delete fCalPar;
}
HTofCalibrater &HTofCalibrater::operator=(HTofCalibrater &c) {
  fCalPar=c.fCalPar;
  fRawCat=c.fRawCat;
  fCalCat=c.fCalCat;
  return c;
}
Int_t HTofCalibrater::execute(void) {  
#if DEBUG_LEVEL>2
  gDebuger->enterFunc("TofCalibrater::execute");
  gDebuger->message("Raw cat points to %p",fRawCat);
#endif
  
  return 0;
}