00001 #include <cstdlib>
00002
00003 #include "AlgDataQuality.h"
00004
00005 #include "Algorithm/AlgConfig.h"
00006 #include "Algorithm/AlgFactory.h"
00007 #include "Algorithm/AlgHandle.h"
00008 #include "CandData/CandRecord.h"
00009 #include "Candidate/CandContext.h"
00010 #include "MessageService/MsgService.h"
00011 #include "MinosObjectMap/MomNavigator.h"
00012
00013 #include "CandDataQualityHandle.h"
00014 #include "CandDeadChipHandle.h"
00015
00016 #include "DQHeader.h"
00017 #include "DQRawDigits.h"
00018 #include "DQHotColdElectronics.h"
00019 #include "DQLightInjection.h"
00020 #include "DQSpillServer.h"
00021 #include "RawChip.h"
00022
00023 #include "TObjArray.h"
00024
00025
00026
00027
00028
00029 ClassImp(AlgDataQuality)
00030
00031 CVSID("$Id: AlgDataQuality.cxx,v 1.4 2009/02/28 21:46:11 gmieg Exp $");
00032
00033 AlgDataQuality::AlgDataQuality()
00034 {
00035
00036 }
00037
00038 AlgDataQuality::~AlgDataQuality()
00039 {
00040
00041 }
00042
00043 void AlgDataQuality::RunAlg(AlgConfig& , CandHandle& ch, CandContext& cx)
00044 {
00045 MSG("DataQuality", Msg::kDebug) << " AlgDataQuality::RunAlg(...) " << endl;
00046
00047 Int_t i,j;
00048 Int_t addme;
00049 Int_t time,subtime;
00050 Int_t fSnarlPassFail;
00051
00052 CandDataQualityHandle& cdh = dynamic_cast<CandDataQualityHandle&>(ch);
00053 const TObjArray* arr = dynamic_cast<const TObjArray*>(cx.GetDataIn());
00054
00055 CandRecord* candrec = (CandRecord*)(cx.GetCandRecord());
00056 Detector::Detector_t detector = candrec->GetVldContext()->GetDetector();
00057
00058
00059
00060
00061
00062
00063 MSG("DataQuality", Msg::kDebug) << " Store the Header Information " << endl;
00064
00065
00066
00067 DQHeader* myDQHeader = (DQHeader*)(arr->At(0));
00068 MSG("DataQuality", Msg::kDebug) << " Header (+" << myDQHeader->GetTime()-myDQHeader->GetTime() << ")" << endl;
00069 MSG("DataQuality", Msg::kDebug) << " [run=" << myDQHeader->GetRun() << ", snarl=" << myDQHeader->GetSnarl() << "]" << endl;
00070 MSG("DataQuality", Msg::kDebug) << " [trigger=" << myDQHeader->GetTriggerNanosec() << ", base=" << myDQHeader->GetBaseNanosec() << ", subtracted=" << myDQHeader->GetTriggerNanosec()-myDQHeader->GetBaseNanosec() << "]" << endl;
00071 cdh.SetTime(myDQHeader->GetTime());
00072 cdh.SetRunType(myDQHeader->GetRunType());
00073 cdh.SetRun(myDQHeader->GetRun());
00074 cdh.SetSubRun(myDQHeader->GetSubRun());
00075 cdh.SetTimeFrame(myDQHeader->GetTimeFrame());
00076 cdh.SetSnarl(myDQHeader->GetSnarl());
00077 cdh.SetTriggerSource(myDQHeader->GetTriggerSource());
00078 cdh.SetTriggerTime(myDQHeader->GetTriggerNanosec());
00079 cdh.SetErrorCode(myDQHeader->GetErrorCode());
00080 fSnarlPassFail = 1;
00081
00082
00083
00084 DQRawDigits* myDQRawDigits = (DQRawDigits*)(arr->At(1));
00085 MSG("DataQuality", Msg::kDebug) << " Raw Digits (+" << myDQRawDigits->GetTime()-myDQHeader->GetTime() << ")" << endl;
00086 MSG("DataQuality", Msg::kDebug) << " [pre hits=" << myDQRawDigits->GetPreTriggerDigits() << ", post hits=" << myDQRawDigits->GetPostTriggerDigits() << ", snarl hits=" << myDQRawDigits->GetSnarlMultiplicity() << ", busy/error chips=" << 1+myDQRawDigits->GetLast()<< ", pass/fail=" << myDQRawDigits->GetSnarlPassFail() << "]" << endl;
00087 cdh.SetPreTriggerDigits(myDQRawDigits->GetPreTriggerDigits());
00088 cdh.SetPostTriggerDigits(myDQRawDigits->GetPostTriggerDigits());
00089 cdh.SetSnarlMultiplicity(myDQRawDigits->GetSnarlMultiplicity());
00090 fSnarlPassFail = myDQRawDigits->GetSnarlPassFail();
00091
00092
00093
00094 DQHotColdElectronics* myDQHotColdElectronics = (DQHotColdElectronics*)(arr->At(2));
00095 if( myDQHotColdElectronics->GetTime()>0 ){
00096 MSG("DataQuality", Msg::kDebug) << " Hot/Cold Electronics (+" << myDQHotColdElectronics->GetTime()-myDQHeader->GetTime() << ")" << endl;
00097 MSG("DataQuality", Msg::kDebug) << " [crates=" << myDQHotColdElectronics->GetNumberOfCrates() << ", hot/cold chips=" << 1+myDQHotColdElectronics->GetLast() << "]" << endl;
00098 }
00099 if( myDQHotColdElectronics->GetTime()>0
00100 && myDQHotColdElectronics->GetTime()-myDQHeader->GetTime()==0 ){
00101 cdh.SetCrateMask(myDQHotColdElectronics->GetNumberOfCratesInReadout());
00102 }
00103
00104
00105
00106 DQLightInjection* myDQLightInjection = (DQLightInjection*)(arr->At(3));
00107 if( myDQLightInjection->GetTime()>0 ){
00108 MSG("DataQuality", Msg::kDebug) << " Light Injection (+" << myDQLightInjection->GetTime()-myDQHeader->GetTime() << ")" << endl;
00109 MSG("DataQuality", Msg::kDebug) << " [box=" << myDQLightInjection->GetPulserBox() << ", led=" << myDQLightInjection->GetPulserLed() << ", tpmt hits=" << 1+myDQLightInjection->GetLast()<< "]" << endl;
00110 }
00111 if( myDQLightInjection->GetTime()>0
00112 && myDQLightInjection->GetTime()-myDQHeader->GetTime()==0 ){
00113 cdh.SetLiCalibPoint(myDQLightInjection->GetCalibPoint());
00114 cdh.SetLiCalibType(myDQLightInjection->GetCalibType());
00115 cdh.SetLiPulserBox(myDQLightInjection->GetPulserBox());
00116 cdh.SetLiPulserLed(myDQLightInjection->GetPulserLed());
00117 cdh.SetLiPulseHeight(myDQLightInjection->GetPulseHeight());
00118 cdh.SetLiPulseWidth(myDQLightInjection->GetPulseWidth());
00119 }
00120
00121
00122
00123 DQSpillServer* myDQSpillServer = (DQSpillServer*)(arr->At(4));
00124 if( myDQSpillServer->GetTime()>0 ){
00125 MSG("DataQuality", Msg::kDebug) << " Spill Server (+" << myDQSpillServer->GetTime()-myDQHeader->GetTime() << ")" << endl;
00126 MSG("DataQuality", Msg::kDebug) << " [status=" << myDQSpillServer->GetSpillStatus() << ", type=" << myDQSpillServer->GetSpillType() << ", error=" << myDQSpillServer->GetSpillTimeError() << "]" << endl;
00127 }
00128 if( myDQSpillServer->GetTime()>0
00129 && myDQSpillServer->GetTime()-myDQHeader->GetTime()==0 ){
00130 cdh.SetSpillStatus(myDQSpillServer->GetSpillStatus());
00131 cdh.SetSpillType(myDQSpillServer->GetSpillType());
00132 cdh.SetSpillTimeError(myDQSpillServer->GetSpillTimeError());
00133 }
00134
00135
00136
00137
00138
00139
00140 if( myDQLightInjection->GetTime()>0
00141 && myDQLightInjection->GetTime()-myDQHeader->GetTime()==0 ){
00142
00143 Int_t fMinSubTime=-100000;
00144 Int_t fMaxSubTime=+100000;
00145
00146 Int_t litrigger=0;
00147 Int_t litime=-99999;
00148 Int_t lisubtime=-99999;
00149 Int_t lireltime=-99999;
00150
00151 for(i=0;i<1+myDQLightInjection->GetLast();i++){
00152 RawChip* tpmt = (RawChip*)(myDQLightInjection->At(i));
00153
00154 time=tpmt->GetNanosec();
00155 subtime=tpmt->GetNanosec()-(myDQHeader->GetTriggerNanosec()-myDQHeader->GetBaseNanosec());
00156
00157 if( (subtime>fMinSubTime && subtime<fMaxSubTime)
00158 && (lireltime<0 || abs(subtime)<lireltime) ){
00159 litrigger=1;
00160 litime=time;
00161 lisubtime=subtime;
00162 lireltime=abs(subtime);
00163 }
00164 }
00165
00166 MSG("DataQuality", Msg::kDebug) << " Tpmt Hits (+" << myDQLightInjection->GetTime()-myDQHeader->GetTime() << ")" << endl;
00167 MSG("DataQuality", Msg::kDebug) << " [trigger=" << litrigger << ", litime=" << litime << ", lisubtime=" << lisubtime << ", lireltime=" << lireltime << "]" << endl;
00168
00169 cdh.SetLiTrigger(litrigger);
00170 cdh.SetLiTime(litime);
00171 cdh.SetLiSubtractedTime(lisubtime);
00172 cdh.SetLiRelativeTime(lireltime);
00173 }
00174
00175
00176
00177
00178
00179
00180 MSG("DataQuality", Msg::kDebug) << " Sort the Bad Chips " << endl;
00181
00182 TObjArray* badelectronics = new TObjArray();
00183
00184
00185 for(i=0;i<1+myDQHotColdElectronics->GetLast();i++){
00186 RawChip* badchip = (RawChip*)(myDQHotColdElectronics->At(i));
00187 addme=1;
00188 for(j=0;j<1+badelectronics->GetLast();j++){
00189 TObjArray* tmparray = (TObjArray*)(badelectronics->At(j));
00190 RawChip* tmpchip = (RawChip*)(tmparray->First());
00191 if( badchip->IsSameChip(tmpchip) ){
00192 tmparray->Add(badchip);
00193 addme=0;
00194 }
00195 }
00196 if( addme ){
00197 TObjArray* newarray = new TObjArray();
00198 newarray->Add(badchip);
00199 badelectronics->Add(newarray);
00200 }
00201 }
00202
00203
00204 for(i=0;i<1+myDQRawDigits->GetLast();i++){
00205 RawChip* badchip = (RawChip*)(myDQRawDigits->At(i));
00206 addme=1;
00207 for(j=0;j<1+badelectronics->GetLast();j++){
00208 TObjArray* tmparray = (TObjArray*)(badelectronics->At(j));
00209 RawChip* tmpchip = (RawChip*)(tmparray->First());
00210 if( badchip->IsSameChip(tmpchip) ){
00211 tmparray->Add(badchip);
00212 addme=0;
00213 }
00214 }
00215 if( addme ){
00216 TObjArray* newarray = new TObjArray();
00217 newarray->Add(badchip);
00218 badelectronics->Add(newarray);
00219 }
00220 }
00221
00222 MSG("DataQuality", Msg::kDebug) << " ... Found " << 1+badelectronics->GetLast() << " Bad Chips " << endl;
00223
00224
00225 AlgFactory &af = AlgFactory::GetInstance();
00226 AlgHandle ah = af.GetAlgHandle("AlgDeadChip", "default");
00227 CandContext mycx(this, cx.GetMom());
00228 mycx.SetCandRecord(candrec);
00229
00230 for(i=0;i<1+badelectronics->GetLast();i++){
00231 TObjArray* tmparray = (TObjArray*)(badelectronics->At(i));
00232 mycx.SetDataIn(tmparray);
00233 CandDeadChipHandle deadchip = CandDeadChip::MakeCandidate(ah,mycx);
00234 deadchip.SetName(TString("CandDeadChipHandle"));
00235 deadchip.SetTitle(TString("Created by CandDataQualityModule"));
00236 cdh.AddDaughterLink(deadchip);
00237 }
00238
00239 badelectronics->Delete();
00240 delete badelectronics;
00241
00242
00243
00244
00245
00246 CandDataQuality::DataQuality_t quality(CandDataQuality::kOkay);
00247
00248
00249 if( detector==Detector::kFar ){
00250
00251 Int_t fMinMultiplicity=10;
00252 Int_t fMaxMultiplicity=1000;
00253 Int_t fMaxColdChips=20;
00254 Int_t fMaxBusyChips=20;
00255 Int_t fMaxHotChips=9999;
00256 Int_t fMaxReadoutErrors=9999;
00257
00258
00259 if( cdh.GetSnarlMultiplicity()<fMinMultiplicity ){
00260 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kLowMultiplicity);
00261 }
00262
00263
00264 if( cdh.GetSnarlMultiplicity()>fMaxMultiplicity ){
00265 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kHighMultiplicity);
00266 }
00267
00268
00269 if( cdh.GetLiTrigger()==1 ){
00270 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kLightInjection);
00271 };
00272
00273
00274 if( cdh.GetTriggerTime()-1000000000>-100000 ){
00275 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kTimeFrameBoundary);
00276 }
00277
00278
00279 if( cdh.GetColdChips()>fMaxColdChips ){
00280 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kBad);
00281 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kManyColdChips);
00282 }
00283
00284
00285 if( cdh.GetBusyChips()>fMaxHotChips ){
00286 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kBad);
00287 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kManyHotChips);
00288 }
00289
00290
00291 if( cdh.GetBusyChips()>fMaxBusyChips ){
00292 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kBad);
00293 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kManyBusyChips);
00294 }
00295
00296
00297 if( cdh.GetReadoutErrors()>fMaxReadoutErrors ){
00298 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kBad);
00299 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kManyReadoutErrors);
00300 }
00301
00302 }
00303
00304
00305 if( detector==Detector::kNear ){
00306
00307
00308
00309
00310
00311 }
00312
00313
00314 if( fSnarlPassFail==0 ){
00315 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kBad);
00316 quality=(CandDataQuality::DataQuality_t)(quality|CandDataQuality::kFailed);
00317 }
00318
00319
00320 cdh.SetDataQuality(quality);
00321
00322
00323 MSG("DataQuality", Msg::kDebug) << endl
00324 << " NEW CANDDATAQUALITYHANDLE " << endl
00325 << " ========================= " << endl
00326 << " Time=" << cdh.GetTime() << endl
00327 << " RunType=" << cdh.GetRunType() << endl
00328 << " Run=" << cdh.GetRun() << endl
00329 << " SubRun=" << cdh.GetSubRun() << endl
00330 << " TimeFrame=" << cdh.GetTimeFrame() << endl
00331 << " Snarl=" << cdh.GetSnarl() << endl
00332 << " TriggerSource=" << cdh.GetTriggerSource() << endl
00333 << " TriggerTime=" << cdh.GetTriggerTime() << endl
00334 << " ErrorCode=" << cdh.GetErrorCode() << endl
00335 << " CrateMask=" << cdh.GetCrateMask() << endl
00336 << " PreTriggerDigits=" << cdh.GetPreTriggerDigits() << endl
00337 << " PostTriggerDigits=" << cdh.GetPostTriggerDigits() << endl
00338 << " SnarlMultiplicity=" << cdh.GetSnarlMultiplicity() << endl
00339 << " SpillStatus=" << cdh.GetSpillStatus() << endl
00340 << " SpillType=" << cdh.GetSpillType() << endl
00341 << " SpillTimeError=" << cdh.GetSpillTimeError() << endl
00342 << " LiTrigger=" << cdh.GetLiTrigger() << endl
00343 << " LiTime=" << cdh.GetLiTime() << endl
00344 << " LiSubtractedTime=" << cdh.GetLiSubtractedTime() << endl
00345 << " LiRelativeTime=" << cdh.GetLiRelativeTime() << endl
00346 << " LiCalibPoint=" << cdh.GetLiCalibPoint() << endl
00347 << " LiCalibType=" << cdh.GetLiCalibType() << endl
00348 << " LiPulserBox=" << cdh.GetLiPulserBox() << endl
00349 << " LiPulserLed=" << cdh.GetLiPulserLed() << endl
00350 << " LiPulseHeight=" << cdh.GetLiPulseHeight() << endl
00351 << " LiPulseWidth=" << cdh.GetLiPulseWidth() << endl
00352 << " ColdChips=" << cdh.GetColdChips() << endl
00353 << " HotChips=" << cdh.GetHotChips() << endl
00354 << " BusyChips=" << cdh.GetBusyChips() << endl
00355 << " ReadoutErrors=" << cdh.GetReadoutErrors() << endl
00356 << " DataQuality=" << cdh.GetDataQuality() << endl;
00357
00358 return;
00359 }
00360
00361 void AlgDataQuality::Trace(const char * ) const
00362 {
00363
00364 }
00365
00366