]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
more user friendly interface (Ben)
authorabercuci <abercuci@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 11 Sep 2008 12:07:18 +0000 (12:07 +0000)
committerabercuci <abercuci@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 11 Sep 2008 12:07:18 +0000 (12:07 +0000)
EVE/EveDet/AliEveTRDTrackList.cxx
EVE/EveDet/AliEveTRDTrackListEditor.cxx
EVE/EveDet/AliEveTRDTrackListEditor.h

index ddd1bf3b6b541be70e5a97b0ee75f89025743d0d..d4f37e114582cefe6b76eb8cfaefc5f6a9f5ce84 100644 (file)
@@ -38,7 +38,7 @@ AliEveTRDTrackList::AliEveTRDTrackList(const Text_t* n, const Text_t* t, Bool_t
   AddStandardMacros();
 }
 
-//__________________________________________________________
+//______________________________________________________
 AliEveTRDTrackList::~AliEveTRDTrackList()
 {
   if (fMacroList != 0)
@@ -66,7 +66,7 @@ AliEveTRDTrackList::~AliEveTRDTrackList()
   } 
 }
 
-//__________________________________________________________
+//______________________________________________________
 Int_t AliEveTRDTrackList::AddMacro(const Char_t* path, const Char_t* nameC)
 {
   // First check the type of the macro:
@@ -125,22 +125,31 @@ Int_t AliEveTRDTrackList::AddMacro(const Char_t* path, const Char_t* nameC)
 
   // Selection macro?
   TFunction* f = gROOT->GetGlobalFunctionWithPrototype(name, "AliTRDtrackV1*", kTRUE);
-  if (f != 0x0){
-    if (!strcmp(f->GetReturnTypeName(), "Bool_t")){
+  if (f != 0x0)
+  {
+    if (!strcmp(f->GetReturnTypeName(), "Bool_t")) 
+    {
       // Some additional check (is the parameter EXACTLY of the desired type?)
-      if (strstr(f->GetMangledName(), "AliTRDtrackV1mUsP") != 0x0) {
+      if (strstr(f->GetMangledName(), "AliTRDtrackV1mUsP") != 0x0)
+      {
         hasCorrectSignature = kTRUE;
         isSelectionMacro = kTRUE;
       }
     }
-  } else {  // Process macro?
+  }
+  // Process macro?
+  else
+  {
     f = gROOT->GetGlobalFunctionWithPrototype(name, "AliTRDtrackV1*, Double_t*&, Int_t&", kTRUE);
-    if (f != 0x0) {
-      if (!strcmp(f->GetReturnTypeName(), "void")) {
+    if (f != 0x0)
+    {
+      if (!strcmp(f->GetReturnTypeName(), "void"))
+      {
         // Some additional check (are the parameters EXACTLY of the desired type?)
         if (strstr(f->GetMangledName(), "AliTRDtrackV1mUsP") != 0x0 &&
             strstr(f->GetMangledName(), "Double_tmUaNsP") != 0x0 &&
-            strstr(f->GetMangledName(), "Int_taNsP") != 0x0){
+            strstr(f->GetMangledName(), "Int_taNsP") != 0x0)
+        {
           hasCorrectSignature = kTRUE;
           isSelectionMacro = kFALSE;
         }
@@ -190,11 +199,12 @@ Int_t AliEveTRDTrackList::AddMacro(const Char_t* path, const Char_t* nameC)
   return returnValue;
 }
 
-//__________________________________________________________
+//______________________________________________________
 void AliEveTRDTrackList::AddMacroFast(const Char_t* path, const Char_t* name, Bool_t toSelectionList)
 {
   Char_t* entry = MakeMacroEntry(path, name);
-  if (entry != 0) {
+  if (entry != 0)
+  {
     if (toSelectionList)  fMacroSelList->Add(new TObjString(entry));
     else                  fMacroList->Add(new TObjString(entry));
     
@@ -206,14 +216,16 @@ void AliEveTRDTrackList::AddMacroFast(const Char_t* path, const Char_t* name, Bo
     printf("#AliEveTRDTrackList: Standard macros: Added macro %s/%s to %s list\n", path, name, 
            (toSelectionList ? "selection" : "process"));
 #endif
-  } else {
+  }
+  else
+  {
     // Error will always be displayed
     printf("#AliEveTRDTrackList: Standard macros: ERROR: Could not add macro %s/%s to %s list\n", path, name, 
            (toSelectionList ? "selection" : "process"));
   } 
 }
 
-//__________________________________________________________
+//______________________________________________________
 void AliEveTRDTrackList::AddStandardMacros()
 {
   // Add your standard macros here, e.g.: 
@@ -227,13 +239,15 @@ void AliEveTRDTrackList::AddStandardMacros()
   AddMacro("$(ALICE_ROOT)/TRD/qaRec/macros", "chargeDistr.C");
 }
 
-//__________________________________________________________
+//______________________________________________________
 void AliEveTRDTrackList::ApplyProcessMacros(TList* iterator)
 {
+  if (iterator->GetEntries() <= 0)  return;
+
   Char_t name[100];
   Char_t path[300];
   Char_t pathname[400];
-  Char_t cmd[430];
+  Char_t** cmds = new Char_t*[iterator->GetEntries()];
 
   AliEveTRDTrack* track = 0;
   AliTRDtrackV1 *trackv1 = 0;
@@ -246,15 +260,36 @@ void AliEveTRDTrackList::ApplyProcessMacros(TList* iterator)
   fDataFromMacroList = new TList();
 
   if (fDataTree == 0) fDataTree = new TTreeSRedirector("TRD.TrackListMacroData.root");
+
+  // Collect the commands for each macro and add them to "data-from-list"
+  for (Int_t i = 0; i < iterator->GetEntries(); i++)
+  {
+    memset(name, '\0', sizeof(Char_t) * 100);
+    memset(path, '\0', sizeof(Char_t) * 300);
+    memset(pathname, '\0', sizeof(Char_t) * 400);
+
+    cmds[i] = new Char_t[430];
+    memset(cmds[i], '\0', sizeof(Char_t) * 430);
+
+#ifdef ALIEVETRDTRACKLIST_DEBUG
+    printf("AliEveTRDTrackList: Applying process macro: %s\n", iterator->At(i)->GetTitle());
+#endif
+    // Extract path and name -> Make pathname
+    sscanf(iterator->At(i)->GetTitle(), "%s (Path: %s)", name, path);
+   
+    // Add to "data-from-list"
+    fDataFromMacroList->Add(new TObjString(name));
+
+    // Delete ")" at the end of path
+    path[strlen(path)] = '\0';
+    path[strlen(path) - 1] = '\0';
+    sprintf(pathname, "%s/%s", path, name);
+    sprintf(cmds[i], ".x %s(automaticTrackV1, results, n);", pathname);    
+  }  
   
-  // Walk through the list of tracks
-  Int_t trackNum = 0;
-  
-  //Double_t* results = new Double_t[iterator->GetEntries()];
-  //for (Int_t i = 0; i < iterator->GetEntries(); i++)  results[i] = 0;
-  //Double_t result = 0;
-    
-  for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter, ++trackNum)
+  // Walk through the list of tracks     
+  for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
   {
     track = dynamic_cast<AliEveTRDTrack*>(*iter);
 
@@ -272,44 +307,16 @@ void AliEveTRDTrackList::ApplyProcessMacros(TList* iterator)
     // Collect data for each macro
     for (Int_t i = 0; i < iterator->GetEntries(); i++)
     {
-      memset(name, '\0', sizeof(Char_t) * 100);
-      memset(path, '\0', sizeof(Char_t) * 300);
-      memset(pathname, '\0', sizeof(Char_t) * 400);
-      memset(cmd, '\0', sizeof(Char_t) * 430);
-
-#ifdef ALIEVETRDTRACKLIST_DEBUG
-      // Display this message only once
-      if (iter == this->BeginChildren()) 
-        printf("AliEveTRDTrackList: Applying process macro: %s\n", iterator->At(i)->GetTitle());
-#endif
-
-      // Extract path and name -> Make pathname
-      sscanf(iterator->At(i)->GetTitle(), "%s (Path: %s)", name, path);
-      // Delete ")" at the end of path
-      path[strlen(path)] = '\0';
-      path[strlen(path) - 1] = '\0';
-      sprintf(pathname, "%s/%s", path, name);
-      sprintf(cmd, ".x %s(automaticTrackV1, results, n);", pathname);
-
-      // Add to "data-from-list", but only once!
-      if (iter == this->BeginChildren())  fDataFromMacroList->Add(new TObjString(name));
-
-      //results[i] += (Double_t)gROOT->ProcessLineSync(cmd); 
-      //result = (Double_t)gROOT->ProcessLineSync(cmd);
-
-      //(*fDataTree) << Form("TrackData%d", i)
-      //  << Form("Macro%d=", i) << result << "\n";   
-      
       // Create data pointers in CINT, execute the macro and get the data
       gROOT->ProcessLineSync("Double_t* results = 0;");
       gROOT->ProcessLineSync("Int_t n = 0;");
-      gROOT->ProcessLineSync(cmd);
+      gROOT->ProcessLineSync(cmds[i]);
       Double_t* results = (Double_t*)gROOT->ProcessLineSync("results;");
       Int_t nResults = (Int_t)gROOT->ProcessLineSync("n;");
       
       if (results == 0)
       {
-        Error("Apply macros", Form("Error reading data from macro \"%s\"", name));
+        Error("Apply macros", Form("Error reading data from macro \"%s\"", iterator->At(i)->GetTitle()));
         continue;
       }
       for (Int_t resInd = 0; resInd < nResults; resInd++)
@@ -321,18 +328,12 @@ void AliEveTRDTrackList::ApplyProcessMacros(TList* iterator)
       results = 0;
     }
   }    
-/*  for (Int_t i = 0; i < iterator->GetEntries(); i++)
-  {
-    (*fDataTree) << Form("TrackData") << Form("Macro%d=", i) << results[i] << "\n";    
-  }
-
-  if (results != 0) delete results;
-  results = 0;
-*/
 
   delete fDataTree;
   fDataTree = 0;
 
+  if (cmds != 0)  delete [] cmds;
+
   // Clear root
   gROOT->Reset();
   
@@ -340,10 +341,11 @@ void AliEveTRDTrackList::ApplyProcessMacros(TList* iterator)
   // The editor will access this file to display the data
 }
 
-
-//__________________________________________________________
+//______________________________________________________
 void AliEveTRDTrackList::ApplySelectionMacros(TList* iterator)
 {
+  if (iterator->GetEntries() <= 0)  return;
+
   Char_t name[100];
   Char_t path[300];
   Char_t pathname[400];
@@ -397,8 +399,7 @@ void AliEveTRDTrackList::ApplySelectionMacros(TList* iterator)
   gROOT->Reset();  
 }
 
-
-//__________________________________________________________
+//______________________________________________________
 Char_t* AliEveTRDTrackList::MakeMacroEntry(const Char_t* path, const Char_t* name)
 {
   Char_t* entry = new Char_t[400];
@@ -412,8 +413,7 @@ Char_t* AliEveTRDTrackList::MakeMacroEntry(const Char_t* path, const Char_t* nam
   return entry;
 }
 
-
-//__________________________________________________________
+//______________________________________________________
 void AliEveTRDTrackList::RemoveProcessMacros(TList* iterator) 
 {
   for (Int_t i = 0; i < iterator->GetEntries(); i++)
@@ -422,8 +422,7 @@ void AliEveTRDTrackList::RemoveProcessMacros(TList* iterator)
   }
 }
 
-
-//__________________________________________________________
+//______________________________________________________
 void AliEveTRDTrackList::RemoveSelectionMacros(TList* iterator) 
 {
   for (Int_t i = 0; i < iterator->GetEntries(); i++)
index 9490b18ba3f9b5c890069e5418916ced8b1d8802..87c4c8307ba1c37a7af0c788318ba981ac9ee677 100644 (file)
@@ -1,24 +1,27 @@
-#include "TTreeStream.h"
+#include <EveDet/AliEveTRDData.h>
 #include <EveDet/AliEveTRDTrackList.h>
 #include "AliEveTRDTrackListEditor.h"
 
-#include <TGFileDialog.h>
-#include <TFile.h>
+#include <AliTRDtrackV1.h>
 #include <TGButton.h>
-#include <TGedEditor.h>     ////// MAYBE THIS CAN BE REMOVED
-#include <TGTextEntry.h>
-#include <TGTextView.h>
-#include <TGListBox.h>
-#include <TGMsgBox.h>
-#include <TGLabel.h>
-#include <TG3DLine.h>
+#include <TCanvas.h>     
+#include <TEveGedEditor.h> 
 #include <TEveMacro.h>
 #include <TEveManager.h>
+#include <TFile.h>
+#include <TG3DLine.h>
+#include <TGFileDialog.h>
+#include <TGLabel.h>
+#include <TGListBox.h>
+#include <TGMsgBox.h>
+#include <TGTab.h>
 #include <TObjString.h>
-#include <TSystem.h>
 #include <TROOT.h>
-#include <AliTRDtrackV1.h>
-#include <EveDet/AliEveTRDData.h>
+#include <TSystem.h>
+#include <TGTextEntry.h>
+#include <TGTextView.h>
+#include <TTreeStream.h>
+
 
 ClassImp(AliEveTRDTrackListEditor)
 
@@ -29,6 +32,7 @@ AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t widt
                                                   UInt_t options, Pixel_t back) :
   TGedFrame(p, width, height, options, back),
   fM(0),
+  fInitState(0),
   fMainFrame(0),
   fHistoFrame(0),
   fHistoSubFrame(0),
@@ -123,10 +127,6 @@ AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t widt
   fFileInfo->fFileTypes = (const Char_t**)fFileTypes;
   fFileInfo->fFileTypeIdx = 2;
   fFileInfo->fMultipleSelection = kTRUE;
-
-  // Set focus on "Apply macros" tab
-  //fMainFrame->TGWindow::RequestFocus();
-  //Update();
 }
 
 //______________________________________________________
@@ -208,19 +208,34 @@ void AliEveTRDTrackListEditor::ApplyMacros()
     return;  
   }
     
+  Char_t macroName[100];
   TTree* t = 0;
-  for (Int_t i = 0; i < iterator->GetEntries(); i++) {
+  for (Int_t i = 0; i < iterator->GetEntries(); i++)
+  {
     t = (TTree*)file->Get(Form("TrackData%d", i));
-    if (t != 0) {
-      gEve->AddCanvasTab(Form("Macro%d", i));
+    if (t != 0)
+    {
+      memset(macroName, '\0', sizeof(Char_t) * 100);
+      sscanf(iterator->At(i)->GetTitle(), "%s (Path:%*s)", macroName);
+      
+      TCanvas* canvas = (TCanvas*)gROOT->GetListOfCanvases()->TCollection::FindObject(macroName);
+      if (!canvas)
+      {
+        canvas = gEve->AddCanvasTab(macroName);
+        canvas->SetName(macroName);
+      }
+      gPad = canvas;
       t->Draw(Form("Macro%d", i), "1");
+      canvas->Update();
  
       delete t;
       t = 0;
 
       // ONLY DISPLAY ONE MACRO (the first one possible) -> Remove the next line to display all
-      break;
-    } else {
+      //break;
+    }
+    else
+    {
       Error("Apply macros", Form("No data for macro%d found!", i));
       new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Apply macros", 
                    Form("No data for macro%d found!", i), kMBIconExclamation, kMBOk);  
@@ -234,12 +249,12 @@ void AliEveTRDTrackListEditor::ApplyMacros()
   iterator = 0;  
 
   // Update histogram tab (data has to be reloaded)
-  //fHistoFrame->TGWindow::RequestFocus();
-  //fGedEditor->TGCompositeFrame::ShowFrame(fHistoFrame);
   SetModel(fM);
   Update();
-}
 
+  // Set focus on "Histograms" tab
+  GetGedEditor()->GetTab()->SetTab("Histograms");
+}
 
 //______________________________________________________
 void AliEveTRDTrackListEditor::BrowseMacros()
@@ -325,8 +340,16 @@ void AliEveTRDTrackListEditor::DrawHistos()
         // 1d histogram   
         if (nHistograms == 1) 
         {
-          gEve->AddCanvasTab(Form("Macro%d", indexOfMacro1));
+          TCanvas* canvas = (TCanvas*)gROOT->GetListOfCanvases()->TCollection::FindObject(fM->fDataFromMacroList->At(indexOfMacro1)->GetName());
+          if (!canvas)
+          {
+            canvas = gEve->AddCanvasTab(fM->fDataFromMacroList->At(indexOfMacro1)->GetName());
+            canvas->SetName(fM->fDataFromMacroList->At(indexOfMacro1)->GetName());
+          }
+          gPad = canvas;
           t->Draw(Form("Macro%d", indexOfMacro1), "1");
+          gROOT->SetSelectedPad(canvas);
+          canvas->Update();
 
           break;     
         }
@@ -345,9 +368,22 @@ void AliEveTRDTrackListEditor::DrawHistos()
         // 2d histogram
         if (nHistograms == 2) 
         {
-          gEve->AddCanvasTab(Form("Macro%d - Macro%d", indexOfMacro1, indexOfMacro2));
+          TCanvas* canvas = (TCanvas*)gROOT->GetListOfCanvases()->TCollection::FindObject(Form("%s - %s",
+                              fM->fDataFromMacroList->At(indexOfMacro1)->GetName(), 
+                              fM->fDataFromMacroList->At(indexOfMacro2)->GetName()));
+          if (!canvas)
+          {
+            canvas = gEve->AddCanvasTab(Form("%s - %s",
+                                             fM->fDataFromMacroList->At(indexOfMacro1)->GetName(), 
+                                             fM->fDataFromMacroList->At(indexOfMacro2)->GetName()));
+            canvas->SetName(Form("%s - %s",
+                                 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(), 
+                                 fM->fDataFromMacroList->At(indexOfMacro2)->GetName()));
+          }
+          gPad = canvas;
           t->AddFriend(tFriend1);
           t->Draw(Form("Macro%d:Macro%d", indexOfMacro1, indexOfMacro2), "1");
+          canvas->Update();        
  
           break;     
         }
@@ -364,10 +400,26 @@ void AliEveTRDTrackListEditor::DrawHistos()
           break;   
         }
         
-        gEve->AddCanvasTab(Form("Macro%d - Macro%d - Macro%d", indexOfMacro1, indexOfMacro2, indexOfMacro3));
+        TCanvas* canvas = (TCanvas*)gROOT->GetListOfCanvases()->TCollection::FindObject(Form("%s - %s - %s",
+                            fM->fDataFromMacroList->At(indexOfMacro1)->GetName(), 
+                            fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
+                            fM->fDataFromMacroList->At(indexOfMacro3)->GetName()));
+        if (!canvas)
+        {
+          canvas = gEve->AddCanvasTab(Form("%s - %s - %s",
+                                           fM->fDataFromMacroList->At(indexOfMacro1)->GetName(), 
+                                           fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
+                                           fM->fDataFromMacroList->At(indexOfMacro3)->GetName()));
+          canvas->SetName(Form("%s - %s - %s",
+                               fM->fDataFromMacroList->At(indexOfMacro1)->GetName(), 
+                               fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
+                               fM->fDataFromMacroList->At(indexOfMacro3)->GetName()));
+        }
+        gPad = canvas;
         t->AddFriend(tFriend1);
         t->AddFriend(tFriend2);
         t->Draw(Form("Macro%d:Macro%d:Macro%d", indexOfMacro1, indexOfMacro2, indexOfMacro3), "1");
+        canvas->Update();      
  
         break;     
       }
@@ -475,15 +527,36 @@ void AliEveTRDTrackListEditor::RemoveMacros()
   iterator = 0;
 }
 
-
 //______________________________________________________
 void AliEveTRDTrackListEditor::SetModel(TObject* obj)
-{
+{  
   // Set model object
   fM = dynamic_cast<AliEveTRDTrackList*>(obj);
 
+  if (fM == 0) 
+  {
+    Error("SetModel", "Parameter is zero pointer");
+    return;
+  }
+
   UpdateMacroList();
-  UpdateHistoList();  
+  UpdateHistoList(); 
+
+  // Set focus on "Apply macros" tab, if the editor has just been initialized.
+  // To prevent refocusing on "Style" tab, disable "Style" and during the next call
+  // re-enable "Style"
+  if (fInitState == 0)
+  {
+    GetGedEditor()->GetTab()->SetEnabled(0, kFALSE);
+    GetGedEditor()->GetTab()->SetTab("Apply macros"); 
+    
+    fInitState = 1;
+  } 
+  else if (fInitState == 1)
+  {
+    GetGedEditor()->GetTab()->SetEnabled(0, kTRUE);
+    fInitState = 2; 
+  }
 }
 
 //______________________________________________________
@@ -508,7 +581,6 @@ void AliEveTRDTrackListEditor::UpdateHistoList()
   }  
 }
 
-
 //______________________________________________________
 void AliEveTRDTrackListEditor::UpdateMacroList()
 {
index 868a008b295271f3a2eedc7ae2dd8e98219f598f..093ef65add45ecec160a29ad7a04fbe03e64359e 100644 (file)
@@ -5,6 +5,9 @@
 
 class AliEveTRDTrack;
 class AliEveTRDTrackList;
+class TCanvas;                
+class TEveGedEditor;
+class TEveManager;
 class TFile;
 class TGCheckButton;
 class TGFileInfo;
@@ -12,6 +15,7 @@ class TGHorizontal3DLine;
 class TGHorizontalFrame;
 class TGLabel;
 class TGListBox;
+class TGTab;
 class TGTextButton;
 class TGTextEntry;
 class TGVerticalFrame;
@@ -44,7 +48,7 @@ private:
   void UpdateHistoList();                                 // Updates the histogram list
   void UpdateMacroList();                                 // Updates the macro list
 
-
+  Int_t             fInitState;              // Holds the initialization state
   TGVerticalFrame*  fMainFrame;              // Top frame for macro functionality.
   TGVerticalFrame*  fHistoFrame;             // Top frame for the histogram stuff
   TGVerticalFrame*  fHistoSubFrame;          // Frame for the histogram buttons themselves