00001 #include "emcCalibrationData.h"
00002 #include "emcObjectManagerRegister.h"
00003 #include "emcRawDataAccessor.h"
00004 #include "EmcStaticData.h"
00005 #include "EmcIndexer.h"
00006 #include "EmcSector.h"
00007
00008 #include "emcObjectManager.h"
00009
00014 class emcOMIniCalConstruction : public emcObjectManager
00015 {
00016 public:
00017 emcOMIniCalConstruction(const char* name="", const char* title="");
00018 virtual ~emcOMIniCalConstruction();
00019
00020 virtual bool CanCollect(const emcManageable&) const { return false; }
00021
00022 virtual bool CanRead(const emcManageable& object) const;
00023
00024 virtual bool CanWrite(const emcManageable&) const { return false; }
00025
00026 virtual emcManageable* Collect(const emcManageable&,
00027 const PHTimeStamp&) { return 0; }
00028
00029 bool GetTypeAndNumber(int id, size_t& type,
00030 size_t& number) const;
00031
00032 int GetID(size_t type, size_t number);
00033
00034 using emcObjectManager::Read;
00035
00036 virtual bool Read(emcManageable& object,
00037 const PHTimeStamp& time_stamp,
00038 int id);
00039
00040 virtual void Reset(void);
00041
00042 virtual bool Write(const emcManageable&, const PHTimeStamp&, int)
00043 { return false; }
00044 };
00045
00046 using namespace std;
00047
00048 namespace
00049 {
00050 emcOMIniCalConstruction gemcOMIniCalConstruction(
00051 "Construction DB:emcOMIniCalConstruction",
00052 "Very specific OM to read inical PbSc calibrations from Construction DB");
00053 }
00054
00055
00056 emcOMIniCalConstruction::emcOMIniCalConstruction(const char* name, const char* title) : emcObjectManager(name,title)
00057 {
00058 }
00059
00060
00061 emcOMIniCalConstruction::~emcOMIniCalConstruction()
00062 {
00063 }
00064
00065
00066 bool
00067 emcOMIniCalConstruction::CanRead(const emcManageable& object) const
00068 {
00069 bool rv = false;
00070 const emcManageable* object_ptr = &object;
00071 const emcCalibrationData* test =
00072 dynamic_cast<const emcCalibrationData*>(object_ptr);
00073
00074 if (test && object.GetSource() == emcManageable::kDB_Construction)
00075 {
00076 rv = true;
00077 }
00078
00079 return rv;
00080 }
00081
00082
00083 bool
00084 emcOMIniCalConstruction::GetTypeAndNumber(int id,
00085 size_t& type, size_t& number) const
00086 {
00087
00088
00089
00090
00091 type = ( id & 0xFF000000 ) >> 24;
00092 number = ( id & 0xFFFFFF );
00093
00094 return true;
00095 }
00096
00097
00098 int
00099 emcOMIniCalConstruction::GetID(size_t type, size_t number)
00100 {
00101
00102
00103
00104
00105 int id;
00106
00107 id = ( ( type << 24 ) & ( 0xFF000000 ) ) + ( number & 0xFFFFFF );
00108
00109 return id;
00110 }
00111
00112
00113 bool
00114 emcOMIniCalConstruction::Read(emcManageable& object,
00115 const PHTimeStamp& ,
00116 int id)
00117 {
00118 emcCalibrationData& cal = static_cast<emcCalibrationData&>(object);
00119
00120 cal.Reset();
00121
00122 size_t type;
00123 size_t number;
00124
00125 if ( id >= 0 )
00126 {
00127 GetTypeAndNumber(id,type,number);
00128 if (type!=static_cast<size_t>(cal.GetType()) ||
00129 number!=cal.GetNumber())
00130 {
00131 cerr << "<W> emcOMIniCalConstruction::Read : "
00132 << "the 3rd parameter is not"
00133 << " consistent with the object you give. Might well be what "
00134 << " you want, but hum, are you really sure you know what "
00135 << " you are doing here ?! "
00136 << endl;
00137 }
00138 }
00139 else
00140 {
00141 type = cal.GetType();
00142 number = cal.GetNumber();
00143 id = GetID(type,number);
00144 }
00145
00146 cout << "emcOMIniCalConstruction::Read !!!" << endl;
00147
00148 EmcStaticData* sd = EmcStaticData::buildEmcStaticData() ;
00149
00150 if ( !sd )
00151 {
00152 cerr << "<E> emcOMIniCalConstruction::Read : "
00153 << "cannot build EmcStaticData ?!"
00154 << endl;
00155 return false;
00156 }
00157
00158 EmcSector * sector = sd->getSector(number) ;
00159
00160 if( !sector )
00161 {
00162 sd ->buildEmcSector( EmcIndexer::EmcSectorId(number));
00163 sector = sd->getSector(number) ;
00164 }
00165
00166 assert(sector->IsOK()) ;
00167
00168 int length = 2592;
00169 if ( number > 5 )
00170 {
00171 length = 4608;
00172 }
00173
00174 cal.SetTypeAndSize(static_cast<emcCalibrationData::EType>(type),length);
00175
00176 for ( int ist = 0; ist < length; ++ist )
00177 {
00178 float one,two,three;
00179 float error = 0.0;
00180 sector->GetEnergyCalibration(ist,one,two,three);
00181 cal.Set(ist,one,error,0);
00182 cal.Set(ist,two,error,1);
00183 cal.Set(ist,three,error,2);
00184 }
00185
00186 return true;
00187 }
00188
00189
00190 void
00191 emcOMIniCalConstruction::Reset()
00192 {
00193 }
00194