]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/Monitor/macros/TPCMonitor.C
Install macros
[u/mrichter/AliRoot.git] / TPC / Monitor / macros / TPCMonitor.C
1 ////////////////////////////////////////////////////////////////////////////////
2 // 
3 // Macro to launch Monitoring program for TPC raw data
4 // 
5 // Author: Stefan Kniege, IKF, Frankfurt
6 //
7 ////////////////////////////////////////////////////////////////////////////////
8
9 #include "iostream"
10
11 #include "TGFrame.h"
12 #include "TGButton.h"
13 #include "TGTextEntry.h"
14 #include "TGLabel.h"
15 #include "TGFileDialog.h"
16 #include "TGClient.h"
17 #include "TGApplication.h"
18 #include "TSystem.h"
19 #include "TStyle.h"
20 #include "TDirectory.h"
21 #include "TFileMerger.h"
22 #include "TGComboBox.h"
23
24 #include "AliTPCMonitor.h"
25 #include "AliTPCMonitorMappingHandler.h"
26 //#include "AliTPCMonitorEditor.h"
27 #include "AliTPCMonitorDialog.h"
28
29 using namespace std;
30
31
32 static    AliTPCMonitor*               fMon               = 0;
33 static    AliTPCMonitorMappingHandler* fMapHand           = 0;
34
35 static    TGMainFrame*                 fFrameMain         = 0;
36 static    TGCheckButton*               fFrameChDisFit     = 0;
37 static    TGCheckButton*               fFrameCh10bit      = 0;
38 static    TGCheckButton*               fFrameCheckVerb    = 0;
39 static    TGCheckButton*               fFrameCheckProcOne = 0;
40 static    TGCheckButton*               fFrameCheckPed     = 0;
41 static    TGCheckButton*               fFrameCalcBSL      = 0;           
42
43 static    TGComboBox*                  fTableField        = 0;
44
45 static    Int_t                        fVerb              = 0;
46 static    TGTextEntry*                 fTextEvId          = 0;
47
48 void      WriteChannel();
49 void      WriteHistos();  
50 void      SetConfig();
51 void      DisableFit();
52 //void      ProcessSector(char* fdata,char* ffil, Int_t side, Int_t sector);
53 void      ProcessSector(Int_t sid, Int_t sector);
54 //Int_t     DrawFit();
55 Int_t     DrawRMSMap();
56 void      ShowSelected();
57 //void      SetSize() ;
58 void      ResizeCanv();
59 void      ReadMe();
60 void      OpenDir();
61 void      SetWrite10Bit();
62 void      SetCheckVerb();
63 void      SetProcOne();
64 void      SetPedestalRun(Int_t val);
65 void      InitDialog(Int_t id);
66 //void      Resize(Int_t update,Int_t doit , Int_t side);
67 void      MonitorGui(AliTPCMonitor* fMon);
68 void      SetStyle();
69  
70
71 //_________________________________________________________________________
72 void TPCMonitor()
73 {
74   // Initialize the monitor 
75   SetStyle();
76   
77   TString aliceroot=gSystem->Getenv("ALICE_ROOT");
78   TString dateroot=gSystem->Getenv("DATE_ROOT");
79   
80   cout << " ALICE_ROOT : " << aliceroot.Data() << endl;
81   cout << " DATE_ROOT  : " << dateroot.Data()  << endl;
82   
83   // MappingHandler
84   TString fglobalmap=Form("%s/TPC/mapping/MappingGlobal.txt", aliceroot.Data());
85   TString frowmap=Form("%s/TPC/mapping/MappingRow.txt",    aliceroot.Data());
86   TString ffecmap=Form("%s/TPC/mapping/MappingCards.txt",  aliceroot.Data());
87   TString fnameconf=Form("%s/TPC/Monitor/AliTPCMonitorConfig.txt",   aliceroot.Data());
88   fMapHand = new AliTPCMonitorMappingHandler("maphand","maphand");
89   fMapHand->ReadMapping(fglobalmap.Data());
90   fMapHand->ReadRowMappingGlob(frowmap.Data());
91   fMapHand->ReadFECMapping(    ffecmap.Data());
92   if (gDirectory) { gDirectory->Append(fMapHand); }
93   
94   // Monitor
95   fMon = new AliTPCMonitor("monitor","monitor");
96   fMon->ReadConfig(fnameconf.Data());
97   fMon->SetMappingHandler(fMapHand);
98   MonitorGui(fMon);
99 }
100
101 //_________________________________________________________________________
102 void MonitorGui(AliTPCMonitor */*fMon*/)
103 {
104   // Display the main Window 
105
106   Float_t xsize   = fMon->GetButtonXSize();
107   Float_t ysize   = fMon->GetButtonYSize();
108   Float_t xfirst1 = fMon->GetButtonXFirst1();
109   Float_t xfirst2 = fMon->GetButtonXFirst2();
110   Float_t yfirst  = fMon->GetButtonYFirst();
111   Float_t mainx   = fMon->GetMainXSize();
112   Float_t mainy   = fMon->GetMainYSize();
113   
114   // main frame
115   fFrameMain = new TGMainFrame(gClient->GetRoot(),10,10,kMainFrame | kVerticalFrame);
116   fFrameMain->SetLayoutBroken(kTRUE);
117
118 //  TGTextButton*  fFrameSelForm    = new TGTextButton(fFrameMain,  "Sel. Format "         );
119   TGTextButton*  fFrameSelFil     = new TGTextButton(fFrameMain,  "Sel. File/Stream"     );
120                  fTableField      = new TGComboBox(fFrameMain                            );
121   TGTextButton*  fFrameFFT        = new TGTextButton(fFrameMain,  "FFT"                  );
122   TGTextButton*  fFrameWRITE      = new TGTextButton(fFrameMain,  "Write Channel"        );
123   fFrameChDisFit                  = new TGCheckButton(fFrameMain, "Disable G4-fit"       );
124   TGTextButton*  fFrameRMS        = new TGTextButton(fFrameMain,  "Show RMS map"         );
125   TGTextButton*  fFrameSetConf    = new TGTextButton(fFrameMain,  "Conf. Ranges"         );
126   fFrameCh10bit                   = new TGCheckButton(fFrameMain, "Write 10bit      "    );
127   fFrameCheckVerb                 = new TGCheckButton(fFrameMain, "Set Verbose      "    );
128   fFrameCheckProcOne              = new TGCheckButton(fFrameMain, "Proc one Sector  "    );
129   fFrameCalcBSL                   = new TGCheckButton(fFrameMain, "Calc BSL (onl)   "    );
130   fFrameCheckPed                  = new TGCheckButton(fFrameMain, "No BSL sub.      "    );
131   TGTextButton*  fFrameSideA      = new TGTextButton(fFrameMain,  "Side A"               );
132   TGTextButton*  fFrameSideB      = new TGTextButton(fFrameMain,  "Side C"               );
133   TGTextButton*  fFrameNextEvent  = new TGTextButton(fFrameMain,  "Next Event"           );
134   TGTextButton*  fFramesel        = new TGTextButton(fFrameMain,  "Show Component"       );
135   TGTextButton*  fFrameres        = new TGTextButton(fFrameMain,  "Resize Canvases"      );
136   TGTextButton*  fFramewrite      = new TGTextButton(fFrameMain,  "Write Histos"         );
137   TGTextButton*  fFrameQuit       = new TGTextButton(fFrameMain,  "Quit"                 );
138  
139 //  fFrameSelForm->SetCommand(   "InitDialog(1)"     );
140   fFrameSelFil->SetCommand(    "OpenDir()"        );
141   fFrameFFT->SetCommand(       "FFT()"             );
142   fFrameWRITE->SetCommand(     "WriteChannel()"    );
143   fFrameCheckPed->SetCommand(  "SetPedestalRun(0)" );
144   fFrameCh10bit->SetCommand(   "SetWrite10Bit()"   );
145   fFrameCalcBSL->SetCommand(   "SetPedestalRun(1)" );
146   fFrameChDisFit->SetCommand(  "DisableFit()"      );
147   fFrameRMS->SetCommand(       "DrawRMSMap()"      );
148   fFrameSetConf->SetCommand(   "SetConfig()"       );
149   fFrameCheckVerb->SetCommand( "SetCheckVerb()"    );
150   fFrameCheckProcOne->SetCommand("SetProcOne()"      );
151   fFrameNextEvent->SetCommand( "NextEvent()"       );  fFrameNextEvent->SetTextColor(200);
152   fFramesel->SetCommand(       "ShowSelected()"    );
153   fFrameres->SetCommand(       "ResizeCanv()"      );
154   fFramewrite->SetCommand(     "WriteHistos()"     );
155   fFrameQuit->SetCommand(      "Quit()"            );
156
157   
158   fTableField->EnableTextInput(kTRUE);
159   Int_t id=0;
160   fTableField->RemoveAll();
161   fTableField->AddEntry("PHY,Y,73,*",id++);
162   fTableField->AddEntry("PHY,Y,*,*",id++);
163   TString fields=gSystem->GetFromPipe("cat ~/TPCMonTable");
164   TObjArray *arr=fields.Tokenize("\n");
165   for (Int_t ifield=0; ifield<arr->GetEntries(); ++ifield) fTableField->AddEntry(arr->At(ifield)->GetName(),id++);
166   fTableField->Select(0,kFALSE);
167 //   fTableField->Connect("ReturnPressed()", "", this, "DoCustomDraw()");
168 //   fTableField->Connect("Selected(Int_t)", "", this, "DoCustomDraw()");
169
170   fFrameCalcBSL->SetDown(  1);
171   fFrameCheckPed->SetDown( 1);
172   fFrameChDisFit->SetDown( 1);
173   fFrameCh10bit->SetDown(  0);
174   fFrameCheckVerb->SetDown(0);
175   fFrameCheckProcOne->SetDown(0);
176   SetPedestalRun(0); // !!
177   
178   TGLayoutHints* fLayout = new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5);
179   fFrameMain->AddFrame(fFrameSideA     , fLayout);
180   fFrameMain->AddFrame(fFrameSideB     , fLayout);
181   fFrameMain->AddFrame(fFrameQuit      , fLayout);
182   fFrameMain->AddFrame(fFrameCh10bit   , fLayout);
183   fFrameMain->AddFrame(fFrameRMS       , fLayout);
184   fFrameMain->AddFrame(fFrameSetConf   , fLayout);
185   fFrameMain->AddFrame(fFrameSelFil    , fLayout);
186   fFrameMain->AddFrame(fTableField     , fLayout);
187 //  fFrameMain->AddFrame(fFrameSelForm   , fLayout);
188   fFrameMain->AddFrame(fFrameFFT       , fLayout);
189 //  Int_t step = (Int_t)(ysize/2.);
190   Int_t start = 5; 
191   
192 //  fFrameSelForm->MoveResize(     10, (Int_t)(start+ 1.0*ysize)        ,(UInt_t)(mainx-20)  ,(UInt_t)ysize);
193   fFrameSelFil->MoveResize(      10, (Int_t)(start+ 1.0*ysize)        ,(UInt_t)(mainx-20)  ,(UInt_t)ysize);
194  
195   fFrameSetConf->MoveResize(     10, (Int_t)(start+ 2.0*ysize)        ,(UInt_t)(mainx-20)  ,(UInt_t)ysize);
196   fTableField->MoveResize(       10, (Int_t)(start+ 3.0*ysize)        ,(UInt_t)(mainx-20)  ,(UInt_t)ysize+5);
197  
198   fFrameCalcBSL->MoveResize(     10, (Int_t)(start+   5*ysize)        ,(UInt_t)(mainx-20)  ,(UInt_t)ysize);
199   fFrameCheckPed->MoveResize(    10, (Int_t)(start+   6*ysize)        ,(UInt_t)(mainx-20)  ,(UInt_t)ysize);
200   fFrameChDisFit->MoveResize(    10, (Int_t)(start+   7*ysize)        ,(UInt_t)(mainx-20)  ,(UInt_t)ysize);
201   fFrameCh10bit->MoveResize(     10, (Int_t)(start+   8*ysize)        ,(UInt_t)(mainx-20)  ,(UInt_t)ysize);
202   fFrameCheckVerb->MoveResize(   10, (Int_t)(start+   9*ysize)        ,(UInt_t)(mainx-20)  ,(UInt_t)ysize);
203   
204   
205   yfirst = start+ 14*ysize;
206   fFrameSideA->MoveResize(  (Int_t)xfirst1, (Int_t)yfirst-30               ,(UInt_t)xsize     ,(UInt_t)ysize);
207   fFrameSideB->MoveResize(  (Int_t)xfirst2, (Int_t)yfirst-30               ,(UInt_t)xsize     ,(UInt_t)ysize);
208   
209   // sector buttons 
210   TObjArray     * fFrameArr   = new TObjArray();
211   TGTextButton  * fTextButton = 0;
212   Int_t side   = 0;  
213   Int_t sector = 0;
214   for(Int_t i = 0; i<36; i++)
215     {
216       char nameb[256] ; 
217       if(i<18)sprintf(nameb,"Sector %i",i);
218       else    sprintf(nameb,"Sector %i",i-18);
219       fTextButton = new TGTextButton(fFrameMain,nameb);
220       fFrameMain->AddFrame(fTextButton, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
221       if(i<18)fTextButton->MoveResize((Int_t)xfirst1,(Int_t)(yfirst     +i*ysize),(UInt_t)xsize,(UInt_t)ysize);
222       else    fTextButton->MoveResize((Int_t)xfirst2,(Int_t)(yfirst+(i-18)*ysize),(UInt_t)xsize,(UInt_t)ysize);
223       if(i<18){ side = 0; sector = i;   }
224       else    { side = 1; sector = i-18;}
225       char bef[50]; sprintf(bef,"ProcessSector(%i,%i)",side,sector);
226       fTextButton->SetCommand(bef);
227       fFrameArr->Add(fTextButton);
228     }
229   
230   TGLabel*      flab  = new TGLabel(fFrameMain, new TGHotString("Next Ev.ID"));
231   TGTextBuffer* ftbuf = new TGTextBuffer(10); ftbuf->AddText(0, "1");
232   fTextEvId = new TGTextEntry(fFrameMain, ftbuf);
233   fTextEvId->SetTextColor(200);
234   
235   fFramesel->MoveResize(         10         , (Int_t)(mainy- 15.0*ysize)   ,(UInt_t)mainx-20  ,(UInt_t)ysize);
236   fFrameRMS->MoveResize(         10         , (Int_t)(mainy- 14.0*ysize)   ,(UInt_t)mainx-20  ,(UInt_t)ysize);
237
238   fFrameFFT->MoveResize(         10         , (Int_t)(mainy- 12.0*ysize)   ,(UInt_t)mainx-20  ,(UInt_t)ysize);
239   fFramewrite->MoveResize(       10         , (Int_t)(mainy- 11.0*ysize)   ,(UInt_t)mainx-20  ,(UInt_t)ysize);
240  
241   fFrameWRITE->MoveResize(       10         , (Int_t)(mainy-  9.0*ysize)   ,(UInt_t)mainx-20  ,(UInt_t)ysize);
242   fFrameres->MoveResize(         10         , (Int_t)(mainy-  8.0*ysize)   ,(UInt_t)mainx-20  ,(UInt_t)ysize);
243   
244
245   fFrameCheckProcOne->MoveResize(10         , (Int_t)(mainy-  6.5*ysize)   ,(UInt_t)mainx-20  ,(UInt_t)ysize);
246   
247   flab->MoveResize(             10          , (Int_t)(mainy-  5.0*ysize)   ,(UInt_t)xsize+5   ,(UInt_t)ysize);
248   fTextEvId->MoveResize(      (Int_t)(mainx/2 +10)   , (Int_t)(mainy-  5.0*ysize)   ,(UInt_t)xsize-10  ,(UInt_t)ysize);
249   
250   fFrameNextEvent->MoveResize(   10         , (Int_t)(mainy-  3.5*ysize)   ,(UInt_t)mainx-20  ,(UInt_t)ysize);
251
252   fFrameQuit->MoveResize(        30         , (Int_t)(mainy-  1.5*ysize)   ,(UInt_t)mainx-60  ,(UInt_t)ysize);
253   
254   fFrameMain->MapSubwindows();
255   fFrameMain->MapWindow();
256   fFrameMain->SetWindowName("OM");
257   fFrameMain->MoveResize(0,0,(UInt_t)mainx,(UInt_t)mainy);
258 }  
259
260 //_________________________________________________________________________
261 void WriteHistos()  
262
263   // Write Monitor Histos to file 
264   fMon->WriteHistos() ;
265
266
267 //_________________________________________________________________________
268 void WriteChannel()
269 {
270   // Write 10 bit words to file for current channel
271   fMon->Write10bitChannel();
272 }
273
274 //_________________________________________________________________________
275 void FFT()
276 {
277   // Make Fourier Transformation for current channel
278   fMon->ExecTransform();
279 }
280
281 //_________________________________________________________________________
282 void NextEvent()
283 {
284   // Process next event
285   fMon->SetProcNextEvent(1);
286   fMon->SetupMonitoringTable(fTableField->GetTextEntry()->GetText());
287   Int_t eventid =0;
288   TString s1 =  fTextEvId->GetDisplayText();
289   if(!s1.IsDigit()) { cout << " Invalid EventID  " << endl; return ;}
290   else eventid = s1.Atoi();
291   fMon->SetEventID(eventid);
292   fMon->ResizeCanv();
293   fMon->ProcessEvent();
294   fMon->SetProcNextEvent(0);
295   char tenttext[20] ; sprintf(tenttext,"%i",fMon->GetEventID()+1);
296   fTextEvId->SetText(tenttext);
297 }
298
299 //_________________________________________________________________________
300 void SetCheckVerb()
301 {
302   // Change verbose mode
303   if(fFrameCheckVerb->IsDown())     {     fVerb = 1; fMon->SetVerbose(1); }
304   else                              {     fVerb = 0; fMon->SetVerbose(0); }
305 }
306 //_________________________________________________________________________
307 void SetPedestalRun(Int_t val)
308 {
309   // Set Pedestal calculation mode 
310   if(val==0)
311     {
312       // check pedestal run button
313       if(fFrameCheckPed->IsDown())  {     fMon->SetPedestals(0);          fFrameCalcBSL->SetDown(0);    }
314       else                          {     fMon->SetPedestals(1);          fFrameCalcBSL->SetDown(1);    }
315     }
316   else  
317     {
318       // check online calc button
319       if(fFrameCalcBSL->IsDown())   {     fMon->SetPedestals(1);          fFrameCheckPed->SetDown(0);   }
320       else                          {     fMon->SetPedestals(2);          fFrameCheckPed->SetDown(0);   }
321     } 
322 }
323
324 //_________________________________________________________________________
325 void SetWrite10Bit()
326 {
327   // Set Write 10Bit mode
328   // 10 bit words will be written in AliTPCMonitorAltro for each equipment
329   if(fMon->GetWrite10Bit()==1) fMon->SetWrite10Bit(0);
330   else                         fMon->SetWrite10Bit(1);
331 }
332
333 //_________________________________________________________________________
334 void DisableFit()
335 {
336   // Disable Gamma4 fit to maximum peak
337   if(fMon->GetFitPulse())      fMon->SetFitPulse(0);
338   else                         fMon->SetFitPulse(1);
339 }
340
341 //_________________________________________________________________________
342 Int_t DrawRMSMap()
343 {
344   // Draw RMS map for IROC and OROC
345   if(fMon->GetLastSector()==-1) cout << " no sector written yet " << endl;
346   else fMon->DrawRMSMap();
347   return 0;
348 }
349
350 //_________________________________________________________________________
351 void ProcessSector(Int_t sid, Int_t sec)
352 {
353   // Process specific sector. Initiated by button
354   if(fMon->GetSectorFilled(sec,sid))
355     {
356       fMon->SetLastSector(sec +sid*18);
357       fMon->SetProcNextEvent(0);
358       fMon->ProcessEvent();
359     }
360   else 
361     {
362       cout << " Sector not filled " << endl;
363     }
364 }
365
366 //_________________________________________________________________________
367 void OpenDir()
368 {
369   TString dir ;
370   TString lastfile(fMon->GetLastProcFile());
371   if ( lastfile == "" ) dir=gSystem->pwd();
372   else dir=gSystem->DirName(lastfile);
373   dir="/";
374   TGFileInfo* fi = new TGFileInfo();
375   fi->fIniDir    = StrDup(dir);
376   fi->fFilename  = StrDup(lastfile);
377   if(fVerb) printf("fIniDir = %s\n", fi->fIniDir);
378   
379   new TGFileDialog(gClient->GetRoot(), fFrameMain, kFDOpen, fi);
380   if(!fi->fFilename)            return;
381   if(!strcmp(fi->fFilename,"")) return;
382   string fname(fi->fFilename);
383   Int_t    ffirst   = fname.find_first_not_of("/",0);
384   Int_t    fstart   = 0;  
385   string   firsts   = fname.substr(ffirst,1);
386   Int_t    firstsl  = strcmp(firsts.data(),":");
387   Int_t    firstcol = strcmp(firsts.data(),"@");
388   if ( (fname.find("mem:")!=string::npos) || (fname.find("rfio")!=string::npos) || (fname.find("http")!=string::npos)
389        || !firstsl || !firstcol  )  fstart= ffirst  ;
390   else                              fstart= ffirst-1; 
391   
392   if(fstart <0){ cout << " return : missing slash at beginning of file " << endl ; return ;}
393   
394   string fsubname =  fname.substr(fstart,fname.length()-fstart);
395   fMon->SetFile((Char_t *)fsubname.data());
396
397   if(fVerb) 
398     {
399       cout << "Monitor.C OpenDir:: dir    : " << fi->fIniDir       << endl; 
400       cout << "Monitor.C OpenDir:: file   : " << fsubname.data()   << endl;
401       cout << "Monitor.C OpenDir:: format : " << fMon->GetFormat() << endl;
402     }
403 }
404
405 //_________________________________________________________________________
406 void InitDialog(Int_t id)
407 {
408   if(id>0&&id<4)  new AliTPCMonitorDialog((TGWindow*)gClient->GetRoot(), fFrameMain, 400, 400,0,id,fMon);
409   else cout << "Error : Invalid Id " << endl;
410   return;
411 }
412
413 //_________________________________________________________________________
414 void ShowSelected()
415 {
416   InitDialog(2);
417   return;
418 }
419
420 //_________________________________________________________________________
421 void SetConfig()
422 {
423   InitDialog(3);
424 }
425
426 //_________________________________________________________________________
427 void ResizeCanv()
428 {
429   fMon->ResizeCanv();
430   return;
431 }
432
433 //_________________________________________________________________________
434 void SetStyle() 
435 {
436   gStyle->SetScreenFactor(1);
437   gStyle->SetPadTopMargin(0.17);
438   gStyle->SetPadBottomMargin(0.17);
439   gStyle->SetPadLeftMargin(0.17);
440   gStyle->SetPadRightMargin(0.19);
441   gStyle->SetStatColor(kWhite);
442   gStyle->SetPadColor(kWhite);
443   gStyle->SetCanvasColor(kWhite);
444   gStyle->SetPadBorderMode(0);
445   gStyle->SetPadBorderSize(0);
446   gStyle->SetCanvasBorderMode(0);
447   gStyle->SetCanvasBorderSize(0);
448   gStyle->SetFrameBorderMode(0);
449   gStyle->SetFrameBorderSize(1);
450   gStyle->SetOptStat(0);
451   gStyle->SetPalette(1);
452   gStyle->SetTitleFillColor(0);
453   gStyle->SetTitleOffset(1.3,"X");
454   gStyle->SetTitleOffset(1.9,"Y");
455   gStyle->SetTitleOffset(1.7,"Z");
456   gStyle->SetPalette(1);
457
458 }
459
460 //_________________________________________________________________________
461 void ReadMe()
462 {
463 //  AliTPCMonitorEditor *ed = new AliTPCMonitorEditor(fFrameMain, 700, 400);
464 //  char nameread[256]; sprintf(nameread,"%s/TPC/Monitor/TPCMonitorReadMe.txt",gSystem->Getenv("ALICE_ROOT"));
465 //  ed->LoadFile(nameread);
466 //  ed->Popup();
467 }
468
469 //_________________________________________________________________________
470 void SetProcOne()
471 {
472   if(fFrameCheckProcOne->IsDown())  { fMon->SetProcOneSector(1); }
473   else                              { fMon->SetProcOneSector(0); }
474   
475 }
476 //_________________________________________________________________________
477 void Quit() 
478 {
479   gApplication->Terminate(0);
480 }
481