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