00001
00002
00003
00004
00006
00007
00008
00009
00010
00011
00012
00013
00015
00016 #include <TSystem.h>
00017 #include <TStyle.h>
00018 #include <TRandom.h>
00019
00020 #include "TFndStbMonFrame.h"
00021 #include "TFndRun.h"
00022 #include "TFndStbMon.h"
00023
00024 ClassImp(TFndStbMonFrame)
00025
00026
00027 TFndStbMonFrame::TFndStbMonFrame(TString filename):TFndMonFrame(filename),fMap(),fShm(),fNMaxCrown(K_N_STB_CROWNS),fNMaxTube(K_N_STB_TUBES),fcrown(),ftube(),h1(),h2(),hpat(),fCrownPad(),fTubePad(),fHistoPad(),fActionPad(),fMessagePad(),fCrownPadTitBut(),fTubePadTitBut(),fCrownBut(),fTubeBut(),fStatusBut(),fErrorBut(),fPatternBut(),fTdcMapBut(),fMulBut(),fCrownButCol(),fTubeButCol(),fMessageButCol(),fHistoButCol(),fMulButCol(),fLastAction(-1)
00028 {
00029
00030
00031 Init();
00032 }
00033
00034
00035 void TFndStbMonFrame::Init() {
00036
00037 SetStyle();
00038
00039
00040 return;
00041 }
00042
00043
00044 void TFndStbMonFrame::Open() {
00045
00046 if(!fClosed) return;
00047 if(!StartInterface()) return;
00048 fClosed = kFALSE;
00049 }
00050
00051
00052 TFndStbMonFrame::~TFndStbMonFrame() {
00053
00054
00055 if(!fClosed) Close();
00056 }
00057
00058
00059 void TFndStbMonFrame::Close() {
00060
00061 if(!fClosed){
00062
00063
00064
00065
00066
00067
00068 if(fMap) {fMap->Close(); fMap = 0; }
00069 for(Int_t i=0;i<K_N_STB_CROWNS;i++)if(fShm[i]) {fShm[i]->Close(); fShm[i] = 0; }
00070
00071
00072 delete fCrownPadTitBut; fCrownPadTitBut = 0;
00073 delete fTubePadTitBut; fTubePadTitBut = 0;
00074
00075 for(Int_t i=0;i<K_N_STB_CROWNS;i++){
00076 delete fCrownBut[i]; fCrownBut[i] = 0;
00077 delete fTubeBut[i]; fTubeBut[i] = 0;
00078 }
00079
00080 delete fStatusBut; fStatusBut = 0;
00081 delete fErrorBut; fErrorBut = 0;
00082 delete fMulBut; fMulBut = 0;
00083
00084 fCrownPad->Close(); delete fCrownPad; fCrownPad = 0;
00085 fTubePad->Close(); delete fTubePad; fTubePad = 0;
00086 fHistoPad->Close(); delete fHistoPad; fHistoPad = 0;
00087 fMessagePad->Close(); delete fMessagePad; fMessagePad = 0;
00088 fActionPad->Close(); delete fActionPad; fActionPad = 0;
00089 }
00090 fClosed = kTRUE;
00091 }
00092
00093
00094 Bool_t TFndStbMonFrame::ReloadMapFiles(){
00095
00096 Bool_t result = kTRUE;
00097 if(!fIsOnline) return result;
00098
00099 if( CheckProducerMessages() != 0 ) return kFALSE;
00100 TString shr_file_map_name[7] = 0;
00101
00102
00103 #if defined _FND_ONL_USE_MAP_FILES_
00104 if(fndrun->GetDebug()) cout << "...closing and re-initializing to zero all mapfiles..." << endl;
00105 if(fMap) {fMap->Close(); fMap = 0; }
00106 for(Int_t i=0;i<K_N_STB_CROWNS;i++) if(fShm[i]) {fShm[i]->Close(); fShm[i] = 0; }
00107 if(fndrun->GetDebug()) cout << "...done" << endl;
00108
00109 shr_file_map_name[0] = "$FND_SHR/stb.map";
00110 shr_file_map_name[1] = "$FND_SHR/stb_tdc_1.map";
00111 shr_file_map_name[2] = "$FND_SHR/stb_tdc_2.map";
00112 shr_file_map_name[3] = "$FND_SHR/stb_tdc_3.map";
00113 shr_file_map_name[4] = "$FND_SHR/stb_tdc_4.map";
00114 shr_file_map_name[5] = "$FND_SHR/stb_tdc_5.map";
00115 shr_file_map_name[6] = "$FND_SHR/stb_tdc_6.map";
00116 #elif defined _FND_ONL_USE_SHARED_FILES_
00117 if(fMap) {fMap->Close(); delete fMap; fMap = 0; }
00118 for(Int_t i=0;i<K_N_STB_CROWNS;i++) if(fShm[i]) { if(fShm[i]->IsOpen()) fShm[i]->Close(); delete fShm[i]; fShm[i] = 0; }
00119
00120 shr_file_map_name[0] = "$FND_SHR/stb.file.map";
00121 shr_file_map_name[1] = "$FND_SHR/stb_tdc_1.file.map";
00122 shr_file_map_name[2] = "$FND_SHR/stb_tdc_2.file.map";
00123 shr_file_map_name[3] = "$FND_SHR/stb_tdc_3.file.map";
00124 shr_file_map_name[4] = "$FND_SHR/stb_tdc_4.file.map";
00125 shr_file_map_name[5] = "$FND_SHR/stb_tdc_5.file.map";
00126 shr_file_map_name[6] = "$FND_SHR/stb_tdc_6.file.map";
00127 #endif
00128
00129
00130
00131 if(!gSystem->AccessPathName(FROOT::ExpandPathName(shr_file_map_name[0].Data()))){
00132 #if defined _FND_ONL_USE_MAP_FILES_
00133 fMap = TMapFile::Create(FROOT::ExpandPathName(shr_file_map_name[0].Data()),"READ");
00134 if(fndrun->GetDebug()) fMap->Print();
00135 #elif defined _FND_ONL_USE_SHARED_FILES_
00136 fMap = new TFile(FROOT::ExpandPathName(shr_file_map_name[0].Data()),"READ");
00137 #endif
00138 }
00139 else result = kFALSE;
00140
00141 for(Int_t shr_id=0;shr_id<6;shr_id++){
00142 if(!gSystem->AccessPathName(FROOT::ExpandPathName(shr_file_map_name[shr_id+1].Data()))){
00143 #if defined _FND_ONL_USE_MAP_FILES_
00144 fShm[shr_id] = TMapFile::Create(FROOT::ExpandPathName(shr_file_map_name[shr_id+1].Data()),"READ");
00145 if(fndrun->GetDebug()) fShm[shr_id]->Print();
00146 #elif defined _FND_ONL_USE_SHARED_FILES_
00147 fShm[shr_id] = new TFile(FROOT::ExpandPathName(shr_file_map_name[shr_id+1].Data()),"READ");
00148 #endif
00149 }
00150 else result = kFALSE;
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 if(fndrun->GetDebug()){
00184 if(result) cout << "...done" << endl << endl;
00185 else cout << "STB - shared memories not found!" << endl << endl;
00186 }
00187 return result;
00188
00189 }
00190
00191
00192 void TFndStbMonFrame::RefreshSingleMonView(){
00193
00194
00195
00196
00197 if(fLastAction==-1) return;
00198
00199 FlashDisplayPad();
00200 switch(fLastAction){
00201 case 0:
00202 fCrownBut[fcrown-1]->ExecuteEvent(11,0,0);
00203 break;
00204 case 1:
00205 fPatternBut->ExecuteEvent(11,0,0);
00206 break;
00207 case 2:
00208 fTdcMapBut->ExecuteEvent(11,0,0);
00209 break;
00210 case 3:
00211 fMulBut->ExecuteEvent(11,0,0);
00212 break;
00213 }
00214
00215 }
00216
00217
00218
00219 Bool_t TFndStbMonFrame::StartInterface() {
00220
00221
00222 fcrown = 1;
00223 ftube = 1;
00224
00225
00226 if(!fCanStartGUI) return kFALSE;
00227
00228
00229 ReloadMapFiles();
00230
00231
00232
00233
00234
00235 fCrownButCol=50;
00236 fTubeButCol=50;
00237 fMessageButCol=190;
00238 fHistoButCol=30;
00239 fMulButCol=38;
00240 fHighlightCol[0]=5;
00241
00242
00243 fMainCanvas[0] = new TCanvas("Stb_MainCanvas","STB Detector Display",
00244 fMainCanvCoord[0],fMainCanvCoord[1],
00245 fMainCanvCoord[2],fMainCanvCoord[3]);
00246 SetMonitorTitle(0,"STB");
00247 fMainCanvas[0]->SetEditable(kFALSE);
00248
00249 fMainCanvas[0]->SetFillColor(1);
00250 fMainCanvas[0]->Draw();
00251
00252 fCrownPad = new TPad("CrownPad","Crown Pad",0.,0.5,0.1,1.);
00253 fCrownPad->SetFillColor(44);
00254 fCrownPad->SetBorderSize(2);
00255 fCrownPad->Draw();
00256
00257 fTubePad = new TPad("TubePad","Tube Pad",0.1,0.5,0.2,1.);
00258 fTubePad->SetFillColor(33);
00259 fTubePad->SetBorderSize(2);
00260 fTubePad->Draw();
00261
00262 fMessagePad = new TPad("MessagePad","Message Pad",0.,.35,.2,.50);
00263 fMessagePad->SetFillColor(24);
00264 fMessagePad->SetBorderSize(2);
00265 fMessagePad->Draw();
00266
00267 fHistoPad = new TPad("HistoPad","Histo Pad",0.,.15,0.2,0.35);
00268 fHistoPad->SetFillColor(33);
00269 fHistoPad->SetBorderSize(2);
00270 fHistoPad->Draw();
00271
00272 fActionPad = new TPad("ActionPad","Action Pad",0.,0.,.2,.15);
00273 fActionPad->SetFillColor(14);
00274 fActionPad->SetBorderSize(2);
00275 fActionPad->Draw();
00276
00277 fDisplayPad[0] = new TPad("StbDisplayPad","Stb Display Pad",0.2,0.,1.,1.);
00278 fDisplayPad[0]->SetFillColor(33);
00279 fDisplayPad[0]->SetBorderSize(2);
00280 fDisplayPad[0]->Draw();
00281
00282
00283 DrawButtons();
00284 BuildConnections();
00285
00286 fCrownPad->SetEditable(kFALSE);
00287 fTubePad->SetEditable(kFALSE);
00288 fMessagePad->SetEditable(kFALSE);
00289 fHistoPad->SetEditable(kFALSE);
00290 fActionPad->SetEditable(kFALSE);
00291
00292
00293 return kTRUE;
00294
00295 }
00296
00297
00298 void TFndStbMonFrame::DrawButtons() {
00299
00300 fCrownPad->cd();
00301
00302 Float_t xMinBut = 0.07 ;
00303 Float_t xMaxBut = 0.93 ;
00304 Float_t y=0.8;
00305 Float_t HeightBut=0.1;
00306 Float_t dy=0.03;
00307
00308 TButton *CrownPadTitBut = new TButton("Crown","",xMinBut,.88,xMaxBut,.98);
00309 CrownPadTitBut->SetFillColor(71);
00310 CrownPadTitBut->Draw();
00311
00312 TString *titlec = new TString("Crown ");
00313 TString *methodc = new TString("fndrun->StbMonFrame()->SetCrown(0)");
00314
00315 Char_t crn[2];
00316 for (Int_t c=0;c<fNMaxCrown;c++) {
00317 sprintf(crn,"%d",c+1);
00318 titlec->Replace(6,1,crn);
00319 methodc->Replace(32,1,crn);
00320
00321 fCrownBut[c] = new TButton(titlec->Data(), methodc->Data(),xMinBut,y-HeightBut,xMaxBut,y);
00322 fCrownBut[c]->SetFillColor(fCrownButCol);
00323 fCrownBut[c]->SetTextSize(0.5);
00324 fCrownBut[c]->Draw();
00325 y -= HeightBut + dy;
00326 }
00327 delete titlec;
00328 delete methodc;
00329
00330
00331 fTubePad->cd();
00332
00333 y=0.80;
00334
00335 TButton *fTubePadTitBut = new TButton("Tube","",xMinBut,.88,xMaxBut,.98);
00336 fTubePadTitBut->SetFillColor(71);
00337 fTubePadTitBut->Draw();
00338
00339 TString *titlet = new TString(" ");
00340 TString *methodt = new TString("fndrun->StbMonFrame()->ShiftTube(");
00341 Char_t shiftstep[4];
00342 Int_t shift = 1;
00343 for (Int_t t=0;t<6;t++) {
00344 methodt->Remove(33,5);
00345
00346 if(t%2==0) {
00347 titlet->Replace(0,1,"-");
00348 methodt->Append("-");
00349 if(t!=0) shift = shift * 10;
00350 }
00351 else {
00352 titlet->Replace(0,3,"+");
00353 methodt->Append("+");
00354 }
00355 sprintf(shiftstep,"%d",shift);
00356 titlet->Replace(1,3,shiftstep);
00357 methodt->Append(shiftstep);
00358 methodt->Append(")");
00359
00360 fTubeBut[t] = new TButton(titlet->Data(),methodt->Data(),xMinBut,y-HeightBut,xMaxBut,y);
00361 fTubeBut[t]->SetFillColor(fTubeButCol);
00362 fTubeBut[t]->Draw();
00363 y -= HeightBut + dy;
00364 }
00365
00366
00367 fMessagePad->cd();
00368
00369 fStatusBut = new TButton(" ","",.02,.52,.98,.9);
00370 fStatusBut->SetFillColor(fMessageButCol);
00371 fStatusBut->SetTextSize(0.5);
00372 fStatusBut->Draw();
00373
00374 fErrorBut = new TButton(" ","",.02,.1,.98,.48);
00375 fErrorBut->SetFillColor(fMessageButCol);
00376 fErrorBut->SetTextSize(0.5);
00377 fErrorBut->Draw();
00378
00379 fHistoPad->cd();
00380
00381 fPatternBut = new TButton("Pattern","fndrun->StbMonFrame()->DrawPatterns()",.02,.7,.98,.95);
00382 fPatternBut->SetFillColor(fHistoButCol);
00383 fPatternBut->Draw();
00384
00385 fTdcMapBut = new TButton("TDC Map","fndrun->StbMonFrame()->DrawTdcMap()",.02,.4,.98,.65);
00386 fTdcMapBut->SetFillColor(fHistoButCol);
00387 fTdcMapBut->Draw();
00388
00389 fMulBut = new TButton("MULT","fndrun->StbMonFrame()->DrawMultiplicity()",.02,.1,.98,.35);
00390 fMulBut->SetFillColor(fMulButCol);
00391 fMulBut->Draw();
00392
00393
00394 fActionPad->cd();
00395
00396
00397 }
00398
00399
00400 void TFndStbMonFrame::SetCrown(Int_t cr) {
00401
00402 if(!ReloadMapFiles()){
00403 fDisplayPad[0]->Clear();
00404 fDisplayPad[0]->Modified();
00405 return;
00406 }
00407 fcrown = cr;
00408
00409
00410 ClearButton();
00411 fCrownBut[fcrown-1]->SetFillColor(fHighlightCol[0]);
00412
00413 TellSelection();
00414 fStatusBut->SetFillColor(fMessageButCol);
00415 fStatusBut->Modified();
00416
00417 DrawHist();
00418 }
00419
00420
00421 void TFndStbMonFrame::ShiftTube(Int_t shift) {
00422
00423 ClearButton();
00424
00425 if(!ReloadMapFiles()){
00426 fDisplayPad[0]->Clear();
00427 fDisplayPad[0]->Modified();
00428 return;
00429 }
00430 if(ftube+shift>0 && ftube+shift<=fNMaxTube) {
00431 ftube = ftube + shift;
00432
00433 }
00434 else {
00435 fErrorBut->SetFillColor(100);
00436 fErrorBut->SetTitle("Tube Out Of Range");
00437 fErrorBut->Modified();
00438 cout << "..... straw tube number out of range ....." << endl;
00439 if(ftube+shift<1) ftube = 1;
00440 if(ftube+shift>fNMaxTube) ftube = K_N_STB_TUBES;
00441 }
00442
00443 TellSelection();
00444 if(shift==-1) fTubeBut[0]->SetFillColor(fHighlightCol[0]);
00445 if(shift==+1) fTubeBut[1]->SetFillColor(fHighlightCol[0]);
00446 if(shift==-10) fTubeBut[2]->SetFillColor(fHighlightCol[0]);
00447 if(shift==+10) fTubeBut[3]->SetFillColor(fHighlightCol[0]);
00448 if(shift==-100) fTubeBut[4]->SetFillColor(fHighlightCol[0]);
00449 if(shift==+100) fTubeBut[5]->SetFillColor(fHighlightCol[0]);
00450 fCrownBut[fcrown-1]->SetFillColor(fHighlightCol[0]);
00451
00452 DrawHist();
00453 }
00454
00455
00456 void TFndStbMonFrame::TellSelection() {
00457 TString *title = new TString("crown - ");
00458 TString *titlet = new TString("tube ");
00459 Char_t crownsel[2];
00460 Char_t tubesel[4];
00461 sprintf(crownsel,"%d",fcrown);
00462 sprintf(tubesel,"%d",ftube);
00463 title->Replace(6,1,crownsel);
00464 titlet->Replace(5,3,tubesel);
00465 title->Append(titlet->Data());
00466 fStatusBut->SetTitle(title->Data());
00467 fStatusBut->Modified();
00468 delete titlet;
00469 delete title;
00470 }
00471
00472
00473 void TFndStbMonFrame::T0Calib() {
00474
00475 Info("T0Calib","deprecated method");
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496 return;
00497 }
00498
00499
00500 void TFndStbMonFrame::ClearButton() {
00501
00502 for (Int_t c=0;c<fNMaxCrown;c++) {
00503 fCrownBut[c]->SetFillColor(fCrownButCol);
00504 fTubeBut[c]->SetFillColor(fTubeButCol);
00505 fCrownBut[c]->Modified();
00506 fTubeBut[c]->Modified();
00507 }
00508 fErrorBut->SetFillColor(fMessageButCol);
00509 fErrorBut->SetTitle(" ");
00510 fErrorBut->Modified();
00511
00512 fPatternBut->SetFillColor(fHistoButCol);
00513 fPatternBut->Modified();
00514
00515 fTdcMapBut->SetFillColor(fHistoButCol);
00516 fTdcMapBut->Modified();
00517
00518 fMulBut->SetFillColor(fHistoButCol);
00519 fMulBut->Modified();
00520
00521 fDisplayPad[0]->Clear();
00522 }
00523
00524
00525 void TFndStbMonFrame::DrawHist(){
00526
00527
00528
00529 TString h1name("stbtdc_");
00530
00531 Char_t crownsel[2];
00532 Char_t tubesel[4];
00533 sprintf(crownsel,"%d",fcrown);
00534 sprintf(tubesel,"%d",ftube);
00535 h1name.Append(crownsel);
00536 h1name.Append("_");
00537 h1name.Append(tubesel);
00538
00539 if(!fRF) {
00540 h1 = (TH1F*) fShm[fcrown-1]->Get(h1name.Data());
00541 } else {
00542 h1 = (TH1F*) fRF->Get(h1name.Data());
00543 }
00544
00545 fDisplayPad[0]->cd();
00546 if(h1) h1->Draw();
00547
00548 Int_t maxcont = 0;
00549 Int_t stb_tdc_bins = h1->GetNbinsX();
00550 for(Int_t nb=0; nb<stb_tdc_bins; nb++) {
00551 Int_t cont = (Int_t) h1->GetBinContent(nb+1);
00552 if(cont >= maxcont) {
00553 maxcont = cont;
00554 }
00555 }
00556
00557
00558 fLastAction = 0;
00559 return;
00560 }
00561
00562 void TFndStbMonFrame::DrawTdcMap(){
00563
00564 if(!ReloadMapFiles()){
00565 fDisplayPad[0]->Clear();
00566 fDisplayPad[0]->Modified();
00567 return;
00568 }
00569
00570
00571
00572 ClearButton();
00573 fTdcMapBut->SetFillColor(fHighlightCol[0]);
00574 fTdcMapBut->Modified();
00575
00576 if(!fRF) {
00577 h2 = (TH2F*) fMap->Get("stbmaptdc");
00578 } else {
00579 h2 = (TH2F*) fRF->Get("stbmaptdc");
00580 }
00581 fStatusBut->SetTitle("TDC map");
00582 fStatusBut->Modified();
00583 fDisplayPad[0]->cd();
00584 if(h2) h2->Draw("");
00585 fLastAction = 2;
00586 return;
00587 }
00588
00589
00590 void TFndStbMonFrame::DrawPatterns(){
00591
00592 if(!ReloadMapFiles()){
00593 fDisplayPad[0]->Clear();
00594 fDisplayPad[0]->Modified();
00595 return;
00596 }
00597
00598
00599
00600 ClearButton();
00601 fPatternBut->SetFillColor(fHighlightCol[0]);
00602 fPatternBut->Modified();
00603 fStatusBut->SetTitle("TDC Patterns");
00604 fStatusBut->Modified();
00605
00606 fDisplayPad[0]->Divide(3,2,.001,.001);
00607
00608 TString title = TString("stb_pattern_ ");
00609 Char_t cr[2];
00610 for(Int_t i=0;i<K_N_STB_CROWNS;i++){
00611 sprintf(cr,"%d",i+1);
00612 title.Replace(12,1,cr);
00613 if(!fRF) {
00614 hpat[i] = (TH1F*) fMap->Get(title.Data());
00615 } else {
00616 hpat[i] = (TH1F*) fRF->Get(title.Data());
00617 }
00618 fDisplayPad[0]->cd(i+1);
00619 if(hpat[i]) hpat[i]->Draw();
00620 }
00621 fLastAction = 1;
00622 }
00623
00624
00625
00626 void TFndStbMonFrame::DrawMultiplicity(){
00627
00628 if(!ReloadMapFiles()){
00629 fDisplayPad[0]->Clear();
00630 fDisplayPad[0]->Modified();
00631 return;
00632 }
00633
00634 ClearButton();
00635 fMulBut->SetFillColor(fHighlightCol[0]);
00636 fMulBut->Modified();
00637 fStatusBut->SetTitle("TDC Mult");
00638 fStatusBut->Modified();
00639
00640 if(!fRF) {
00641 h1 = (TH1F*) fMap->Get("stbmult");
00642 } else {
00643 h1 = (TH1F*) fRF->Get("stbmult");
00644 }
00645 fStatusBut->SetTitle("TDC mult");
00646 fStatusBut->Modified();
00647 fDisplayPad[0]->cd();
00648 if(h1) h1->Draw("");
00649 fLastAction = 3;
00650 return;
00651
00652 }
00653