]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveListAnalyserEditor.cxx
Re-import from release requested by Chiara Oppedisano
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveListAnalyserEditor.cxx
CommitLineData
00dc25ef 1// Author: Benjamin Hess 06/11/2009
2
3/*************************************************************************
4 * Copyright (C) 2009, Alexandru Bercuci, Benjamin Hess. *
5 * All rights reserved. *
6 *************************************************************************/
7
8//////////////////////////////////////////////////////////////////////////
9// //
10// AliEveListAnalyserEditor //
11// //
12// The AliEveListAnalyserEditor provides the graphical //
13// functionality for the AliEveTRDAnalyseObject. It creates the tabs //
14// and canvases, when they are needed and, as well, frees allocated //
15// memory on destruction (or if new events are loaded and thus some //
16// tabs are closed). The function DrawHistos() accesses the temporary //
17// file created by the AliEveListAnalyser and draws the desired //
18// data (the file will be created within the call of ApplyMacros()). //
19// Have a look at this function to learn more about the structure of //
20// the file and how to access the data. //
21//////////////////////////////////////////////////////////////////////////
22
23#include <EveDet/AliEveTRDData.h>
24#include <EveDet/AliEveListAnalyser.h>
25#include "AliEveListAnalyserEditor.h"
26
27#include <EveBase/AliEveEventManager.h>
28#include <AliTRDReconstructor.h>
29//#include <AliTRDtrackV1.h>
30#include <TCanvas.h>
31#include <TEveBrowser.h>
32#include <TEveGedEditor.h>
33#include <TEveMacro.h>
34#include <TEveManager.h>
35#include <TFile.h>
36#include <TG3DLine.h>
37#include <TGButton.h>
38#include <TGButtonGroup.h>
39#include <TGFileDialog.h>
40#include <TGLabel.h>
41#include <TGListBox.h>
42#include <TGMsgBox.h>
43#include <TGTab.h>
44#include <TMap.h>
45#include <TObjString.h>
46#include <TROOT.h>
47#include <TString.h>
48#include <TSystem.h>
49#include <TGTextEntry.h>
50#include <TGTextEdit.h>
51#include <TGComboBox.h>
52#include <TGTextView.h>
53#include <TH1.h>
54#include <TTreeStream.h>
55
56
57ClassImp(AliEveListAnalyserEditor)
58
59///////////////////////////////////////////////////////////
60///////////// AliEveListAnalyserEditor //////////
61///////////////////////////////////////////////////////////
62AliEveListAnalyserEditor::AliEveListAnalyserEditor(const TGWindow* p, Int_t width, Int_t height,
63 UInt_t options, Pixel_t back) :
64 TGedFrame(p, width, height, options, back),
65 fM(0),
66 fHistoCanvas(0),
67 fHistoCanvasName(0),
68 fInheritedMacroList(0),
69 fInheritSettings(kFALSE),
70// fStyleFrame(0),
71 fMainFrame(0),
72 fHistoFrame(0),
73 fHistoSubFrame(0),
74 fBrowseFrame(0),
75// fbgStyleColor(0),
76// fbgStyleTrack(0),
77// frbColor(new TGRadioButton*[3]),
78// frbTrack(new TGRadioButton*[3]),
79 fbBrowse(0),
80 fbNew(0),
81 fbApplyMacros(0),
82 fbRemoveMacros(0),
83 fbDrawHisto(0),
84 fteField(0),
85 ftlMacroList(0),
86 ftlMacroSelList(0),
87 fFileInfo(0),
88 fFileTypes(0),
89 fLabel1(0), fLabel2(0), fLabel3(0), fLabel4(0),
90 fLine1(0), fLine2(0), fLine3(0), fLine4(0),
91// fLine5(0),
92 fCheckButtons(0)
93{
94 // Creates the AliEveListAnalyserEditor.
95
96/*
97 // Style stuff
98 fLine5 = new TGHorizontal3DLine(this, 194, 8);
99 AddFrame(fLine5, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 8));
100 fStyleFrame = new TGHorizontalFrame(this);
101 AddFrame(fStyleFrame);
102
103 // Style - Track model
104 fbgStyleTrack = new TGButtonGroup(fStyleFrame, "Track model");
105 fbgStyleTrack->SetMapSubwindows(kTRUE);
106 fbgStyleTrack->Resize(194, 200);
107 fStyleFrame->AddFrame(fbgStyleTrack);
108
109 frbTrack[0] = new TGRadioButton(fbgStyleTrack, "Rieman", 0);
110 frbTrack[0]->SetToolTipText("Set the track model to \"Rieman\" (i.e. the used fit method)");
111 fbgStyleTrack->AddFrame(frbTrack[0]);
112 frbTrack[1] = new TGRadioButton(fbgStyleTrack, "Kalman", 1);
113 frbTrack[1]->SetToolTipText("Set the track model to \"Kalman\" (i.e. the used fit method)");
114 fbgStyleTrack->AddFrame(frbTrack[1]);
115 frbTrack[2] = new TGRadioButton(fbgStyleTrack, "Line", 2);
116 frbTrack[2]->SetToolTipText("Set the track model to \"Line\" (i.e. the used fit method)");
117 fbgStyleTrack->AddFrame(frbTrack[2]);
118
119 // Style - Color model
120 fbgStyleColor = new TGButtonGroup(fStyleFrame, "Color model");
121 fbgStyleColor->SetMapSubwindows(kTRUE);
122 fbgStyleColor->Resize(194, 200);
123 fStyleFrame->AddFrame(fbgStyleColor);
124
125 frbColor[0] = new TGRadioButton(fbgStyleColor, "PID LQ", 0);
126 frbColor[0]->SetToolTipText("Set color model to \"PID LQ\" -> 2 dimensional likelihood particle identification");
127 fbgStyleColor->AddFrame(frbColor[0]);
128 frbColor[1] = new TGRadioButton(fbgStyleColor, "PID NN", 1);
129 frbColor[1]->SetToolTipText("Set color model to \"PID NN\" -> Neural network particle identification");
130 fbgStyleColor->AddFrame(frbColor[1]);
131 frbColor[2] = new TGRadioButton(fbgStyleColor, "ESD Source", 2);
132 frbColor[2]->SetToolTipText("Set color model to \"ESD Source\" -> By source (TPC track prolongation or TRD stand alone)");
133 fbgStyleColor->AddFrame(frbColor[2]);
134*/
135
136 // Functionality for adding macros
137 fMainFrame = CreateEditorTabSubFrame("Process");
138
139 fLabel1 = new TGLabel(fMainFrame,"Add macro(s):");
140 fMainFrame->AddFrame(fLabel1);
141 fBrowseFrame = new TGHorizontalFrame(fMainFrame);
142
143 fteField = new TGTextEntry(fBrowseFrame);
144 fteField->SetToolTipText("Enter the pathname of the macro you want to add here and press \"Enter\"");
145 fteField->Connect("ReturnPressed()","AliEveListAnalyserEditor", this, "HandleMacroPathSet()");
146 fBrowseFrame->AddFrame(fteField);
147
148 fbBrowse = new TGTextButton(fBrowseFrame, "Browse");
149 fbBrowse->SetToolTipText("Browse the macro you want to add");
150 fbBrowse->Connect("Clicked()", "AliEveListAnalyserEditor", this, "BrowseMacros()");
151 fBrowseFrame->AddFrame(fbBrowse);
152
153 fbNew = new TGTextButton(fBrowseFrame, "New");
154 fbNew->SetToolTipText("Start macro creation wizard");
155 fbNew->Connect("Clicked()", "AliEveListAnalyserEditor", this, "NewMacros()");
156 fBrowseFrame->AddFrame(fbNew);
157 fMainFrame->AddFrame(fBrowseFrame);
158
159 fLine1 = new TGHorizontal3DLine(fMainFrame, 194, 8);
160 fMainFrame->AddFrame(fLine1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
161 fLabel2 = new TGLabel(fMainFrame,"Selection macros:");
162 fMainFrame->AddFrame(fLabel2);
163
164 ftlMacroSelList = new TGListBox(fMainFrame);
165 ftlMacroSelList->Resize(194, 94);
166 ftlMacroSelList->SetMultipleSelections(kTRUE);
167 fMainFrame->AddFrame(ftlMacroSelList);
168
169 fLine2 = new TGHorizontal3DLine(fMainFrame, 194, 8);
170 fMainFrame->AddFrame(fLine2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
171 fLabel3 = new TGLabel(fMainFrame,"Process plugins:");
172 fMainFrame->AddFrame(fLabel3);
173
174 ftlMacroList = new TGListBox(fMainFrame);
175 ftlMacroList->Resize(194, 94);
176 ftlMacroList->SetMultipleSelections(kTRUE);
177 fMainFrame->AddFrame(ftlMacroList);
178
179 fLine3 = new TGHorizontal3DLine(fMainFrame, 194, 8);
180 fMainFrame->AddFrame(fLine3, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
181
182 fbApplyMacros = new TGTextButton(fMainFrame, "Apply plugin(s)");
183 fbApplyMacros->SetToolTipText("Apply all selected macros/class functins to the list of objects -> A data file will be generated");
184 fbApplyMacros->Connect("Clicked()", "AliEveListAnalyserEditor", this, "ApplyMacros()");
185 fbApplyMacros->SetRightMargin(12);
186 fMainFrame->AddFrame(fbApplyMacros);
187
188 fbRemoveMacros = new TGTextButton(fMainFrame, "Remove plugin(s)");
189 fbRemoveMacros->SetToolTipText("Remove the selected macros/class functions from the list(s)");
190 fbRemoveMacros->Connect("Clicked()", "AliEveListAnalyserEditor", this, "RemoveMacros()");
191 fMainFrame->AddFrame(fbRemoveMacros);
192
193 // Stuff for displaying histograms
194 fHistoFrame = CreateEditorTabSubFrame("Results");
195 fHistoFrame->SetMapSubwindows(kTRUE);
196 fLabel4 = new TGLabel(fHistoFrame,"Data from plugins:");
197 fHistoFrame->AddFrame(fLabel4);
198
199 fHistoSubFrame = new TGVerticalFrame(fHistoFrame);
200 fHistoSubFrame->SetMapSubwindows(kTRUE);
201 fHistoSubFrame->Resize(194, 200);
202 fHistoFrame->AddFrame(fHistoSubFrame);
203
204 fLine4 = new TGHorizontal3DLine(fHistoFrame, 194, 8);
205 fHistoFrame->AddFrame(fLine4, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
206
207 fbDrawHisto = new TGTextButton(fHistoFrame, "Draw projections");
208 fbDrawHisto->SetToolTipText("Uses the data file created by the last \"Apply selected macro(s)\".\nClick here to display the data histograms of the selected macros.\nSelect multiple macros to create multi-dimensional plots.\nHisto macros cannot be used for multi-dimensional plots!");
209 fbDrawHisto->Connect("Clicked()", "AliEveListAnalyserEditor", this, "DrawHistos()");
210 fHistoFrame->AddFrame(fbDrawHisto);
211
212 // Set up file dialog
213 fFileInfo = new TGFileInfo();
214 fFileInfo->SetMultipleSelection(kTRUE);
215
216 fFileTypes = new Char_t*[6];
217 fFileTypes[0] = (Char_t*)"All files"; fFileTypes[1] = (Char_t*)"*";
218 fFileTypes[2] = (Char_t*)"ROOT macros"; fFileTypes[3] = (Char_t*)"*.C";
219 fFileTypes[4] = 0; fFileTypes[5] = 0;
220 fFileInfo->fFileTypes = (const Char_t**)fFileTypes;
221 fFileInfo->fFileTypeIdx = 2;
222 fFileInfo->fMultipleSelection = kTRUE;
223
224 fHistoCanvasName = new TGString("");
225
226/*
227 // Handle style changed signals:
228 fbgStyleTrack->Connect("Clicked(Int_t)", "AliEveListAnalyserEditor", this, "SetTrackModel(Int_t)");
229 fbgStyleColor->Connect("Clicked(Int_t)", "AliEveListAnalyserEditor", this, "SetTrackColor(Int_t)");
230*/
231
232 // Handle the signal "Selected(Int_t ind)"
233 ftlMacroList->Connect("Selected(Int_t)", "AliEveListAnalyserEditor", this, "UpdateMacroListSelection(Int_t)");
234 ftlMacroSelList->Connect("Selected(Int_t)", "AliEveListAnalyserEditor", this, "UpdateMacroListSelection(Int_t)");
235
236 // Handle the signal "NewEventLoaded"
237 AliEveEventManager::GetMaster()->Connect("NewEventLoaded()", "AliEveListAnalyserEditor", this, "HandleNewEventLoaded()");
238
239 // Handle the signal "Selected" (another tab has been selected)
240 GetGedEditor()->GetTab()->Connect("Selected(Int_t)", "AliEveListAnalyserEditor", this, "HandleTabChangedToIndex(Int_t)");
241}
242
243//______________________________________________________
244AliEveListAnalyserEditor::~AliEveListAnalyserEditor()
245{
246 // Destructor: Closes all tabs created by this object and
247 // frees the corresponding memory.
248
249 if (fFileTypes != 0)
250 {
251 delete [] fFileTypes;
252 fFileTypes = 0;
253 }
254
255 if (fFileInfo != 0)
256 {
257 delete fFileInfo;
258 fFileInfo = 0;
259 }
260 // Close and delete all tabs that have been created by this class
261 CloseTabs();
262
263 if (fHistoCanvasName != 0)
264 {
265 delete fHistoCanvasName;
266 fHistoCanvasName = 0;
267 }
268 if (fInheritedMacroList != 0)
269 {
270 fInheritedMacroList->Delete();
271 delete fInheritedMacroList;
272 fInheritedMacroList = 0;
273 }
274}
275
276//______________________________________________________
277void AliEveListAnalyserEditor::AddMacro(const Char_t* name, const Char_t* path)
278{
279 // Adds the macro path/name to the macro list. A warning is provided, if there is
280 // something wrong, e.g. if the macro does not have the correct signature.
281 Int_t result = fM->AddMacro(path, name);
282
283 switch (result)
284 {
285 case SUCCESS:
286 UpdateMacroList();
287 break;
288 case WARNING:
289 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Warning", "Macro is already in list (won't be added again)!",
290 kMBIconExclamation, kMBOk);
291 break;
292 case ERROR:
293 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", "Fail to load the macro (check messages in the terminal)!",
294 kMBIconExclamation, kMBOk);
295 break;
296 case SIGNATURE_ERROR:
297 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
298 "Macro has not the signature of...\n...a single object selection macro: Bool_t YourMacro(const TObject*)\n...a correlated objects selection macro: Bool_t YourMacro(const TObject*, const TObject*)\n...a single object analyse macro: void YourMacro(const TObject*, Double_t*&, Int_t&)\n...a correlated objects analyse macro: void YourMacro(const TObject*, const TObject*, Double_t*&, Int_t&)\n...a single object histo macro: TH1* YourMacro(const TObject*)\n...a correlated objects histo macro: TH1* YourMacro(const TObject*, const TObject*)",
299 kMBIconExclamation, kMBOk);
300 break;
301 case NOT_EXIST_ERROR:
302 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
303 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
304 break;
305 case UNKNOWN_OBJECT_TYPE_ERROR:
306 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
307 "Unknown object type of macro parameter!", kMBIconExclamation, kMBOk);
308 break;
309 default:
310 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
311 Form("AliEveListAnalyser::AddMacro exited with unknown return value: %d", result),
312 kMBIconExclamation, kMBOk);
313 break;
314 }
315}
316
317//______________________________________________________
318void AliEveListAnalyserEditor::ApplyMacros()
319{
320 // Applies the selected macros and updates the view.
321
322 Bool_t success = kFALSE;
323
324 // First apply the single object selection macros
325 TList* selIterator = new TList();
326 ftlMacroSelList->GetSelectedEntries(selIterator);
327 fM->ApplySTSelectionMacros(selIterator);
328
329 // Update view
330 gEve->Redraw3D();
331
332 // Now apply the process macros
333 TList* procIterator = new TList();
334 ftlMacroList->GetSelectedEntries(procIterator);
335 success = fM->ApplyProcessMacros(selIterator, procIterator);
336
337 // Update histogram tab (data has to be reloaded)
338 SetModel(fM);
339 Update();
340
341 // AliEveListAnalyser::ApplyProcessMacros() automatically selects a macro -> Draw the histogram for it,
342 // if a process macro has been applied
343 if (success && procIterator->GetEntries() > 0)
344 {
345 // Set focus on "Histograms" tab
346 GetGedEditor()->GetTab()->SetTab("Results");
347
348 DrawHistos();
349 }
350
351 if (selIterator != 0) delete selIterator;
352 selIterator = 0;
353 if (procIterator != 0) delete procIterator;
354 procIterator = 0;
355
356 if (!success)
357 {
358 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
359 "AliEveListAnalyser::ApplyProcessMacros experienced an error (cf. CINT-output)!",
360 kMBIconExclamation, kMBOk);
361 }
362}
363
364//______________________________________________________
365void AliEveListAnalyserEditor::BrowseMacros()
366{
367 // Creates a file-dialog. The selected files will be added to the macro list
368 // via AddMacro(...).
369
370 new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fFileInfo);
371
372 if (fFileInfo->fIniDir != 0 && fFileInfo->fFileNamesList != 0)
373 {
374 // Extract filenames
375 TObject* iter = fFileInfo->fFileNamesList->First();
376
377 Char_t* name = 0;
378
379 while (iter != 0)
380 {
381 // NOTE: fileInfo->fFileNamesList will be changed by that, too!
382 name = (Char_t*)strrchr(iter->GetName(), '/');
383 // Delete '"' at the end
384 name[strlen(name)] = '\0';
385
386 AddMacro(name + 1, fFileInfo->fIniDir);
387 iter = (TObjString*)fFileInfo->fFileNamesList->After(iter);
388 }
389 }
390
391 // -> The following problem has been fixed (trunk -> Changes according to 03 September 2008):
392 // Some error occurs, when one ends the filedialog with "cancel": fileInfo->fFileNamesList is set to 0x0, but
393 // in the next launch no new memory is allocated. So do this manually.
394 //if (fileInfo->fFileNamesList == 0) fileInfo->fFileNamesList = new TList();
395}
396
397//______________________________________________________
398void AliEveListAnalyserEditor::CloseTabs()
399{
400 // Closes + deletes the tabs created by this object
401
402 if (fHistoCanvas != 0)
403 {
404 // Close the created tab, if it exists
405 if (fHistoCanvasName != 0)
406 {
407 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()))
408 {
409 // Now the created tab is the current one and can be deleted
410 gEve->GetBrowser()->GetTab(1)->RemoveTab();
411 }
412 }
413 // With the tab removal, the canvas will be deleted automatically!
414 fHistoCanvas = 0;
415 }
416}
417
418//______________________________________________________
419void AliEveListAnalyserEditor::DrawHistos()
420{
421 // Accesses the temporary data file created by the last call of ApplyMacros() and draws
422 // histograms according to the selection in the "Histograms"-tab.
423
424 Int_t nHistograms = GetNSelectedHistograms();
425 if (nHistograms <= 0)
426 {
427 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
428 "No data selected. Please select the data you want to plot!", kMBIconExclamation, kMBOk);
429 return;
430 }
431 if (nHistograms > 3)
432 {
433 new TGMsgBox(gClient->GetRoot(), GetMainFrame(),
434 "Error", "Only histograms with up to 3 dimensions supported. Please select 1,2 or 3 data macros!",
435 kMBIconExclamation, kMBOk);
436 return;
437 }
438
439 // Check, if a histo macro shall be drawn
440 Int_t indexOfHistoMacro = -1;
441 Int_t selectedChecked = 0;
442 for (Int_t j = 0; j < fM->fDataFromMacroList->GetEntries(); j++)
443 {
444 if (fCheckButtons[j]->TGButton::GetState() == kButtonDown)
445 {
446 selectedChecked++;
447
448 // Histo macro? -> To check this, look for the substring "(histo macro)"
449 if (strstr(fM->fDataFromMacroList->At(j)->GetName(), "(histo macro)") != 0)
450 {
451 // Is also another macro selected?
452 if (nHistograms > 1)
453 {
454 // Histo macros cannot(!) be correlated!
455 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
456 "Histo macros (return value \"TH1*\") cannot be combined with other macros",
457 kMBIconExclamation, kMBOk);
458 return;
459 }
460
461 // Mark this histo macro for drawing
462 indexOfHistoMacro = j;
463
464 // Have all selected macros been checked? -> If yes, we are done with this
465 if (selectedChecked == nHistograms) break;
466 }
467 }
468 }
469
470 TFile* file = new TFile(Form("/tmp/ListAnalyserMacroData_%s.root", gSystem->Getenv("USER")), "READ");
471 if (!file)
472 {
473 Error("Draw histograms", Form("Cannot open file \"/tmp/ListAnalyserMacroData_%s.root\"",
474 gSystem->Getenv("USER")));
475 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
476 Form("Cannot open file \"/tmp/ListAnalyserMacroData_%s.root\"", gSystem->Getenv("USER")),
477 kMBIconExclamation, kMBOk);
478 return;
479 }
480
481 TTree* t = 0;
482 TTree* tFriend1 = 0;
483 TTree* tFriend2 = 0;
484
485 Int_t indexOfMacro1 = 0;
486 Int_t indexOfMacro2 = 0;
487 Int_t indexOfMacro3 = 0;
488
489 // Variable for the loop below -> Will be set to aborting value, if a histo macro is drawn
490 Int_t i = 0;
491
492 // Draw histo macro?
493 if (indexOfHistoMacro >= 0)
494 {
495 if ((t = (TTree*)file->Get(Form("ObjectData%d", indexOfHistoMacro))))
496 {
497 SetDrawingToHistoCanvasTab();
498
499 TH1* myHist = 0;
500 t->SetBranchAddress(Form("Macro%d", indexOfHistoMacro), &myHist);
501 t->GetEntry(0);
502 if (myHist != 0) myHist->Draw();
503 else
504 {
505 Error("Draw histograms", Form("No histogram for histo macro \"%s\" found!",
506 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()));
507 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
508 Form("No histogram for histo macro \"%s\" found!",
509 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk);
510
511 }
512
513 UpdateHistoCanvasTab();
514 }
515 else
516 {
517 Error("Draw histograms", Form("No data for histo macro \"%s\" found!\nMaybe no objects have been selected.",
518 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()));
519 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
520 Form("No data for histo macro \"%s\" found!\nMaybe no objects have been selected.",
521 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk);
522 }
523
524 // Skip the loop below
525 i = fM->fDataFromMacroList->GetEntries();
526 }
527
528 // Load the trees in succession and remember the entries -> Plot the analyse macros
529 for ( ; i < fM->fDataFromMacroList->GetEntries(); i++)
530 {
531 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown)
532 {
533 if (t == 0)
534 {
535 indexOfMacro1 = i;
536 if (!(t = (TTree*)file->Get(Form("ObjectData%d", i))))
537 {
538 Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no objects have been selected.",
539 fM->fDataFromMacroList->At(i)->GetName()));
540 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
541 Form("No data for macro \"%s\" found!\nMaybe no objects have been selected.",
542 fM->fDataFromMacroList->At(i)->GetName()), kMBIconExclamation, kMBOk);
543 break;
544 }
545
546 // 1d histogram
547 if (nHistograms == 1)
548 {
549 SetDrawingToHistoCanvasTab();
550
551 t->Draw(Form("Macro%d", indexOfMacro1), "1");
552 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s;%s",
553 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
554 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
555 UpdateHistoCanvasTab();
556
557 break;
558 }
559 }
560 else if (tFriend1 == 0)
561 {
562 indexOfMacro2 = i;
563 if (!(tFriend1 = (TTree*)file->Get(Form("ObjectData%d", i))))
564 {
565 Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no objects have been selected.",
566 fM->fDataFromMacroList->At(i)->GetName()));
567 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
568 Form("No data for macro \"%s\" found!\nMaybe no objects have been selected.",
569 fM->fDataFromMacroList->At(i)->GetName()),
570 kMBIconExclamation, kMBOk);
571 break;
572 }
573
574 // 2d histogram
575 if (nHistograms == 2)
576 {
577 SetDrawingToHistoCanvasTab();
578
579 t->AddFriend(tFriend1);
580 t->Draw(Form("Macro%d:Macro%d", indexOfMacro1, indexOfMacro2), "1");
581 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s;%s;%s",
582 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
583 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
584 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
585 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
586
587 UpdateHistoCanvasTab();
588
589 break;
590 }
591 }
592 // 3d histogram
593 else
594 {
595 indexOfMacro3 = i;
596 if (!(tFriend2 = (TTree*)file->Get(Form("ObjectData%d", i))))
597 {
598 Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no objects have been selected.",
599 fM->fDataFromMacroList->At(i)->GetName()));
600 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
601 Form("No data for macro \"%s\" found!\nMaybe no objects have been selected.",
602 fM->fDataFromMacroList->At(i)->GetName()), kMBIconExclamation, kMBOk);
603 break;
604 }
605
606 SetDrawingToHistoCanvasTab();
607
608 t->AddFriend(tFriend1);
609 t->AddFriend(tFriend2);
610 t->Draw(Form("Macro%d:Macro%d:Macro%d", indexOfMacro1, indexOfMacro2, indexOfMacro3), "1");
611 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s - %s;%s;%s;%s",
612 fM->fDataFromMacroList->At(indexOfMacro3)->GetName(),
613 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
614 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
615 fM->fDataFromMacroList->At(indexOfMacro3)->GetName(),
616 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
617 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
618
619 UpdateHistoCanvasTab();
620
621 break;
622 }
623 }
624 }
625
626 if (t != 0) delete t;
627 t = 0;
628 if (tFriend1 != 0) delete tFriend1;
629 tFriend1 = 0;
630 if (tFriend2 != 0) delete tFriend2;
631 tFriend2 = 0;
632
633 file->Close("R");
634 delete file;
635 file = 0;
636}
637
638//______________________________________________________
639Int_t AliEveListAnalyserEditor::GetNSelectedHistograms() const
640{
641 // Returns the number of selected macros (or rather: of their selected data) in the "Histograms"-tab
642
643 Int_t count = 0;
644
645 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
646 {
647 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown) count++;
648 }
649
650 return count;
651}
652
653//______________________________________________________
654void AliEveListAnalyserEditor::HandleMacroPathSet()
655{
656 // Takes the input of the text field (adding a macro), checks if the macro can be
657 // accessed (and that it exists) and adds the macro to the macro list via AddMacro(...).
658 // You can use environment variables in the text field, e.g. "$ALICE_ROOT/Eve/alice-macro/myMacro.C".
659
660 if (strlen(fteField->GetText()) != 0)
661 {
662 // Expand the pathname
663 Char_t* systemPath = gSystem->ExpandPathName(fteField->GetText());
664 fteField->SetText(systemPath);
665 delete systemPath;
666 systemPath = 0;
667
668 // Check if file exists
669 FILE* fp = NULL;
670
671 fp = fopen(fteField->GetText(), "rb");
672 if (fp != NULL)
673 {
674 fclose(fp);
675
676 // Extract filename
677 Char_t* name = (Char_t*)strrchr(fteField->GetText(), '/');
678
679 // Current path
680 if (name == NULL)
681 {
682 name = new Char_t[AliEveListAnalyser::fkMaxMacroNameLength];
683 memset(name, '\0', sizeof(Char_t) * AliEveListAnalyser::fkMaxMacroNameLength);
684 sprintf(name, "%s", fteField->GetText());
685
686 // Add path to textfield -> Path is "./" -> Use length for the name + 2
687 Char_t pathname[AliEveListAnalyser::fkMaxMacroNameLength + 2];
688 memset(pathname, '\0', sizeof(Char_t) * (AliEveListAnalyser::fkMaxMacroNameLength + 2));
689 sprintf(pathname, "./%s", fteField->GetText());
690 fteField->SetText(pathname);
691
692 AddMacro(name);
693 if (name != 0) delete name;
694 name = 0;
695 }
696 // Different path
697 else
698 {
699 // Extract path
700 Char_t* path = new Char_t[AliEveListAnalyser::fkMaxMacroPathLength];
701 memset(path, '\0', sizeof(Char_t) * AliEveListAnalyser::fkMaxMacroPathLength);
702 strncpy(path, fteField->GetText(), strlen(fteField->GetText()) - strlen(name));
703
704 // Ignore the slash "/" in name
705 AddMacro(name + 1, path);
706
707 if (path != 0) delete path;
708 path = 0;
709 }
710 }
711 else
712 {
713 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
714 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
715 }
716 }
717}
718
719//______________________________________________________
720void AliEveListAnalyserEditor::HandleNewEventLoaded()
721{
722 // Closes the tabs created by this object and sets a flag that will
723 // cause the function SetModel() to inherit the macro lists + style
724 // for the next AliEveListAnalyser from the current one.
725
726//TODO: Old version with style tab....
727 // Inherit the macro list and track style for the next track list!
728
729 // Inherit the macro list for the next analyse object list!
730 fInheritSettings = kTRUE;
731
732 // Close the tabs
733 CloseTabs();
734}
735
736//______________________________________________________
737void AliEveListAnalyserEditor::HandleTabChangedToIndex(Int_t index)
738{
739 // Saves the current tab in the current AliEveListAnalyser.
740
741 fM->SetSelectedTab(index);
742}
743
744//______________________________________________________
745void AliEveListAnalyserEditor::InheritMacroList()
746{
747 // The old macro list is possibly stored in the corresponding interior map. This function will
748 // use this interior map to move the data from the interior map to the newly loaded AliEveListAnalyser.
749 // Then the interior map will be cleaned up. With this, the settings will be inherited from the previously
750 // loaded AliEveListAnalyser.
751
752 if (fInheritedMacroList == 0) return;
753
754 // Clear list
755 fM->fMacroList->Delete();
756
757 // Store data from interior list in the analyse object list's map
758 TMapIter* iter = (TMapIter*)fInheritedMacroList->MakeIterator();
759
760 TObject* key = 0;
761 TGeneralMacroData* macro = 0;
762
763 while ((key = iter->Next()) != 0)
764 {
765 macro = (TGeneralMacroData*)fInheritedMacroList->GetValue(key);
766 if (macro != 0) fM->fMacroList->Add(new TObjString(key->GetName()),
767 new TGeneralMacroData(macro->GetName(), macro->GetPath(), macro->GetType()));
768 else
769 {
770 Error("AliEveListAnalyserEditor::InheritMacroList", Form("Failed to inherit the macro \"%s\"!", key));
771 }
772 }
773
774 fInheritedMacroList->Delete();
775 delete fInheritedMacroList;
776 fInheritedMacroList = 0;
777}
778
779/*
780//______________________________________________________
781void AliEveListAnalyserEditor::InheritStyle()
782{
783 // The old styles are stored in the corresponding button groups. This function will replace
784 // the style settings of the newly loaded AliEveListAnalyser with the old styles. With this, the settings
785 // will be inherited from the previously loaded AliEveListAnalyser.
786
787 for (Int_t ind = 0; ind < 3; ind++)
788 {
789 if (fbgStyleTrack->GetButton(ind)->IsOn())
790 {
791 SetTrackModel(ind);
792 break;
793 }
794 }
795 for (Int_t ind = 0; ind < 3; ind++)
796 {
797 if (fbgStyleColor->GetButton(ind)->IsOn())
798 {
799 SetTrackColor(ind);
800 break;
801 }
802 }
803}
804*/
805
806//______________________________________________________
807void AliEveListAnalyserEditor::NewMacros()
808{
809 // Start the macro creation wizard.
810 // thanks to Jacek Otwinowski<J.Otwinowski@GSI.DE> for this suggestion
811
812 AliEveGeneralMacroWizard *wizz = new AliEveGeneralMacroWizard();
813 wizz->Connect("Create(Char_t*)", "AliEveListAnalyserEditor", this, "AddMacro(Char_t*)");
814}
815
816//______________________________________________________
817void AliEveListAnalyserEditor::RemoveMacros()
818{
819 // Removes the selected macros from the corresponding list.
820
821 TList* iterator = new TList();
822
823 ftlMacroList->GetSelectedEntries(iterator);
824 fM->RemoveSelectedMacros(iterator);
825
826 if (iterator != 0) delete iterator;
827
828 iterator = new TList();
829 ftlMacroSelList->GetSelectedEntries(iterator);
830 fM->RemoveSelectedMacros(iterator);
831
832 // Selected macros are deleted from the list -> No selected entries left
833 fM->fMacroListSelected = 0;
834
835 UpdateMacroList();
836
837 if (iterator != 0) delete iterator;
838 iterator = 0;
839}
840
841//______________________________________________________
842void AliEveListAnalyserEditor::SetDrawingToHistoCanvasTab()
843{
844 // Sets gPad to the tab with the name of the current AliEveListAnalyser. If this tab does
845 // not exist, it will be created. Otherwise, it is re-used.
846
847 // If the tab with the canvas has been closed, the canvas will be deleted.
848 // So, if there is no tab, set the canvas pointer to zero and recreate it in a new tab.
849 if (fHistoCanvas != 0)
850 {
851 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()) == 0)
852 {
853 fHistoCanvas = 0;
854 }
855 }
856
857 if (!fHistoCanvas)
858 {
859 fHistoCanvas = gEve->AddCanvasTab(fM->GetName());
860 }
861
862 gPad = fHistoCanvas;
863}
864
865//______________________________________________________
866void AliEveListAnalyserEditor::SetModel(TObject* obj)
867{
868 // Sets the model object, updates the related data in the GUI and
869 // inherits settings (cf. Inherit*(...)), if the flag fInheritSettings is set to kTRUE.
870
871 fM = dynamic_cast<AliEveListAnalyser*>(obj);
872
873 if (fM == 0)
874 {
875 Error("SetModel", "Parameter is zero pointer");
876 return;
877 }
878
879 // Provide a pointer to this editor
880 fM->fEditor = this;
881
882 // If macro list + track style shall be inherited from previously loaded track list, do so
883 if (fInheritSettings)
884 {
885 InheritMacroList();
886 //TODO
887 //InheritStyle();
888
889 fInheritSettings = kFALSE;
890 }
891//TODO
892/*
893 // Select the correct styles
894 Int_t b = 0;
895 UChar_t style = fM->GetSelectedTrackStyle();
896 if (TESTBIT(style, AliEveTRDTrack::kSource)) b = 2;
897 else
898 {
899 if (TESTBIT(style, AliEveTRDTrack::kPID)) b = 1;
900 else b = 0;
901 }
902 fbgStyleColor->SetButton(b, kTRUE);
903
904
905 if (TESTBIT(style, AliEveTRDTrack::kTrackCosmics)) b = 2;
906 else
907 {
908 if (TESTBIT(style, AliEveTRDTrack::kTrackModel)) b = 1;
909 else b = 0;
910 }
911 fbgStyleTrack->SetButton(b, kTRUE);
912*/
913 UpdateMacroList();
914 UpdateHistoList();
915
916 // View correct tab
917 GetGedEditor()->GetTab()->SetTab(fM->GetSelectedTab());
918}
919
920//______________________________________________________
921void AliEveListAnalyserEditor::SaveMacroList(TMap* list)
922{
923 // Saves the provided macro list in an interior list. This list will be used by
924 // InheritMacroList() to restore the data in "list". With this method one is able
925 // to inherit the macro list from analyse object list to analyse object list (i.e. from event to event).
926
927 if (fInheritedMacroList != 0)
928 {
929 fInheritedMacroList->Delete();
930 delete fInheritedMacroList;
931 }
932 fInheritedMacroList = new TMap();
933 fInheritedMacroList->SetOwnerKeyValue(kTRUE, kTRUE);
934
935 TMapIter* iter = (TMapIter*)list->MakeIterator();
936 TObject* key = 0;
937 TGeneralMacroData* macro = 0;
938
939 while ((key = iter->Next()) != 0)
940 {
941 macro = (TGeneralMacroData*)fM->fMacroList->GetValue(key);
942 if (macro != 0) fInheritedMacroList->Add(new TObjString(key->GetName()),
943 new TGeneralMacroData(macro->GetName(), macro->GetPath(), macro->GetType()));
944 else
945 {
946 Error("AliEveListAnalyserEditor::SaveMacroList", Form("Failed to inherit the macro \"%s\"!", key));
947 }
948 }
949}
950
951/*
952//______________________________________________________
953void AliEveListAnalyserEditor::SetTrackColor(Int_t ind)
954{
955 // Sets the color model for the tracks, updates the tracks with this model and
956 // redraws the scene.
957
958 switch(ind)
959 {
960 case AliTRDpidUtil::kLQ:
961 fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kLQ);
962 break;
963 case AliTRDpidUtil::kNN:
964 fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kNN);
965 break;
966 default:
967 fM->UpdateTrackStyle(AliEveTRDTrack::kSource);
968 break;
969 }
970
971 gEve->Redraw3D();
972}
973
974//______________________________________________________
975void AliEveListAnalyserEditor::SetTrackModel(Int_t ind)
976{
977 // Sets the track model for the tracks, updates the tracks with this model and
978 // redraws the scene.
979
980 switch(ind)
981 {
982 case AliEveTRDTrack::kRieman:
983 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kRieman);
984 break;
985 case AliEveTRDTrack::kKalman:
986 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kKalman);
987 break;
988 default:
989 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackCosmics);
990 break;
991 }
992
993 gEve->Redraw3D();
994}
995*/
996
997//______________________________________________________
998void AliEveListAnalyserEditor::UpdateDataFromMacroListSelection()
999{
1000 // Saves the current selection in the "Histograms"-tab to the current
1001 // AliEveListAnalyser. This means that the selection is updated and won't
1002 // get lost, if another editor is loaded in Eve.
1003
1004 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
1005 {
1006 fM->SetHistoDataSelection(i, fCheckButtons[i]->IsOn());
1007 }
1008}
1009
1010//______________________________________________________
1011void AliEveListAnalyserEditor::UpdateHistoCanvasTab()
1012{
1013 // Updates the histogram and the corresponding tab (including titles).
1014
1015 // Update name of the tab (tab has been set to current tab!)
1016 fHistoCanvasName->SetString(fM->GetName());
1017
1018 // Use a copy of fHistoCanvasName!! -> If the user closes a tab manually, the TGString
1019 // will be deleted -> Error might occur, when accessing the pointer
1020 gEve->GetBrowser()->GetTab(1)->GetCurrentTab()->SetText(new TGString(fHistoCanvasName));
1021
1022 // Switch tabs to force redrawing
1023 gEve->GetBrowser()->GetTab(1)->SetTab(0);
1024 gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString());
1025 fHistoCanvas->Update();
1026}
1027
1028//______________________________________________________
1029void AliEveListAnalyserEditor::UpdateHistoList()
1030{
1031 // Reloads (updates) the buttons in the "Histograms"-tab via
1032 // the current AliEveListAnalyser (data).
1033
1034 fHistoSubFrame->TGCompositeFrame::Cleanup();
1035
1036 // Set buttons for histograms
1037 if (fCheckButtons != 0) delete fCheckButtons;
1038 fCheckButtons = new TGCheckButton*[fM->fDataFromMacroList->GetEntries()];
1039
1040 TObjString* iter = (TObjString*)fM->fDataFromMacroList->First();
1041 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries() && iter != 0; i++)
1042 {
1043 fCheckButtons[i] = new TGCheckButton(fHistoSubFrame, iter->GetName());
1044 fHistoSubFrame->AddFrame(fCheckButtons[i]);
1045
1046 fCheckButtons[i]->SetState(kButtonUp, kFALSE);
1047 fCheckButtons[i]->MapRaised();
1048 fCheckButtons[i]->SetOn(fM->HistoDataIsSelected(i));
1049 fCheckButtons[i]->Connect("Clicked()", "AliEveListAnalyserEditor", this, "UpdateDataFromMacroListSelection()");
1050
1051 iter = (TObjString*)fM->fDataFromMacroList->After(iter);
1052 }
1053}
1054
1055//______________________________________________________
1056void AliEveListAnalyserEditor::UpdateMacroList()
1057{
1058 // Reloads (updates) the macro list (selection AND process macros) via
1059 // the current AliEveListAnalyser (data).
1060
1061 ftlMacroList->RemoveAll();
1062 ftlMacroSelList->RemoveAll();
1063
1064 TMapIter* iter = (TMapIter*)fM->fMacroList->MakeIterator();
1065 TObject* key = 0;
1066 TGeneralMacroData* macro = 0;
1067
1068 Int_t ind = 0;
1069 while ((key = iter->Next()) != 0)
1070 {
1071 macro = (TGeneralMacroData*)fM->fMacroList->GetValue(key);
1072 if (macro != 0)
1073 {
1074 if (macro->IsProcessMacro())
1075 {
1076 ftlMacroList->AddEntry(macro->GetName(), ind);
1077 // Select, what has been selected before
1078 ftlMacroList->Select(ind, fM->MacroListIsSelected(ind));
1079 ind++;
1080 }
1081 else if (macro->IsSelectionMacro())
1082 {
1083 ftlMacroSelList->AddEntry(macro->GetName(), ind);
1084 // Select, what has been selected before
1085 ftlMacroSelList->Select(ind, fM->MacroListIsSelected(ind));
1086 ind++;
1087 }
1088 else
1089 {
1090 Error("AliEveListAnalyserEditor::UpdateMacroList()",
1091 Form("Macro \"%s/%s.C\" is neither a selection macro nor a process macro!",
1092 macro->GetPath(), macro->GetName()));
1093 }
1094 }
1095 else
1096 {
1097 Error("AliEveListAnalyserEditor::UpdateMacroList()",
1098 Form("Macro list is corrupted: Macro \"%s\" not found!", key->GetName()));
1099 }
1100 }
1101
1102 ftlMacroList->SortByName();
1103 ftlMacroSelList->SortByName();
1104}
1105
1106//______________________________________________________
1107void AliEveListAnalyserEditor::UpdateMacroListSelection(Int_t ind)
1108{
1109 // Saves the current selection in the macro listS to the current
1110 // AliEveListAnalyser. This means that the selection is updated and won't
1111 // get lost, if another editor is loaded in Eve.
1112 // NOTE: The indices in BOTH lists will be unique!
1113
1114 // Toggle selected item
1115 fM->SetMacroListSelection(ind, !fM->MacroListIsSelected(ind));
1116}
1117
1118
1119/////////////////////////////////////////////////
1120ClassImp(AliEveGeneralMacroWizard)
1121
1122//______________________________________________________
1123AliEveGeneralMacroWizard::AliEveGeneralMacroWizard(const TGWindow* p)
1124 :TGMainFrame(p ? p : gClient->GetRoot(), 10, 10, kMainFrame | kVerticalFrame)
1125 ,fTextName(0x0)
1126 ,fTextObjectType(0x0)
1127 ,fCombo(0x0)
1128 ,fTextEdit(0x0)
1129 ,fbCreate(0x0)
1130 ,fbCancel(0x0)
1131{
1132 const Int_t width = 300;
1133
1134 // horizontal frame
1135 TGHorizontalFrame *fFrameName = new TGHorizontalFrame(this, 10, 10, kHorizontalFrame);
1136 TGLabel *fLabel = new TGLabel(fFrameName, "Name*");
1137 fLabel->SetTextJustify(36);
1138 fLabel->SetMargins(0,0,0,0);
1139 fLabel->SetWrapLength(-1);
1140 fFrameName->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1141
1142 fTextName = new TGTextEntry(fFrameName);
1143 fTextName->SetMaxLength(255);
1144 fTextName->SetAlignment(kTextLeft);
1145 fTextName->SetText("");
1146 fTextName->SetToolTipText("The name of your macro");
1147 fTextName->Resize(width, fTextName->GetDefaultHeight());
1148 fFrameName->AddFrame(fTextName, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1149
1150 // horizontal frame
1151 TGHorizontalFrame *fFrameObjectType = new TGHorizontalFrame(this, 10, 10, kHorizontalFrame);
1152 fLabel = new TGLabel(fFrameObjectType, "Object type of macro");
1153 fLabel->SetTextJustify(36);
1154 fLabel->SetMargins(0,0,0,0);
1155 fLabel->SetWrapLength(-1);
1156 fFrameObjectType->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1157
1158 fTextObjectType = new TGTextEntry(fFrameObjectType);
1159 fTextObjectType->SetMaxLength(255);
1160 fTextObjectType->SetAlignment(kTextLeft);
1161 fTextObjectType->SetText("");
1162 // Limit max.length to 80 characters
1163 fTextObjectType->SetMaxLength(80);
1164 fTextObjectType->SetToolTipText("The type of objects, your macro will work with");
1165 fTextObjectType->Resize(width, fTextObjectType->GetDefaultHeight());
1166 fFrameObjectType->AddFrame(fTextObjectType, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1167
1168 // horizontal frame
1169 TGHorizontalFrame *fFrameComment = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1170 fLabel = new TGLabel(fFrameComment, "Comment");
1171 fLabel->SetTextJustify(36);
1172 fLabel->SetMargins(0,0,0,0);
1173 fLabel->SetWrapLength(-1);
1174 fFrameComment->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1175
1176 fTextEdit = new TGTextEdit(fFrameComment, width, 5*fTextName->GetDefaultHeight());
1177 fFrameComment->AddFrame(fTextEdit, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1178
1179 // horizontal frame
1180 TGHorizontalFrame *fFrameType = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1181 fLabel = new TGLabel(fFrameType, "Type*");
1182 fLabel->SetTextJustify(36);
1183 fLabel->SetMargins(0,0,0,0);
1184 fLabel->SetWrapLength(-1);
1185 fFrameType->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1186
1187 fCombo = new TGComboBox(fFrameType, -1, kHorizontalFrame | kSunkenFrame | kDoubleBorder | kOwnBackground);
1188 fCombo->AddEntry("Single Object Selection", AliEveListAnalyser::kSingleObjectSelect);
1189 fCombo->AddEntry("Pair Objects Selection", AliEveListAnalyser::kCorrelObjectSelect);
1190 fCombo->AddEntry("Single Object Analyse", AliEveListAnalyser::kSingleObjectAnalyse);
1191 fCombo->AddEntry("Single Object Histo", AliEveListAnalyser::kSingleObjectHisto);
1192 fCombo->AddEntry("Pair Objects Analyse", AliEveListAnalyser::kCorrelObjectAnalyse);
1193 fCombo->AddEntry("Pair Objects Histo", AliEveListAnalyser::kCorrelObjectHisto);
1194 fCombo->Select(-1);
1195 fCombo->Resize(width, fTextName->GetDefaultHeight());
1196 fFrameType->AddFrame(fCombo, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1197
1198 // horizontal frame
1199 TGHorizontalFrame *fFrameAction = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1200 fbCancel = new TGTextButton(fFrameAction, "Cancel");
1201 fbCancel->SetToolTipText("Exit macro creation wizard");
1202 fFrameAction->AddFrame(fbCancel, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1203 fbCreate = new TGTextButton(fFrameAction, "Done");
1204 fbCreate->SetToolTipText("Use settings to create the macro");
1205 fFrameAction->AddFrame(fbCreate, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1206
1207
1208 // horizontal frame
1209 TGHorizontalFrame *fFrameText = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1210 fLabel = new TGLabel(fFrameText, "(*) Mandatory fields");
1211 fLabel->SetTextJustify(36);
1212 fLabel->SetMargins(0,0,0,0);
1213 fLabel->SetWrapLength(-1);
1214 fFrameText->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1215
1216 // put things together
1217 AddFrame(fFrameName, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1218 AddFrame(fFrameObjectType, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1219 AddFrame(fFrameComment, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1220 AddFrame(fFrameType, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1221 AddFrame(fFrameAction, new TGLayoutHints(kLHintsRight | kLHintsTop | kLHintsExpandX,2,2,2,2));
1222
1223 TGHorizontal3DLine *fLine = new TGHorizontal3DLine(this, 281, 2);
1224 AddFrame(fLine, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1225 AddFrame(fFrameText, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1226
1227
1228 SetWindowName("Macro Wizard");
1229 SetMWMHints(kMWMDecorAll,
1230 kMWMFuncAll,
1231 kMWMInputModeless);
1232 MapSubwindows();
1233
1234 Resize(GetDefaultSize());
1235 MapWindow();
1236
1237 // Do the linking
1238 //fCombo->Connect("Selected(Int_t)", "AliEveGeneralMacroWizard", this, "Create(Int_t)");
1239 fbCreate->Connect("Clicked()", "AliEveGeneralMacroWizard", this, "HandleCreate()");
1240 fbCancel->Connect("Clicked()", "AliEveGeneralMacroWizard", this, "CloseWindow()");
1241
1242 // Standard choice
1243 fCombo->Select(1, kFALSE);
1244}
1245
1246const Char_t *fGeneralIncludes =
1247// TODO: Remove include files corresponding to a track list
1248"#if !defined(__CINT__) || defined(__MAKECINT__)\n"
1249"#include <TROOT.h>\n"
1250"#include <TH1.h>\n"
1251"#include <TRD/AliTRDgeometry.h>\n"
1252"#include <TRD/AliTRDcluster.h>\n"
1253"#include <TRD/AliTRDseedV1.h>\n"
1254"#include <TRD/AliTRDtrackV1.h>\n"
1255"#endif\n";
1256
1257const Char_t *fGeneralMacroTemplate[7] = {
1258""
1259," if (!object) return kFALSE;\n"
1260
1261," n = 0;\n"
1262" r = 0x0;\n"
1263" if (!object) return;\n"
1264
1265," if (!object) return 0x0;\n"
1266" TH1* h = 0x0;\n\n"
1267"// Set bins, xmin and xmax here\n"
1268" Int_t n = 1;\n"
1269" Double_t xmin = 0;\n"
1270" Double_t xmax = 100;\n\n"
1271" if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1272" h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1273" h->GetXaxis()->SetTitle("");\n"
1274" h->GetYaxis()->SetTitle("");\n"
1275" } else h->Reset();\n"
1276
1277," if (!object) return kFALSE;\n"
1278" if (!object2) return kFALSE;\n"
1279
1280," n = 0;\n"
1281" r = 0x0;\n"
1282" if (!object) return;\n"
1283" if (!object2) return;\n"
1284
1285," if (!object) return 0x0;\n"
1286" if (!object2) return 0x0;\n"
1287" TH1* h = 0x0;\n\n"
1288"// Set bins, xmin and xmax here\n"
1289" Int_t n = 1;\n"
1290" Double_t xmin = 0;\n"
1291" Double_t xmax = 100;\n\n"
1292" if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1293" h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1294" h->GetXaxis()->SetTitle("");\n"
1295" h->GetYaxis()->SetTitle("");\n"
1296" } else h->Reset();\n"
1297};
1298
1299
1300const Char_t *fGeneralMacroTemplate_WithType[7] = {
1301""
1302," if (!object) return kFALSE;\n"
1303" if (object->IsA() != OBJECTTYPE::Class()) return kFALSE;\n\n"
1304" const OBJECTTYPE* myObject = dynamic_cast<const OBJECTTYPE*>(object);\n"
1305" if (!myObject) return kFALSE;\n"
1306
1307," n = 0;\n"
1308" r = 0x0;\n"
1309" if (!object) return;\n"
1310" if (object->IsA() != OBJECTTYPE::Class()) return;\n\n"
1311" const OBJECTTYPE* myObject = dynamic_cast<const OBJECTTYPE*>(object);\n"
1312" if (!myObject) return;\n"
1313
1314," if (!object) return 0x0;\n"
1315" if (object->IsA() != OBJECTTYPE::Class()) return 0x0;\n\n"
1316" const OBJECTTYPE* myObject = dynamic_cast<const OBJECTTYPE*>(object);\n"
1317" if (!myObject) return 0x0;\n\n"
1318" TH1* h = 0x0;\n\n"
1319"// Set bins, xmin and xmax here\n"
1320" Int_t n = 1;\n"
1321" Double_t xmin = 0;\n"
1322" Double_t xmax = 100;\n\n"
1323" if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1324" h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1325" h->GetXaxis()->SetTitle("");\n"
1326" h->GetYaxis()->SetTitle("");\n"
1327" } else h->Reset();\n"
1328
1329," if (!object) return kFALSE;\n"
1330" if (!object2) return kFALSE;\n"
1331" if (object->IsA() != OBJECTTYPE::Class()) return kFALSE;\n"
1332" if (object2->IsA() != OBJECTTYPE::Class()) return kFALSE;\n\n"
1333" const OBJECTTYPE* myObject = dynamic_cast<const OBJECTTYPE*>(object);\n"
1334" const OBJECTTYPE* myObject2 = dynamic_cast<const OBJECTTYPE*>(object2);\n"
1335" if (!myObject) return kFALSE;\n"
1336" if (!myObject2) return kFALSE;\n"
1337
1338," n = 0;\n"
1339" r = 0x0;\n"
1340" if (!object) return;\n"
1341" if (!object2) return;\n"
1342" if (object->IsA() != OBJECTTYPE::Class()) return;\n"
1343" if (object2->IsA() != OBJECTTYPE::Class()) return;\n\n"
1344" const OBJECTTYPE* myObject = dynamic_cast<const OBJECTTYPE*>(object);\n"
1345" const OBJECTTYPE* myObject2 = dynamic_cast<const OBJECTTYPE*>(object2);\n"
1346" if (!myObject) return;\n"
1347" if (!myObject2) return;\n"
1348
1349," if (!object) return 0x0;\n"
1350" if (!object2) return 0x0;\n"
1351" if (object->IsA() != OBJECTTYPE::Class()) return 0x0;\n"
1352" if (object2->IsA() != OBJECTTYPE::Class()) return 0x0;\n\n"
1353" const OBJECTTYPE* myObject = dynamic_cast<const OBJECTTYPE*>(object);\n"
1354" const OBJECTTYPE* myObject2 = dynamic_cast<const OBJECTTYPE*>(object2);\n"
1355" if (!myObject) return 0x0;\n"
1356" if (!myObject2) return 0x0;\n"
1357" TH1* h = 0x0;\n\n"
1358"// Set bins, xmin and xmax here\n"
1359" Int_t n = 1;\n"
1360" Double_t xmin = 0;\n"
1361" Double_t xmax = 100;\n\n"
1362" if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1363" h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1364" h->GetXaxis()->SetTitle("");\n"
1365" h->GetYaxis()->SetTitle("");\n"
1366" } else h->Reset();\n"
1367};
1368
1369//______________________________________________________
1370void AliEveGeneralMacroWizard::Create(Int_t type)
1371{
1372 const Char_t* name = fTextName->GetText();
1373 if(strcmp(name,"")==0){
1374 AliInfo("Please specify a name for your macro.");
1375 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1376 "Please specify a name for your macro.", kMBIconExclamation, kMBOk);
1377 //fCombo->Select(-1);
1378 return;
1379 }
1380
1381 Bool_t useGivenType = kFALSE;
1382
1383 // Remove white-spaces
1384 TString* typeStr = new TString();
1385
1386 typeStr->Append(fTextObjectType->GetText());
1387 typeStr->ReplaceAll(" ", "");
1388 fTextObjectType->SetText(typeStr->Data(), kFALSE);
1389
1390 // If an object type is provided by the user, use it!
1391 if (strlen(typeStr->Data()) > 0)
1392 {
1393 // Check, if the class really exists
1394 if (TClass::GetClass(typeStr->Data()) != 0x0)
1395 {
1396 useGivenType = kTRUE;
1397 }
1398 else
1399 {
1400 Int_t buttonsPressed = 0;
1401 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Unknown object type",
1402 Form("The class of your object, \"%s\" has not been found. Do you really want to create your macro with this object type?",
1403 typeStr->Data()), kMBIconExclamation, kMBYes | kMBNo, &buttonsPressed);
1404
1405 if (buttonsPressed & kMBYes) useGivenType = kTRUE;
1406 else useGivenType = kFALSE;
1407
1408 // Cancel creation
1409 if (!useGivenType)
1410 {
1411 typeStr->Clear();
1412 if (typeStr != 0) delete typeStr;
1413 typeStr = 0;
1414 return;
1415 }
1416 }
1417 }
1418
1419 // Note: gSystem->AccessPathName(...) returns kTRUE, if the access FAILED!
1420 if(!gSystem->AccessPathName(Form("./%s.C", name))){
1421 // If there is already a file with this name -> Error
1422 AliInfo(Form("A macro \"%s.C\" already exists in the current directory!\nPlease choose another name!", name));
1423 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1424 Form("A macro \"%s.C\" already exists in the current directory!\nPlease choose another name!", name), kMBIconExclamation, kMBOk);
1425 //fCombo->Select(-1);
1426 return;
1427 }
1428
1429 FILE* fp = 0x0;
1430 if(!(fp = fopen(Form("%s.C", name), "wt"))){
1431 AliInfo("Couldn't create macro file.");
1432 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1433 "Couldn't create macro file.", kMBIconExclamation, kMBOk);
1434 //fCombo->Select(-1);
1435 return;
1436 }
1437
1438 TGText* comment = fTextEdit->GetText();
1439 Char_t* line = 0x0; Int_t iline = 0;
1440 while((line = comment->GetLine(TGLongPosition(0,iline++), 200))) fprintf(fp, "// %s\n", line);
1441
1442 fprintf(fp, "\n%s\n", fGeneralIncludes);
1443
1444 TString* tempStr = new TString();
1445
1446 // Use default type
1447 if (!useGivenType)
1448 {
1449 typeStr->Clear();
1450 typeStr->Append("TObject");
1451 }
1452
1453 switch(type){
1454 case AliEveListAnalyser::kSingleObjectSelect:
1455 // Use "Bool_t 'NAME'(const 'OBJECTTYPE' *object)\n"
1456 tempStr->Append("Bool_t ").Append(name).Append("(const ").Append(typeStr->Data()).Append(" *object)\n");
1457 fprintf(fp, tempStr->Data());
1458 break;
1459 case AliEveListAnalyser::kCorrelObjectSelect:
1460 // Use "Bool_t 'NAME'(const 'OBJECTTYPE' *object, const 'OBJECTTYPE' *object2)\n"
1461 tempStr->Append("Bool_t ").Append(name).Append("(const ").Append(typeStr->Data()).Append(" *object, const ").Append(typeStr->Data()).Append(" *object2)\n");
1462 fprintf(fp, tempStr->Data());
1463 break;
1464 case AliEveListAnalyser::kSingleObjectAnalyse:
1465 // Use "void 'NAME'(const 'OBJECTTYPE' *object, Double_t*& r, Int_t& n)\n"
1466 tempStr->Append("void ").Append(name).Append("(const ").Append(typeStr->Data()).Append(" *object, Double_t*& r, Int_t& n)\n");
1467 fprintf(fp, tempStr->Data());
1468 break;
1469 case AliEveListAnalyser::kSingleObjectHisto:
1470 // Use "TH1* 'NAME'(const 'OBJECTTYPE' *object)\n"
1471 tempStr->Append("TH1* ").Append(name).Append("(const ").Append(typeStr->Data()).Append(" *object)\n");
1472 fprintf(fp, tempStr->Data());
1473 break;
1474 case AliEveListAnalyser::kCorrelObjectAnalyse:
1475 // Use "void 'NAME'(const TObject *object, const TObject *object2, Double_t*& r, Int_t& n)\n"
1476 tempStr->Append("void ").Append(name).Append("(const ").Append(typeStr->Data()).Append(" *object, const ").Append(typeStr->Data()).Append(" *object2, Double_t*& r, Int_t& n)\n");
1477 fprintf(fp, tempStr->Data());
1478 break;
1479 case AliEveListAnalyser::kCorrelObjectHisto:
1480 // Use "TH1* 'NAME'(const 'OBJECTTYPE' *object, const 'OBJECTTYPE' *object2)\n"
1481 tempStr->Append("TH1* ").Append(name).Append("(const ").Append(typeStr->Data()).Append(" *object, const ").Append(typeStr->Data()).Append(" *object2)\n");
1482 fprintf(fp, tempStr->Data());
1483 break;
1484 default:
1485 AliInfo(Form("Unknown type[%d]", type));
1486 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1487 Form("Unknown type[%d]", type), kMBIconExclamation, kMBOk);
1488 fclose(fp);
1489 gSystem->Exec(Form("rm -f %s.C", name));
1490 //fCombo->Select(-1);
1491
1492 tempStr->Clear();
1493 if (tempStr != 0) delete tempStr;
1494 tempStr = 0;
1495
1496 typeStr->Clear();
1497 if (typeStr != 0) delete typeStr;
1498 typeStr = 0;
1499
1500 return;
1501 }
1502
1503 tempStr->Clear();
1504 if (tempStr != 0) delete tempStr;
1505 tempStr = 0;
1506
1507 typeStr->Clear();
1508 if (typeStr != 0) delete typeStr;
1509 typeStr = 0;
1510
1511 if (useGivenType)
1512 {
1513 // Replace "OBJECTTYPE" with the class name
1514 TString* tempStr = new TString();
1515 tempStr->Append(fGeneralMacroTemplate_WithType[type]);
1516
1517 tempStr->ReplaceAll("OBJECTTYPE", fTextObjectType->GetText());
1518
1519 fprintf(fp, "{\n%s\n", tempStr->Data());
1520
1521 if (tempStr != 0)
1522 {
1523 tempStr->Clear();
1524 delete tempStr;
1525 tempStr = 0;
1526 }
1527 }
1528 else
1529 {
1530 fprintf(fp, "{\n%s\n", fGeneralMacroTemplate[type]);
1531 }
1532 fprintf(fp, "// add your own code here\n\n\n}\n");
1533 fclose(fp);
1534
1535 Emit("Create(Int_t)", type);
1536 Create((Char_t*)name);
1537 CloseWindow();
1538}
1539
1540//______________________________________________________
1541void AliEveGeneralMacroWizard::Create(Char_t *name)
1542{
1543 Emit("Create(Char_t*)", Form("%s.C", name));
1544}
1545
1546//______________________________________________________
1547void AliEveGeneralMacroWizard::HandleCreate()
1548{
1549 Create(fCombo->GetSelected());
1550}