1 ////////////////////////////////////////////////////////////////////////////////
3 // Macro to launch Monitoring program for TPC raw data
5 // Author: Stefan Kniege, IKF, Frankfurt
7 ////////////////////////////////////////////////////////////////////////////////
13 #include "TGTextEntry.h"
15 #include "TGFileDialog.h"
17 #include "TGApplication.h"
20 #include "TDirectory.h"
21 #include "TFileMerger.h"
23 #include "AliTPCMonitor.h"
24 #include "AliTPCMonitorMappingHandler.h"
25 //#include "AliTPCMonitorEditor.h"
26 #include "AliTPCMonitorDialog.h"
31 static AliTPCMonitor* fMon = 0;
32 static AliTPCMonitorMappingHandler* fMapHand = 0;
34 static TGMainFrame* fFrameMain = 0;
35 static TGCheckButton* fFrameChDisFit = 0;
36 static TGCheckButton* fFrameCh10bit = 0;
37 static TGCheckButton* fFrameCheckVerb = 0;
38 static TGCheckButton* fFrameCheckProcOne = 0;
39 static TGCheckButton* fFrameCheckPed = 0;
40 static TGCheckButton* fFrameCalcBSL = 0;
42 static Int_t fVerb = 0;
43 static TGTextEntry* fTextEvId = 0;
49 //void ProcessSector(char* fdata,char* ffil, Int_t side, Int_t sector);
50 void ProcessSector(Int_t sid, Int_t sector);
61 void SetPedestalRun(Int_t val);
62 void InitDialog(Int_t id);
63 //void Resize(Int_t update,Int_t doit , Int_t side);
64 void MonitorGui(AliTPCMonitor* fMon);
68 //_________________________________________________________________________
71 // Initialize the monitor
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"));
80 cout << " ALICE_ROOT : " << gSystem->Getenv("ALICE_ROOT") << endl;
81 cout << " DATE_ROOT : " << gSystem->Getenv("DATE_ROOT") << endl;
83 fMapHand = new AliTPCMonitorMappingHandler("maphand","maphand");
84 fMapHand->ReadMapping(fglobalmap);
85 fMapHand->ReadRowMappingGlob(frowmap);
86 fMapHand->ReadFECMapping( ffecmap);
87 if (gDirectory) { gDirectory->Append(fMapHand); }
90 fMon = new AliTPCMonitor("monitor","monitor");
91 fMon->ReadConfig(fnameconf);
92 fMon->SetMappingHandler(fMapHand);
97 //_________________________________________________________________________
98 void MonitorGui(AliTPCMonitor *fMon)
100 // Display the main Window
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();
111 fFrameMain = new TGMainFrame(gClient->GetRoot(),10,10,kMainFrame | kVerticalFrame);
112 fFrameMain->SetLayoutBroken(kTRUE);
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" );
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()" );
152 fFrameCalcBSL->SetDown( 1);
153 fFrameCheckPed->SetDown( 1);
154 fFrameChDisFit->SetDown( 1);
155 fFrameCh10bit->SetDown( 0);
156 fFrameCheckVerb->SetDown(0);
157 fFrameCheckProcOne->SetDown(0);
158 SetPedestalRun(0); // !!
160 TGLayoutHints* fLayout = new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5);
161 fFrameMain->AddFrame(fFrameSideA , fLayout);
162 fFrameMain->AddFrame(fFrameSideB , fLayout);
163 fFrameMain->AddFrame(fFrameQuit , fLayout);
164 fFrameMain->AddFrame(fFrameCh10bit , fLayout);
165 fFrameMain->AddFrame(fFrameRMS , fLayout);
166 fFrameMain->AddFrame(fFrameSetConf , fLayout);
167 fFrameMain->AddFrame(fFrameSelFil , fLayout);
168 // fFrameMain->AddFrame(fFrameSelForm , fLayout);
169 fFrameMain->AddFrame(fFrameFFT , fLayout);
170 // Int_t step = (Int_t)(ysize/2.);
173 // fFrameSelForm->MoveResize( 10, (Int_t)(start+ 1.0*ysize) ,(UInt_t)(mainx-20) ,(UInt_t)ysize);
174 fFrameSelFil->MoveResize( 10, (Int_t)(start+ 1.0*ysize) ,(UInt_t)(mainx-20) ,(UInt_t)ysize);
176 fFrameSetConf->MoveResize( 10, (Int_t)(start+ 2.5*ysize) ,(UInt_t)(mainx-20) ,(UInt_t)ysize);
178 fFrameCalcBSL->MoveResize( 10, (Int_t)(start+ 5*ysize) ,(UInt_t)(mainx-20) ,(UInt_t)ysize);
179 fFrameCheckPed->MoveResize( 10, (Int_t)(start+ 6*ysize) ,(UInt_t)(mainx-20) ,(UInt_t)ysize);
180 fFrameChDisFit->MoveResize( 10, (Int_t)(start+ 7*ysize) ,(UInt_t)(mainx-20) ,(UInt_t)ysize);
181 fFrameCh10bit->MoveResize( 10, (Int_t)(start+ 8*ysize) ,(UInt_t)(mainx-20) ,(UInt_t)ysize);
182 fFrameCheckVerb->MoveResize( 10, (Int_t)(start+ 9*ysize) ,(UInt_t)(mainx-20) ,(UInt_t)ysize);
185 yfirst = start+ 14*ysize;
186 fFrameSideA->MoveResize( (Int_t)xfirst1, (Int_t)yfirst-30 ,(UInt_t)xsize ,(UInt_t)ysize);
187 fFrameSideB->MoveResize( (Int_t)xfirst2, (Int_t)yfirst-30 ,(UInt_t)xsize ,(UInt_t)ysize);
190 TObjArray * fFrameArr = new TObjArray();
191 TGTextButton * fTextButton = 0;
194 for(Int_t i = 0; i<36; i++)
197 if(i<18)sprintf(nameb,"Sector %i",i);
198 else sprintf(nameb,"Sector %i",i-18);
199 fTextButton = new TGTextButton(fFrameMain,nameb);
200 fFrameMain->AddFrame(fTextButton, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
201 if(i<18)fTextButton->MoveResize((Int_t)xfirst1,(Int_t)(yfirst +i*ysize),(UInt_t)xsize,(UInt_t)ysize);
202 else fTextButton->MoveResize((Int_t)xfirst2,(Int_t)(yfirst+(i-18)*ysize),(UInt_t)xsize,(UInt_t)ysize);
203 if(i<18){ side = 0; sector = i; }
204 else { side = 1; sector = i-18;}
205 char bef[50]; sprintf(bef,"ProcessSector(%i,%i)",side,sector);
206 fTextButton->SetCommand(bef);
207 fFrameArr->Add(fTextButton);
210 TGLabel* flab = new TGLabel(fFrameMain, new TGHotString("Next Ev.ID"));
211 TGTextBuffer* ftbuf = new TGTextBuffer(10); ftbuf->AddText(0, "1");
212 fTextEvId = new TGTextEntry(fFrameMain, ftbuf);
213 fTextEvId->SetTextColor(200);
215 fFramesel->MoveResize( 10 , (Int_t)(mainy- 15.0*ysize) ,(UInt_t)mainx-20 ,(UInt_t)ysize);
216 fFrameRMS->MoveResize( 10 , (Int_t)(mainy- 14.0*ysize) ,(UInt_t)mainx-20 ,(UInt_t)ysize);
218 fFrameFFT->MoveResize( 10 , (Int_t)(mainy- 12.0*ysize) ,(UInt_t)mainx-20 ,(UInt_t)ysize);
219 fFramewrite->MoveResize( 10 , (Int_t)(mainy- 11.0*ysize) ,(UInt_t)mainx-20 ,(UInt_t)ysize);
221 fFrameWRITE->MoveResize( 10 , (Int_t)(mainy- 9.0*ysize) ,(UInt_t)mainx-20 ,(UInt_t)ysize);
222 fFrameres->MoveResize( 10 , (Int_t)(mainy- 8.0*ysize) ,(UInt_t)mainx-20 ,(UInt_t)ysize);
225 fFrameCheckProcOne->MoveResize(10 , (Int_t)(mainy- 6.5*ysize) ,(UInt_t)mainx-20 ,(UInt_t)ysize);
227 flab->MoveResize( 10 , (Int_t)(mainy- 5.0*ysize) ,(UInt_t)xsize+5 ,(UInt_t)ysize);
228 fTextEvId->MoveResize( (Int_t)(mainx/2 +10) , (Int_t)(mainy- 5.0*ysize) ,(UInt_t)xsize-10 ,(UInt_t)ysize);
230 fFrameNextEvent->MoveResize( 10 , (Int_t)(mainy- 3.5*ysize) ,(UInt_t)mainx-20 ,(UInt_t)ysize);
232 fFrameQuit->MoveResize( 30 , (Int_t)(mainy- 1.5*ysize) ,(UInt_t)mainx-60 ,(UInt_t)ysize);
234 fFrameMain->MapSubwindows();
235 fFrameMain->MapWindow();
236 fFrameMain->SetWindowName("OM");
237 fFrameMain->MoveResize(0,0,(UInt_t)mainx,(UInt_t)mainy);
240 //_________________________________________________________________________
243 // Write Monitor Histos to file
244 fMon->WriteHistos() ;
247 //_________________________________________________________________________
250 // Write 10 bit words to file for current channel
251 fMon->Write10bitChannel();
254 //_________________________________________________________________________
257 // Make Fourier Transformation for current channel
258 fMon->ExecTransform();
261 //_________________________________________________________________________
264 // Process next event
265 fMon->SetProcNextEvent(1);
267 TString s1 = fTextEvId->GetDisplayText();
268 if(!s1.IsDigit()) { cout << " Invalid EventID " << endl; return ;}
269 else eventid = s1.Atoi();
270 fMon->SetEventID(eventid);
272 fMon->ProcessEvent();
273 fMon->SetProcNextEvent(0);
274 char tenttext[20] ; sprintf(tenttext,"%i",fMon->GetEventID()+1);
275 fTextEvId->SetText(tenttext);
278 //_________________________________________________________________________
281 // Change verbose mode
282 if(fFrameCheckVerb->IsDown()) { fVerb = 1; fMon->SetVerbose(1); }
283 else { fVerb = 0; fMon->SetVerbose(0); }
285 //_________________________________________________________________________
286 void SetPedestalRun(Int_t val)
288 // Set Pedestal calculation mode
291 // check pedestal run button
292 if(fFrameCheckPed->IsDown()) { fMon->SetPedestals(0); fFrameCalcBSL->SetDown(0); }
293 else { fMon->SetPedestals(1); fFrameCalcBSL->SetDown(1); }
297 // check online calc button
298 if(fFrameCalcBSL->IsDown()) { fMon->SetPedestals(1); fFrameCheckPed->SetDown(0); }
299 else { fMon->SetPedestals(2); fFrameCheckPed->SetDown(0); }
303 //_________________________________________________________________________
306 // Set Write 10Bit mode
307 // 10 bit words will be written in AliTPCMonitorAltro for each equipment
308 if(fMon->GetWrite10Bit()==1) fMon->SetWrite10Bit(0);
309 else fMon->SetWrite10Bit(1);
312 //_________________________________________________________________________
315 // Disable Gamma4 fit to maximum peak
316 if(fMon->GetFitPulse()) fMon->SetFitPulse(0);
317 else fMon->SetFitPulse(1);
320 //_________________________________________________________________________
323 // Draw RMS map for IROC and OROC
324 if(fMon->GetLastSector()==-1) cout << " no sector written yet " << endl;
325 else fMon->DrawRMSMap();
329 //_________________________________________________________________________
330 void ProcessSector(Int_t sid, Int_t sec)
332 // Process specific sector. Initiated by button
333 if(fMon->GetSectorFilled(sec,sid))
335 fMon->SetLastSector(sec +sid*18);
336 fMon->SetProcNextEvent(0);
337 fMon->ProcessEvent();
341 cout << " Sector not filled " << endl;
345 //_________________________________________________________________________
349 TString lastfile(fMon->GetLastProcFile());
350 if ( lastfile == "" ) dir=gSystem->pwd();
351 else dir=gSystem->DirName(lastfile);
353 TGFileInfo* fi = new TGFileInfo();
354 fi->fIniDir = StrDup(dir);
355 fi->fFilename = StrDup(lastfile);
356 if(fVerb) printf("fIniDir = %s\n", fi->fIniDir);
358 new TGFileDialog(gClient->GetRoot(), fFrameMain, kFDOpen, fi);
359 if(!fi->fFilename) return;
360 if(!strcmp(fi->fFilename,"")) return;
361 string fname(fi->fFilename);
362 Int_t ffirst = fname.find_first_not_of("/",0);
364 string firsts = fname.substr(ffirst,1);
365 Int_t firstsl = strcmp(firsts.data(),":");
366 Int_t firstcol = strcmp(firsts.data(),"@");
367 if ( (fname.find("mem:")!=string::npos) || (fname.find("rfio")!=string::npos) || (fname.find("http")!=string::npos)
368 || !firstsl || !firstcol ) fstart= ffirst ;
369 else fstart= ffirst-1;
371 if(fstart <0){ cout << " return : missing slash at beginning of file " << endl ; return ;}
373 string fsubname = fname.substr(fstart,fname.length()-fstart);
374 fMon->SetFile((Char_t *)fsubname.data());
378 cout << "Monitor.C OpenDir:: dir : " << fi->fIniDir << endl;
379 cout << "Monitor.C OpenDir:: file : " << fsubname.data() << endl;
380 cout << "Monitor.C OpenDir:: format : " << fMon->GetFormat() << endl;
384 //_________________________________________________________________________
385 void InitDialog(Int_t id)
387 if(id>0&&id<4) new AliTPCMonitorDialog((TGWindow*)gClient->GetRoot(), fFrameMain, 400, 400,0,id,fMon);
388 else cout << "Error : Invalid Id " << endl;
392 //_________________________________________________________________________
399 //_________________________________________________________________________
405 //_________________________________________________________________________
412 //_________________________________________________________________________
415 gStyle->SetScreenFactor(1);
416 gStyle->SetPadTopMargin(0.17);
417 gStyle->SetPadBottomMargin(0.17);
418 gStyle->SetPadLeftMargin(0.17);
419 gStyle->SetPadRightMargin(0.19);
420 gStyle->SetStatColor(kWhite);
421 gStyle->SetPadColor(kWhite);
422 gStyle->SetCanvasColor(kWhite);
423 gStyle->SetPadBorderMode(0);
424 gStyle->SetPadBorderSize(0);
425 gStyle->SetCanvasBorderMode(0);
426 gStyle->SetCanvasBorderSize(0);
427 gStyle->SetFrameBorderMode(0);
428 gStyle->SetFrameBorderSize(1);
429 gStyle->SetOptStat(0);
430 gStyle->SetPalette(1);
431 gStyle->SetTitleFillColor(0);
432 gStyle->SetTitleOffset(1.3,"X");
433 gStyle->SetTitleOffset(1.9,"Y");
434 gStyle->SetTitleOffset(1.7,"Z");
435 gStyle->SetPalette(1);
439 //_________________________________________________________________________
442 // AliTPCMonitorEditor *ed = new AliTPCMonitorEditor(fFrameMain, 700, 400);
443 // char nameread[256]; sprintf(nameread,"%s/TPC/AliTPCMonitorReadMe.txt",gSystem->Getenv("ALICE_ROOT"));
444 // ed->LoadFile(nameread);
448 //_________________________________________________________________________
451 if(fFrameCheckProcOne->IsDown()) { fMon->SetProcOneSector(1); }
452 else { fMon->SetProcOneSector(0); }
455 //_________________________________________________________________________
458 gApplication->Terminate(0);