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