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