]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveTRDTrackListEditor.cxx
Cure raw version mismatch (MinJung)
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTRDTrackListEditor.cxx
CommitLineData
caaf90d2 1#include "TTreeStream.h"
2#include <EveDet/AliEveTRDTrackList.h>
2ef0687e 3#include "AliEveTRDTrackListEditor.h"
4
caaf90d2 5#include <TGFileDialog.h>
6#include <TFile.h>
7#include <TGButton.h>
c04e790a 8#include <TGedEditor.h> ////// MAYBE THIS CAN BE REMOVED
caaf90d2 9#include <TGTextEntry.h>
10#include <TGTextView.h>
11#include <TGListBox.h>
12#include <TGMsgBox.h>
13#include <TGLabel.h>
14#include <TG3DLine.h>
15#include <TEveMacro.h>
16#include <TEveManager.h>
17#include <TObjString.h>
18#include <TSystem.h>
19#include <TROOT.h>
20#include <AliTRDtrackV1.h>
21#include <EveDet/AliEveTRDData.h>
22
2ef0687e 23ClassImp(AliEveTRDTrackListEditor)
24
25///////////////////////////////////////////////////////////
26///////////// AliEveTRDTrackListEditor //////////////////
27///////////////////////////////////////////////////////////
28AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t width, Int_t height,
29 UInt_t options, Pixel_t back) :
30 TGedFrame(p, width, height, options, back),
31 fM(0),
32 fMainFrame(0),
caaf90d2 33 fHistoFrame(0),
34 fHistoSubFrame(0),
2ef0687e 35 fBrowseFrame(0),
caaf90d2 36 fbBrowse(0),
37 fbApplyMacros(0),
38 fbRemoveMacros(0),
39 fbDrawHisto(0),
40 fteField(0),
41 ftlMacroList(0),
42 ftlMacroSelList(0),
43 fFileInfo(0),
44 fFileTypes(0),
45 fLabel1(0), fLabel2(0), fLabel3(0), fLabel4(0),
46 fLine1(0), fLine2(0), fLine3(0), fLine4(0),
47 fCheckButtons(0)
48{
2ef0687e 49 fMainFrame = CreateEditorTabSubFrame("Apply macros");
3f797131 50
2ef0687e 51 // Functionality for adding macros
3f797131 52 fLabel1 = new TGLabel(fMainFrame,"Add macro(s):");
53 fMainFrame->AddFrame(fLabel1);
2ef0687e 54 fBrowseFrame = new TGHorizontalFrame(fMainFrame);
55
caaf90d2 56 fteField = new TGTextEntry(fBrowseFrame);
57 fteField->Connect("ReturnPressed()","AliEveTRDTrackListEditor", this, "HandleMacroPathSet()");
58 fBrowseFrame->AddFrame(fteField);
2ef0687e 59
caaf90d2 60 fbBrowse = new TGTextButton(fBrowseFrame, "Browse");
61 fbBrowse->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "BrowseMacros()");
62 fBrowseFrame->AddFrame(fbBrowse);
2ef0687e 63 fMainFrame->AddFrame(fBrowseFrame);
64
3f797131 65 fLine1 = new TGHorizontal3DLine(fMainFrame, 194, 8);
caaf90d2 66 fMainFrame->AddFrame(fLine1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
3f797131 67 fLabel2 = new TGLabel(fMainFrame,"Selection macros:");
68 fMainFrame->AddFrame(fLabel2);
69
caaf90d2 70 ftlMacroSelList = new TGListBox(fMainFrame);
71 ftlMacroSelList->Resize(194, 94);
72 ftlMacroSelList->SetMultipleSelections(kTRUE);
73 fMainFrame->AddFrame(ftlMacroSelList);
3f797131 74
75 fLine2 = new TGHorizontal3DLine(fMainFrame, 194, 8);
caaf90d2 76 fMainFrame->AddFrame(fLine2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
3f797131 77 fLabel3 = new TGLabel(fMainFrame,"Process macros:");
78 fMainFrame->AddFrame(fLabel3);
79
caaf90d2 80 ftlMacroList = new TGListBox(fMainFrame);
81 ftlMacroList->Resize(194, 94);
82 ftlMacroList->SetMultipleSelections(kTRUE);
83 fMainFrame->AddFrame(ftlMacroList);
2ef0687e 84
3f797131 85 fLine3 = new TGHorizontal3DLine(fMainFrame, 194, 8);
caaf90d2 86 fMainFrame->AddFrame(fLine3, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
3f797131 87
caaf90d2 88 fbApplyMacros = new TGTextButton(fMainFrame, "Apply selected macro(s)");
89 fbApplyMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "ApplyMacros()");
90 fbApplyMacros->SetRightMargin(12);
91 fMainFrame->AddFrame(fbApplyMacros);
2ef0687e 92
caaf90d2 93 fbRemoveMacros = new TGTextButton(fMainFrame, "Remove selected macro(s)");
94 fbRemoveMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "RemoveMacros()");
95 fMainFrame->AddFrame(fbRemoveMacros);
2ef0687e 96
caaf90d2 97 // Stuff for displaying histograms
98 fHistoFrame = CreateEditorTabSubFrame("Histograms");
99 fHistoFrame->SetMapSubwindows(kTRUE);
100 fLabel4 = new TGLabel(fHistoFrame,"Data from applied macros:");
101 fHistoFrame->AddFrame(fLabel4);
102
103 fHistoSubFrame = new TGVerticalFrame(fHistoFrame);
104 fHistoSubFrame->SetMapSubwindows(kTRUE);
105 fHistoSubFrame->Resize(194, 200);
106 fHistoFrame->AddFrame(fHistoSubFrame);
107
108 fLine4 = new TGHorizontal3DLine(fHistoFrame, 194, 8);
109 fHistoFrame->AddFrame(fLine4, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
110
111 fbDrawHisto = new TGTextButton(fHistoFrame, "Draw histogram");
112 fbDrawHisto->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "DrawHistos()");
113 fHistoFrame->AddFrame(fbDrawHisto);
2ef0687e 114
115 // Set up file dialog
caaf90d2 116 fFileInfo = new TGFileInfo();
117 fFileInfo->SetMultipleSelection(kTRUE);
118
119 fFileTypes = new Char_t*[6];
120 fFileTypes[0] = (Char_t*)"All files"; fFileTypes[1] = (Char_t*)"*";
121 fFileTypes[2] = (Char_t*)"ROOT macros"; fFileTypes[3] = (Char_t*)"*.C";
122 fFileTypes[4] = 0; fFileTypes[5] = 0;
123 fFileInfo->fFileTypes = (const Char_t**)fFileTypes;
124 fFileInfo->fFileTypeIdx = 2;
125 fFileInfo->fMultipleSelection = kTRUE;
126
127 // Set focus on "Apply macros" tab
caaf90d2 128 //fMainFrame->TGWindow::RequestFocus();
129 //Update();
2ef0687e 130}
131
c04e790a 132//______________________________________________________
caaf90d2 133AliEveTRDTrackListEditor::~AliEveTRDTrackListEditor()
3f797131 134{
caaf90d2 135 if (fFileTypes != 0)
39b891ff 136 {
caaf90d2 137 delete [] fFileTypes;
138 fFileTypes = 0;
2ef0687e 139 }
3f797131 140
caaf90d2 141 if (fFileInfo != 0)
39b891ff 142 {
caaf90d2 143 delete fFileInfo;
144 fFileInfo = 0;
39b891ff 145 }
caaf90d2 146}
147
c04e790a 148//______________________________________________________
caaf90d2 149void AliEveTRDTrackListEditor::AddMacro(const Char_t* path, const Char_t* name)
150{
151 Int_t result = fM->AddMacro(path, name);
152
153 switch (result)
39b891ff 154 {
caaf90d2 155 case SUCCESS:
156 UpdateMacroList();
157 break;
158 case WARNING:
39b891ff 159 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Warning", "Macro is already in list (won't be added again)!",
160 kMBIconExclamation, kMBOk);
caaf90d2 161 break;
162 case SIGNATURE_ERROR:
163 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
164 "Macro has not the signature of...\n...a selection macro: Bool_t YourMacro(AliTRDtrackV1*)\n...a process macro: void YourMacro(AliTRDtrackV1*, Double_t*&, Int_t&)",
165 kMBIconExclamation, kMBOk);
166 break;
167 case NOT_EXIST_ERROR:
168 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
169 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
170 break;
171 default:
172 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
173 Form("AliEveTRDTrackList::AddMacro exited with unknown return value: %d", result),
174 kMBIconExclamation, kMBOk);
175 break;
2ef0687e 176 }
177}
178
c04e790a 179//______________________________________________________
2ef0687e 180void AliEveTRDTrackListEditor::ApplyMacros()
181{
3f797131 182 // First apply the selection macros
caaf90d2 183 TList* iterator = new TList();
184 ftlMacroSelList->GetSelectedEntries(iterator);
185 fM->ApplySelectionMacros(iterator);
186
39b891ff 187 // Update view
188 gEve->Redraw3D();
39b891ff 189
caaf90d2 190 if (iterator != 0) delete iterator;
2ef0687e 191
3f797131 192 // Now apply the process macros
193 iterator = new TList();
caaf90d2 194 ftlMacroList->GetSelectedEntries(iterator);
195 fM->ApplyProcessMacros(iterator);
196
197 // Now the data is stored in the following file and can easily be accessed
198 TFile* file = new TFile("TRD.TrackListMacroData.root", "READ");
199 if (!file)
200 {
201 Error("Apply macros", "Cannot open file \"TRD.TrackListMacroData.root\"");
202 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Apply macros",
203 "Cannot open file \"TRD.TrackListMacroData.root\"", kMBIconExclamation, kMBOk);
204
205 if (iterator != 0) delete iterator;
206 iterator = 0;
2ef0687e 207
caaf90d2 208 return;
209 }
210
211 TTree* t = 0;
c04e790a 212 for (Int_t i = 0; i < iterator->GetEntries(); i++) {
caaf90d2 213 t = (TTree*)file->Get(Form("TrackData%d", i));
c04e790a 214 if (t != 0) {
caaf90d2 215 gEve->AddCanvasTab(Form("Macro%d", i));
216 t->Draw(Form("Macro%d", i), "1");
39b891ff 217
caaf90d2 218 delete t;
219 t = 0;
c04e790a 220
221 // ONLY DISPLAY ONE MACRO (the first one possible) -> Remove the next line to display all
222 break;
223 } else {
caaf90d2 224 Error("Apply macros", Form("No data for macro%d found!", i));
225 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Apply macros",
226 Form("No data for macro%d found!", i), kMBIconExclamation, kMBOk);
227 }
2ef0687e 228 }
caaf90d2 229 file->Close("R");
230 delete file;
231 file = 0;
2ef0687e 232
caaf90d2 233 if (iterator != 0) delete iterator;
234 iterator = 0;
235
236 // Update histogram tab (data has to be reloaded)
c04e790a 237 //fHistoFrame->TGWindow::RequestFocus();
238 //fGedEditor->TGCompositeFrame::ShowFrame(fHistoFrame);
caaf90d2 239 SetModel(fM);
240 Update();
2ef0687e 241}
2ef0687e 242
c04e790a 243
244//______________________________________________________
2ef0687e 245void AliEveTRDTrackListEditor::BrowseMacros()
246{
caaf90d2 247 new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fFileInfo);
2ef0687e 248
caaf90d2 249 if (fFileInfo->fIniDir != 0 && fFileInfo->fFileNamesList != 0)
3f797131 250 {
2ef0687e 251 // Extract filenames
caaf90d2 252 TObject* iter = fFileInfo->fFileNamesList->First();
2ef0687e 253
254 Char_t* name = 0;
255
256 while (iter != 0)
257 {
caaf90d2 258 // NOTE: fileInfo->fFileNamesList will be changed by that, too!
2ef0687e 259 name = strrchr(iter->GetName(), '/');
260 // Delete '"' at the end
261 name[strlen(name)] = '\0';
caaf90d2 262
263 AddMacro(fFileInfo->fIniDir, name + 1);
264 iter = (TObjString*)fFileInfo->fFileNamesList->After(iter);
2ef0687e 265 }
266 }
3f797131 267
caaf90d2 268 // -> The following problem has been fixed (trunk -> Changes according to 03 September 2008):
3f797131 269 // Some error occurs, when one ends the filedialog with "cancel": fileInfo->fFileNamesList is set to 0x0, but
270 // in the next launch no new memory is allocated. So do this manually.
caaf90d2 271 //if (fileInfo->fFileNamesList == 0) fileInfo->fFileNamesList = new TList();
272}
273
c04e790a 274//______________________________________________________
caaf90d2 275void AliEveTRDTrackListEditor::DrawHistos()
276{
277 Int_t nHistograms = GetNSelectedHistograms();
278 if (nHistograms <= 0)
279 {
280 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
281 "No data selected. Please select the data you want to plot!", kMBIconExclamation, kMBOk);
282 return;
283 }
284 if (nHistograms > 3)
285 {
286 new TGMsgBox(gClient->GetRoot(), GetMainFrame(),
287 "Error", "Only histograms with up to 3 dimensions supported. Please select 1,2 or 3 data macros!",
288 kMBIconExclamation, kMBOk);
289 return;
290 }
291
292 TFile* file = new TFile("TRD.TrackListMacroData.root", "READ");
293 if (!file)
294 {
295 Error("Draw histograms", "Cannot open file \"TRD.TrackListMacroData.root\"");
296 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
297 "Cannot open file \"TRD.TrackListMacroData.root\"", kMBIconExclamation, kMBOk);
298 return;
299 }
300
301 TTree* t = 0;
302 TTree* tFriend1 = 0;
303 TTree* tFriend2 = 0;
304
305 Int_t indexOfMacro1 = 0;
306 Int_t indexOfMacro2 = 0;
307 Int_t indexOfMacro3 = 0;
308
309 // Load the trees in succession and remember the entries
310 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
311 {
312 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown)
313 {
314 if (t == 0)
315 {
316 indexOfMacro1 = i;
317 if (!(t = (TTree*)file->Get(Form("TrackData%d", i))))
318 {
319 Error("Draw histograms", Form("No data for macro%d found!", i));
320 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
321 Form("No data for macro%d found!", i), kMBIconExclamation, kMBOk);
322 break;
323 }
324
325 // 1d histogram
326 if (nHistograms == 1)
327 {
328 gEve->AddCanvasTab(Form("Macro%d", indexOfMacro1));
329 t->Draw(Form("Macro%d", indexOfMacro1), "1");
330
331 break;
332 }
333 }
334 else if (tFriend1 == 0)
335 {
336 indexOfMacro2 = i;
337 if (!(tFriend1 = (TTree*)file->Get(Form("TrackData%d", i))))
338 {
339 Error("Draw histograms", Form("No data for macro%d found!", i));
340 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
341 Form("No data for macro%d found!", i), kMBIconExclamation, kMBOk);
342 break;
343 }
344
345 // 2d histogram
346 if (nHistograms == 2)
347 {
348 gEve->AddCanvasTab(Form("Macro%d - Macro%d", indexOfMacro1, indexOfMacro2));
349 t->AddFriend(tFriend1);
350 t->Draw(Form("Macro%d:Macro%d", indexOfMacro1, indexOfMacro2), "1");
351
352 break;
353 }
354 }
355 // 3d histogram
356 else
357 {
358 indexOfMacro3 = i;
359 if (!(tFriend2 = (TTree*)file->Get(Form("TrackData%d", i))))
360 {
361 Error("Draw histograms", Form("No data for macro%d found!", i));
362 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
363 Form("No data for macro%d found!", i), kMBIconExclamation, kMBOk);
364 break;
365 }
366
367 gEve->AddCanvasTab(Form("Macro%d - Macro%d - Macro%d", indexOfMacro1, indexOfMacro2, indexOfMacro3));
368 t->AddFriend(tFriend1);
369 t->AddFriend(tFriend2);
370 t->Draw(Form("Macro%d:Macro%d:Macro%d", indexOfMacro1, indexOfMacro2, indexOfMacro3), "1");
371
372 break;
373 }
374 }
375 }
376
377 if (t != 0) delete t;
378 t = 0;
379 if (tFriend1 != 0) delete tFriend1;
380 tFriend1 = 0;
381 if (tFriend2 != 0) delete tFriend2;
382 tFriend2 = 0;
383
384 file->Close("R");
385 delete file;
386 file = 0;
387}
388
c04e790a 389//______________________________________________________
caaf90d2 390Int_t AliEveTRDTrackListEditor::GetNSelectedHistograms()
391{
392 Int_t count = 0;
393
394 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
395 {
396 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown) count++;
397 }
398
399 return count;
2ef0687e 400}
401
c04e790a 402//______________________________________________________
2ef0687e 403void AliEveTRDTrackListEditor::HandleMacroPathSet()
404{
caaf90d2 405 if (strlen(fteField->GetText()) != 0)
39b891ff 406 {
2ef0687e 407 // Check if file exists
408 FILE* fp = NULL;
409
caaf90d2 410 fp = fopen(fteField->GetText(), "rb");
39b891ff 411 if (fp != NULL)
412 {
3f797131 413 fclose(fp);
caaf90d2 414
3f797131 415 // Extract filename
caaf90d2 416 Char_t* name = strrchr(fteField->GetText(), '/');
3f797131 417
418 // Current path
39b891ff 419 if (name == NULL)
420 {
caaf90d2 421 name = new Char_t[100];
422 memset(name, '\0', sizeof(Char_t) * 100);
423 sprintf(name, "%s", fteField->GetText());
3f797131 424
425 // Add path to textfield
426 Char_t pathname[100];
427 memset(pathname, '\0', sizeof(Char_t) * 100);
caaf90d2 428 sprintf(pathname, "./%s", fteField->GetText());
429 fteField->SetText(pathname);
430
431 AddMacro(".", name);
432 if (name != 0) delete name;
433 name = 0;
39b891ff 434 }
435 // Different path
436 else
437 {
3f797131 438 // Extract path
439 Char_t* path = new Char_t[240];
440 memset(path, '\0', sizeof(Char_t) * 240);
caaf90d2 441 strncpy(path, fteField->GetText(), strlen(fteField->GetText()) - strlen(name));
442
443 // Ignore the slash "/" in name
444 AddMacro(path, name + 1);
445
446 if (path != 0) delete path;
447 path = 0;
448 }
39b891ff 449 }
450 else
451 {
3f797131 452 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
39b891ff 453 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
2ef0687e 454 }
455 }
456}
457
c04e790a 458//______________________________________________________
2ef0687e 459void AliEveTRDTrackListEditor::RemoveMacros()
460{
461 TList* iterator = new TList();
462
caaf90d2 463 ftlMacroList->GetSelectedEntries(iterator);
464 fM->RemoveProcessMacros(iterator);
3f797131 465
caaf90d2 466 if (iterator != 0) delete iterator;
3f797131 467
caaf90d2 468 iterator = new TList();
469 ftlMacroSelList->GetSelectedEntries(iterator);
470 fM->RemoveSelectionMacros(iterator);
2ef0687e 471
472 UpdateMacroList();
caaf90d2 473
474 if (iterator != 0) delete iterator;
475 iterator = 0;
2ef0687e 476}
477
c04e790a 478
479//______________________________________________________
2ef0687e 480void AliEveTRDTrackListEditor::SetModel(TObject* obj)
481{
caaf90d2 482 // Set model object
2ef0687e 483 fM = dynamic_cast<AliEveTRDTrackList*>(obj);
484
2ef0687e 485 UpdateMacroList();
caaf90d2 486 UpdateHistoList();
487}
488
c04e790a 489//______________________________________________________
caaf90d2 490void AliEveTRDTrackListEditor::UpdateHistoList()
491{
492 fHistoSubFrame->TGCompositeFrame::RemoveAll();
493
494 // Set buttons for histograms
495 if (fCheckButtons != 0) delete fCheckButtons;
496 fCheckButtons = new TGCheckButton*[fM->fDataFromMacroList->GetEntries()];
497
498 TObjString* iter = (TObjString*)fM->fDataFromMacroList->First();
499 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries() && iter != 0; i++)
500 {
501 fCheckButtons[i] = new TGCheckButton(fHistoSubFrame, iter->GetName());
502 fHistoSubFrame->AddFrame(fCheckButtons[i]);
503
504 fCheckButtons[i]->SetState(kButtonUp, kFALSE);
505 fCheckButtons[i]->MapRaised();
506
507 iter = (TObjString*)fM->fDataFromMacroList->After(iter);
508 }
2ef0687e 509}
510
c04e790a 511
512//______________________________________________________
2ef0687e 513void AliEveTRDTrackListEditor::UpdateMacroList()
514{
caaf90d2 515 ftlMacroList->RemoveAll();
2ef0687e 516
caaf90d2 517 TObjString* iter = (TObjString*)fM->fMacroList->First();
2ef0687e 518
519 while (iter != 0)
520 {
caaf90d2 521 ftlMacroList->AddEntry(iter->GetName(), -1);
522 iter = (TObjString*)fM->fMacroList->After(iter);
2ef0687e 523 }
524
caaf90d2 525 ftlMacroList->SortByName();
3f797131 526
527
caaf90d2 528 ftlMacroSelList->RemoveAll();
3f797131 529
caaf90d2 530 iter = (TObjString*)fM->fMacroSelList->First();
3f797131 531
532 while (iter != 0)
533 {
caaf90d2 534 ftlMacroSelList->AddEntry(iter->GetName(), -1);
535 iter = (TObjString*)fM->fMacroSelList->After(iter);
3f797131 536 }
537
caaf90d2 538 ftlMacroSelList->SortByName();
2ef0687e 539}