00001 // Author: Laurent Aphecetche (aphecetc@in2p3.fr) 00002 // <EK> 111302 - Included reference to emcRawDataCalibratorv2 - Run3 00003 #include "emcCalibratorFactory.h" 00004 #include "emcCalibrator.h" 00005 00006 #include "emcRawDataCalibrator.h" 00007 #include "emcRawDataCalibratorV1.h" 00008 #include "emcRawDataCalibratorV2.h" 00009 #include <string> 00010 #include <iostream> 00011 #include <cassert> 00012 00013 using namespace std; 00014 00015 emcCalibrator* emcCalibratorFactory::fCalibrator = 0 ; 00016 00017 //_____________________________________________________________________________ 00018 emcCalibratorFactory::~emcCalibratorFactory() 00019 { 00020 } 00021 00022 //_____________________________________________________________________________ 00023 emcCalibrator* emcCalibratorFactory::GetCalibrator(void) 00024 { 00025 if (!fCalibrator) { 00026 cerr << "<E> emcCalibratorFactory::GetCalibrator : Factory has not " 00027 << " been initialized. Please call " 00028 << " emcCalibratorFactory::Initialize first. " << endl ; 00029 } 00030 00031 return fCalibrator ; 00032 } 00033 00034 //_____________________________________________________________________________ 00035 bool emcCalibratorFactory::Initialize(const char* calibrator_classname) 00036 { 00037 bool ok = false ; 00038 string newname = calibrator_classname ; 00039 string oldname ; 00040 00041 if (fCalibrator) { 00042 oldname = fCalibrator->GetName() ; 00043 if ( oldname != newname ) { 00044 cout << "<W> emcCalibratorFactory::Initialize : You requested " << endl 00045 << " a different calibrator type. " << endl 00046 << " I'm switching from :" << oldname << endl 00047 << " to : " << newname << endl ; 00048 } 00049 delete fCalibrator ; 00050 fCalibrator = 0 ; 00051 } 00052 00053 assert(fCalibrator==0) ; 00054 00055 if ( newname != "emcRawDataCalibrator" && 00056 newname != "emcRawDataCalibratorV1" && 00057 newname != "emcRawDataCalibratorV2") { 00058 cerr << "<E> emcCalibratorFactory::Initialize : Wrong calibrator type." 00059 << endl 00060 << "Initialization failed." << endl ; 00061 } 00062 else { 00063 if ( newname == "emcRawDataCalibrator") { 00064 fCalibrator = new emcRawDataCalibrator() ; 00065 ok=true ; 00066 } 00067 else if ( newname == "emcRawDataCalibratorV1") { 00068 fCalibrator = new emcRawDataCalibratorV1() ; 00069 ok=true; 00070 } 00071 else if ( newname == "emcRawDataCalibratorV2") { 00072 fCalibrator = new emcRawDataCalibratorV2() ; 00073 ok=true; 00074 } 00075 } 00076 return ok ; 00077 } 00078