00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include "Plex/PlexValidate.h"
00013
00014 #include "Plex/PlexStripEndId.h"
00015 #include "Plex/PlexSEIdAltL.h"
00016 #include "Plex/PlexHandle.h"
00017 #include "Plex/PlexLoanPool.h"
00018
00019 #include "Validity/VldContext.h"
00020
00021 #include "MessageService/MsgService.h"
00022 CVSID("$Id: PlexValidate.cxx,v 1.14 2005/08/26 18:47:04 rhatcher Exp $");
00023
00024 ClassImp(PlexValidate)
00025
00026
00027 PlexValidate::PlexValidate()
00028 {
00029
00030
00031
00032 MsgService* msvc = MsgService::Instance();
00033 MsgStream* mstr = msvc->GetStream("Plex");
00034
00035 mstr->SetLogLevel(Msg::kVerbose);
00036 mstr->SetFormat(Msg::kVerbose,0xffff);
00037
00038 }
00039
00040
00041 PlexValidate::~PlexValidate()
00042 {
00043
00044
00045 }
00046
00047
00048 Bool_t PlexValidate::RunAllTests()
00049 {
00050 Int_t fail = 0;
00051
00052 if (!TestPlaneId()) fail++;
00053 if (!TestStripEndId()) fail++;
00054
00055
00056 MSG("Plex",Msg::kInfo)
00057 << "PlexValidate::RunAllTests had " << fail << " failures "
00058 << endl << endl;
00059
00060 return (!fail);
00061
00062 }
00063
00064
00065 Bool_t PlexValidate::TestPlaneId(void)
00066 {
00067
00068
00069
00070 cout << "Test PlaneId (en|de)coding and printout" << endl << endl;
00071
00072 Int_t fail = 0;
00073
00074 cout << "default ctor: " << flush;
00075 PlexPlaneId defctor;
00076 defctor.Print("");
00077
00078 PlexPlaneId active(Detector::kFar,0,kFALSE);
00079 PlexPlaneId steel(Detector::kFar,0,kTRUE);
00080
00081 cout << "active Far plane 0: \"" << active.AsString() << "\"" << endl;
00082 cout << "steel Far plane 0: \"" << steel.AsString() << "\"" << endl;
00083
00084 if (active.IsSteel()) {
00085 fail++;
00086 cout << " active thought it was steel " << endl;
00087 }
00088 if (! steel.IsSteel()) {
00089 fail++;
00090 cout << " steel thought it was ! steel " << endl;
00091 }
00092
00093 PlexPlaneId flipflop = steel;
00094
00095 flipflop.SetIsSteel(kTRUE);
00096 if ( ! (steel == flipflop) ) fail++;
00097 flipflop.SetIsSteel(kFALSE);
00098 if ( ! (active == flipflop) ) fail++;
00099
00100 MSG("Plex",Msg::kInfo)
00101 << "PlexValidate::TestPlaneId had " << fail << " failures "
00102 << endl << endl;
00103
00104 return (!fail);
00105
00106 }
00107
00108 Bool_t PlexValidate::TestStripEndId(void)
00109 {
00110
00111
00112 cout << "Test StripEndId (en|de)coding and printout" << endl << endl;
00113
00114 Int_t fail = 0;
00115
00116 cout << "default ctor: ";
00117 PlexStripEndId defctor;
00118 defctor.Print("");
00119
00120 cout << endl << "test building and unpacking PlexStripEndId's" << endl;
00121 Detector::Detector_t detectors[5] =
00122 { Detector::kNear, Detector::kFar, Detector::kCalib,
00123 Detector::kTestStand, Detector::kMapper };
00124
00125 Int_t lastplanes[5] =
00126 { 282, 249+249-1, 64, 10, 10 };
00127
00128 StripEnd::StripEnd_t ends[8] =
00129 { StripEnd::kUnknown, StripEnd::kNegative, StripEnd::kPositive,
00130 StripEnd::kEast, StripEnd::kWest, StripEnd::kUp, StripEnd::kDown,
00131 StripEnd::kWhole };
00132
00133 StripEnd::StripEnd_t *subparts = ends;
00134
00135 PlaneView::PlaneView_t views[5] =
00136 { PlaneView::kX, PlaneView::kY, PlaneView::kU, PlaneView::kV,
00137 PlaneView::kUnknown };
00138
00139 PlaneCoverage::PlaneCoverage_t coverages[5] =
00140 { PlaneCoverage::kUnknown, PlaneCoverage::kUninstrumented,
00141 PlaneCoverage::kNearPartial, PlaneCoverage::kNearFull,
00142 PlaneCoverage::kComplete };
00143
00144
00145
00146 for (Int_t i=0; i<4; i++ ) {
00147 cout << endl << Detector::AsString(detectors[i]);
00148 Int_t last_plane = lastplanes[i];
00149 Int_t fail_detector = 0;
00150 for (Int_t iplane=0; iplane<=last_plane; iplane++) {
00151 if (iplane>2 && iplane<last_plane-6) continue;
00152 cout << endl << " plane " << setw(4) << iplane << " strip ";
00153 for (Int_t istrip=0; istrip<256; istrip++) {
00154 if (istrip>2 && istrip<254) continue;
00155 cout << setw(3) << istrip << " ";
00156 for (Int_t j=0; j<8; j++) {
00157 for (Int_t k=0; k<8; k++) {
00158 for (Int_t m=0; m<5; m++) {
00159 for (Int_t n=0; n<5; n++) {
00160
00161 Bool_t success =
00162 BuildAndTestSEId(detectors[i],iplane,istrip,
00163 ends[j],subparts[k],
00164 views[m],coverages[n]);
00165 if (!success) fail_detector++;
00166 }
00167 }
00168 }
00169 }
00170 }
00171 }
00172 cout << endl << " had " << fail_detector << " failures " << endl;
00173 fail += fail_detector;
00174 }
00175 cout << endl;
00176
00177 PlexStripEndId seid0(Detector::kNear,1,2,StripEnd::kWest);
00178
00179
00180
00181
00182 char string0[40];
00183 char string1[40];
00184
00185 cout << endl;
00186
00187 strcpy(string0,seid0.AsString());
00188 printf(" %s SameStrip SameEnd OppositeEnd\n",string0);
00189
00190 for (Int_t itest=0; itest<7; itest++) {
00191
00192 Bool_t samestrip, sameend, otherend;
00193 Bool_t samestriptrue, sameendtrue,otherendtrue;
00194 Int_t failtest = 0;
00195
00196 PlexStripEndId seid1;
00197 switch (itest) {
00198 case 0:
00199 seid1 = PlexStripEndId(Detector::kNear,1,2,StripEnd::kWest);
00200 samestriptrue = kTRUE;
00201 sameendtrue = kTRUE;
00202 otherendtrue = kFALSE;
00203 break;
00204 case 1:
00205 seid1 = PlexStripEndId(Detector::kNear,1,2,StripEnd::kEast);
00206 samestriptrue = kTRUE;
00207 sameendtrue = kFALSE;
00208 otherendtrue = kTRUE;
00209 break;
00210 case 2:
00211 seid1 = seid0.GetOppositeSEId();
00212 samestriptrue = kTRUE;
00213 sameendtrue = kFALSE;
00214 otherendtrue = kTRUE;
00215 break;
00216 case 3:
00217 seid1 = PlexStripEndId(Detector::kFar,1,2,StripEnd::kEast);
00218 samestriptrue = kFALSE;
00219 sameendtrue = kFALSE;
00220 otherendtrue = kFALSE;
00221 break;
00222 case 4:
00223 seid1 = PlexStripEndId(Detector::kNear,2,2,StripEnd::kEast);
00224 samestriptrue = kFALSE;
00225 sameendtrue = kFALSE;
00226 otherendtrue = kFALSE;
00227 break;
00228 case 5:
00229 seid1 = PlexStripEndId(Detector::kNear,3,2,StripEnd::kEast);
00230 samestriptrue = kFALSE;
00231 sameendtrue = kFALSE;
00232 otherendtrue = kFALSE;
00233 break;
00234 default:
00235 samestriptrue = kFALSE;
00236 sameendtrue = kFALSE;
00237 otherendtrue = kFALSE;
00238 break;
00239 }
00240
00241 strcpy(string1,seid1.AsString());
00242 samestrip = seid0.IsSameStrip(seid1);
00243 sameend = seid0.IsSameStripEnd(seid1);
00244 otherend = seid0.IsOppositeStripEnd(seid1);
00245
00246 printf(" vs. %s %9d %7d %11d\n",
00247 string1,samestrip,sameend,otherend);
00248
00249 if (samestrip != samestriptrue) failtest++;
00250 if (sameend != sameendtrue) failtest++;
00251 if (otherend != otherendtrue) failtest++;
00252
00253 if (failtest) {
00254 fail++;
00255 cout << " ^^^^^^^^^ incorrect results " << endl;
00256 }
00257
00258 }
00259 cout << endl;
00260
00261 MSG("Plex",Msg::kInfo)
00262 << " Test output to MSG service: " << seid0 << endl;
00263
00264 MSG("Plex",Msg::kInfo)
00265 << "PlexValidate::TestStripEndId had " << fail << " failures "
00266 << endl << endl;
00267
00268 return (!fail);
00269 }
00270
00271
00272 Bool_t PlexValidate::TestAltL(void)
00273 {
00274
00275
00276 cout << "Test PlexSEIdAltL" << endl << endl;
00277
00278 Int_t fail = 0;
00279
00280 PlexStripEndId seid;
00281
00282 printf("\n start with empty list:\n");
00283 PlexSEIdAltL alt;
00284 alt.Print("");
00285
00286 printf("\n add one entry, then drop:\n");
00287 PlexStripEndId seidxxx;
00288
00289 PlexPixelSpotId spotidxxx;
00290
00291 alt.AddStripEndId(seidxxx,spotidxxx);
00292
00293
00294 alt.Print("");
00295 alt.DropCurrent();
00296 alt.Print("");
00297 printf("IsValid() returns %d\n",(int)alt.IsValid());
00298
00299 printf("\n add three real entries:\n");
00300 PlexStripEndId seid11(Detector::kNear,1,2,StripEnd::kEast);
00301 PlexStripEndId seid12(Detector::kFar ,3,4,StripEnd::kWest);
00302 PlexStripEndId seid13(Detector::kCalib,5,6,StripEnd::kUp);
00303
00304 PlexPixelSpotId spot11(Detector::kNear,ElecType::kQIE,'E','U',1,2,0,1,2);
00305 PlexPixelSpotId spot12(Detector::kFar,ElecType::kVA,'W','L',1,2,0,1,2);
00306 PlexPixelSpotId spot13(Detector::kCalib,ElecType::kVA,'E','U',1,2,0,1,2);
00307
00308 alt.AddStripEndId(seid11,spot11,1);
00309 alt.AddStripEndId(seid12,spot12,20);
00310 alt.AddStripEndId(seid13,spot13,4);
00311
00312 alt.Print("");
00313 printf("move back 2\n");
00314 alt.Previous();
00315 alt.Previous();
00316 alt.Print("");
00317 printf("move forward 2\n");
00318 alt.Next();
00319 alt.Next();
00320 alt.Print("");
00321 printf("move forward 1 more\n");
00322 alt.Next();
00323 alt.Print("");
00324
00325 alt.SetFirst();
00326 printf("SetFirst() gives %s weight %g\n",
00327 (alt.GetCurrentSEId()).AsString(),alt.GetCurrentWeight());
00328
00329 alt.SetLast();
00330 printf("SetLast() gives %s weight %g\n",
00331 (alt.GetCurrentSEId()).AsString(),alt.GetCurrentWeight());
00332
00333
00334 printf("GetBestX() gives %s weight %g\n",
00335 (alt.GetBestSEId()).AsString(),alt.GetBestWeight());
00336
00337 alt.SetLast();
00338 printf("SetLast() IsValid returns %d\n",(int)alt.IsValid());
00339 alt.Next();
00340 printf("out-of-range IsValid returns %d\n",(int)alt.IsValid());
00341 alt.SetFirst();
00342 printf("SetFirst() IsValid returns %d\n",(int)alt.IsValid());
00343 alt.Previous();
00344 printf("out-of-range IsValid returns %d\n",(int)alt.IsValid());
00345
00346 #ifdef WILL_ASSERT
00347 alt.SetLast();
00348 alt.Next();
00349 printf("SetLast()+1 gives %s weight %g\n",
00350 (alt.GetCurrentSEId()).AsString(),alt.GetCurrentWeight());
00351
00352 alt.SetFirst();
00353 alt.Previous();
00354 printf("SetFirst()-1 gives %s weight %g\n",
00355 (alt.GetCurrentSEId()).AsString(),alt.GetCurrentWeight());
00356 #endif
00357
00358 printf("\n iterate\n");
00359 alt.SetFirst();
00360 while (alt.IsValid()) {
00361 printf(" SEId %s weight %g\n",
00362 (alt.GetCurrentSEId()).AsString(),alt.GetCurrentWeight());
00363 alt.Next();
00364 };
00365
00366
00367 #ifdef SILLYMEMLEAKCHECK
00368 printf("\n check for memory leaks by repeated copy construction\n");
00369 printf(" look for size change in 'top'\n");
00370 printf(" ...hey it ain't pretty, but it's a stopgap solution\n");
00371 cout << flush;
00372 cout << "type x<return> to continue" << endl;
00373 char c;
00374 cin >> c;
00375 for (Int_t j=0; j<10; j++) {
00376 for (Int_t i=0; i<100000; i++) {
00377 PlexSEIdAltL alt2(alt);
00378
00379 alt2 = alt;
00380 }
00381
00382 }
00383 alt = alt;
00384 alt.Print();
00385 printf("\n");
00386 #endif
00387
00388 Int_t plane;
00389 StripEnd::StripEnd_t end;
00390
00391 cout << "using previous AltL: " << endl;
00392 plane = alt.GetPlane();
00393 cout << " alt list returned Plane " << plane << endl;
00394 end = alt.GetEnd();
00395 cout << " alt list returned End " << StripEnd::AsString(end) << endl;
00396
00397 cout << "using empty AltL: " << endl;
00398 PlexSEIdAltL alt2;
00399 plane = alt2.GetPlane();
00400 cout << " alt list returned Plane " << plane << endl;
00401 end = alt2.GetEnd();
00402 cout << " alt list returned End " << StripEnd::AsString(end) << endl;
00403
00404 cout << "using new AltL: " << endl;
00405 PlexStripEndId seid21(Detector::kNear,1,1,StripEnd::kEast);
00406 PlexStripEndId seid22(Detector::kNear,1,2,StripEnd::kEast);
00407 PlexStripEndId seid23(Detector::kNear,1,3,StripEnd::kEast);
00408
00409 PlexPixelSpotId spot21(Detector::kNear,ElecType::kQIE,'E','U',1,2,0,1,1);
00410 PlexPixelSpotId spot22(Detector::kNear,ElecType::kQIE,'E','U',1,2,0,1,2);
00411 PlexPixelSpotId spot23(Detector::kNear,ElecType::kQIE,'E','U',1,2,0,1,3);
00412
00413 alt2.AddStripEndId(seid21,spot21,0);
00414 alt2.AddStripEndId(seid22,spot22,1);
00415 alt2.AddStripEndId(seid23,spot23,0);
00416
00417 alt2.Print();
00418 plane = alt2.GetPlane();
00419 cout << " alt list returned Plane " << plane << endl;
00420 end = alt2.GetEnd();
00421 cout << " alt list returned End " << StripEnd::AsString(end) << endl;
00422 printf(" drop entries with zero weights\n");
00423 alt2.DropZeroWeights();
00424 alt2.Print();
00425
00426 printf("\n working on:\n");
00427 alt.Print();
00428 printf("\n");
00429
00430 printf("\n Normalize the weights:\n");
00431 alt.NormalizeWeights();
00432
00433 MSG("Plex",Msg::kInfo)
00434 << " Test output to MSG service: " << endl
00435 << alt << " ... done " << endl << endl;
00436
00437
00438 printf("loop in reverse, drop all elements with weight < 0.799\n");
00439 alt.SetLast();
00440 while ( alt.IsValid() ) {
00441 if ( alt.GetCurrentWeight() < 0.799 ) alt.DropCurrent();
00442 alt.Previous();
00443 }
00444 alt.Print();
00445 printf("\n");
00446
00447 printf(" clear all weights\n");
00448 alt.ClearWeights();
00449 alt.Print();
00450 printf("\n");
00451
00452 printf("drop all zero weight entries (should give empty list)\n");
00453 alt.SetLast();
00454 while ( alt.IsValid() ) {
00455 if ( alt.GetCurrentWeight() == 0.0 ) alt.DropCurrent();
00456 alt.Previous();
00457 }
00458 alt.Print();
00459 printf("\n");
00460
00461
00462 cout << "using new AltL: " << endl;
00463 PlexStripEndId seid31(Detector::kNear,1,1,StripEnd::kEast);
00464 PlexStripEndId seid32(Detector::kNear,1,2,StripEnd::kEast);
00465 PlexStripEndId seid33(Detector::kNear,1,3,StripEnd::kEast);
00466 PlexStripEndId seid34(Detector::kNear,1,4,StripEnd::kEast);
00467 PlexStripEndId seid35(Detector::kNear,1,5,StripEnd::kEast);
00468
00469 PlexPixelSpotId spot31(Detector::kNear,ElecType::kQIE,'E','U',1,2,0,1,1);
00470 PlexPixelSpotId spot32(Detector::kNear,ElecType::kQIE,'E','U',1,2,0,1,2);
00471 PlexPixelSpotId spot33(Detector::kNear,ElecType::kQIE,'E','U',1,2,0,1,3);
00472 PlexPixelSpotId spot34(Detector::kNear,ElecType::kQIE,'E','U',1,2,0,1,4);
00473 PlexPixelSpotId spot35(Detector::kNear,ElecType::kQIE,'E','U',1,2,0,1,5);
00474
00475 alt.AddStripEndId(seid31,spot31,1);
00476 alt.AddStripEndId(seid32,spot32,2);
00477 alt.AddStripEndId(seid33,spot33,3);
00478 alt.AddStripEndId(seid34,spot34,4);
00479 alt.AddStripEndId(seid35,spot35,3);
00480
00481 alt.Print();
00482 cout << "KeepTopWeights(3,true) " << endl;
00483 alt.KeepTopWeights(3,kTRUE);
00484 alt.Print();
00485 cout << "KeepTopWeights(3,false) " << endl;
00486 alt.KeepTopWeights(3,kFALSE);
00487 alt.Print();
00488 cout << "KeepTopWeights(2,false) " << endl;
00489 alt.KeepTopWeights(2,kFALSE);
00490 alt.Print();
00491 cout << "KeepTopWeights(1) " << endl;
00492 alt.KeepTopWeights(1);
00493 alt.Print();
00494
00495 MSG("Plex",Msg::kInfo)
00496 << "PlexValidate::TestAltL had " << fail << " failures " << endl;
00497 return (!fail);
00498 }
00499
00500
00501 Bool_t PlexValidate::BuildAndTestSEId(Detector::Detector_t detector,
00502 Int_t plane, Int_t strip,
00503 StripEnd::StripEnd_t end,
00504 StripEnd::StripEnd_t subpart,
00505 PlaneView::PlaneView_t view,
00506 PlaneCoverage::PlaneCoverage_t cover)
00507 {
00508 PlexStripEndId seid(detector,plane,strip,end,subpart,view,cover);
00509 Int_t fail = 0;
00510
00511 enum failenum {
00512 faildetector = 0x01,
00513 failplane = 0x02,
00514 failstrip = 0x04,
00515 failend = 0x08,
00516 failsubpart = 0x10,
00517 failplnview = 0x20,
00518 failplncover = 0x40
00519 };
00520
00521 if (seid.GetDetector() != detector ) fail |= faildetector;
00522 if (seid.GetPlane() != plane ) fail |= failplane;
00523 if (seid.GetStrip() != strip ) fail |= failstrip;
00524 if (seid.GetEnd() != end ) fail |= failend;
00525 if (seid.GetSubPart() != subpart ) fail |= failsubpart;
00526 if (seid.GetPlaneView() != view &&
00527 view != PlaneView::kUnknown ) fail |= failplnview;
00528 if (seid.GetPlaneCoverage() != cover &&
00529 cover != PlaneCoverage::kUnknown) fail |= failplncover;
00530
00531 if (fail) {
00532 MSG("Plex",Msg::kWarning)
00533 << "PlexValidate::BuildAndTestSEId failed (0x"
00534 << hex << fail << dec << ") for "
00535 << seid.AsString()
00536 << " != " << Detector::AsString(detector)
00537 << "/" << plane
00538 << "/" << strip
00539 << "/" << StripEnd::AsString(end)
00540 << "/" << StripEnd::AsString(subpart)
00541 << "/" << PlaneView::AsString(view)
00542 << "/" << PlaneCoverage::AsString(cover)
00543 << endl;
00544 }
00545
00546 Bool_t success = ! fail;
00547 return success;
00548 }
00549