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"
22 #include "TGComboBox.h"
24 #include "AliTPCMonitor.h"
25 #include "AliTPCMonitorMappingHandler.h"
26 //#include "AliTPCMonitorEditor.h"
27 #include "AliTPCMonitorDialog.h"
32 static AliTPCMonitor* fMon = 0;
33 static AliTPCMonitorMappingHandler* fMapHand = 0;
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;
43 static TGComboBox* fTableField = 0;
45 static Int_t fVerb = 0;
46 static TGTextEntry* fTextEvId = 0;
52 //void ProcessSector(char* fdata,char* ffil, Int_t side, Int_t sector);
53 void ProcessSector(Int_t sid, Int_t sector);
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);
71 //_________________________________________________________________________
74 // Initialize the monitor
77 TString aliceroot=gSystem->Getenv("ALICE_ROOT");
78 TString dateroot=gSystem->Getenv("DATE_ROOT");
80 cout << " ALICE_ROOT : " << aliceroot.Data() << endl;
81 cout << " DATE_ROOT : " << dateroot.Data() << endl;
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); }
95 fMon = new AliTPCMonitor("monitor","monitor");
96 fMon->ReadConfig(fnameconf.Data());
97 fMon->SetMappingHandler(fMapHand);
101 //_________________________________________________________________________
102 void MonitorGui(AliTPCMonitor */*fMon*/)
104 // Display the main Window
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();
115 fFrameMain = new TGMainFrame(gClient->GetRoot(),10,10,kMainFrame | kVerticalFrame);
116 fFrameMain->SetLayoutBroken(kTRUE);
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" );
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()" );
158 fTableField->EnableTextInput(kTRUE);
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()");
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); // !!
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.);
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);
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);
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);
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);
210 TObjArray * fFrameArr = new TObjArray();
211 TGTextButton * fTextButton = 0;
214 for(Int_t i = 0; i<36; i++)
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);
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);
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);
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);
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);
245 fFrameCheckProcOne->MoveResize(10 , (Int_t)(mainy- 6.5*ysize) ,(UInt_t)mainx-20 ,(UInt_t)ysize);
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);
250 fFrameNextEvent->MoveResize( 10 , (Int_t)(mainy- 3.5*ysize) ,(UInt_t)mainx-20 ,(UInt_t)ysize);
252 fFrameQuit->MoveResize( 30 , (Int_t)(mainy- 1.5*ysize) ,(UInt_t)mainx-60 ,(UInt_t)ysize);
254 fFrameMain->MapSubwindows();
255 fFrameMain->MapWindow();
256 fFrameMain->SetWindowName("OM");
257 fFrameMain->MoveResize(0,0,(UInt_t)mainx,(UInt_t)mainy);
260 //_________________________________________________________________________
263 // Write Monitor Histos to file
264 fMon->WriteHistos() ;
267 //_________________________________________________________________________
270 // Write 10 bit words to file for current channel
271 fMon->Write10bitChannel();
274 //_________________________________________________________________________
277 // Make Fourier Transformation for current channel
278 fMon->ExecTransform();
281 //_________________________________________________________________________
284 // Process next event
285 fMon->SetProcNextEvent(1);
286 fMon->SetupMonitoringTable(fTableField->GetTextEntry()->GetText());
288 TString s1 = fTextEvId->GetDisplayText();
289 if(!s1.IsDigit()) { cout << " Invalid EventID " << endl; return ;}
290 else eventid = s1.Atoi();
291 fMon->SetEventID(eventid);
293 fMon->ProcessEvent();
294 fMon->SetProcNextEvent(0);
295 char tenttext[20] ; sprintf(tenttext,"%i",fMon->GetEventID()+1);
296 fTextEvId->SetText(tenttext);
299 //_________________________________________________________________________
302 // Change verbose mode
303 if(fFrameCheckVerb->IsDown()) { fVerb = 1; fMon->SetVerbose(1); }
304 else { fVerb = 0; fMon->SetVerbose(0); }
306 //_________________________________________________________________________
307 void SetPedestalRun(Int_t val)
309 // Set Pedestal calculation mode
312 // check pedestal run button
313 if(fFrameCheckPed->IsDown()) { fMon->SetPedestals(0); fFrameCalcBSL->SetDown(0); }
314 else { fMon->SetPedestals(1); fFrameCalcBSL->SetDown(1); }
318 // check online calc button
319 if(fFrameCalcBSL->IsDown()) { fMon->SetPedestals(1); fFrameCheckPed->SetDown(0); }
320 else { fMon->SetPedestals(2); fFrameCheckPed->SetDown(0); }
324 //_________________________________________________________________________
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);
333 //_________________________________________________________________________
336 // Disable Gamma4 fit to maximum peak
337 if(fMon->GetFitPulse()) fMon->SetFitPulse(0);
338 else fMon->SetFitPulse(1);
341 //_________________________________________________________________________
344 // Draw RMS map for IROC and OROC
345 if(fMon->GetLastSector()==-1) cout << " no sector written yet " << endl;
346 else fMon->DrawRMSMap();
350 //_________________________________________________________________________
351 void ProcessSector(Int_t sid, Int_t sec)
353 // Process specific sector. Initiated by button
354 if(fMon->GetSectorFilled(sec,sid))
356 fMon->SetLastSector(sec +sid*18);
357 fMon->SetProcNextEvent(0);
358 fMon->ProcessEvent();
362 cout << " Sector not filled " << endl;
366 //_________________________________________________________________________
370 TString lastfile(fMon->GetLastProcFile());
371 if ( lastfile == "" ) dir=gSystem->pwd();
372 else dir=gSystem->DirName(lastfile);
374 TGFileInfo* fi = new TGFileInfo();
375 fi->fIniDir = StrDup(dir);
376 fi->fFilename = StrDup(lastfile);
377 if(fVerb) printf("fIniDir = %s\n", fi->fIniDir);
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);
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;
392 if(fstart <0){ cout << " return : missing slash at beginning of file " << endl ; return ;}
394 string fsubname = fname.substr(fstart,fname.length()-fstart);
395 fMon->SetFile((Char_t *)fsubname.data());
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;
405 //_________________________________________________________________________
406 void InitDialog(Int_t id)
408 if(id>0&&id<4) new AliTPCMonitorDialog((TGWindow*)gClient->GetRoot(), fFrameMain, 400, 400,0,id,fMon);
409 else cout << "Error : Invalid Id " << endl;
413 //_________________________________________________________________________
420 //_________________________________________________________________________
426 //_________________________________________________________________________
433 //_________________________________________________________________________
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);
460 //_________________________________________________________________________
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);
469 //_________________________________________________________________________
472 if(fFrameCheckProcOne->IsDown()) { fMon->SetProcOneSector(1); }
473 else { fMon->SetProcOneSector(0); }
476 //_________________________________________________________________________
479 gApplication->Terminate(0);