Coverity fixes (Jens)
[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"
37a4e693 22#include "TGComboBox.h"
c4607f01 23
24#include "AliTPCMonitor.h"
25#include "AliTPCMonitorMappingHandler.h"
26//#include "AliTPCMonitorEditor.h"
27#include "AliTPCMonitorDialog.h"
28
29using namespace std;
30
48265b32 31
32static AliTPCMonitor* fMon = 0;
33static AliTPCMonitorMappingHandler* fMapHand = 0;
34
35static TGMainFrame* fFrameMain = 0;
36static TGCheckButton* fFrameChDisFit = 0;
37static TGCheckButton* fFrameCh10bit = 0;
38static TGCheckButton* fFrameCheckVerb = 0;
39static TGCheckButton* fFrameCheckProcOne = 0;
40static TGCheckButton* fFrameCheckPed = 0;
41static TGCheckButton* fFrameCalcBSL = 0;
42
37a4e693 43static TGComboBox* fTableField = 0;
44
48265b32 45static Int_t fVerb = 0;
46static TGTextEntry* fTextEvId = 0;
47
48void WriteChannel();
49void WriteHistos();
50void SetConfig();
51void DisableFit();
c4607f01 52//void ProcessSector(char* fdata,char* ffil, Int_t side, Int_t sector);
53void ProcessSector(Int_t sid, Int_t sector);
54//Int_t DrawFit();
55Int_t DrawRMSMap();
48265b32 56void ShowSelected();
c4607f01 57//void SetSize() ;
48265b32 58void ResizeCanv();
59void ReadMe();
60void OpenDir();
61void SetWrite10Bit();
62void SetCheckVerb();
63void SetProcOne();
c4607f01 64void SetPedestalRun(Int_t val);
48265b32 65void InitDialog(Int_t id);
c4607f01 66//void Resize(Int_t update,Int_t doit , Int_t side);
48265b32 67void MonitorGui(AliTPCMonitor* fMon);
c4607f01 68void SetStyle();
48265b32 69
70
71//_________________________________________________________________________
72void TPCMonitor()
73{
74 // Initialize the monitor
75 SetStyle();
76
6f19bddf 77 TString aliceroot=gSystem->Getenv("ALICE_ROOT");
78 TString dateroot=gSystem->Getenv("DATE_ROOT");
48265b32 79
6f19bddf 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/AliTPCMonitorConfig.txt", aliceroot.Data());
48265b32 88 fMapHand = new AliTPCMonitorMappingHandler("maphand","maphand");
6f19bddf 89 fMapHand->ReadMapping(fglobalmap.Data());
90 fMapHand->ReadRowMappingGlob(frowmap.Data());
91 fMapHand->ReadFECMapping( ffecmap.Data());
48265b32 92 if (gDirectory) { gDirectory->Append(fMapHand); }
93
94 // Monitor
95 fMon = new AliTPCMonitor("monitor","monitor");
6f19bddf 96 fMon->ReadConfig(fnameconf.Data());
48265b32 97 fMon->SetMappingHandler(fMapHand);
98 MonitorGui(fMon);
48265b32 99}
100
101//_________________________________________________________________________
37a4e693 102void MonitorGui(AliTPCMonitor */*fMon*/)
48265b32 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
1d32f273 118// TGTextButton* fFrameSelForm = new TGTextButton(fFrameMain, "Sel. Format " );
48265b32 119 TGTextButton* fFrameSelFil = new TGTextButton(fFrameMain, "Sel. File/Stream" );
37a4e693 120 fTableField = new TGComboBox(fFrameMain );
48265b32 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
1d32f273 139// fFrameSelForm->SetCommand( "InitDialog(1)" );
48265b32 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()" );
37a4e693 156
48265b32 157
37a4e693 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
48265b32 170 fFrameCalcBSL->SetDown( 1);
1d32f273 171 fFrameCheckPed->SetDown( 1);
172 fFrameChDisFit->SetDown( 1);
48265b32 173 fFrameCh10bit->SetDown( 0);
174 fFrameCheckVerb->SetDown(0);
175 fFrameCheckProcOne->SetDown(0);
1d32f273 176 SetPedestalRun(0); // !!
48265b32 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);
37a4e693 186 fFrameMain->AddFrame(fTableField , fLayout);
1d32f273 187// fFrameMain->AddFrame(fFrameSelForm , fLayout);
48265b32 188 fFrameMain->AddFrame(fFrameFFT , fLayout);
c4607f01 189// Int_t step = (Int_t)(ysize/2.);
48265b32 190 Int_t start = 5;
191
1d32f273 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);
48265b32 194
37a4e693 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);
48265b32 197
1d32f273 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);
48265b32 203
204
205 yfirst = start+ 14*ysize;
c4607f01 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);
48265b32 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));
c4607f01 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);
48265b32 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
c4607f01 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);
48265b32 237
c4607f01 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);
48265b32 240
c4607f01 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);
48265b32 243
244
c4607f01 245 fFrameCheckProcOne->MoveResize(10 , (Int_t)(mainy- 6.5*ysize) ,(UInt_t)mainx-20 ,(UInt_t)ysize);
48265b32 246
c4607f01 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);
48265b32 249
c4607f01 250 fFrameNextEvent->MoveResize( 10 , (Int_t)(mainy- 3.5*ysize) ,(UInt_t)mainx-20 ,(UInt_t)ysize);
48265b32 251
c4607f01 252 fFrameQuit->MoveResize( 30 , (Int_t)(mainy- 1.5*ysize) ,(UInt_t)mainx-60 ,(UInt_t)ysize);
48265b32 253
254 fFrameMain->MapSubwindows();
255 fFrameMain->MapWindow();
256 fFrameMain->SetWindowName("OM");
c4607f01 257 fFrameMain->MoveResize(0,0,(UInt_t)mainx,(UInt_t)mainy);
48265b32 258}
259
260//_________________________________________________________________________
261void WriteHistos()
262{
263 // Write Monitor Histos to file
264 fMon->WriteHistos() ;
265}
266
267//_________________________________________________________________________
268void WriteChannel()
269{
270 // Write 10 bit words to file for current channel
271 fMon->Write10bitChannel();
272}
273
274//_________________________________________________________________________
275void FFT()
276{
277 // Make Fourier Transformation for current channel
278 fMon->ExecTransform();
279}
280
281//_________________________________________________________________________
282void NextEvent()
283{
37a4e693 284 // Process next event
48265b32 285 fMon->SetProcNextEvent(1);
37a4e693 286 fMon->SetupMonitoringTable(fTableField->GetTextEntry()->GetText());
48265b32 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//_________________________________________________________________________
300void SetCheckVerb()
301{
302 // Change verbose mode
303 if(fFrameCheckVerb->IsDown()) { fVerb = 1; fMon->SetVerbose(1); }
304 else { fVerb = 0; fMon->SetVerbose(0); }
305}
306//_________________________________________________________________________
307void 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//_________________________________________________________________________
325void 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//_________________________________________________________________________
334void DisableFit()
335{
336 // Disable Gamma4 fit to maximum peak
337 if(fMon->GetFitPulse()) fMon->SetFitPulse(0);
338 else fMon->SetFitPulse(1);
339}
340
341//_________________________________________________________________________
342Int_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();
c4607f01 347 return 0;
48265b32 348}
349
350//_________________________________________________________________________
351void 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//_________________________________________________________________________
367void OpenDir()
368{
369 TString dir ;
370 TString lastfile(fMon->GetLastProcFile());
ac940b58 371 if ( lastfile == "" ) dir=gSystem->pwd();
372 else dir=gSystem->DirName(lastfile);
373 dir="/";
48265b32 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);
c4607f01 380 if(!fi->fFilename) return;
48265b32 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(),"@");
1d32f273 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;
48265b32 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);
c4607f01 395 fMon->SetFile((Char_t *)fsubname.data());
48265b32 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//_________________________________________________________________________
406void InitDialog(Int_t id)
407{
c4607f01 408 if(id>0&&id<4) new AliTPCMonitorDialog((TGWindow*)gClient->GetRoot(), fFrameMain, 400, 400,0,id,fMon);
48265b32 409 else cout << "Error : Invalid Id " << endl;
410 return;
411}
412
413//_________________________________________________________________________
414void ShowSelected()
415{
416 InitDialog(2);
417 return;
418}
419
420//_________________________________________________________________________
421void SetConfig()
422{
423 InitDialog(3);
424}
425
426//_________________________________________________________________________
427void ResizeCanv()
428{
429 fMon->ResizeCanv();
430 return;
431}
432
433//_________________________________________________________________________
434void 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//_________________________________________________________________________
461void ReadMe()
462{
c4607f01 463// AliTPCMonitorEditor *ed = new AliTPCMonitorEditor(fFrameMain, 700, 400);
464// char nameread[256]; sprintf(nameread,"%s/TPC/AliTPCMonitorReadMe.txt",gSystem->Getenv("ALICE_ROOT"));
465// ed->LoadFile(nameread);
466// ed->Popup();
48265b32 467}
468
469//_________________________________________________________________________
470void SetProcOne()
471{
472 if(fFrameCheckProcOne->IsDown()) { fMon->SetProcOneSector(1); }
473 else { fMon->SetProcOneSector(0); }
474
475}
476//_________________________________________________________________________
477void Quit()
478{
479 gApplication->Terminate(0);
480}
481