]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveTRDTrackListEditor.cxx
deletion of compiled macros from qa (related to AliEveTRDTrackList)
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTRDTrackListEditor.cxx
CommitLineData
8e27fca1 1#include <EveDet/AliEveTRDData.h>
caaf90d2 2#include <EveDet/AliEveTRDTrackList.h>
2ef0687e 3#include "AliEveTRDTrackListEditor.h"
4
4f6473f6 5#include <EveBase/AliEveEventManager.h>
8e27fca1 6#include <AliTRDtrackV1.h>
caaf90d2 7#include <TGButton.h>
8e27fca1 8#include <TCanvas.h>
4f6473f6 9#include <TEveBrowser.h>
8e27fca1 10#include <TEveGedEditor.h>
caaf90d2 11#include <TEveMacro.h>
12#include <TEveManager.h>
8e27fca1 13#include <TFile.h>
14#include <TG3DLine.h>
15#include <TGFileDialog.h>
16#include <TGLabel.h>
17#include <TGListBox.h>
18#include <TGMsgBox.h>
19#include <TGTab.h>
caaf90d2 20#include <TObjString.h>
caaf90d2 21#include <TROOT.h>
8e27fca1 22#include <TSystem.h>
23#include <TGTextEntry.h>
24#include <TGTextView.h>
bcb45225 25#include <TH1.h>
8e27fca1 26#include <TTreeStream.h>
27
caaf90d2 28
2ef0687e 29ClassImp(AliEveTRDTrackListEditor)
30
31///////////////////////////////////////////////////////////
32///////////// AliEveTRDTrackListEditor //////////////////
33///////////////////////////////////////////////////////////
34AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t width, Int_t height,
35 UInt_t options, Pixel_t back) :
36 TGedFrame(p, width, height, options, back),
37 fM(0),
4f6473f6 38 fHistoCanvas(0),
39 fHistoCanvasName(0),
bcb45225 40 fInheritMacroList(kFALSE),
2ef0687e 41 fMainFrame(0),
caaf90d2 42 fHistoFrame(0),
43 fHistoSubFrame(0),
2ef0687e 44 fBrowseFrame(0),
caaf90d2 45 fbBrowse(0),
46 fbApplyMacros(0),
47 fbRemoveMacros(0),
48 fbDrawHisto(0),
49 fteField(0),
50 ftlMacroList(0),
51 ftlMacroSelList(0),
52 fFileInfo(0),
53 fFileTypes(0),
54 fLabel1(0), fLabel2(0), fLabel3(0), fLabel4(0),
55 fLine1(0), fLine2(0), fLine3(0), fLine4(0),
56 fCheckButtons(0)
57{
2ef0687e 58 fMainFrame = CreateEditorTabSubFrame("Apply macros");
3f797131 59
2ef0687e 60 // Functionality for adding macros
3f797131 61 fLabel1 = new TGLabel(fMainFrame,"Add macro(s):");
62 fMainFrame->AddFrame(fLabel1);
2ef0687e 63 fBrowseFrame = new TGHorizontalFrame(fMainFrame);
64
caaf90d2 65 fteField = new TGTextEntry(fBrowseFrame);
66 fteField->Connect("ReturnPressed()","AliEveTRDTrackListEditor", this, "HandleMacroPathSet()");
67 fBrowseFrame->AddFrame(fteField);
2ef0687e 68
caaf90d2 69 fbBrowse = new TGTextButton(fBrowseFrame, "Browse");
70 fbBrowse->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "BrowseMacros()");
71 fBrowseFrame->AddFrame(fbBrowse);
2ef0687e 72 fMainFrame->AddFrame(fBrowseFrame);
73
3f797131 74 fLine1 = new TGHorizontal3DLine(fMainFrame, 194, 8);
caaf90d2 75 fMainFrame->AddFrame(fLine1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
3f797131 76 fLabel2 = new TGLabel(fMainFrame,"Selection macros:");
77 fMainFrame->AddFrame(fLabel2);
78
caaf90d2 79 ftlMacroSelList = new TGListBox(fMainFrame);
80 ftlMacroSelList->Resize(194, 94);
81 ftlMacroSelList->SetMultipleSelections(kTRUE);
82 fMainFrame->AddFrame(ftlMacroSelList);
3f797131 83
84 fLine2 = new TGHorizontal3DLine(fMainFrame, 194, 8);
caaf90d2 85 fMainFrame->AddFrame(fLine2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
3f797131 86 fLabel3 = new TGLabel(fMainFrame,"Process macros:");
87 fMainFrame->AddFrame(fLabel3);
88
caaf90d2 89 ftlMacroList = new TGListBox(fMainFrame);
90 ftlMacroList->Resize(194, 94);
91 ftlMacroList->SetMultipleSelections(kTRUE);
92 fMainFrame->AddFrame(ftlMacroList);
2ef0687e 93
3f797131 94 fLine3 = new TGHorizontal3DLine(fMainFrame, 194, 8);
caaf90d2 95 fMainFrame->AddFrame(fLine3, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
3f797131 96
caaf90d2 97 fbApplyMacros = new TGTextButton(fMainFrame, "Apply selected macro(s)");
98 fbApplyMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "ApplyMacros()");
99 fbApplyMacros->SetRightMargin(12);
100 fMainFrame->AddFrame(fbApplyMacros);
2ef0687e 101
caaf90d2 102 fbRemoveMacros = new TGTextButton(fMainFrame, "Remove selected macro(s)");
103 fbRemoveMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "RemoveMacros()");
104 fMainFrame->AddFrame(fbRemoveMacros);
2ef0687e 105
caaf90d2 106 // Stuff for displaying histograms
107 fHistoFrame = CreateEditorTabSubFrame("Histograms");
108 fHistoFrame->SetMapSubwindows(kTRUE);
109 fLabel4 = new TGLabel(fHistoFrame,"Data from applied macros:");
110 fHistoFrame->AddFrame(fLabel4);
111
112 fHistoSubFrame = new TGVerticalFrame(fHistoFrame);
113 fHistoSubFrame->SetMapSubwindows(kTRUE);
114 fHistoSubFrame->Resize(194, 200);
115 fHistoFrame->AddFrame(fHistoSubFrame);
116
117 fLine4 = new TGHorizontal3DLine(fHistoFrame, 194, 8);
118 fHistoFrame->AddFrame(fLine4, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
119
120 fbDrawHisto = new TGTextButton(fHistoFrame, "Draw histogram");
121 fbDrawHisto->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "DrawHistos()");
122 fHistoFrame->AddFrame(fbDrawHisto);
2ef0687e 123
124 // Set up file dialog
caaf90d2 125 fFileInfo = new TGFileInfo();
126 fFileInfo->SetMultipleSelection(kTRUE);
127
128 fFileTypes = new Char_t*[6];
129 fFileTypes[0] = (Char_t*)"All files"; fFileTypes[1] = (Char_t*)"*";
130 fFileTypes[2] = (Char_t*)"ROOT macros"; fFileTypes[3] = (Char_t*)"*.C";
131 fFileTypes[4] = 0; fFileTypes[5] = 0;
132 fFileInfo->fFileTypes = (const Char_t**)fFileTypes;
133 fFileInfo->fFileTypeIdx = 2;
134 fFileInfo->fMultipleSelection = kTRUE;
4f6473f6 135
136 fHistoCanvasName = new TGString("");
137
138 // Handle the signal "Selected(Int_t ind)"
139 ftlMacroList->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "UpdateMacroListSelection(Int_t)");
140 ftlMacroSelList->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "UpdateMacroSelListSelection(Int_t)");
141
142 // Handle the signal "NewEventLoaded"
143 gAliEveEvent->Connect("NewEventLoaded()", "AliEveTRDTrackListEditor", this, "HandleNewEventLoaded()");
144
145 // Handle the signal "Selected" (another tab has been selected)
146 GetGedEditor()->GetTab()->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor",
147 this, "HandleTabChangedToIndex(Int_t)");
2ef0687e 148}
149
c04e790a 150//______________________________________________________
caaf90d2 151AliEveTRDTrackListEditor::~AliEveTRDTrackListEditor()
3f797131 152{
caaf90d2 153 if (fFileTypes != 0)
39b891ff 154 {
caaf90d2 155 delete [] fFileTypes;
156 fFileTypes = 0;
2ef0687e 157 }
3f797131 158
caaf90d2 159 if (fFileInfo != 0)
39b891ff 160 {
caaf90d2 161 delete fFileInfo;
162 fFileInfo = 0;
39b891ff 163 }
4f6473f6 164 // Close and delete all tabs that have been created by this class
165 CloseTabs();
166
167 if (fHistoCanvasName != 0)
168 {
169 delete fHistoCanvasName;
170 fHistoCanvasName = 0;
171 }
caaf90d2 172}
173
c04e790a 174//______________________________________________________
caaf90d2 175void AliEveTRDTrackListEditor::AddMacro(const Char_t* path, const Char_t* name)
176{
177 Int_t result = fM->AddMacro(path, name);
178
179 switch (result)
39b891ff 180 {
caaf90d2 181 case SUCCESS:
182 UpdateMacroList();
183 break;
184 case WARNING:
39b891ff 185 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Warning", "Macro is already in list (won't be added again)!",
186 kMBIconExclamation, kMBOk);
caaf90d2 187 break;
188 case SIGNATURE_ERROR:
189 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
bcb45225 190 "Macro has not the signature of...\n...a selection macro: Bool_t YourMacro(const AliTRDtrackV1*)\n...a process macro (type 1): void YourMacro(const AliTRDtrackV1*, Double_t*&, Int_t&)\n...a process macro (type2): TH1* YourMacro(const AliTRDtrackV1*)",
caaf90d2 191 kMBIconExclamation, kMBOk);
192 break;
193 case NOT_EXIST_ERROR:
194 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
195 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
196 break;
197 default:
198 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
199 Form("AliEveTRDTrackList::AddMacro exited with unknown return value: %d", result),
200 kMBIconExclamation, kMBOk);
201 break;
2ef0687e 202 }
203}
204
c04e790a 205//______________________________________________________
2ef0687e 206void AliEveTRDTrackListEditor::ApplyMacros()
207{
3f797131 208 // First apply the selection macros
caaf90d2 209 TList* iterator = new TList();
210 ftlMacroSelList->GetSelectedEntries(iterator);
211 fM->ApplySelectionMacros(iterator);
212
39b891ff 213 // Update view
214 gEve->Redraw3D();
39b891ff 215
caaf90d2 216 if (iterator != 0) delete iterator;
2ef0687e 217
3f797131 218 // Now apply the process macros
219 iterator = new TList();
caaf90d2 220 ftlMacroList->GetSelectedEntries(iterator);
221 fM->ApplyProcessMacros(iterator);
2ef0687e 222
caaf90d2 223 // Update histogram tab (data has to be reloaded)
224 SetModel(fM);
225 Update();
2ef0687e 226
bcb45225 227 // AlieveTRDTrackList::ApplyProcessMacros() automatically selects a macro -> Draw the histogram for it,
228 // if a process macro has been applied
229 if (iterator->GetEntries() > 0)
4f6473f6 230 {
231 // Set focus on "Histograms" tab
232 GetGedEditor()->GetTab()->SetTab("Histograms");
233
234 DrawHistos();
235 }
bcb45225 236
237 if (iterator != 0) delete iterator;
238 iterator = 0;
8e27fca1 239}
c04e790a 240
241//______________________________________________________
2ef0687e 242void AliEveTRDTrackListEditor::BrowseMacros()
243{
caaf90d2 244 new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fFileInfo);
2ef0687e 245
caaf90d2 246 if (fFileInfo->fIniDir != 0 && fFileInfo->fFileNamesList != 0)
3f797131 247 {
2ef0687e 248 // Extract filenames
caaf90d2 249 TObject* iter = fFileInfo->fFileNamesList->First();
2ef0687e 250
251 Char_t* name = 0;
252
253 while (iter != 0)
254 {
caaf90d2 255 // NOTE: fileInfo->fFileNamesList will be changed by that, too!
2ef0687e 256 name = strrchr(iter->GetName(), '/');
257 // Delete '"' at the end
258 name[strlen(name)] = '\0';
caaf90d2 259
260 AddMacro(fFileInfo->fIniDir, name + 1);
261 iter = (TObjString*)fFileInfo->fFileNamesList->After(iter);
2ef0687e 262 }
263 }
3f797131 264
caaf90d2 265 // -> The following problem has been fixed (trunk -> Changes according to 03 September 2008):
3f797131 266 // Some error occurs, when one ends the filedialog with "cancel": fileInfo->fFileNamesList is set to 0x0, but
267 // in the next launch no new memory is allocated. So do this manually.
caaf90d2 268 //if (fileInfo->fFileNamesList == 0) fileInfo->fFileNamesList = new TList();
269}
270
4f6473f6 271//______________________________________________________
272void AliEveTRDTrackListEditor::CloseTabs()
273{
274 if (fHistoCanvas != 0)
275 {
276 // Close the created tab, if it exists
277 if (fHistoCanvasName != 0)
278 {
279 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()))
280 {
281 // Now the created tab is the current one and can be deleted
282 gEve->GetBrowser()->GetTab(1)->RemoveTab();
283 }
284 }
285 // With the tab removal, the canvas will be deleted automatically!
286 fHistoCanvas = 0;
287 }
288}
289
c04e790a 290//______________________________________________________
caaf90d2 291void AliEveTRDTrackListEditor::DrawHistos()
292{
293 Int_t nHistograms = GetNSelectedHistograms();
294 if (nHistograms <= 0)
295 {
296 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
297 "No data selected. Please select the data you want to plot!", kMBIconExclamation, kMBOk);
298 return;
299 }
300 if (nHistograms > 3)
301 {
302 new TGMsgBox(gClient->GetRoot(), GetMainFrame(),
303 "Error", "Only histograms with up to 3 dimensions supported. Please select 1,2 or 3 data macros!",
304 kMBIconExclamation, kMBOk);
305 return;
306 }
307
bcb45225 308 // Check, if a histo macro shall be drawn
309 Int_t indexOfHistoMacro = -1;
310 Int_t selectedChecked = 0;
311 for (Int_t j = 0; j < fM->fDataFromMacroList->GetEntries(); j++)
312 {
313 if (fCheckButtons[j]->TGButton::GetState() == kButtonDown)
314 {
315 selectedChecked++;
316
317 // Histo macro?
318 if (fM->IsHistogramMacro(fM->fDataFromMacroList->At(j)->GetName()))
319 {
320 // Is also another macro selected?
321 if (nHistograms > 1)
322 {
323 // Histo macros cannot(!) be correlated!
324 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
325 "Process macros of type 2 (return value \"TH1*\") cannot be correlated with other macros",
326 kMBIconExclamation, kMBOk);
327 return;
328 }
329
330 // Mark this histo macro for drawing
331 indexOfHistoMacro = j;
332
333 // Have all selected macros been checked? -> If yes, we are done with this
334 if (selectedChecked == nHistograms) break;
335 }
336 }
337 }
338
caaf90d2 339 TFile* file = new TFile("TRD.TrackListMacroData.root", "READ");
340 if (!file)
341 {
342 Error("Draw histograms", "Cannot open file \"TRD.TrackListMacroData.root\"");
343 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
344 "Cannot open file \"TRD.TrackListMacroData.root\"", kMBIconExclamation, kMBOk);
345 return;
346 }
347
348 TTree* t = 0;
349 TTree* tFriend1 = 0;
350 TTree* tFriend2 = 0;
351
352 Int_t indexOfMacro1 = 0;
353 Int_t indexOfMacro2 = 0;
354 Int_t indexOfMacro3 = 0;
355
bcb45225 356 // Variable for the loop below -> Will be set to aborting value, if a histo macro is drawn
357 Int_t i = 0;
358
359 // Draw histo macro?
360 if (indexOfHistoMacro >= 0)
361 {
362 if ((t = (TTree*)file->Get(Form("TrackData%d", indexOfHistoMacro))))
363 {
364 SetDrawingToHistoCanvasTab();
365
366 TH1* myHist = 0;
367 t->SetBranchAddress(Form("Macro%d", indexOfHistoMacro), &myHist);
368 t->GetEntry(0);
369 if (myHist != 0) myHist->Draw();
370 else
371 {
372 Error("Draw histograms", Form("No histogram for histo macro \"%s\" found!",
373 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()));
374 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
375 Form("No histogram for histo macro \"%s\" found!",
376 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk);
377
378 }
379
5715955a 380 UpdateHistoCanvasTab();
bcb45225 381 }
382 else
383 {
384 Error("Draw histograms", Form("No data for histo macro \"%s\" found!",
385 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()));
386 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
387 Form("No data for histo macro \"%s\" found!",
388 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk);
389 }
390
391 // Skip the loop below
392 i = fM->fDataFromMacroList->GetEntries();
393 }
394
395 // Load the trees in succession and remember the entries -> Plot the process macros of type 1
396 for ( ; i < fM->fDataFromMacroList->GetEntries(); i++)
caaf90d2 397 {
398 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown)
399 {
400 if (t == 0)
401 {
402 indexOfMacro1 = i;
403 if (!(t = (TTree*)file->Get(Form("TrackData%d", i))))
404 {
bcb45225 405 Error("Draw histograms", Form("No data for macro \"%s\" found!", fM->fDataFromMacroList->At(i)->GetName()));
caaf90d2 406 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
bcb45225 407 Form("No data for macro \"%s\" found!", fM->fDataFromMacroList->At(i)->GetName()),
408 kMBIconExclamation, kMBOk);
caaf90d2 409 break;
410 }
bcb45225 411
412 // 1d histogram - macro of type 1
caaf90d2 413 if (nHistograms == 1)
414 {
bcb45225 415 SetDrawingToHistoCanvasTab();
4f6473f6 416
bcb45225 417 t->Draw(Form("Macro%d", indexOfMacro1), "1");
418 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s;%s",
419 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
420 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
4f6473f6 421
bcb45225 422 UpdateHistoCanvasTab();
caaf90d2 423
424 break;
425 }
426 }
427 else if (tFriend1 == 0)
428 {
429 indexOfMacro2 = i;
430 if (!(tFriend1 = (TTree*)file->Get(Form("TrackData%d", i))))
431 {
bcb45225 432 Error("Draw histograms", Form("No data for macro \"%s\" found!", fM->fDataFromMacroList->At(i)->GetName()));
caaf90d2 433 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
bcb45225 434 Form("No data for macro \"%s\" found!", fM->fDataFromMacroList->At(i)->GetName()),
435 kMBIconExclamation, kMBOk);
caaf90d2 436 break;
437 }
438
439 // 2d histogram
440 if (nHistograms == 2)
441 {
bcb45225 442 SetDrawingToHistoCanvasTab();
443
caaf90d2 444 t->AddFriend(tFriend1);
445 t->Draw(Form("Macro%d:Macro%d", indexOfMacro1, indexOfMacro2), "1");
bcb45225 446 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s;%s;%s",
447 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
448 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
449 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
450 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
4f6473f6 451
bcb45225 452 UpdateHistoCanvasTab();
caaf90d2 453
454 break;
455 }
456 }
457 // 3d histogram
458 else
459 {
460 indexOfMacro3 = i;
461 if (!(tFriend2 = (TTree*)file->Get(Form("TrackData%d", i))))
462 {
bcb45225 463 Error("Draw histograms", Form("No data for macro \"%s\" found!", fM->fDataFromMacroList->At(i)->GetName()));
caaf90d2 464 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
bcb45225 465 Form("No data for macro \"%s\" found!", fM->fDataFromMacroList->At(i)->GetName()),
466 kMBIconExclamation, kMBOk);
caaf90d2 467 break;
468 }
4f6473f6 469
bcb45225 470 SetDrawingToHistoCanvasTab();
4f6473f6 471
caaf90d2 472 t->AddFriend(tFriend1);
473 t->AddFriend(tFriend2);
474 t->Draw(Form("Macro%d:Macro%d:Macro%d", indexOfMacro1, indexOfMacro2, indexOfMacro3), "1");
bcb45225 475 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s - %s;%s;%s;%s",
476 fM->fDataFromMacroList->At(indexOfMacro3)->GetName(),
477 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
478 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
479 fM->fDataFromMacroList->At(indexOfMacro3)->GetName(),
480 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
481 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
482
483 UpdateHistoCanvasTab();
caaf90d2 484
485 break;
486 }
487 }
488 }
489
490 if (t != 0) delete t;
491 t = 0;
492 if (tFriend1 != 0) delete tFriend1;
493 tFriend1 = 0;
494 if (tFriend2 != 0) delete tFriend2;
495 tFriend2 = 0;
496
497 file->Close("R");
498 delete file;
499 file = 0;
500}
501
c04e790a 502//______________________________________________________
caaf90d2 503Int_t AliEveTRDTrackListEditor::GetNSelectedHistograms()
504{
505 Int_t count = 0;
506
507 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
508 {
509 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown) count++;
510 }
511
512 return count;
2ef0687e 513}
514
c04e790a 515//______________________________________________________
2ef0687e 516void AliEveTRDTrackListEditor::HandleMacroPathSet()
517{
caaf90d2 518 if (strlen(fteField->GetText()) != 0)
5715955a 519 {
520 // Expand the pathname
521 Char_t* systemPath = gSystem->ExpandPathName(fteField->GetText());
522 fteField->SetText(systemPath);
523 delete systemPath;
524 systemPath = 0;
525
2ef0687e 526 // Check if file exists
527 FILE* fp = NULL;
528
caaf90d2 529 fp = fopen(fteField->GetText(), "rb");
39b891ff 530 if (fp != NULL)
531 {
3f797131 532 fclose(fp);
caaf90d2 533
3f797131 534 // Extract filename
caaf90d2 535 Char_t* name = strrchr(fteField->GetText(), '/');
3f797131 536
537 // Current path
39b891ff 538 if (name == NULL)
539 {
4f6473f6 540 name = new Char_t[AliEveTRDTrackList::fkMaxMacroNameLength];
541 memset(name, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroNameLength);
caaf90d2 542 sprintf(name, "%s", fteField->GetText());
3f797131 543
4f6473f6 544 // Add path to textfield -> Path is "./" -> Use length for the name + 2
545 Char_t pathname[AliEveTRDTrackList::fkMaxMacroNameLength + 2];
546 memset(pathname, '\0', sizeof(Char_t) * (AliEveTRDTrackList::fkMaxMacroNameLength + 2));
caaf90d2 547 sprintf(pathname, "./%s", fteField->GetText());
548 fteField->SetText(pathname);
549
550 AddMacro(".", name);
551 if (name != 0) delete name;
552 name = 0;
39b891ff 553 }
554 // Different path
555 else
556 {
3f797131 557 // Extract path
4f6473f6 558 Char_t* path = new Char_t[AliEveTRDTrackList::fkMaxMacroPathLength];
559 memset(path, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroPathLength);
caaf90d2 560 strncpy(path, fteField->GetText(), strlen(fteField->GetText()) - strlen(name));
561
562 // Ignore the slash "/" in name
563 AddMacro(path, name + 1);
564
565 if (path != 0) delete path;
566 path = 0;
567 }
39b891ff 568 }
569 else
570 {
3f797131 571 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
39b891ff 572 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
2ef0687e 573 }
574 }
575}
576
4f6473f6 577//______________________________________________________
578void AliEveTRDTrackListEditor::HandleNewEventLoaded()
579{
bcb45225 580 // Inherit the macro list for the next track list!
581 fInheritMacroList = kTRUE;
582
583 // Close the tabs
4f6473f6 584 CloseTabs();
585}
586
587//______________________________________________________
588void AliEveTRDTrackListEditor::HandleTabChangedToIndex(Int_t index)
589{
590 fM->SetSelectedTab(index);
591}
592
bcb45225 593//______________________________________________________
594void AliEveTRDTrackListEditor::InheritMacroList()
595{
596 // The old macro lists are stored in the corresponding list boxes -> add them to the track list
597
598 // Selection macros
599 fM->fMacroSelList->Delete();
600 for (Int_t i = 0; i < ftlMacroSelList->GetNumberOfEntries(); i++)
601 {
602 fM->AddMacroFast(ftlMacroSelList->GetEntry(i)->GetTitle(), kTRUE);
603 }
604
605 // Process macros
606 fM->fMacroList->Delete();
607 for (Int_t i = 0; i < ftlMacroList->GetNumberOfEntries(); i++)
608 {
609 fM->AddMacroFast(ftlMacroList->GetEntry(i)->GetTitle(), kFALSE);
610 }
611}
612
c04e790a 613//______________________________________________________
2ef0687e 614void AliEveTRDTrackListEditor::RemoveMacros()
615{
616 TList* iterator = new TList();
617
caaf90d2 618 ftlMacroList->GetSelectedEntries(iterator);
619 fM->RemoveProcessMacros(iterator);
3f797131 620
caaf90d2 621 if (iterator != 0) delete iterator;
3f797131 622
caaf90d2 623 iterator = new TList();
624 ftlMacroSelList->GetSelectedEntries(iterator);
625 fM->RemoveSelectionMacros(iterator);
2ef0687e 626
4f6473f6 627 // Selected macros are deleted from the list -> No selected entries left
628 fM->fMacroListSelected = 0;
629 fM->fMacroSelListSelected = 0;
630
2ef0687e 631 UpdateMacroList();
caaf90d2 632
633 if (iterator != 0) delete iterator;
634 iterator = 0;
2ef0687e 635}
636
bcb45225 637//______________________________________________________
638void AliEveTRDTrackListEditor::SetDrawingToHistoCanvasTab()
639{
640 // If the tab with the canvas has been closed, the canvas will be deleted.
641 // So, if there is no tab, set the canvas pointer to zero and recreate it in a new tab.
642 if (fHistoCanvas != 0)
643 {
644 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()) == 0)
645 {
646 fHistoCanvas = 0;
647 }
648 }
649
650 if (!fHistoCanvas)
651 {
652 fHistoCanvas = gEve->AddCanvasTab(fM->GetName());
653 }
654
655 gPad = fHistoCanvas;
656}
657
658//______________________________________________________
659void AliEveTRDTrackListEditor::UpdateHistoCanvasTab()
660{
661 // Update name of the tab (tab has been set to current tab!)
662 fHistoCanvasName->SetString(fM->GetName());
663
664 // Use a copy of fHistoCanvasName!! -> If the user closes a tab manually, the TGString
665 // will be deleted -> Error might occur, when accessing the pointer
666 gEve->GetBrowser()->GetTab(1)->GetCurrentTab()->SetText(new TGString(fHistoCanvasName));
667
668 // Switch tabs to force redrawing
669 gEve->GetBrowser()->GetTab(1)->SetTab(0);
670 gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString());
671 fHistoCanvas->Update();
672}
673
c04e790a 674//______________________________________________________
2ef0687e 675void AliEveTRDTrackListEditor::SetModel(TObject* obj)
8e27fca1 676{
caaf90d2 677 // Set model object
2ef0687e 678 fM = dynamic_cast<AliEveTRDTrackList*>(obj);
679
8e27fca1 680 if (fM == 0)
681 {
682 Error("SetModel", "Parameter is zero pointer");
683 return;
684 }
685
bcb45225 686 // If macro list shall be inherited from previously loaded track list, do so
687 if (fInheritMacroList)
688 {
689 InheritMacroList();
690 fInheritMacroList = kFALSE;
691 }
692
2ef0687e 693 UpdateMacroList();
8e27fca1 694 UpdateHistoList();
695
4f6473f6 696 // View correct tab
697 GetGedEditor()->GetTab()->SetTab(fM->fSelectedTab);
698}
699
700//______________________________________________________
701void AliEveTRDTrackListEditor::UpdateDataFromMacroListSelection()
702{
703 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
8e27fca1 704 {
4f6473f6 705 fM->SetHistoDataSelection(i, fCheckButtons[i]->IsOn());
8e27fca1 706 }
caaf90d2 707}
708
c04e790a 709//______________________________________________________
caaf90d2 710void AliEveTRDTrackListEditor::UpdateHistoList()
711{
4f6473f6 712 fHistoSubFrame->TGCompositeFrame::Cleanup();
caaf90d2 713
714 // Set buttons for histograms
715 if (fCheckButtons != 0) delete fCheckButtons;
716 fCheckButtons = new TGCheckButton*[fM->fDataFromMacroList->GetEntries()];
717
718 TObjString* iter = (TObjString*)fM->fDataFromMacroList->First();
719 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries() && iter != 0; i++)
720 {
721 fCheckButtons[i] = new TGCheckButton(fHistoSubFrame, iter->GetName());
722 fHistoSubFrame->AddFrame(fCheckButtons[i]);
723
724 fCheckButtons[i]->SetState(kButtonUp, kFALSE);
725 fCheckButtons[i]->MapRaised();
4f6473f6 726 fCheckButtons[i]->SetOn(fM->HistoDataIsSelected(i));
727 fCheckButtons[i]->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "UpdateDataFromMacroListSelection()");
caaf90d2 728
729 iter = (TObjString*)fM->fDataFromMacroList->After(iter);
730 }
2ef0687e 731}
732
c04e790a 733//______________________________________________________
2ef0687e 734void AliEveTRDTrackListEditor::UpdateMacroList()
735{
caaf90d2 736 ftlMacroList->RemoveAll();
2ef0687e 737
caaf90d2 738 TObjString* iter = (TObjString*)fM->fMacroList->First();
2ef0687e 739
4f6473f6 740 Int_t ind = 0;
2ef0687e 741 while (iter != 0)
742 {
4f6473f6 743 ftlMacroList->AddEntry(iter->GetName(), ind++);
caaf90d2 744 iter = (TObjString*)fM->fMacroList->After(iter);
2ef0687e 745 }
746
caaf90d2 747 ftlMacroList->SortByName();
3f797131 748
4f6473f6 749 // Select, what has been selected before
750 for (Int_t i = 0; i < fM->fMacroList->GetEntries(); i++)
751 {
752 ftlMacroList->Select(i, fM->MacroListIsSelected(i));
753 }
754
755
3f797131 756
caaf90d2 757 ftlMacroSelList->RemoveAll();
3f797131 758
caaf90d2 759 iter = (TObjString*)fM->fMacroSelList->First();
3f797131 760
4f6473f6 761 ind = 0;
3f797131 762 while (iter != 0)
763 {
4f6473f6 764 ftlMacroSelList->AddEntry(iter->GetName(), ind++);
caaf90d2 765 iter = (TObjString*)fM->fMacroSelList->After(iter);
3f797131 766 }
767
caaf90d2 768 ftlMacroSelList->SortByName();
4f6473f6 769
770 // Select, what has been selected before
771 for (Int_t i = 0; i < fM->fMacroSelList->GetEntries(); i++)
772 {
773 ftlMacroSelList->Select(i, fM->MacroSelListIsSelected(i));
774 }
775}
776
777//______________________________________________________
778void AliEveTRDTrackListEditor::UpdateMacroListSelection(Int_t ind)
779{
780 // Toggle selected item
781 fM->SetMacroListSelection(ind, !fM->MacroListIsSelected(ind));
782}
783
784//______________________________________________________
785void AliEveTRDTrackListEditor::UpdateMacroSelListSelection(Int_t ind)
786{
787 // Toggle selected item
788 fM->SetMacroSelListSelection(ind, !fM->MacroSelListIsSelected(ind));
2ef0687e 789}