]>
Commit | Line | Data |
---|---|---|
2ef0687e | 1 | #include "AliEveTRDTrackListEditor.h" |
2 | ||
3 | ClassImp(AliEveTRDTrackListEditor) | |
4 | ||
5 | /////////////////////////////////////////////////////////// | |
6 | ///////////// AliEveTRDTrackListEditor ////////////////// | |
7 | /////////////////////////////////////////////////////////// | |
8 | AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t width, Int_t height, | |
9 | UInt_t options, Pixel_t back) : | |
10 | TGedFrame(p, width, height, options, back), | |
11 | fM(0), | |
12 | fMainFrame(0), | |
13 | fMemberFrame(0), | |
14 | fBrowseFrame(0), | |
15 | bBrowse(0), | |
16 | bApplyMacros(0), | |
17 | bRemoveMacros(0), | |
18 | teField(0), | |
19 | tvMemberList(0), | |
20 | tlMacroList(0), | |
3f797131 | 21 | tlMacroSelList(0), |
2ef0687e | 22 | fileInfo(0), |
3f797131 | 23 | fileTypes(0), |
24 | fLabel1(0), fLabel2(0), fLabel3(0), | |
39b891ff | 25 | fLine1(0), fLine2(0), fLine3(0) |
2ef0687e | 26 | { |
27 | // Constructor. | |
28 | fMainFrame = CreateEditorTabSubFrame("Apply macros"); | |
3f797131 | 29 | |
2ef0687e | 30 | // Functionality for adding macros |
3f797131 | 31 | fLabel1 = new TGLabel(fMainFrame,"Add macro(s):"); |
32 | fMainFrame->AddFrame(fLabel1); | |
2ef0687e | 33 | fBrowseFrame = new TGHorizontalFrame(fMainFrame); |
34 | ||
35 | teField = new TGTextEntry(fBrowseFrame); | |
36 | teField->Connect("ReturnPressed()","AliEveTRDTrackListEditor", this, "HandleMacroPathSet()"); | |
37 | fBrowseFrame->AddFrame(teField); | |
38 | ||
39 | bBrowse = new TGTextButton(fBrowseFrame, "Browse"); | |
40 | bBrowse->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "BrowseMacros()"); | |
41 | fBrowseFrame->AddFrame(bBrowse); | |
42 | fMainFrame->AddFrame(fBrowseFrame); | |
43 | ||
3f797131 | 44 | fLine1 = new TGHorizontal3DLine(fMainFrame, 194, 8); |
45 | fMainFrame->AddFrame(fLine1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2)); | |
46 | fLabel2 = new TGLabel(fMainFrame,"Selection macros:"); | |
47 | fMainFrame->AddFrame(fLabel2); | |
48 | ||
49 | tlMacroSelList = new TGListBox(fMainFrame); | |
50 | tlMacroSelList->Resize(194, 94); | |
51 | tlMacroSelList->SetMultipleSelections(kTRUE); | |
52 | fMainFrame->AddFrame(tlMacroSelList); | |
53 | ||
54 | fLine2 = new TGHorizontal3DLine(fMainFrame, 194, 8); | |
55 | fMainFrame->AddFrame(fLine2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2)); | |
56 | fLabel3 = new TGLabel(fMainFrame,"Process macros:"); | |
57 | fMainFrame->AddFrame(fLabel3); | |
58 | ||
2ef0687e | 59 | tlMacroList = new TGListBox(fMainFrame); |
3f797131 | 60 | tlMacroList->Resize(194, 94); |
2ef0687e | 61 | tlMacroList->SetMultipleSelections(kTRUE); |
62 | fMainFrame->AddFrame(tlMacroList); | |
63 | ||
3f797131 | 64 | fLine3 = new TGHorizontal3DLine(fMainFrame, 194, 8); |
65 | fMainFrame->AddFrame(fLine3, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2)); | |
66 | ||
2ef0687e | 67 | bApplyMacros = new TGTextButton(fMainFrame, "Apply selected macro(s)"); |
68 | bApplyMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "ApplyMacros()"); | |
69 | bApplyMacros->SetRightMargin(12); | |
70 | fMainFrame->AddFrame(bApplyMacros); | |
71 | ||
72 | bRemoveMacros = new TGTextButton(fMainFrame, "Remove selected macro(s)"); | |
73 | bRemoveMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "RemoveMacros()"); | |
74 | fMainFrame->AddFrame(bRemoveMacros); | |
75 | ||
76 | // List members | |
77 | fMemberFrame = CreateEditorTabSubFrame("Members"); | |
78 | ||
79 | tvMemberList = new TGTextView(fMemberFrame, 220, 120, ""); | |
80 | fMemberFrame->AddFrame(tvMemberList); | |
81 | ||
82 | // Set up file dialog | |
83 | fileInfo = new TGFileInfo(); | |
84 | fileInfo->SetMultipleSelection(kTRUE); | |
85 | ||
86 | fileTypes = new Char_t*[6]; | |
39b891ff | 87 | fileTypes[0] = (Char_t*)"All files"; fileTypes[1] = (Char_t*)"*"; |
88 | fileTypes[2] = (Char_t*)"ROOT macros"; fileTypes[3] = (Char_t*)"*.C"; | |
2ef0687e | 89 | fileTypes[4] = 0; fileTypes[5] = 0; |
90 | fileInfo->fFileTypes = (const Char_t**)fileTypes; | |
91 | fileInfo->fFileTypeIdx = 2; | |
92 | fileInfo->fMultipleSelection = kTRUE; | |
93 | } | |
94 | ||
3f797131 | 95 | void AliEveTRDTrackListEditor::AddMacro(const Char_t* entryName, const Char_t* nameC, const Char_t* pathname) |
96 | { | |
97 | // First check the type of the macro: | |
98 | // If it has the signature of a selection macro: | |
39b891ff | 99 | // Bool_t MacroName(AliTRDtrackV1 |
3f797131 | 100 | // it is assumed to be a selection macro. In all other cases: Process macro |
101 | TEveMacro* macro = NULL; | |
102 | Bool_t isSelectionMacro = kFALSE; | |
103 | Char_t signature[120]; | |
104 | memset(signature, '\0', sizeof(Char_t) * 120); | |
105 | ||
106 | // Delete ".C" from filename | |
107 | Char_t* name = new Char_t[strlen(nameC)]; | |
108 | memset(name, '\0', sizeof(Char_t) * strlen(nameC)); | |
109 | strncpy(name, nameC, strlen(nameC) - 2); | |
110 | ||
111 | // Create signature | |
39b891ff | 112 | sprintf(signature, "Bool_t %s(AliTRDtrackV1", name); |
3f797131 | 113 | |
114 | macro = new TEveMacro(pathname); | |
39b891ff | 115 | if (!macro) |
116 | { | |
3f797131 | 117 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", |
118 | "Cannot access file!", kMBIconExclamation, kMBOk); | |
119 | return; | |
2ef0687e | 120 | } |
3f797131 | 121 | if (macro->TMacro::GetLineWith(signature) != 0) isSelectionMacro = kTRUE; |
122 | else isSelectionMacro = kFALSE; | |
123 | delete macro; | |
124 | macro = 0; | |
125 | ||
126 | // Only add macro, if it is not already in the list | |
39b891ff | 127 | if (!isSelectionMacro && fM->macroList->FindObject(entryName) == 0) |
128 | { | |
3f797131 | 129 | fM->macroList->Add(new TObjString(entryName)); |
130 | fM->macroList->Sort(); | |
131 | ||
132 | UpdateMacroList(); | |
39b891ff | 133 | } |
134 | else if (isSelectionMacro && fM->macroSelList->FindObject(entryName) == 0) | |
135 | { | |
3f797131 | 136 | fM->macroSelList->Add(new TObjString(entryName)); |
137 | fM->macroSelList->Sort(); | |
39b891ff | 138 | |
3f797131 | 139 | UpdateMacroList(); |
39b891ff | 140 | } |
141 | else | |
142 | { | |
143 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Warning", "Macro is already in list (won't be added again)!", | |
144 | kMBIconExclamation, kMBOk); | |
2ef0687e | 145 | } |
146 | } | |
147 | ||
148 | void AliEveTRDTrackListEditor::ApplyMacros() | |
149 | { | |
150 | TList* iterator = new TList(); | |
39b891ff | 151 | //TEveMacro* macro = 0; |
2ef0687e | 152 | Char_t name[100]; |
153 | Char_t path[300]; | |
154 | Char_t pathname[400]; | |
39b891ff | 155 | Char_t cmd[430]; |
3f797131 | 156 | |
157 | // First apply the selection macros | |
158 | tlMacroSelList->GetSelectedEntries(iterator); | |
159 | AliEveTRDTrack* track = 0; | |
39b891ff | 160 | AliTRDtrackV1 *trackv1 = 0; |
3f797131 | 161 | Bool_t selectedByMacro = kFALSE; |
162 | ||
39b891ff | 163 | for (Int_t i = 0; i < iterator->GetEntries(); i++) |
164 | { | |
3f797131 | 165 | memset(name, '\0', sizeof(Char_t) * 100); |
166 | memset(path, '\0', sizeof(Char_t) * 300); | |
167 | memset(pathname, '\0', sizeof(Char_t) * 400); | |
39b891ff | 168 | memset(cmd, '\0', sizeof(Char_t) * 430); |
169 | ||
3f797131 | 170 | // Extract path and name -> Make pathname |
171 | sscanf(iterator->At(i)->GetTitle(), "%s (Path: %s)", name, path); | |
39b891ff | 172 | // Delete ")" at the end of path. |
173 | path[strlen(path)] = '\0'; | |
3f797131 | 174 | path[strlen(path) - 1] = '\0'; |
3f797131 | 175 | |
39b891ff | 176 | sprintf(pathname, "%s/%s", path, name); |
177 | sprintf(cmd, ".x %s(automaticTrack)", pathname); | |
178 | ||
179 | //TString sPathname(pathname); | |
180 | //gSystem->ExpandPathName(sPathname); | |
181 | ||
3f797131 | 182 | // Load and execute macro |
39b891ff | 183 | //macro = new TEveMacro(sPathname); |
3f797131 | 184 | |
185 | // Walk through the list of tracks | |
39b891ff | 186 | for (TEveElement::List_i iter = fM->BeginChildren(); iter != fM->EndChildren(); ++iter) |
187 | { | |
3f797131 | 188 | track = dynamic_cast<AliEveTRDTrack*>(*iter); |
189 | ||
190 | if (!track) continue; | |
3f797131 | 191 | |
39b891ff | 192 | trackv1 = (AliTRDtrackV1*)track->GetUserData(); |
193 | ||
3f797131 | 194 | // Make this track available |
39b891ff | 195 | //selectedByMacro = gROOT->ProcessLine(cmd); |
196 | ||
197 | ||
198 | ///// gROOT->LoadMacro("$path/selection.C"); | |
199 | /////... use selection() | |
200 | ||
3f797131 | 201 | |
39b891ff | 202 | //gROOT->Reset(); |
203 | track->ExportToCINT((Text_t*)"automaticTrack"); | |
204 | //selectedByMacro = (Bool_t)macro->Exec("automaticTrack"); | |
205 | selectedByMacro = (Bool_t)gROOT->ProcessLine(cmd); | |
206 | track->SetRnrState(selectedByMacro); | |
3f797131 | 207 | } |
39b891ff | 208 | |
209 | //if (macro != NULL) delete macro; | |
3f797131 | 210 | } |
2ef0687e | 211 | |
39b891ff | 212 | // Update view |
213 | gEve->Redraw3D(); | |
214 | //return; /////////////////// FOR TESTING | |
215 | ||
3f797131 | 216 | if (iterator != NULL) delete iterator; |
2ef0687e | 217 | |
3f797131 | 218 | // Now apply the process macros |
219 | iterator = new TList(); | |
2ef0687e | 220 | tlMacroList->GetSelectedEntries(iterator); |
221 | ||
222 | // Make tracklist availabe | |
39b891ff | 223 | fM->ExportToCINT((Text_t*)"trackList"); |
224 | for (Int_t i = 0; i < iterator->GetEntries(); i++) | |
225 | { | |
3f797131 | 226 | memset(name, '\0', sizeof(Char_t) * 100); |
227 | memset(path, '\0', sizeof(Char_t) * 300); | |
228 | memset(pathname, '\0', sizeof(Char_t) * 400); | |
39b891ff | 229 | memset(cmd, '\0', sizeof(Char_t) * 430); |
3f797131 | 230 | |
231 | // Extract path and name -> Make pathname | |
232 | sscanf(iterator->At(i)->GetTitle(), "%s (Path: %s)", name, path); | |
233 | // Delete ")" at the end of path | |
39b891ff | 234 | path[strlen(path)] = '\0'; |
3f797131 | 235 | path[strlen(path) - 1] = '\0'; |
236 | sprintf(pathname, "%s/%s", path, name); | |
237 | ||
39b891ff | 238 | //TString sPathname(pathname); |
239 | //gSystem->ExpandPathName(sPathname); | |
240 | ||
241 | sprintf(cmd, ".x %s(trackList)", pathname); | |
242 | gROOT->ProcessLine(cmd); | |
3f797131 | 243 | // Load and execute macro |
39b891ff | 244 | //macro = new TEveMacro(sPathname); |
3f797131 | 245 | |
39b891ff | 246 | //macro->Exec("trackList"); |
247 | //if (macro != NULL) delete macro; | |
2ef0687e | 248 | } |
249 | ||
250 | if (iterator != NULL) delete iterator; | |
251 | } | |
2ef0687e | 252 | |
253 | void AliEveTRDTrackListEditor::BrowseMacros() | |
254 | { | |
255 | new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fileInfo); | |
256 | ||
3f797131 | 257 | if (fileInfo->fIniDir != 0 && fileInfo->fFileNamesList != 0) |
258 | { | |
259 | Char_t entryName[300]; | |
260 | memset(entryName, '\0', sizeof(Char_t) * 300); | |
2ef0687e | 261 | |
262 | // Extract filenames | |
263 | TObject* iter = fileInfo->fFileNamesList->First(); | |
264 | ||
265 | Char_t* name = 0; | |
266 | ||
267 | while (iter != 0) | |
268 | { | |
269 | name = strrchr(iter->GetName(), '/'); | |
270 | // Delete '"' at the end | |
271 | name[strlen(name)] = '\0'; | |
3f797131 | 272 | sprintf(entryName, "%s (Path: %s)", name + 1, fileInfo->fIniDir); |
273 | ||
274 | AddMacro(entryName, name + 1, iter->GetName()); | |
2ef0687e | 275 | iter = (TObjString*)fileInfo->fFileNamesList->After(iter); |
276 | } | |
277 | } | |
3f797131 | 278 | |
279 | // Some error occurs, when one ends the filedialog with "cancel": fileInfo->fFileNamesList is set to 0x0, but | |
280 | // in the next launch no new memory is allocated. So do this manually. | |
281 | if (fileInfo->fFileNamesList == 0) fileInfo->fFileNamesList = new TList(); | |
2ef0687e | 282 | } |
283 | ||
284 | void AliEveTRDTrackListEditor::HandleMacroPathSet() | |
285 | { | |
39b891ff | 286 | if (strlen(teField->GetText()) != 0) |
287 | { | |
2ef0687e | 288 | // Check if file exists |
289 | FILE* fp = NULL; | |
290 | ||
291 | fp = fopen(teField->GetText(), "rb"); | |
39b891ff | 292 | if (fp != NULL) |
293 | { | |
3f797131 | 294 | fclose(fp); |
295 | Char_t entryName[300]; | |
296 | memset(entryName, '\0', sizeof(Char_t) * 300); | |
39b891ff | 297 | |
3f797131 | 298 | // Extract filename |
299 | Char_t* name = strrchr(teField->GetText(), '/'); | |
300 | ||
301 | // Current path | |
39b891ff | 302 | if (name == NULL) |
303 | { | |
3f797131 | 304 | sprintf(entryName, "%s (Path: .)", teField->GetText()); |
305 | sprintf(name, "%s", teField->GetText()); | |
306 | ||
307 | // Add path to textfield | |
308 | Char_t pathname[100]; | |
309 | memset(pathname, '\0', sizeof(Char_t) * 100); | |
310 | sprintf(pathname, "./%s", teField->GetText()); | |
311 | teField->SetText(pathname); | |
39b891ff | 312 | } |
313 | // Different path | |
314 | else | |
315 | { | |
3f797131 | 316 | // Extract path |
317 | Char_t* path = new Char_t[240]; | |
318 | memset(path, '\0', sizeof(Char_t) * 240); | |
319 | strncpy(path, teField->GetText(), strlen(teField->GetText()) - strlen(name)); | |
320 | sprintf(entryName, "%s (Path: %s)", name + 1, path); | |
321 | ||
322 | if (path != NULL) delete path; | |
323 | ||
324 | // Ignore the slash "/" in the following | |
39b891ff | 325 | name++; |
3f797131 | 326 | } |
39b891ff | 327 | |
3f797131 | 328 | AddMacro(entryName, name, teField->GetText()); |
39b891ff | 329 | } |
330 | else | |
331 | { | |
3f797131 | 332 | new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", |
39b891ff | 333 | "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk); |
2ef0687e | 334 | } |
335 | } | |
336 | } | |
337 | ||
338 | void AliEveTRDTrackListEditor::RemoveMacros() | |
339 | { | |
340 | TList* iterator = new TList(); | |
341 | ||
342 | tlMacroList->GetSelectedEntries(iterator); | |
343 | ||
39b891ff | 344 | for (Int_t i = 0; i < iterator->GetEntries(); i++) |
345 | { | |
346 | fM->macroList->Remove(fM->macroList->FindObject(iterator->At(i)->GetTitle())); | |
3f797131 | 347 | } |
348 | ||
349 | tlMacroSelList->GetSelectedEntries(iterator); | |
350 | ||
2ef0687e | 351 | for (Int_t i = 0; i < iterator->GetEntries(); i++) |
352 | { | |
39b891ff | 353 | fM->macroSelList->Remove(fM->macroSelList->FindObject(iterator->At(i)->GetTitle())); |
2ef0687e | 354 | } |
355 | ||
356 | UpdateMacroList(); | |
357 | } | |
358 | ||
359 | void AliEveTRDTrackListEditor::SetModel(TObject* obj) | |
360 | { | |
361 | // Set model object. | |
362 | fM = dynamic_cast<AliEveTRDTrackList*>(obj); | |
363 | ||
364 | // Add members to a list | |
365 | tvMemberList->Clear(); | |
3f797131 | 366 | // In order to prevent the first line from being empty, do the following: |
367 | TEveElement::List_i iterator = fM->BeginChildren(); | |
368 | if (iterator != fM->EndChildren()) | |
2ef0687e | 369 | { |
3f797131 | 370 | tvMemberList->SetText(new TGText(((AliEveTRDTrack*)(*iterator))->GetName())); |
371 | iterator++; | |
372 | for ( ; iterator != fM->EndChildren(); ++iterator) | |
373 | tvMemberList->AddLineFast(((AliEveTRDTrack*)(*iterator))->GetName()); | |
374 | } | |
375 | ||
2ef0687e | 376 | tvMemberList->ShowTop(); |
377 | tvMemberList->Update(); | |
378 | ||
379 | UpdateMacroList(); | |
380 | } | |
381 | ||
382 | void AliEveTRDTrackListEditor::UpdateMacroList() | |
383 | { | |
384 | tlMacroList->RemoveAll(); | |
385 | ||
386 | TObjString* iter = (TObjString*)fM->macroList->First(); | |
387 | ||
388 | while (iter != 0) | |
389 | { | |
390 | tlMacroList->AddEntry(iter->GetName(), -1); | |
391 | iter = (TObjString*)fM->macroList->After(iter); | |
392 | } | |
393 | ||
394 | tlMacroList->SortByName(); | |
3f797131 | 395 | |
396 | ||
397 | tlMacroSelList->RemoveAll(); | |
398 | ||
399 | iter = (TObjString*)fM->macroSelList->First(); | |
400 | ||
401 | while (iter != 0) | |
402 | { | |
403 | tlMacroSelList->AddEntry(iter->GetName(), -1); | |
404 | iter = (TObjString*)fM->macroSelList->After(iter); | |
405 | } | |
406 | ||
407 | tlMacroSelList->SortByName(); | |
2ef0687e | 408 | } |