]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveTRDTrackListEditor.cxx
Removed unnecessary calls to SetEquipmentId (F. Prino)
[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
380 UpdateHistoCanvasTab();
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)
39b891ff 519 {
2ef0687e 520 // Check if file exists
521 FILE* fp = NULL;
522
caaf90d2 523 fp = fopen(fteField->GetText(), "rb");
39b891ff 524 if (fp != NULL)
525 {
3f797131 526 fclose(fp);
caaf90d2 527
3f797131 528 // Extract filename
caaf90d2 529 Char_t* name = strrchr(fteField->GetText(), '/');
3f797131 530
531 // Current path
39b891ff 532 if (name == NULL)
533 {
4f6473f6 534 name = new Char_t[AliEveTRDTrackList::fkMaxMacroNameLength];
535 memset(name, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroNameLength);
caaf90d2 536 sprintf(name, "%s", fteField->GetText());
3f797131 537
4f6473f6 538 // Add path to textfield -> Path is "./" -> Use length for the name + 2
539 Char_t pathname[AliEveTRDTrackList::fkMaxMacroNameLength + 2];
540 memset(pathname, '\0', sizeof(Char_t) * (AliEveTRDTrackList::fkMaxMacroNameLength + 2));
caaf90d2 541 sprintf(pathname, "./%s", fteField->GetText());
542 fteField->SetText(pathname);
543
544 AddMacro(".", name);
545 if (name != 0) delete name;
546 name = 0;
39b891ff 547 }
548 // Different path
549 else
550 {
3f797131 551 // Extract path
4f6473f6 552 Char_t* path = new Char_t[AliEveTRDTrackList::fkMaxMacroPathLength];
553 memset(path, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroPathLength);
caaf90d2 554 strncpy(path, fteField->GetText(), strlen(fteField->GetText()) - strlen(name));
555
556 // Ignore the slash "/" in name
557 AddMacro(path, name + 1);
558
559 if (path != 0) delete path;
560 path = 0;
561 }
39b891ff 562 }
563 else
564 {
3f797131 565 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
39b891ff 566 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
2ef0687e 567 }
568 }
569}
570
4f6473f6 571//______________________________________________________
572void AliEveTRDTrackListEditor::HandleNewEventLoaded()
573{
bcb45225 574 // Inherit the macro list for the next track list!
575 fInheritMacroList = kTRUE;
576
577 // Close the tabs
4f6473f6 578 CloseTabs();
579}
580
581//______________________________________________________
582void AliEveTRDTrackListEditor::HandleTabChangedToIndex(Int_t index)
583{
584 fM->SetSelectedTab(index);
585}
586
bcb45225 587//______________________________________________________
588void AliEveTRDTrackListEditor::InheritMacroList()
589{
590 // The old macro lists are stored in the corresponding list boxes -> add them to the track list
591
592 // Selection macros
593 fM->fMacroSelList->Delete();
594 for (Int_t i = 0; i < ftlMacroSelList->GetNumberOfEntries(); i++)
595 {
596 fM->AddMacroFast(ftlMacroSelList->GetEntry(i)->GetTitle(), kTRUE);
597 }
598
599 // Process macros
600 fM->fMacroList->Delete();
601 for (Int_t i = 0; i < ftlMacroList->GetNumberOfEntries(); i++)
602 {
603 fM->AddMacroFast(ftlMacroList->GetEntry(i)->GetTitle(), kFALSE);
604 }
605}
606
c04e790a 607//______________________________________________________
2ef0687e 608void AliEveTRDTrackListEditor::RemoveMacros()
609{
610 TList* iterator = new TList();
611
caaf90d2 612 ftlMacroList->GetSelectedEntries(iterator);
613 fM->RemoveProcessMacros(iterator);
3f797131 614
caaf90d2 615 if (iterator != 0) delete iterator;
3f797131 616
caaf90d2 617 iterator = new TList();
618 ftlMacroSelList->GetSelectedEntries(iterator);
619 fM->RemoveSelectionMacros(iterator);
2ef0687e 620
4f6473f6 621 // Selected macros are deleted from the list -> No selected entries left
622 fM->fMacroListSelected = 0;
623 fM->fMacroSelListSelected = 0;
624
2ef0687e 625 UpdateMacroList();
caaf90d2 626
627 if (iterator != 0) delete iterator;
628 iterator = 0;
2ef0687e 629}
630
bcb45225 631//______________________________________________________
632void AliEveTRDTrackListEditor::SetDrawingToHistoCanvasTab()
633{
634 // If the tab with the canvas has been closed, the canvas will be deleted.
635 // So, if there is no tab, set the canvas pointer to zero and recreate it in a new tab.
636 if (fHistoCanvas != 0)
637 {
638 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()) == 0)
639 {
640 fHistoCanvas = 0;
641 }
642 }
643
644 if (!fHistoCanvas)
645 {
646 fHistoCanvas = gEve->AddCanvasTab(fM->GetName());
647 }
648
649 gPad = fHistoCanvas;
650}
651
652//______________________________________________________
653void AliEveTRDTrackListEditor::UpdateHistoCanvasTab()
654{
655 // Update name of the tab (tab has been set to current tab!)
656 fHistoCanvasName->SetString(fM->GetName());
657
658 // Use a copy of fHistoCanvasName!! -> If the user closes a tab manually, the TGString
659 // will be deleted -> Error might occur, when accessing the pointer
660 gEve->GetBrowser()->GetTab(1)->GetCurrentTab()->SetText(new TGString(fHistoCanvasName));
661
662 // Switch tabs to force redrawing
663 gEve->GetBrowser()->GetTab(1)->SetTab(0);
664 gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString());
665 fHistoCanvas->Update();
666}
667
c04e790a 668//______________________________________________________
2ef0687e 669void AliEveTRDTrackListEditor::SetModel(TObject* obj)
8e27fca1 670{
caaf90d2 671 // Set model object
2ef0687e 672 fM = dynamic_cast<AliEveTRDTrackList*>(obj);
673
8e27fca1 674 if (fM == 0)
675 {
676 Error("SetModel", "Parameter is zero pointer");
677 return;
678 }
679
bcb45225 680 // If macro list shall be inherited from previously loaded track list, do so
681 if (fInheritMacroList)
682 {
683 InheritMacroList();
684 fInheritMacroList = kFALSE;
685 }
686
2ef0687e 687 UpdateMacroList();
8e27fca1 688 UpdateHistoList();
689
4f6473f6 690 // View correct tab
691 GetGedEditor()->GetTab()->SetTab(fM->fSelectedTab);
692}
693
694//______________________________________________________
695void AliEveTRDTrackListEditor::UpdateDataFromMacroListSelection()
696{
697 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
8e27fca1 698 {
4f6473f6 699 fM->SetHistoDataSelection(i, fCheckButtons[i]->IsOn());
8e27fca1 700 }
caaf90d2 701}
702
c04e790a 703//______________________________________________________
caaf90d2 704void AliEveTRDTrackListEditor::UpdateHistoList()
705{
4f6473f6 706 fHistoSubFrame->TGCompositeFrame::Cleanup();
caaf90d2 707
708 // Set buttons for histograms
709 if (fCheckButtons != 0) delete fCheckButtons;
710 fCheckButtons = new TGCheckButton*[fM->fDataFromMacroList->GetEntries()];
711
712 TObjString* iter = (TObjString*)fM->fDataFromMacroList->First();
713 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries() && iter != 0; i++)
714 {
715 fCheckButtons[i] = new TGCheckButton(fHistoSubFrame, iter->GetName());
716 fHistoSubFrame->AddFrame(fCheckButtons[i]);
717
718 fCheckButtons[i]->SetState(kButtonUp, kFALSE);
719 fCheckButtons[i]->MapRaised();
4f6473f6 720 fCheckButtons[i]->SetOn(fM->HistoDataIsSelected(i));
721 fCheckButtons[i]->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "UpdateDataFromMacroListSelection()");
caaf90d2 722
723 iter = (TObjString*)fM->fDataFromMacroList->After(iter);
724 }
2ef0687e 725}
726
c04e790a 727//______________________________________________________
2ef0687e 728void AliEveTRDTrackListEditor::UpdateMacroList()
729{
caaf90d2 730 ftlMacroList->RemoveAll();
2ef0687e 731
caaf90d2 732 TObjString* iter = (TObjString*)fM->fMacroList->First();
2ef0687e 733
4f6473f6 734 Int_t ind = 0;
2ef0687e 735 while (iter != 0)
736 {
4f6473f6 737 ftlMacroList->AddEntry(iter->GetName(), ind++);
caaf90d2 738 iter = (TObjString*)fM->fMacroList->After(iter);
2ef0687e 739 }
740
caaf90d2 741 ftlMacroList->SortByName();
3f797131 742
4f6473f6 743 // Select, what has been selected before
744 for (Int_t i = 0; i < fM->fMacroList->GetEntries(); i++)
745 {
746 ftlMacroList->Select(i, fM->MacroListIsSelected(i));
747 }
748
749
3f797131 750
caaf90d2 751 ftlMacroSelList->RemoveAll();
3f797131 752
caaf90d2 753 iter = (TObjString*)fM->fMacroSelList->First();
3f797131 754
4f6473f6 755 ind = 0;
3f797131 756 while (iter != 0)
757 {
4f6473f6 758 ftlMacroSelList->AddEntry(iter->GetName(), ind++);
caaf90d2 759 iter = (TObjString*)fM->fMacroSelList->After(iter);
3f797131 760 }
761
caaf90d2 762 ftlMacroSelList->SortByName();
4f6473f6 763
764 // Select, what has been selected before
765 for (Int_t i = 0; i < fM->fMacroSelList->GetEntries(); i++)
766 {
767 ftlMacroSelList->Select(i, fM->MacroSelListIsSelected(i));
768 }
769}
770
771//______________________________________________________
772void AliEveTRDTrackListEditor::UpdateMacroListSelection(Int_t ind)
773{
774 // Toggle selected item
775 fM->SetMacroListSelection(ind, !fM->MacroListIsSelected(ind));
776}
777
778//______________________________________________________
779void AliEveTRDTrackListEditor::UpdateMacroSelListSelection(Int_t ind)
780{
781 // Toggle selected item
782 fM->SetMacroSelListSelection(ind, !fM->MacroSelListIsSelected(ind));
2ef0687e 783}