#include <iostream>
#include <string>

#include "BField/BField.h"
#include "CandFitTrackSR/BFieldSR.h"
#include "Conventions/Detector.h"
#include "Validity/VldContext.h"
#include "MessageService/MsgService.h"
#include <cassert>

//______________________________________________________________________
CVSID("$Id: BFieldSR.cxx,v 1.8 2007/11/11 08:44:45 rhatcher Exp $");

//------------------------------------------------------------------
BFieldSR::BFieldSR(const VldContext *vldc)
{

  bf = 0;
  switch (vldc->GetDetector()) {
  case Detector::kFar:
    bf = new BField(*vldc);
    break;
  case Detector::kNear:
    bf = new BField(*vldc);
    break;
  default:
     MSG("CandFitTrackSR",Msg::kWarning)
        << "BFieldSR does not exist for "
        << Detector::AsString(vldc->GetDetector())
        << " detector " << endl;
  }
}

BFieldSR::~BFieldSR()
{
  if (bf) {
    delete bf;
  }
}

TVector3 BFieldSR::GetBField(TVector3 &xyz)
{
  if (bf) 
    return bf->GetBField(xyz);
  else
    return TVector3(0.,0.,0.);
}
