]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCMonitorDialog.cxx
Set the detector version to 0 for upgrade. Tmp.hack to make the simulation chain...
[u/mrichter/AliRoot.git] / TPC / AliTPCMonitorDialog.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.1  2007/09/17 10:23:31  cvetan
19 New TPC monitoring package from Stefan Kniege. The monitoring package can be started by running TPCMonitor.C macro located in macros folder.
20
21 */ 
22
23 ////////////////////////////////////////////////////////////////////////
24 ////
25 //// AliTPCMonitorDialog class
26 ////
27 //// Class to handle dialogs for settings of files and configurations 
28 //// for the AliTPCMonitor
29 //// 
30 //// The dialog will be called by an AliTPCMonitor object from the macro TPCMonitor.C.
31 //// Depending on the version number passed when creating an Object of this class
32 //// a certain dialog window (see constructor)  for the TPCMonitor will be opened.
33 //// The data inserted will be passed to the configuration handler and read out
34 //// by the monitor object or a the monitor member function will be directly called.
35 ////  
36 //// Author: Stefan Kniege, IKF, Frankfurt
37 ////       
38 ////
39 /////////////////////////////////////////////////////////////////////////
40
41
42
43
44 #include <cstdlib>
45 #include "AliTPCMonitorDialog.h"
46 #include "TGTab.h"
47 #include "TGButton.h"
48 #include "TGLabel.h"
49 #include "TGListBox.h"
50 #include "TGLayout.h"
51 #include "TGTextBuffer.h"
52 #include "TGTextEntry.h" 
53 #include "TGWindow.h"
54 #include "TVirtualPadEditor.h"
55 #include "TTimer.h"
56 #include <Riostream.h>
57 #include "Rtypes.h"
58 #include "AliLog.h"
59
60 using std::string;
61
62 ClassImp(AliTPCMonitorDialog)
63 //_____________________________________________________________________________________________
64 AliTPCMonitorDialog::AliTPCMonitorDialog(TGWindow *p, TGWindow *main, UInt_t w,
65                                          UInt_t h, UInt_t options, Int_t version,AliTPCMonitor* monitor):
66   //fQObject(0),
67 fFrameMain(new TGTransientFrame(p, main, w, h, options)),
68 fFrameComp(0),
69 fFrameHor(new TGHorizontalFrame(fFrameMain, 60, 20, kFixedWidth)),
70 fFrameGroup(0),
71 fOkButton(new TGTextButton(fFrameHor, "&Ok", 1)),
72 fListBox(0),
73 fTab(new TGTab(fFrameMain, 300, 300)),
74 fLayout1(new TGLayoutHints(kLHintsTop    | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2)),
75 fLayout2(new TGLayoutHints(kLHintsBottom | kLHintsRight                , 2, 2, 5, 1)),
76 fLayout3(new TGLayoutHints(kLHintsTop    | kLHintsLeft, 5, 5, 5, 5)),
77 fMonitor(monitor),
78 fWidth(w),
79 fHeight(h),
80 fOptions(options),
81 fVersion(version),
82 fClient(p),
83 fMain(main)
84 {
85   // Constructor for Dialog window.
86   // Create a dialog window.depending on the version it is called with..
87   // Verrion 0: Choose DATA Format
88   // Version 1: Choose FEC components to display
89   // Version 2: Choose Ranges for base and max adc calculation
90   
91   fFrameMain->Connect("CloseWindow()", "AliTPCMonitorDialog", this, "DoClose()");
92   fFrameMain->DontCallClose();
93   fFrameMain->SetCleanup(kDeepCleanup);
94   fOkButton->Connect("Clicked()", "AliTPCMonitorDialog", this, "DoOK()");
95   fFrameHor->AddFrame(fOkButton, fLayout1);
96   fFrameHor->Resize(150, fOkButton->GetDefaultHeight());
97   fFrameMain->AddFrame(    fFrameHor, fLayout2);
98   fTab->Connect("Selected(Int_t)", "AliTPCMonitorDialog", this, "DoTab(Int_t)");
99   CreateDialogVersion(version);
100 }
101
102 //_____________________________________________________________________________
103 AliTPCMonitorDialog::AliTPCMonitorDialog(const AliTPCMonitorDialog &dialog) :
104 TNamed(dialog.GetName(),dialog.GetTitle()),
105 //fQObject(0),
106 fFrameMain(new TGTransientFrame(dialog.GetClient(), dialog.GetMainFrame(), dialog.GetWidth(), dialog.GetHeight())),
107 fFrameComp(0),
108 fFrameHor(new TGHorizontalFrame(fFrameMain, 60, 20, kFixedWidth)),
109 fFrameGroup(0),
110 fOkButton(new TGTextButton(fFrameHor, "&Ok", 1)),
111 fListBox(0),
112 fTab(new TGTab(fFrameMain, 300, 300)),
113 fLayout1(new TGLayoutHints(kLHintsTop    | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2)),
114 fLayout2(new TGLayoutHints(kLHintsBottom | kLHintsRight                , 2, 2, 5, 1)),
115 fLayout3(new TGLayoutHints(kLHintsTop    | kLHintsLeft, 5, 5, 5, 5)),
116 fMonitor(dialog.GetMonitor()),
117 fWidth(dialog.GetWidth()),
118 fHeight(dialog.GetHeight()),
119 fOptions(dialog.GetOptions()),
120 fVersion(dialog.GetVersion()),
121 fClient(dialog.GetClient()),
122 fMain(dialog.GetMainFrame())
123 {
124   // copy constructor (actually none forseen for this class)
125   fFrameMain->Connect("CloseWindow()", "AliTPCMonitorDialog", this, "DoClose()");
126   fFrameMain->DontCallClose();
127   fFrameMain->SetCleanup(kDeepCleanup);
128   fOkButton->Connect("Clicked()", "AliTPCMonitorDialog", this, "DoOK()");
129   fFrameHor->AddFrame(fOkButton, fLayout1);
130   fFrameHor->Resize(150, fOkButton->GetDefaultHeight());
131   fFrameMain->AddFrame(    fFrameHor, fLayout2);
132   fTab->Connect("Selected(Int_t)", "AliTPCMonitorDialog", this, "DoTab(Int_t)");
133   CreateDialogVersion(dialog.GetVersion());
134   
135 }
136
137  //_____________________________________________________________________________
138 AliTPCMonitorDialog &AliTPCMonitorDialog::operator =(const AliTPCMonitorDialog& dialog) 
139 {
140   // assignement operator (actually none forseen for this class)
141   if(this!=&dialog)
142   {
143     fFrameMain  = new TGTransientFrame(dialog.GetClient(), dialog.GetMainFrame(), dialog.GetWidth(), dialog.GetHeight());
144     fFrameComp  = 0;
145     fFrameHor   = new TGHorizontalFrame(fFrameMain, 60, 20, kFixedWidth);
146     fFrameGroup = 0;
147     fOkButton   =  new TGTextButton(fFrameHor, "&Ok", 1);
148     fListBox    = 0;
149     fTab        = new TGTab(fFrameMain, 300, 300);
150     fLayout1    = new TGLayoutHints(kLHintsTop    | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2);
151     fLayout2    = new TGLayoutHints(kLHintsBottom | kLHintsRight                , 2, 2, 5, 1);
152     fLayout3    = new TGLayoutHints(kLHintsTop    | kLHintsLeft, 5, 5, 5, 5);
153     fMonitor    = dialog.GetMonitor();
154     fWidth      = dialog.GetWidth();
155     fHeight     = dialog.GetHeight();
156     fOptions    = dialog.GetOptions();
157     fClient     = dialog.GetClient();
158     fVersion    = dialog.GetVersion();
159     fMain       = dialog.GetMainFrame();
160     fFrameMain->Connect("CloseWindow()", "AliTPCMonitorDialog", this, "DoClose()");
161     fFrameMain->DontCallClose();
162     fFrameMain->SetCleanup(kDeepCleanup);
163     fOkButton->Connect("Clicked()", "AliTPCMonitorDialog", this, "DoOK()");
164     fFrameHor->AddFrame(fOkButton, fLayout1);
165     fFrameHor->Resize(150, fOkButton->GetDefaultHeight());
166     fFrameMain->AddFrame(    fFrameHor, fLayout2);
167     fTab->Connect("Selected(Int_t)", "AliTPCMonitorDialog", this, "DoTab(Int_t)");
168     CreateDialogVersion(dialog.GetVersion());
169   }
170   return *this;
171 }
172
173
174
175 //_____________________________________________________________________________________________
176 void AliTPCMonitorDialog::CreateDialogVersion(Int_t version)
177 {
178   // Create a dialog window depending on the version passed
179   
180   if(version==1)
181   {
182       // Choose DATA Format ////////////////////////////////////////////////////
183     TGTextButton *bt;
184     TGCompositeFrame* tf = fTab->AddTab("Select Format");
185     fFrameComp = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
186     fFrameComp->AddFrame(bt = new TGTextButton(fFrameComp, "Select Entry", 1), fLayout3);
187     
188     bt->Connect("Clicked()", "AliTPCMonitorDialog", this, "HandleButtons()");
189     fFrameComp->AddFrame(fListBox = new TGListBox(fFrameComp, 1), fLayout3);
190     tf->AddFrame(fFrameComp, fLayout3);
191     fListBox->AddEntry("ROOT  file        ", 0);
192     fListBox->AddEntry("DATE  file        ", 1);
193     fListBox->AddEntry("DATE  file/stream ", 2);
194     
195     fListBox->Resize(200, 80);
196     
197   }
198   else if(version==2)
199   {
200       // choose component to be displayed /////////////////////////////////////
201     fFrameGroup = new TGGroupFrame(fFrameMain, "Components", kVerticalFrame);
202     fFrameGroup->SetTitlePos(TGGroupFrame::kRight); // right aligned
203     fFrameMain->AddFrame(fFrameGroup, fLayout3);
204     fFrameGroup->SetLayoutManager(new TGMatrixLayout(fFrameGroup, 0, 2, 10));
205     
206     const Char_t names[6][40] ={
207       "FEC (global)",
208         "RCU (patch) ",
209         "Branch      ",
210         "FEC (local) ",
211         "Connector   ",
212         "Chip        "
213     };
214     for (Int_t j = 0; j < 6; j++)
215     {
216       fFrameGroup->AddFrame(new TGLabel(fFrameGroup, new TGHotString(names[j])));
217       
218       fBuf[j] = new TGTextBuffer(10);
219       fBuf[j]->AddText(0, "all");
220       
221       fEnt[j] = new TGTextEntry(fFrameMain, fBuf[j]);
222       fEnt[j]->Resize(50, fEnt[j]->GetDefaultHeight());
223       fEnt[j]->SetFont("-adobe-courier-bold-r-*-*-14-*-*-*-*-*-iso8859-1");
224       fFrameGroup->AddFrame(fEnt[j]);
225       
226     }
227     TGTextButton* bt2 =0;
228     fFrameGroup->AddFrame(bt2 = new TGTextButton(fFrameGroup, "Select Config", 2), fLayout3);
229     bt2->Connect("Clicked()", "AliTPCMonitorDialog", this, "HandleButtons()");
230     fFrameGroup->Resize();
231   }
232   else if(version==3)
233   {
234       // choose component to be displayed /////////////////////////////////////
235     fFrameGroup = new TGGroupFrame(fFrameMain, "Ranges BASE/MAX/SUM ", kVerticalFrame);
236     fFrameGroup->SetTitlePos(TGGroupFrame::kRight);
237     fFrameMain->AddFrame(fFrameGroup, fLayout3);
238     fFrameGroup->SetLayoutManager(new TGMatrixLayout(fFrameGroup, 0, 2, 10));
239     
240     const Char_t names[3][40] = {
241       "baseline",
242         "maximum adc",
243         "sum adc ",
244     };
245     
246     for (Int_t j = 0; j < 3; j++) {
247       fFrameGroup->AddFrame(new TGLabel(fFrameGroup, new TGHotString(names[j])));
248       
249       fBuf[j] = new TGTextBuffer(30);
250       if(j==0) fBuf[j]->AddText(0,Form("%i,%i",fMonitor->GetRangeBaseMin()  , fMonitor->GetRangeBaseMax()));
251       if(j==1) fBuf[j]->AddText(0,Form("%i,%i",fMonitor->GetRangeMaxAdcMin(), fMonitor->GetRangeMaxAdcMax()));
252       if(j==2) fBuf[j]->AddText(0,Form("%i,%i",fMonitor->GetRangeSumMin()   , fMonitor->GetRangeSumMax()));
253       
254       fEnt[j] = new TGTextEntry(fFrameMain, fBuf[j]);
255       fEnt[j]->Resize(100, fEnt[j]->GetDefaultHeight());
256       fEnt[j]->SetFont("-adobe-courier-bold-r-*-*-14-*-*-*-*-*-iso8859-1");
257       fFrameGroup->AddFrame(fEnt[j]);
258       
259     }
260     TGTextButton* bt2 =0;
261     fFrameGroup->AddFrame(bt2 = new TGTextButton(fFrameGroup, "Select Config", 3), fLayout3);
262     bt2->Connect("Clicked()", "AliTPCMonitorDialog", this, "HandleButtons()");
263     fFrameGroup->Resize(100,300);
264   }
265   
266   TGLayoutHints *fL5 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
267                                          kLHintsExpandY, 2, 2, 5, 1);
268   fFrameMain->AddFrame(fTab, fL5);
269   fFrameMain->MapSubwindows();
270   fFrameMain->Resize();
271   
272   fFrameMain->CenterOnParent();
273   if(     version==3)  fFrameMain->SetWindowName("Select Ranges");
274   else if(version==1)  fFrameMain->SetWindowName("Select Component");
275   else                 fFrameMain->SetWindowName("Select Format");
276   fFrameMain->MapWindow();
277 }
278
279 //_____________________________________________________________________________________________
280 AliTPCMonitorDialog::~AliTPCMonitorDialog()
281 {
282   // Delete test dialog widgets.
283   fFrameMain->DeleteWindow();
284 }
285
286 //_____________________________________________________________________________________________
287 void AliTPCMonitorDialog::HandleButtons(Int_t id)
288 {
289   // Handle different buttons.
290   if (id == -1) {
291     TGButton *btn = (TGButton*) gTQSender;
292     id = btn->WidgetId();
293   }
294   
295   switch (id)
296   {
297   case 1:
298     {
299   // Select Format
300       Int_t fsel = fListBox->GetSelected();
301       if(fsel==-1) {  AliError("Warning: No Format selected "); }
302       TGLBEntry* libentr = (TGLBEntry*)fListBox->GetEntry(fsel);
303       AliInfo(Form("Selected Format : %i : %s",fsel,libentr->GetTitle()));
304       fMonitor->SetFormat(fsel);
305       
306       break;
307     }
308   case 2:
309     {
310   // Select FEE Component
311       Int_t compsel=1;
312       Int_t fComponents[10];
313       for(Int_t j = 0; j < 6; j++)
314       {
315         TString s1 =  fEnt[j]->GetDisplayText();
316         if(s1=="all"){  fComponents[j] = -1;          }
317         else         {  fComponents[j] = (int)atoi(s1.Data()); }
318         if(
319             (j==0 && (fComponents[j] < -1 || fComponents[j]>5000)) ||
320             (j==1 && (fComponents[j] < -1 || fComponents[j]>5   )) ||
321             (j==2 && (fComponents[j] < -1 || fComponents[j]>1   )) ||
322             (j==3 && (fComponents[j] < -1 || fComponents[j]>25  )) ||
323             (j==4 && (fComponents[j] < -1 || fComponents[j]>6   )) ||
324             (j==5 && (fComponents[j] < -1 || fComponents[j]>8   ))    )
325         {
326           compsel =0;
327           AliError("Settings out of range ( version 2) ");
328         }
329       }
330       if(compsel==1)
331       {
332         if(fMonitor!=0 && fMonitor->GetEventProcessed() )fMonitor->ShowSel((Int_t*)fComponents);
333         else                                             AliError("No event processed up to now");
334       }
335       break;
336     }
337   case 3:
338     {
339   // Set Configuration (base, max, sum)
340       Int_t fConfigArr[6];
341       
342       string s1((TString)fEnt[0]->GetDisplayText().Data());
343       string s2((TString)fEnt[1]->GetDisplayText().Data());
344       string s3((TString)fEnt[2]->GetDisplayText().Data());
345       
346       Int_t error = 1;
347       
348       if(s1.find(",")!=string::npos){
349         string sub11 = s1.substr(0,s1.find(","))               ;fConfigArr[0] = atoi(sub11.data());
350         string sub12 = s1.substr(s1.find(",")+1,s1.length() )  ;fConfigArr[1] = atoi(sub12.data());
351         if(fConfigArr[0]<fConfigArr[1] && fConfigArr[1]<1024){
352           fMonitor->SetRangeBase(fConfigArr[0],fConfigArr[1]);
353           error=0;
354         }
355       }
356       if(s2.find(",")!=string::npos){
357         string sub21 = s2.substr(0,s2.find(","))               ;fConfigArr[2] = atoi(sub21.data());
358         string sub22 = s2.substr(s2.find(",")+1,s2.length() )  ;fConfigArr[3] = atoi(sub22.data());
359         if(fConfigArr[2]<fConfigArr[3] && fConfigArr[3]<1024){
360           fMonitor->SetRangeMax(fConfigArr[2],fConfigArr[3]);
361           error=0;
362         }
363       }
364       
365       if(s3.find(",")!=string::npos){
366         string sub31 = s3.substr(0,s3.find(","))               ;fConfigArr[4] = atoi(sub31.data());
367         string sub32 = s3.substr(s3.find(",")+1,s3.length() )  ;fConfigArr[5] = atoi(sub32.data());
368         if(fConfigArr[4]<fConfigArr[5] && fConfigArr[5]<1024){
369           fMonitor->SetRangeSum(fConfigArr[4],fConfigArr[5]);
370           error=0;
371         }
372       }
373       if(error!=0) AliError("Settings out of range (version 3)");
374       break;
375     }
376   default:
377     break;
378   }
379 }
380
381 //_____________________________________________________________________________________________
382 void AliTPCMonitorDialog::DoTab(Int_t id) 
383 {
384   printf("Tab item %d activated\n", id);
385 }
386
387 //_____________________________________________________________________________________________
388 void AliTPCMonitorDialog::DoClose() const
389 {
390   // Close the dialog window
391   printf("\nTerminating dialog: via window manager\n");
392   CloseWindow();
393   // Close the Ged editor if it was activated.
394   if (TVirtualPadEditor::GetPadEditor(kFALSE) != 0)
395     TVirtualPadEditor::Terminate();
396 }
397
398 //_____________________________________________________________________________________________
399 void AliTPCMonitorDialog::CloseWindow() const
400 {
401   // Called when window is closed via the window manager.
402   delete this;
403 }
404
405 //_____________________________________________________________________________________________
406 void AliTPCMonitorDialog::DoOK()
407 {
408   // Call from OK button
409   printf("\nTerminating dialog: OK pressed\n");
410   
411   // The same effect can be obtained by using a singleshot timer:
412   TTimer::SingleShot(150, "AliTPCMonitorDialog", this, "CloseWindow()");
413   
414   // Close the Ged editor if it was activated.
415   if (TVirtualPadEditor::GetPadEditor(kFALSE) != 0)
416     TVirtualPadEditor::Terminate();
417 }
418
419
420 //_____________________________________________________________________________________________
421 void AliTPCMonitorDialog::DoCancel()
422 {
423   // Cancel operation and close the dialog window
424   printf("\nTerminating dialog: Cancel pressed\n");
425   TTimer::SingleShot(150, "AliTPCMonitorDialog", this, "CloseWindow()");
426   
427   // Close the Ged editor if it was activated.
428   if (TVirtualPadEditor::GetPadEditor(kFALSE) != 0)
429     TVirtualPadEditor::Terminate();
430 }
431