]>
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> | |
bcb45225 | 25 | #include <TH1.h> |
8e27fca1 | 26 | #include <TTreeStream.h> |
27 | ||
caaf90d2 | 28 | |
2ef0687e | 29 | ClassImp(AliEveTRDTrackListEditor) |
30 | ||
31 | /////////////////////////////////////////////////////////// | |
32 | ///////////// AliEveTRDTrackListEditor ////////////////// | |
33 | /////////////////////////////////////////////////////////// | |
34 | AliEveTRDTrackListEditor::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 | 151 | AliEveTRDTrackListEditor::~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 | 175 | void 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 | 206 | void AliEveTRDTrackListEditor::ApplyMacros() |
207 | { | |
ea24e1bc | 208 | Bool_t success = kFALSE; |
209 | ||
3f797131 | 210 | // First apply the selection macros |
caaf90d2 | 211 | TList* iterator = new TList(); |
212 | ftlMacroSelList->GetSelectedEntries(iterator); | |
213 | fM->ApplySelectionMacros(iterator); | |
214 | ||
39b891ff | 215 | // Update view |
216 | gEve->Redraw3D(); | |
39b891ff | 217 | |
caaf90d2 | 218 | if (iterator != 0) delete iterator; |
2ef0687e | 219 | |
3f797131 | 220 | // Now apply the process macros |
221 | iterator = new TList(); | |
caaf90d2 | 222 | ftlMacroList->GetSelectedEntries(iterator); |
ea24e1bc | 223 | success = fM->ApplyProcessMacros(iterator); |
2ef0687e | 224 | |
caaf90d2 | 225 | // Update histogram tab (data has to be reloaded) |
226 | SetModel(fM); | |
227 | Update(); | |
2ef0687e | 228 | |
bcb45225 | 229 | // AlieveTRDTrackList::ApplyProcessMacros() automatically selects a macro -> Draw the histogram for it, |
230 | // if a process macro has been applied | |
ea24e1bc | 231 | if (success && iterator->GetEntries() > 0) |
4f6473f6 | 232 | { |
233 | // Set focus on "Histograms" tab | |
234 | GetGedEditor()->GetTab()->SetTab("Histograms"); | |
235 | ||
236 | DrawHistos(); | |
237 | } | |
bcb45225 | 238 | |
239 | if (iterator != 0) delete iterator; | |
240 | iterator = 0; | |
ea24e1bc | 241 | |
242 | if (!success) | |
243 | { | |
244 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", | |
245 | "AliEveTRDTrackList::ApplyProcessMacros experienced an error (cf. CINT-output)!", | |
246 | kMBIconExclamation, kMBOk); | |
247 | } | |
8e27fca1 | 248 | } |
c04e790a | 249 | |
250 | //______________________________________________________ | |
2ef0687e | 251 | void AliEveTRDTrackListEditor::BrowseMacros() |
252 | { | |
caaf90d2 | 253 | new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fFileInfo); |
2ef0687e | 254 | |
caaf90d2 | 255 | if (fFileInfo->fIniDir != 0 && fFileInfo->fFileNamesList != 0) |
3f797131 | 256 | { |
2ef0687e | 257 | // Extract filenames |
caaf90d2 | 258 | TObject* iter = fFileInfo->fFileNamesList->First(); |
2ef0687e | 259 | |
260 | Char_t* name = 0; | |
261 | ||
262 | while (iter != 0) | |
263 | { | |
caaf90d2 | 264 | // NOTE: fileInfo->fFileNamesList will be changed by that, too! |
2ef0687e | 265 | name = strrchr(iter->GetName(), '/'); |
266 | // Delete '"' at the end | |
267 | name[strlen(name)] = '\0'; | |
caaf90d2 | 268 | |
269 | AddMacro(fFileInfo->fIniDir, name + 1); | |
270 | iter = (TObjString*)fFileInfo->fFileNamesList->After(iter); | |
2ef0687e | 271 | } |
272 | } | |
3f797131 | 273 | |
caaf90d2 | 274 | // -> The following problem has been fixed (trunk -> Changes according to 03 September 2008): |
3f797131 | 275 | // Some error occurs, when one ends the filedialog with "cancel": fileInfo->fFileNamesList is set to 0x0, but |
276 | // in the next launch no new memory is allocated. So do this manually. | |
caaf90d2 | 277 | //if (fileInfo->fFileNamesList == 0) fileInfo->fFileNamesList = new TList(); |
278 | } | |
279 | ||
4f6473f6 | 280 | //______________________________________________________ |
281 | void AliEveTRDTrackListEditor::CloseTabs() | |
282 | { | |
283 | if (fHistoCanvas != 0) | |
284 | { | |
285 | // Close the created tab, if it exists | |
286 | if (fHistoCanvasName != 0) | |
287 | { | |
288 | if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString())) | |
289 | { | |
290 | // Now the created tab is the current one and can be deleted | |
291 | gEve->GetBrowser()->GetTab(1)->RemoveTab(); | |
292 | } | |
293 | } | |
294 | // With the tab removal, the canvas will be deleted automatically! | |
295 | fHistoCanvas = 0; | |
296 | } | |
297 | } | |
298 | ||
c04e790a | 299 | //______________________________________________________ |
caaf90d2 | 300 | void AliEveTRDTrackListEditor::DrawHistos() |
301 | { | |
302 | Int_t nHistograms = GetNSelectedHistograms(); | |
303 | if (nHistograms <= 0) | |
304 | { | |
305 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", | |
306 | "No data selected. Please select the data you want to plot!", kMBIconExclamation, kMBOk); | |
307 | return; | |
308 | } | |
309 | if (nHistograms > 3) | |
310 | { | |
311 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), | |
312 | "Error", "Only histograms with up to 3 dimensions supported. Please select 1,2 or 3 data macros!", | |
313 | kMBIconExclamation, kMBOk); | |
314 | return; | |
315 | } | |
316 | ||
bcb45225 | 317 | // Check, if a histo macro shall be drawn |
318 | Int_t indexOfHistoMacro = -1; | |
319 | Int_t selectedChecked = 0; | |
320 | for (Int_t j = 0; j < fM->fDataFromMacroList->GetEntries(); j++) | |
321 | { | |
322 | if (fCheckButtons[j]->TGButton::GetState() == kButtonDown) | |
323 | { | |
324 | selectedChecked++; | |
325 | ||
326 | // Histo macro? | |
327 | if (fM->IsHistogramMacro(fM->fDataFromMacroList->At(j)->GetName())) | |
328 | { | |
329 | // Is also another macro selected? | |
330 | if (nHistograms > 1) | |
331 | { | |
332 | // Histo macros cannot(!) be correlated! | |
333 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", | |
334 | "Process macros of type 2 (return value \"TH1*\") cannot be correlated with other macros", | |
335 | kMBIconExclamation, kMBOk); | |
336 | return; | |
337 | } | |
338 | ||
339 | // Mark this histo macro for drawing | |
340 | indexOfHistoMacro = j; | |
341 | ||
342 | // Have all selected macros been checked? -> If yes, we are done with this | |
343 | if (selectedChecked == nHistograms) break; | |
344 | } | |
345 | } | |
346 | } | |
347 | ||
caaf90d2 | 348 | TFile* file = new TFile("TRD.TrackListMacroData.root", "READ"); |
349 | if (!file) | |
350 | { | |
351 | Error("Draw histograms", "Cannot open file \"TRD.TrackListMacroData.root\""); | |
352 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", | |
353 | "Cannot open file \"TRD.TrackListMacroData.root\"", kMBIconExclamation, kMBOk); | |
354 | return; | |
355 | } | |
356 | ||
357 | TTree* t = 0; | |
358 | TTree* tFriend1 = 0; | |
359 | TTree* tFriend2 = 0; | |
360 | ||
361 | Int_t indexOfMacro1 = 0; | |
362 | Int_t indexOfMacro2 = 0; | |
363 | Int_t indexOfMacro3 = 0; | |
364 | ||
bcb45225 | 365 | // Variable for the loop below -> Will be set to aborting value, if a histo macro is drawn |
366 | Int_t i = 0; | |
367 | ||
368 | // Draw histo macro? | |
369 | if (indexOfHistoMacro >= 0) | |
370 | { | |
371 | if ((t = (TTree*)file->Get(Form("TrackData%d", indexOfHistoMacro)))) | |
372 | { | |
373 | SetDrawingToHistoCanvasTab(); | |
374 | ||
375 | TH1* myHist = 0; | |
376 | t->SetBranchAddress(Form("Macro%d", indexOfHistoMacro), &myHist); | |
377 | t->GetEntry(0); | |
378 | if (myHist != 0) myHist->Draw(); | |
379 | else | |
380 | { | |
381 | Error("Draw histograms", Form("No histogram for histo macro \"%s\" found!", | |
382 | fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName())); | |
383 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", | |
384 | Form("No histogram for histo macro \"%s\" found!", | |
385 | fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk); | |
386 | ||
387 | } | |
388 | ||
5715955a | 389 | UpdateHistoCanvasTab(); |
bcb45225 | 390 | } |
391 | else | |
392 | { | |
393 | Error("Draw histograms", Form("No data for histo macro \"%s\" found!", | |
394 | fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName())); | |
395 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", | |
396 | Form("No data for histo macro \"%s\" found!", | |
397 | fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk); | |
398 | } | |
399 | ||
400 | // Skip the loop below | |
401 | i = fM->fDataFromMacroList->GetEntries(); | |
402 | } | |
403 | ||
404 | // Load the trees in succession and remember the entries -> Plot the process macros of type 1 | |
405 | for ( ; i < fM->fDataFromMacroList->GetEntries(); i++) | |
caaf90d2 | 406 | { |
407 | if (fCheckButtons[i]->TGButton::GetState() == kButtonDown) | |
408 | { | |
409 | if (t == 0) | |
410 | { | |
411 | indexOfMacro1 = i; | |
412 | if (!(t = (TTree*)file->Get(Form("TrackData%d", i)))) | |
413 | { | |
bcb45225 | 414 | Error("Draw histograms", Form("No data for macro \"%s\" found!", fM->fDataFromMacroList->At(i)->GetName())); |
caaf90d2 | 415 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", |
bcb45225 | 416 | Form("No data for macro \"%s\" found!", fM->fDataFromMacroList->At(i)->GetName()), |
417 | kMBIconExclamation, kMBOk); | |
caaf90d2 | 418 | break; |
419 | } | |
bcb45225 | 420 | |
421 | // 1d histogram - macro of type 1 | |
caaf90d2 | 422 | if (nHistograms == 1) |
423 | { | |
bcb45225 | 424 | SetDrawingToHistoCanvasTab(); |
4f6473f6 | 425 | |
bcb45225 | 426 | t->Draw(Form("Macro%d", indexOfMacro1), "1"); |
427 | ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s;%s", | |
428 | fM->fDataFromMacroList->At(indexOfMacro1)->GetName(), | |
429 | fM->fDataFromMacroList->At(indexOfMacro1)->GetName())); | |
4f6473f6 | 430 | |
bcb45225 | 431 | UpdateHistoCanvasTab(); |
caaf90d2 | 432 | |
433 | break; | |
434 | } | |
435 | } | |
436 | else if (tFriend1 == 0) | |
437 | { | |
438 | indexOfMacro2 = i; | |
439 | if (!(tFriend1 = (TTree*)file->Get(Form("TrackData%d", i)))) | |
440 | { | |
bcb45225 | 441 | Error("Draw histograms", Form("No data for macro \"%s\" found!", fM->fDataFromMacroList->At(i)->GetName())); |
caaf90d2 | 442 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", |
bcb45225 | 443 | Form("No data for macro \"%s\" found!", fM->fDataFromMacroList->At(i)->GetName()), |
444 | kMBIconExclamation, kMBOk); | |
caaf90d2 | 445 | break; |
446 | } | |
447 | ||
448 | // 2d histogram | |
449 | if (nHistograms == 2) | |
450 | { | |
bcb45225 | 451 | SetDrawingToHistoCanvasTab(); |
452 | ||
caaf90d2 | 453 | t->AddFriend(tFriend1); |
454 | t->Draw(Form("Macro%d:Macro%d", indexOfMacro1, indexOfMacro2), "1"); | |
bcb45225 | 455 | ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s;%s;%s", |
456 | fM->fDataFromMacroList->At(indexOfMacro2)->GetName(), | |
457 | fM->fDataFromMacroList->At(indexOfMacro1)->GetName(), | |
458 | fM->fDataFromMacroList->At(indexOfMacro2)->GetName(), | |
459 | fM->fDataFromMacroList->At(indexOfMacro1)->GetName())); | |
4f6473f6 | 460 | |
bcb45225 | 461 | UpdateHistoCanvasTab(); |
caaf90d2 | 462 | |
463 | break; | |
464 | } | |
465 | } | |
466 | // 3d histogram | |
467 | else | |
468 | { | |
469 | indexOfMacro3 = i; | |
470 | if (!(tFriend2 = (TTree*)file->Get(Form("TrackData%d", i)))) | |
471 | { | |
bcb45225 | 472 | Error("Draw histograms", Form("No data for macro \"%s\" found!", fM->fDataFromMacroList->At(i)->GetName())); |
caaf90d2 | 473 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", |
bcb45225 | 474 | Form("No data for macro \"%s\" found!", fM->fDataFromMacroList->At(i)->GetName()), |
475 | kMBIconExclamation, kMBOk); | |
caaf90d2 | 476 | break; |
477 | } | |
4f6473f6 | 478 | |
bcb45225 | 479 | SetDrawingToHistoCanvasTab(); |
4f6473f6 | 480 | |
caaf90d2 | 481 | t->AddFriend(tFriend1); |
482 | t->AddFriend(tFriend2); | |
483 | t->Draw(Form("Macro%d:Macro%d:Macro%d", indexOfMacro1, indexOfMacro2, indexOfMacro3), "1"); | |
bcb45225 | 484 | ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s - %s;%s;%s;%s", |
485 | fM->fDataFromMacroList->At(indexOfMacro3)->GetName(), | |
486 | fM->fDataFromMacroList->At(indexOfMacro2)->GetName(), | |
487 | fM->fDataFromMacroList->At(indexOfMacro1)->GetName(), | |
488 | fM->fDataFromMacroList->At(indexOfMacro3)->GetName(), | |
489 | fM->fDataFromMacroList->At(indexOfMacro2)->GetName(), | |
490 | fM->fDataFromMacroList->At(indexOfMacro1)->GetName())); | |
491 | ||
492 | UpdateHistoCanvasTab(); | |
caaf90d2 | 493 | |
494 | break; | |
495 | } | |
496 | } | |
497 | } | |
498 | ||
499 | if (t != 0) delete t; | |
500 | t = 0; | |
501 | if (tFriend1 != 0) delete tFriend1; | |
502 | tFriend1 = 0; | |
503 | if (tFriend2 != 0) delete tFriend2; | |
504 | tFriend2 = 0; | |
505 | ||
506 | file->Close("R"); | |
507 | delete file; | |
508 | file = 0; | |
509 | } | |
510 | ||
c04e790a | 511 | //______________________________________________________ |
caaf90d2 | 512 | Int_t AliEveTRDTrackListEditor::GetNSelectedHistograms() |
513 | { | |
514 | Int_t count = 0; | |
515 | ||
516 | for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++) | |
517 | { | |
518 | if (fCheckButtons[i]->TGButton::GetState() == kButtonDown) count++; | |
519 | } | |
520 | ||
521 | return count; | |
2ef0687e | 522 | } |
523 | ||
c04e790a | 524 | //______________________________________________________ |
2ef0687e | 525 | void AliEveTRDTrackListEditor::HandleMacroPathSet() |
526 | { | |
caaf90d2 | 527 | if (strlen(fteField->GetText()) != 0) |
5715955a | 528 | { |
529 | // Expand the pathname | |
530 | Char_t* systemPath = gSystem->ExpandPathName(fteField->GetText()); | |
531 | fteField->SetText(systemPath); | |
532 | delete systemPath; | |
533 | systemPath = 0; | |
534 | ||
2ef0687e | 535 | // Check if file exists |
536 | FILE* fp = NULL; | |
537 | ||
caaf90d2 | 538 | fp = fopen(fteField->GetText(), "rb"); |
39b891ff | 539 | if (fp != NULL) |
540 | { | |
3f797131 | 541 | fclose(fp); |
caaf90d2 | 542 | |
3f797131 | 543 | // Extract filename |
caaf90d2 | 544 | Char_t* name = strrchr(fteField->GetText(), '/'); |
3f797131 | 545 | |
546 | // Current path | |
39b891ff | 547 | if (name == NULL) |
548 | { | |
4f6473f6 | 549 | name = new Char_t[AliEveTRDTrackList::fkMaxMacroNameLength]; |
550 | memset(name, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroNameLength); | |
caaf90d2 | 551 | sprintf(name, "%s", fteField->GetText()); |
3f797131 | 552 | |
4f6473f6 | 553 | // Add path to textfield -> Path is "./" -> Use length for the name + 2 |
554 | Char_t pathname[AliEveTRDTrackList::fkMaxMacroNameLength + 2]; | |
555 | memset(pathname, '\0', sizeof(Char_t) * (AliEveTRDTrackList::fkMaxMacroNameLength + 2)); | |
caaf90d2 | 556 | sprintf(pathname, "./%s", fteField->GetText()); |
557 | fteField->SetText(pathname); | |
558 | ||
559 | AddMacro(".", name); | |
560 | if (name != 0) delete name; | |
561 | name = 0; | |
39b891ff | 562 | } |
563 | // Different path | |
564 | else | |
565 | { | |
3f797131 | 566 | // Extract path |
4f6473f6 | 567 | Char_t* path = new Char_t[AliEveTRDTrackList::fkMaxMacroPathLength]; |
568 | memset(path, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroPathLength); | |
caaf90d2 | 569 | strncpy(path, fteField->GetText(), strlen(fteField->GetText()) - strlen(name)); |
570 | ||
571 | // Ignore the slash "/" in name | |
572 | AddMacro(path, name + 1); | |
573 | ||
574 | if (path != 0) delete path; | |
575 | path = 0; | |
576 | } | |
39b891ff | 577 | } |
578 | else | |
579 | { | |
3f797131 | 580 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", |
39b891ff | 581 | "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk); |
2ef0687e | 582 | } |
583 | } | |
584 | } | |
585 | ||
4f6473f6 | 586 | //______________________________________________________ |
587 | void AliEveTRDTrackListEditor::HandleNewEventLoaded() | |
588 | { | |
bcb45225 | 589 | // Inherit the macro list for the next track list! |
590 | fInheritMacroList = kTRUE; | |
591 | ||
592 | // Close the tabs | |
4f6473f6 | 593 | CloseTabs(); |
594 | } | |
595 | ||
596 | //______________________________________________________ | |
597 | void AliEveTRDTrackListEditor::HandleTabChangedToIndex(Int_t index) | |
598 | { | |
599 | fM->SetSelectedTab(index); | |
600 | } | |
601 | ||
bcb45225 | 602 | //______________________________________________________ |
603 | void AliEveTRDTrackListEditor::InheritMacroList() | |
604 | { | |
605 | // The old macro lists are stored in the corresponding list boxes -> add them to the track list | |
606 | ||
607 | // Selection macros | |
608 | fM->fMacroSelList->Delete(); | |
609 | for (Int_t i = 0; i < ftlMacroSelList->GetNumberOfEntries(); i++) | |
610 | { | |
611 | fM->AddMacroFast(ftlMacroSelList->GetEntry(i)->GetTitle(), kTRUE); | |
612 | } | |
613 | ||
614 | // Process macros | |
615 | fM->fMacroList->Delete(); | |
616 | for (Int_t i = 0; i < ftlMacroList->GetNumberOfEntries(); i++) | |
617 | { | |
618 | fM->AddMacroFast(ftlMacroList->GetEntry(i)->GetTitle(), kFALSE); | |
619 | } | |
620 | } | |
621 | ||
c04e790a | 622 | //______________________________________________________ |
2ef0687e | 623 | void AliEveTRDTrackListEditor::RemoveMacros() |
624 | { | |
625 | TList* iterator = new TList(); | |
626 | ||
caaf90d2 | 627 | ftlMacroList->GetSelectedEntries(iterator); |
628 | fM->RemoveProcessMacros(iterator); | |
3f797131 | 629 | |
caaf90d2 | 630 | if (iterator != 0) delete iterator; |
3f797131 | 631 | |
caaf90d2 | 632 | iterator = new TList(); |
633 | ftlMacroSelList->GetSelectedEntries(iterator); | |
634 | fM->RemoveSelectionMacros(iterator); | |
2ef0687e | 635 | |
4f6473f6 | 636 | // Selected macros are deleted from the list -> No selected entries left |
637 | fM->fMacroListSelected = 0; | |
638 | fM->fMacroSelListSelected = 0; | |
639 | ||
2ef0687e | 640 | UpdateMacroList(); |
caaf90d2 | 641 | |
642 | if (iterator != 0) delete iterator; | |
643 | iterator = 0; | |
2ef0687e | 644 | } |
645 | ||
bcb45225 | 646 | //______________________________________________________ |
647 | void AliEveTRDTrackListEditor::SetDrawingToHistoCanvasTab() | |
648 | { | |
649 | // If the tab with the canvas has been closed, the canvas will be deleted. | |
650 | // So, if there is no tab, set the canvas pointer to zero and recreate it in a new tab. | |
651 | if (fHistoCanvas != 0) | |
652 | { | |
653 | if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()) == 0) | |
654 | { | |
655 | fHistoCanvas = 0; | |
656 | } | |
657 | } | |
658 | ||
659 | if (!fHistoCanvas) | |
660 | { | |
661 | fHistoCanvas = gEve->AddCanvasTab(fM->GetName()); | |
662 | } | |
663 | ||
664 | gPad = fHistoCanvas; | |
665 | } | |
666 | ||
667 | //______________________________________________________ | |
668 | void AliEveTRDTrackListEditor::UpdateHistoCanvasTab() | |
669 | { | |
670 | // Update name of the tab (tab has been set to current tab!) | |
671 | fHistoCanvasName->SetString(fM->GetName()); | |
672 | ||
673 | // Use a copy of fHistoCanvasName!! -> If the user closes a tab manually, the TGString | |
674 | // will be deleted -> Error might occur, when accessing the pointer | |
675 | gEve->GetBrowser()->GetTab(1)->GetCurrentTab()->SetText(new TGString(fHistoCanvasName)); | |
676 | ||
677 | // Switch tabs to force redrawing | |
678 | gEve->GetBrowser()->GetTab(1)->SetTab(0); | |
679 | gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()); | |
680 | fHistoCanvas->Update(); | |
681 | } | |
682 | ||
c04e790a | 683 | //______________________________________________________ |
2ef0687e | 684 | void AliEveTRDTrackListEditor::SetModel(TObject* obj) |
8e27fca1 | 685 | { |
caaf90d2 | 686 | // Set model object |
2ef0687e | 687 | fM = dynamic_cast<AliEveTRDTrackList*>(obj); |
688 | ||
8e27fca1 | 689 | if (fM == 0) |
690 | { | |
691 | Error("SetModel", "Parameter is zero pointer"); | |
692 | return; | |
693 | } | |
694 | ||
bcb45225 | 695 | // If macro list shall be inherited from previously loaded track list, do so |
696 | if (fInheritMacroList) | |
697 | { | |
698 | InheritMacroList(); | |
699 | fInheritMacroList = kFALSE; | |
700 | } | |
701 | ||
2ef0687e | 702 | UpdateMacroList(); |
8e27fca1 | 703 | UpdateHistoList(); |
704 | ||
4f6473f6 | 705 | // View correct tab |
706 | GetGedEditor()->GetTab()->SetTab(fM->fSelectedTab); | |
707 | } | |
708 | ||
709 | //______________________________________________________ | |
710 | void AliEveTRDTrackListEditor::UpdateDataFromMacroListSelection() | |
711 | { | |
712 | for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++) | |
8e27fca1 | 713 | { |
4f6473f6 | 714 | fM->SetHistoDataSelection(i, fCheckButtons[i]->IsOn()); |
8e27fca1 | 715 | } |
caaf90d2 | 716 | } |
717 | ||
c04e790a | 718 | //______________________________________________________ |
caaf90d2 | 719 | void AliEveTRDTrackListEditor::UpdateHistoList() |
720 | { | |
4f6473f6 | 721 | fHistoSubFrame->TGCompositeFrame::Cleanup(); |
caaf90d2 | 722 | |
723 | // Set buttons for histograms | |
724 | if (fCheckButtons != 0) delete fCheckButtons; | |
725 | fCheckButtons = new TGCheckButton*[fM->fDataFromMacroList->GetEntries()]; | |
726 | ||
727 | TObjString* iter = (TObjString*)fM->fDataFromMacroList->First(); | |
728 | for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries() && iter != 0; i++) | |
729 | { | |
730 | fCheckButtons[i] = new TGCheckButton(fHistoSubFrame, iter->GetName()); | |
731 | fHistoSubFrame->AddFrame(fCheckButtons[i]); | |
732 | ||
733 | fCheckButtons[i]->SetState(kButtonUp, kFALSE); | |
734 | fCheckButtons[i]->MapRaised(); | |
4f6473f6 | 735 | fCheckButtons[i]->SetOn(fM->HistoDataIsSelected(i)); |
736 | fCheckButtons[i]->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "UpdateDataFromMacroListSelection()"); | |
caaf90d2 | 737 | |
738 | iter = (TObjString*)fM->fDataFromMacroList->After(iter); | |
739 | } | |
2ef0687e | 740 | } |
741 | ||
c04e790a | 742 | //______________________________________________________ |
2ef0687e | 743 | void AliEveTRDTrackListEditor::UpdateMacroList() |
744 | { | |
caaf90d2 | 745 | ftlMacroList->RemoveAll(); |
2ef0687e | 746 | |
caaf90d2 | 747 | TObjString* iter = (TObjString*)fM->fMacroList->First(); |
2ef0687e | 748 | |
4f6473f6 | 749 | Int_t ind = 0; |
2ef0687e | 750 | while (iter != 0) |
751 | { | |
4f6473f6 | 752 | ftlMacroList->AddEntry(iter->GetName(), ind++); |
caaf90d2 | 753 | iter = (TObjString*)fM->fMacroList->After(iter); |
2ef0687e | 754 | } |
755 | ||
caaf90d2 | 756 | ftlMacroList->SortByName(); |
3f797131 | 757 | |
4f6473f6 | 758 | // Select, what has been selected before |
759 | for (Int_t i = 0; i < fM->fMacroList->GetEntries(); i++) | |
760 | { | |
761 | ftlMacroList->Select(i, fM->MacroListIsSelected(i)); | |
762 | } | |
763 | ||
764 | ||
3f797131 | 765 | |
caaf90d2 | 766 | ftlMacroSelList->RemoveAll(); |
3f797131 | 767 | |
caaf90d2 | 768 | iter = (TObjString*)fM->fMacroSelList->First(); |
3f797131 | 769 | |
4f6473f6 | 770 | ind = 0; |
3f797131 | 771 | while (iter != 0) |
772 | { | |
4f6473f6 | 773 | ftlMacroSelList->AddEntry(iter->GetName(), ind++); |
caaf90d2 | 774 | iter = (TObjString*)fM->fMacroSelList->After(iter); |
3f797131 | 775 | } |
776 | ||
caaf90d2 | 777 | ftlMacroSelList->SortByName(); |
4f6473f6 | 778 | |
779 | // Select, what has been selected before | |
780 | for (Int_t i = 0; i < fM->fMacroSelList->GetEntries(); i++) | |
781 | { | |
782 | ftlMacroSelList->Select(i, fM->MacroSelListIsSelected(i)); | |
783 | } | |
784 | } | |
785 | ||
786 | //______________________________________________________ | |
787 | void AliEveTRDTrackListEditor::UpdateMacroListSelection(Int_t ind) | |
788 | { | |
789 | // Toggle selected item | |
790 | fM->SetMacroListSelection(ind, !fM->MacroListIsSelected(ind)); | |
791 | } | |
792 | ||
793 | //______________________________________________________ | |
794 | void AliEveTRDTrackListEditor::UpdateMacroSelListSelection(Int_t ind) | |
795 | { | |
796 | // Toggle selected item | |
797 | fM->SetMacroSelListSelection(ind, !fM->MacroSelListIsSelected(ind)); | |
2ef0687e | 798 | } |