00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "mEmcCalibratorModule.h"
00017 #include "emcRawDataAccessor.h"
00018 #include "emcDataFormatter.h"
00019 #include "emcRawDataObject.h"
00020 #include "emcCalibratedDataObject.h"
00021 #include "emcCalibratorFactory.h"
00022 #include "emcCalibrator.h"
00023 #include "dEmcCalibTowerWrapper.h"
00024 #include "EmcDynamicData.h"
00025
00026
00027 #include "PHNode.h"
00028 #include "PHIODataNode.h"
00029 #include "PHNodeIterator.h"
00030 #include "PHDataNodeIterator.h"
00031 #include "Event.h"
00032
00033 #include <iostream>
00034
00035 using namespace std;
00036
00037
00038 mEmcCalibratorModule::mEmcCalibratorModule(const char* configfilename,
00039 const char* calibrator,
00040 emcManageable::EStorage source)
00041 {
00042
00043 name = "mEmcCalibratorModule";
00044 Init(configfilename,calibrator,source);
00045 }
00046
00047
00048 mEmcCalibratorModule::mEmcCalibratorModule(const PHTimeStamp& ts,
00049 const char* calibrator,
00050 emcManageable::EStorage source)
00051 {
00052
00053 name = "mEmcCalibratorModule";
00054 Init(ts,calibrator,source);
00055 }
00056
00057
00058 PHBoolean mEmcCalibratorModule::event(PHCompositeNode *root)
00059 {
00060 emcDataFormatter fDataFormatter;
00061 int j,arm,sector,yrow,zrow;
00062 int temp1;
00063 int type = 1;
00064 float energy,tof;
00065
00066
00067 float adc, tac;
00068
00069
00070 PHTimeStamp* when ;
00071
00072 PHNodeIterator i(root);
00073 PHDataNodeIterator DNiter(root);
00074
00075 if (fVerbose > 0)
00076 cout << "mEmcCalibrator>>> Starting..." << endl;
00077
00078
00079 if (fVerbose > 0)
00080 cout << "mEmcCalibrator>>> Getting raw data from PRDF node " << endl;
00081 PHDataNode<Event> * thisEventNode = (PHDataNode<Event>*) (i.findFirst("PHDataNode","PRDF")) ;
00082
00083
00084 if (fVerbose > 0)
00085 cout << "mEmcCalibrator>>> Getting raw data from PRDF node dstNode " << endl;
00086 PHIODataNode<PHTable>* dEmcCalibTowerNode = (PHIODataNode<PHTable>*)i.findFirst("PHIODataNode","dEmcCalibTower");
00087 dEmcCalibTowerWrapper * dEmcCalibTower = static_cast<dEmcCalibTowerWrapper*>(dEmcCalibTowerNode->getData());
00088
00089
00090 if(fVerbose>0)
00091 {
00092 cout << "mEmcCalibrator>>> Processing event ..." << endl;
00093 }
00094 fDataFormatter.fillRDO(thisEventNode->getData());
00095 if (fVerbose)
00096 {
00097 cout << "RDO size=" << fRdo->GetSize() << endl;
00098 }
00099
00100 if (!fUseTimeStamp) {
00101 when = new PHTimeStamp(thisEventNode->getData()->getTime());
00102 }
00103 else {
00104 when = &fTimeStamp ;
00105 }
00106
00107
00108 if (fVerbose > 0)
00109 cout << "mEmcCalibrator>>> Doing Calibration " << endl;
00110 PHIODataNode<emcCalibratedDataObject>* CdoNode ;
00111 CdoNode = DNiter.FindIODataNode(CdoNode,"EmcCdo") ;
00112 fCdo = CdoNode->getData();
00113 fRdc->Calibrate(*fRdo, fMdo, *when);
00114 if (fVerbose)
00115 {
00116 cout << "MDO size=" << fMdo.GetSize() << endl;
00117 }
00118
00119 fRdc->Calibrate(fMdo, *fCdo, *when);
00120
00121 if (fVerbose)
00122 {
00123 cout << "CDO size=" << fCdo->GetSize() << endl;
00124 }
00125
00126 if (fRdc->GetCollectionStatus("*")==false) {
00127 cerr << "<E><I> Disabling collection of calibration parameters !!!" << endl ;
00128 }
00129
00130 if (!fUseTimeStamp) {
00131 delete when;
00132 }
00133
00134 long softkey ;
00135 short outrow = 0 ;
00136 int dead ;
00137 int warn;
00138
00139 for(j = 0 ; j < fCdo->GetSize(); j++) {
00140
00141 fCdo->Get( j, energy, tof) ;
00142 softkey = fCdo->GetSoftwareKey(j) ;
00143 dead = fCdo->GetDead(j) ;
00144
00145
00146
00147 warn=fCdo->GetWarn(j);
00148
00149 if(energy > 0.001) {
00150 arm = softkey / 100000 ;
00151 sector = (softkey - arm * 100000) / 10000 ;
00152 temp1 = softkey - arm * 100000 - sector * 10000 ;
00153 yrow = temp1 / 100 ;
00154 zrow = temp1 - yrow * 100 ;
00155
00156
00157 dEmcCalibTower->set_id(outrow,outrow) ;
00158 dEmcCalibTower->set_hwkey(outrow,0) ;
00159 dEmcCalibTower->set_swkey(outrow,softkey) ;
00160 dEmcCalibTower->set_type(outrow,type) ;
00161 dEmcCalibTower->set_arm(outrow,arm) ;
00162 dEmcCalibTower->set_sector(outrow,sector) ;
00163 dEmcCalibTower->set_ind(1,outrow,yrow) ;
00164 dEmcCalibTower->set_ind(0,outrow,zrow) ;
00165 dEmcCalibTower->set_ecal(outrow,energy) ;
00166 dEmcCalibTower->set_tof(outrow,tof) ;
00167 dEmcCalibTower->set_deadmap(outrow,dead) ;
00168
00169 dEmcCalibTower->set_warnmap(outrow, warn);
00170
00171
00172 int towerID=fCdo->GetItemId(j);
00173 fIndexMapIter=fIndexMap.find(towerID);
00174 if(fIndexMapIter == fIndexMap.end()){
00175
00176 cerr<<"<E>: mEmcCalibratorModule::Event(): index for towerID="<<towerID<<" not found"<<endl;
00177 adc=0.;
00178 tac=0.;
00179
00180 } else{
00181
00182 int index=fIndexMap[towerID];
00183 fMdo.Get(index, adc, tac);
00184
00185 }
00186
00187 dEmcCalibTower->set_adc(outrow, adc);
00188 dEmcCalibTower->set_tac(outrow, tac);
00189
00190 outrow++ ;
00191
00192 if (fVerbose>1) {
00193 cout << "dEmcCalibTower(id,hwkey,swkey,type,arm,sector,yrow,zrow,ecal,tof, adc, tac) = ("
00194 << outrow << "," << 0 << ","
00195 << softkey<< ","
00196 << type << ","
00197 << arm << ","
00198 << sector<< ","
00199 << yrow<< ","
00200 << zrow<< ","
00201 << energy<< ","
00202 << tof<<","
00203 << adc<<","
00204 << tac<<")"
00205 << endl;
00206 }
00207 }
00208 }
00209 dEmcCalibTower->SetRowCount(outrow);
00210
00211 if ( fVerbose )
00212 {
00213 cout << "dEmcCalibTower size=" << outrow << endl;
00214 }
00215 return true;
00216 }
00217
00218
00219 bool mEmcCalibratorModule::Init(const char* configfilename,
00220 const char* calibrator,
00221 emcManageable::EStorage source )
00222 {
00223 int emc_status ;
00224 fVerbose = 0 ;
00226 fRda = emcRawDataAccessor::GetInstance(emc_status, configfilename);
00227 if (!fRda) return false ;
00228 return Config(calibrator,source) ;
00229 }
00230
00231
00232 bool mEmcCalibratorModule::Init(const PHTimeStamp& ts,
00233 const char* calibrator,
00234 emcManageable::EStorage source )
00235 {
00236 fVerbose = 0 ;
00238 fRda = emcRawDataAccessor::GetInstance(ts) ;
00239 if (!fRda) return false ;
00240 return Config(calibrator,source) ;
00241 }
00242
00243
00244
00245 bool mEmcCalibratorModule::Config(const char* calibrator,
00246 emcManageable::EStorage source )
00247 {
00248
00249 cout<<"<mEmcCalibratorModule::Config> Calibrator: "<<calibrator<<" Data Source "<<source<<endl;
00251 emcCalibratorFactory::Initialize(calibrator) ;
00253 fRdc = emcCalibratorFactory::GetCalibrator() ;
00254 if (!fRdc) return false ;
00256 SelectSource(source) ;
00257 SetHighLowLimit() ;
00258 SetZeroSuppression() ;
00259 fMdo.UseHGLG(true) ;
00260 fRdo = fRda->GetRawDataObject() ;
00261
00262
00263 EmcDynamicData *dynamicData = fRda->GetDynamicData();
00264 int* dataMap=dynamicData->getEmcMap();
00265 int nchannel=dynamicData->getEmcSize();
00266
00267 for(int ind=0; ind<nchannel; ind++) fIndexMap[dataMap[ind]]=ind;
00268
00269 fUseTimeStamp = false ;
00270 fTimeStamp.setToFarFuture() ;
00271
00272 return true ;
00273 }
00274
00275
00276 void mEmcCalibratorModule::SelectSource(emcManageable::EStorage source)
00277 {
00278 fRdc->SelectSource("*", source) ;
00279 }
00280
00281
00282 bool mEmcCalibratorModule::SetCalibrator(const char* calibrator)
00283 {
00284 if (fRdc) {
00285 emcCalibratorFactory::Initialize(calibrator) ;
00287 fRdc = emcCalibratorFactory::GetCalibrator() ;
00288 if (!fRdc) return false ;
00289 return true ;
00290 }
00291 else {
00292 return false ;
00293 }
00294 }
00295
00296
00297 bool mEmcCalibratorModule::SetHighLowLimit(int limit)
00298 {
00299 if (fRdc) {
00300 fHighLowLimit = limit ;
00301 fRdc->SetHighLowLimit(fHighLowLimit) ;
00302 return true ;
00303 }
00304 else {
00305 return false ;
00306 }
00307 }
00308
00309
00310 bool mEmcCalibratorModule::SetZeroSuppression(bool val)
00311 {
00312 if (fRdc) {
00313 fZeroSuppression = val ;
00314 fRdc->SetZeroSuppression(fZeroSuppression) ;
00315 return true ;
00316 }
00317 else {
00318 return false ;
00319 }
00320 }
00321
00322
00323 void
00324 mEmcCalibratorModule::UseTimeStamp(const PHTimeStamp& when)
00325 {
00326 fTimeStamp = when ;
00327 fUseTimeStamp = true ;
00328 }
00329
00330
00331 void
00332 mEmcCalibratorModule::ForceDBCollection()
00333 {
00334 if ( !fRdc )
00335 {
00336 cerr << "<E> mEmcCalibratorModule::ForceDBCollection : uh ? fRdc is "
00337 << " null ?! That's bad, will crash sooner or later"
00338 << endl;
00339 return;
00340 }
00341
00342 cout << "<I> mEmcCalibratorModule::ForceDBCollection TimeStamp="
00343 << fTimeStamp
00344 << endl;
00345
00346 fRdc->ForceDBCollection(fTimeStamp);
00347 }