GTS/TFndGtsMonFrame.cxx

00001 // @(#)fROOT/GTS:$Name:  $:$Id: TFndGtsMonFrame.cxx,v 1.27 2007/09/24 07:32:41 Diego_Faso Exp $
00002 // Revision Author: Diego Faso <mailto:faso@to.infn.it>, 2005/06/24
00003 // Original Author: P. Cerello <mailto:cerello@to.infn.it>, 2001
00004 
00006 //                                                    //
00007 //                 TFndGtsMonFrame                    //
00008 //                                                    //
00009 //  GUI for the GTS monitoring                        //
00010 //                                                    //
00012 
00013 #include <TSystem.h>
00014 #include <TStyle.h>
00015 
00016 #include "FROOT.h"
00017 #include "TFndGtsMonFrame.h" 
00018 #include "TFndRun.h"
00019 
00020 ClassImp(TFndGtsMonFrame)
00021 
00022 //___________________________________________
00023 TFndGtsMonFrame::TFndGtsMonFrame(TString filename):
00024   TFndMonFrame(filename),
00025   fGtsMapFile(),
00026   fButPad(),fSelBut(),
00027   fCurBut(-1)
00028 {
00029   Init();
00030 }
00031 
00032 //___________________________________________
00033 TFndGtsMonFrame::~TFndGtsMonFrame() {
00034   
00035   if(!fClosed) Close();
00036 } 
00037 
00038 //___________________________________________
00039 void TFndGtsMonFrame::Init(){
00040 
00041   SetStyle();
00042   fHighlightCol[0] = 5;
00043   fHighlightCol[1] = 5;
00044   //  fndrun->SetGtsMonFrame(this);
00045   //StartInterface();
00046 }
00047 
00048 //___________________________________________
00049 void TFndGtsMonFrame::Open() {
00050 
00051   if(!fClosed) return;
00052   if(! StartInterface()) return;  
00053   fClosed = kFALSE;
00054 }
00055 
00056 //___________________________________________
00057 void TFndGtsMonFrame::Close() {
00058   // the consumer should not close shared memories
00059   
00060   if(!fClosed){
00061     if(fGtsMapFile) { fGtsMapFile->Close(); fGtsMapFile = 0; }
00062     
00063     //     for(Int_t i=0; i<fNPads; i++) { if(hists[i]) { delete hists[i];   hists[i] = 0;} }
00064     for (Int_t i=0;i<fNBut; i++)  { if(fSelBut[i]) {delete fSelBut[i]; fSelBut[i] = 0;} }
00065     if(fButPad){ fButPad->Close(); delete fButPad; fButPad = 0;}
00066   }
00067   fClosed = kTRUE;
00068 }
00069 
00070 //___________________________________________
00071 Bool_t TFndGtsMonFrame::ReloadMapFiles(){
00072   // this method is automatically called when
00073   // a button is clicked, since histograms must be reloaded
00074   // obviously this is necessary only in online-mode!
00075 
00076   Bool_t result = kTRUE;
00077   if(!fIsOnline) return result;
00078 
00079   if( CheckProducerMessages() != 0 ) return kFALSE; // chech if shared memories are busy (producer message)
00080   //  CheckProducerMessages(); // chech if shared memories are busy (producer message)
00081 
00082   TString shr_file_map_name = 0;
00083 #if defined _FND_ONL_USE_MAP_FILES_
00084   if(fGtsMapFile) { fGtsMapFile->Close(); fGtsMapFile = 0; }
00085   shr_file_map_name = "$FND_SHR/gts.map";
00086 #elif defined _FND_ONL_USE_SHARED_FILES_
00087   if(fGtsMapFile) { if(fGtsMapFile->IsOpen()) fGtsMapFile->Close(); delete fGtsMapFile; fGtsMapFile = 0; }
00088   shr_file_map_name = "$FND_SHR/gts.file.map";
00089 #endif
00090 
00091   //  const Char_t *shname = FROOT::ExpandPathName("$FND_SHR/gts.map");
00092   if(fndrun->GetDebug()) Printf("TFndGtsMonFrame::ReloadMapFiles() ---> Checking shared memory existence...");
00093   if(!gSystem->AccessPathName(FROOT::ExpandPathName(shr_file_map_name.Data()))){
00094     //    fGtsMapFile  = TMapFile::Create(FROOT::ExpandPathName("$FND_SHR/gts.map"),"READ",(Int_t)(1048576*FROOT::K_GtsMapSize));
00095 #if defined _FND_ONL_USE_MAP_FILES_
00096     fGtsMapFile  = TMapFile::Create(FROOT::ExpandPathName(shr_file_map_name.Data()),"READ");
00097     //    if(fndrun->GetDebug()) fGtsMapFile->Print();
00098     fGtsMapFile->Print();
00099 #elif defined _FND_ONL_USE_SHARED_FILES_
00100     fGtsMapFile = new TFile(FROOT::ExpandPathName(shr_file_map_name.Data()),"READ");
00101     Info("TFndGtsMonFrame::ReloadMapFiles","Reloading shared file \"%s\"",shr_file_map_name.Data());
00102     //    fGtsMapFile->ls();
00103 #endif
00104   }
00105   else result = kFALSE;
00106   
00107   if(fndrun->GetDebug()){
00108     if(result)  Printf("TFndGtsMonFrame::ReloadMapFiles() ---> Ok.");
00109     else Printf("TFndGtsMonFrame::ReloadMapFiles() ---> shared memories not found!");
00110   }
00111   
00112   return result;
00113 }
00114 
00115 //___________________________________________
00116 Bool_t TFndGtsMonFrame::StartInterface() {
00117   // 1) Open file (or shared memory)
00118   //     open file(s) if passed to the constructor,
00119   //     otherwise search for existing shared memory(ies)
00120   //
00121   // 2) Build the GUI Frame
00122 
00123   Int_t BackgroundCol = 12; // was 40
00124   Int_t DisplayPadCol = 15; // was 4
00125 
00126   Float_t sep = 0.001;
00127 
00128   Float_t Start_X_displaypad = 0.15;
00129   Float_t Stop_X_displaypad  = 1.;
00130   Float_t Start_Y_displaypad = 0.;
00131   Float_t Stop_Y_displaypad  = 1.;
00132 
00133   // Stop here if no source file was found
00134   if(!fCanStartGUI) return kFALSE;
00135   
00136   // check and open shared memories
00137   // only if the ctor was called for consumer (default)
00138   ReloadMapFiles(); // if not online it will be true
00139   //   fCanStartGUI = ReloadMapFiles(); // if not online it will be true
00140   //   if(!fCanStartGUI) return; 
00141 
00142   if (fRF)  Printf("TFndGtsMonFrame::StartInterface ---> source file found...starting GUI");
00143   
00144   fMainCanvas[0] = new TCanvas("Gts_MainCanvas","GTS Detector Display",
00145                                fMainCanvCoord[0],fMainCanvCoord[1],
00146                                fMainCanvCoord[2],fMainCanvCoord[3]);
00147   
00148   SetMonitorTitle(0,"GTS");
00149   // --------
00150   // --------
00151 
00152   fMainCanvas[0]->SetEditable(kFALSE);
00153   //fMainCanvas[0]->ToggleEventStatus();
00154   fMainCanvas[0]->SetFillColor(BackgroundCol);
00155   fMainCanvas[0]->Draw();
00156 
00157   fDisplayPad[0] = new TPad("GtsMonFrameDisplayPad","GTS histogram display",
00158                             Start_X_displaypad+sep,Start_Y_displaypad+sep,Stop_X_displaypad,Stop_Y_displaypad);
00159   fDisplayPad[0]->Draw();
00160   fDisplayPad[0]->SetFillColor(DisplayPadCol);
00161   fDisplayPad[0]->SetBorderSize(2);
00162   Int_t EachPadCol = 18;
00163   Float_t Margin = 0.002;
00164   fDisplayPad[0]->Divide(2,2,Margin,Margin,EachPadCol);
00165   
00166   fButPad = new TPad("iGtsSelPad","iGtsSelPad",0.,0.,Start_X_displaypad-sep,Stop_Y_displaypad);
00167   fButPad->SetFillColor(13);
00168   fButPad->Draw();
00169 
00170   DrawButtons();  
00171   BuildConnections();
00172 
00173   return kTRUE;
00174 }
00175 //____________________________________________________
00176 TButton *TFndGtsMonFrame::HighlightButtons(){
00177 
00178   fSelBut[fCurBut]->SetFillColor(fHighlightCol[0]);
00179   fSelBut[fCurBut]->Modified();
00180   return fSelBut[fCurBut];
00181 }
00182 
00183 //___________________________________________
00184 void TFndGtsMonFrame::RefreshSingleMonView(){
00185 
00186   if(fCurBut==-1) return;
00187   ResetFrameColors();
00188   FlashDisplayPad();
00189   HighlightButtons()->ExecuteEvent(11,0,0);
00190 }
00191 
00192 //____________________________________________________
00193 void TFndGtsMonFrame::ResetFrameColors() {
00194 
00195   Int_t SelCol = 6;
00196   for (Int_t i=0;i<fNBut;i++){
00197     fSelBut[i]->SetFillColor(SelCol);
00198     fSelBut[i]->Modified();
00199   }
00200 }
00201 
00202 
00203 //___________________________________________
00204 void TFndGtsMonFrame::DrawButtons() {
00205 
00206   fMainCanvas[0]->cd();
00207   fButPad->cd();
00208 
00209   Float_t xi=0.;
00210   Float_t xo=0.;
00211   Float_t yi=0.;
00212   Float_t yo=0.;
00213   // side buttons
00214   for(Int_t i=0;i<fNBut;i++) {
00215     TString modlab = TString();
00216     TString str1 = TString();
00217     switch(i){
00218     case 0:
00219       modlab="Tr.Sel";
00220       str1="fndrun->GtsMonFrame()->DisplaySelector();";
00221       break;
00222     case 1:
00223       modlab="Malu";
00224       str1="fndrun->GtsMonFrame()->DisplayMalus();";
00225       break;
00226     case 2:
00227       modlab="PU 1-2";
00228       str1="fndrun->GtsMonFrame()->DisplayPatternUnits_1_2();";
00229       break;
00230     case 3:
00231       modlab="PU 3-4";
00232       str1="fndrun->GtsMonFrame()->DisplayPatternUnits_3_4();";
00233       break;
00234     case 4:
00235       modlab="TOFI MT";
00236       str1="fndrun->GtsMonFrame()->Display_Tofino_MT();";
00237       break;
00238     case 5:
00239       modlab="TOFO MT";
00240       str1="fndrun->GtsMonFrame()->Display_Tofone_MT();";
00241       break;
00242     default:
00243       Error("DrawButtons()","i out of range!");
00244       break;
00245     }
00246     fButPad->cd();
00247     xi = 0.;
00248     yi = ((Float_t) i)/(fNBut+3);
00249     xo = 1.;
00250     yo = (i+1.)/(fNBut+3);
00251     fSelBut[i] = new TButton(modlab.Data(),str1.Data(),xi,yi,xo,yo);
00252     fSelBut[i]->SetTextSize(0.35);
00253     fSelBut[i]->Draw();
00254   }
00255   ResetFrameColors();
00256   fButPad->SetEditable(kFALSE);
00257 }
00258 
00259 
00260 //___________________________________________
00261 void TFndGtsMonFrame::DisplaySelector(){
00262 
00263   if(!ReloadMapFiles()){
00264     return;
00265   }
00266   ResetDisplayPad(2,1);
00267   
00268   TString hname;
00269   for(Int_t i=0;i < K_N_GTS_SELECTORS ; i++){
00270     fDisplayPad[0]->cd(i+1);
00271     hname.Form("GtsHist_TrigSel_%d",i+1);
00272     
00273     if(fIsOnline)  { if(fGtsMapFile->Get(hname)) fGtsMapFile->Get(hname)->Draw(); }
00274     else           { if(fRF->Get(hname)) fRF->Get(hname)->Draw(); } 
00275   }
00276   
00277   fCurBut = 0;
00278   // ---
00279   ResetFrameColors();
00280   HighlightButtons();
00281 }    
00282 
00283 //___________________________________________
00284 void TFndGtsMonFrame::DisplayMalus(){
00285 
00286   if(!ReloadMapFiles()){
00287     return;
00288   }
00289   ResetDisplayPad(1,2);
00290 
00291   fDisplayPad[0]->cd(1);
00292   if(fIsOnline){
00293     if(fGtsMapFile->Get("GtsHist_MaluPattern")) fGtsMapFile->Get("GtsHist_MaluPattern")->Draw();
00294   }
00295   else{
00296     if(fRF->Get("GtsHist_MaluPattern")) fRF->Get("GtsHist_MaluPattern")->Draw();
00297   }
00298   
00299   fDisplayPad[0]->cd(2);
00300   if(fIsOnline){
00301     if(fGtsMapFile->Get("GtsHist_MaluMultiplicity")) fGtsMapFile->Get("GtsHist_MaluMultiplicity")->Draw();
00302   }
00303   else{
00304     if(fRF->Get("GtsHist_MaluMultiplicity")) fRF->Get("GtsHist_MaluMultiplicity")->Draw();
00305   }
00306   
00307   fCurBut = 1;
00308   // ---
00309   ResetFrameColors();
00310   HighlightButtons();
00311 }    
00312 
00313 //___________________________________________
00314 void TFndGtsMonFrame::DisplayPatternUnits_1_2(){
00315 
00316   if(!ReloadMapFiles()){
00317     return;
00318   }
00319   ResetDisplayPad(1,2);
00320     
00321   TString hname;
00322   for(Int_t i=0;i < 2 ; i++){
00323     fDisplayPad[0]->cd(i+1);
00324     hname.Form("GtsHist_PU_cont_%d",i+1);
00325     if(fIsOnline){
00326       if(fGtsMapFile->Get(hname)) fGtsMapFile->Get(hname)->Draw();
00327     }
00328     else{
00329       if(fRF->Get(hname)) fRF->Get(hname)->Draw();
00330     }
00331   }
00332   
00333   fCurBut = 2;
00334   // ---
00335   ResetFrameColors();
00336   HighlightButtons();
00337 }
00338 
00339 //___________________________________________
00340 void TFndGtsMonFrame::DisplayPatternUnits_3_4(){
00341 
00342   if(!ReloadMapFiles()){
00343     return;
00344   }
00345   ResetDisplayPad(2,2);
00346     
00347   fDisplayPad[0]->cd(1);
00348   if(fIsOnline){
00349     if(fGtsMapFile->Get("GtsHist_PU_cont_3")) fGtsMapFile->Get("GtsHist_PU_cont_3")->Draw();
00350   }
00351   else{
00352     if(fRF->Get("GtsHist_PU_cont_3")) fRF->Get("GtsHist_PU_cont_3")->Draw();
00353   }
00354   
00355   fDisplayPad[0]->cd(2);
00356   if(fIsOnline){
00357     if(fGtsMapFile->Get("GtsHist_PU_cont_4")) fGtsMapFile->Get("GtsHist_PU_cont_4")->Draw();
00358   }
00359   else{
00360     if(fRF->Get("GtsHist_PU_cont_4")) fRF->Get("GtsHist_PU_cont_4")->Draw();
00361   }
00362   
00363   fDisplayPad[0]->cd(3);
00364   if(fIsOnline){
00365     if(fGtsMapFile->Get("GtsHist_PU_mult_3")) fGtsMapFile->Get("GtsHist_PU_mult_3")->Draw();
00366   }
00367   else{
00368     if(fRF->Get("GtsHist_PU_mult_3")) fRF->Get("GtsHist_PU_mult_3")->Draw();
00369   }  
00370 
00371   fDisplayPad[0]->cd(4);
00372   if(fIsOnline){
00373     if(fGtsMapFile->Get("GtsHist_PU_mult_4")) fGtsMapFile->Get("GtsHist_PU_mult_4")->Draw();
00374   }
00375   else{
00376     if(fRF->Get("GtsHist_PU_mult_4")) fRF->Get("GtsHist_PU_mult_4")->Draw();
00377   }
00378   
00379   
00380   fCurBut = 3;
00381   // ---
00382   ResetFrameColors();
00383   HighlightButtons();
00384 }
00385 
00386 //___________________________________________
00387 void TFndGtsMonFrame::Display_Tofino_MT(){
00388   
00389   if(!ReloadMapFiles()){
00390     return;
00391   }
00392   ResetDisplayPad(2,2);
00393   
00394   TString hname;
00395 
00396   fDisplayPad[0]->cd(1);
00397   hname = "GtsHist_TofinoLow_MT_Patt";
00398   if(fIsOnline){
00399     if(fGtsMapFile->Get(hname)) fGtsMapFile->Get(hname)->Draw();
00400   }  
00401   else{
00402     if(fRF->Get(hname)) fRF->Get(hname)->Draw();
00403   }
00404   
00405   fDisplayPad[0]->cd(2);
00406   hname = "GtsHist_TofinoHigh_MT_Patt";
00407   if(fIsOnline){
00408     if(fGtsMapFile->Get(hname)) fGtsMapFile->Get(hname)->Draw();
00409   }
00410   else{
00411     if(fRF->Get(hname)) fRF->Get(hname)->Draw();
00412   }
00413   
00414   fDisplayPad[0]->cd(3);
00415   hname = "GtsHist_TofinoLow_MT_Mult";
00416   if(fIsOnline){
00417     if(fGtsMapFile->Get(hname)) fGtsMapFile->Get(hname)->Draw();
00418   }
00419   else{
00420     if(fRF->Get(hname)) fRF->Get(hname)->Draw();
00421   }
00422   
00423   fDisplayPad[0]->cd(4);
00424   hname = "GtsHist_TofinoHigh_MT_Mult";
00425   if(fIsOnline){
00426     if(fGtsMapFile->Get(hname)) fGtsMapFile->Get(hname)->Draw();
00427   }
00428   else{
00429     if(fRF->Get(hname)) fRF->Get(hname)->Draw();
00430   }
00431   
00432   
00433   fCurBut = 4;
00434   // ---
00435   ResetFrameColors();
00436   HighlightButtons();
00437 }
00438 
00439 //___________________________________________
00440 void TFndGtsMonFrame::Display_Tofone_MT(){
00441   
00442   if(!ReloadMapFiles()){
00443     return;
00444   }
00445   ResetDisplayPad(1,2);
00446   
00447   TString hname;
00448 
00449   fDisplayPad[0]->cd(1);
00450   hname = "GtsHist_Tofone_MT_Patt";
00451   if(fIsOnline){
00452     if(fGtsMapFile->Get(hname)) fGtsMapFile->Get(hname)->Draw();
00453   }
00454   else{
00455     if(fRF->Get(hname)) fRF->Get(hname)->Draw();
00456   }
00457   
00458   fDisplayPad[0]->cd(2);
00459   hname = "GtsHist_Tofone_MT_Mult";
00460   if(fIsOnline){
00461     if(fGtsMapFile->Get(hname)) fGtsMapFile->Get(hname)->Draw();
00462   }
00463   else{
00464     if(fRF->Get(hname)) fRF->Get(hname)->Draw();
00465   }
00466   
00467   fCurBut = 5;
00468   // ---
00469   ResetFrameColors();
00470   HighlightButtons();
00471 }
00472 
00473 
00474 //___________________________________________
00475 void TFndGtsMonFrame::ResetDisplayPad(Int_t dividex,Int_t dividey){
00476 
00477   if(!fDisplayPad[0]) return;
00478   Int_t DisplayPadCol = 15;
00479   Int_t EachPadCol = 18;
00480   Float_t Margin = 0.002;
00481 
00482   fDisplayPad[0]->Clear();
00483   fDisplayPad[0]->SetFillColor(DisplayPadCol);
00484   fDisplayPad[0]->SetBorderSize(2);
00485   fDisplayPad[0]->Divide(dividex, dividey,Margin,Margin,EachPadCol);
00486   fDisplayPad[0]->Modified();
00487 
00488 }

Generated on Tue Oct 16 15:40:46 2007 by  doxygen 1.5.2