]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
introduction of selection macros (Ben)
authorabercuci <abercuci@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 3 Sep 2008 13:58:13 +0000 (13:58 +0000)
committerabercuci <abercuci@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 3 Sep 2008 13:58:13 +0000 (13:58 +0000)
EVE/EveDet/AliEveTRDLoader.cxx
EVE/EveDet/AliEveTRDTrackList.cxx
EVE/EveDet/AliEveTRDTrackList.h
EVE/EveDet/AliEveTRDTrackListEditor.cxx
EVE/EveDet/AliEveTRDTrackListEditor.h

index a19cc783d2f32ee4dfe42fe5d9f4e067e5f00650..10acc0f7e11e54787797e59d940695ab1cae79ba 100644 (file)
@@ -220,7 +220,7 @@ Bool_t AliEveTRDLoader::LoadClusters(TTree *tC)
   // Load clusters.
 
   AliInfo("Loading ...");
-  if(!fChildren.size()) return kTRUE;
+  if(!fChildren.size()) return kFALSE;
 
   TObjArray *clusters = new TObjArray();
   tC->SetBranchAddress("TRDcluster", &clusters);
@@ -245,7 +245,7 @@ Bool_t AliEveTRDLoader::LoadDigits(TTree *tD)
 
   AliInfo("Loading ...");
 
-  if(!fChildren.size()) return kTRUE;
+  if(!fChildren.size()) return kFALSE;
 
   AliEveTRDChamber *chmb;
   AliTRDdigitsManager dm;
@@ -267,7 +267,7 @@ Bool_t AliEveTRDLoader::LoadTracklets(TTree *tT)
   // Load tracklets.
 
   AliInfo("Loading ...");
-  if(!fChildren.size()) return kTRUE;
+  if(!fChildren.size()) return kFALSE;
 
   TObjArray *tracks = new TObjArray();
   tT->SetBranchAddress("TRDmcmTracklet",&tracks);
index 1a661dbbf15bd9937235f097f3fe1edfa9488719..bfb9eb5c000d86ff1b827f0fe775290de92a8207 100644 (file)
@@ -7,9 +7,11 @@ ClassImp(AliEveTRDTrackList)
 ///////////////////////////////////////////////////////////
 AliEveTRDTrackList::AliEveTRDTrackList(const Text_t* n, const Text_t* t, Bool_t doColor):
   TEveElementList(n, t, doColor),
-  macroList(0)
+  macroList(0),
+  macroSelList(0)
 {
   SetChildClass(AliEveTRDTrack::Class());
 
   macroList = new TList();
+  macroSelList = new TList();
 }
index c5a1276077009153271fd264f71f8121ec76ac07..a8ad4c621b5b22452bad014f8d197802e66c7cee 100644 (file)
@@ -14,13 +14,14 @@ public:
   AliEveTRDTrackList(const Text_t* n = "AliEveTRDTrackList", const Text_t* t = "", Bool_t doColor = kFALSE);
  
 protected:
-  TList* macroList; // List of macros
+  TList* macroList;                 // List of (process) macros
+  TList* macroSelList;              // List of (selection) macros
 
 private:
   AliEveTRDTrackList(const AliEveTRDTrackList&);            // Not implemented
   AliEveTRDTrackList& operator=(const AliEveTRDTrackList&); // Not implemented
 
-  ClassDef(AliEveTRDTrackList, 0); // Class containing a list of tracks
+  ClassDef(AliEveTRDTrackList, 0);  // Class containing a list of tracks
 };
 
 #endif
index d63464aa63e22de452b84cc997ad32fcda11f87a..f6a2016a43caa428b8852f17b3949ec686d4aab3 100644 (file)
@@ -18,13 +18,18 @@ AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t widt
   teField(0),
   tvMemberList(0),
   tlMacroList(0),
+  tlMacroSelList(0),
   fileInfo(0),
-  fileTypes(0)
+  fileTypes(0),
+  fLabel1(0), fLabel2(0), fLabel3(0),
+  fLine1(0), fLine2(0), fLine3(0)
 {
   // Constructor.
   fMainFrame = CreateEditorTabSubFrame("Apply macros");
-  
   // Functionality for adding macros 
+  fLabel1 = new TGLabel(fMainFrame,"Add macro(s):");
+  fMainFrame->AddFrame(fLabel1);
   fBrowseFrame = new TGHorizontalFrame(fMainFrame);
 
   teField = new TGTextEntry(fBrowseFrame);
@@ -36,11 +41,29 @@ AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t widt
   fBrowseFrame->AddFrame(bBrowse);
   fMainFrame->AddFrame(fBrowseFrame);
 
+  fLine1 = new TGHorizontal3DLine(fMainFrame, 194, 8);
+  fMainFrame->AddFrame(fLine1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
+  fLabel2 = new TGLabel(fMainFrame,"Selection macros:");
+  fMainFrame->AddFrame(fLabel2);
+
+  tlMacroSelList = new TGListBox(fMainFrame);
+  tlMacroSelList->Resize(194, 94);
+  tlMacroSelList->SetMultipleSelections(kTRUE);
+  fMainFrame->AddFrame(tlMacroSelList);
+
+  fLine2 = new TGHorizontal3DLine(fMainFrame, 194, 8);
+  fMainFrame->AddFrame(fLine2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
+  fLabel3 = new TGLabel(fMainFrame,"Process macros:");
+  fMainFrame->AddFrame(fLabel3);
+
   tlMacroList = new TGListBox(fMainFrame);
-  tlMacroList->Resize(194, 120);
+  tlMacroList->Resize(194, 94);
   tlMacroList->SetMultipleSelections(kTRUE);
   fMainFrame->AddFrame(tlMacroList);
 
+  fLine3 = new TGHorizontal3DLine(fMainFrame, 194, 8);
+  fMainFrame->AddFrame(fLine3, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));  
+
   bApplyMacros = new TGTextButton(fMainFrame, "Apply selected macro(s)");
   bApplyMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "ApplyMacros()");
   bApplyMacros->SetRightMargin(12);
@@ -69,90 +92,150 @@ AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t widt
   fileInfo->fMultipleSelection = kTRUE;
 }
 
-void AliEveTRDTrackListEditor::AddMacro(const Char_t* pathname)
-{
-  // Only add macro, if it is not already in the list
-  if (fM->macroList->FindObject(pathname) == 0)
-  {
-      fM->macroList->Add(new TObjString(pathname));
-      fM->macroList->Sort();
 
-      UpdateMacroList();
+//________________________________________________________
+void AliEveTRDTrackListEditor::AddMacro(const Char_t* entryName, const Char_t* nameC, const Char_t* pathname)
+{
+  // First check the type of the macro:
+  // If it has the signature of a selection macro:
+  // Bool_t MacroName(AliEveTRDTrack
+  // it is assumed to be a selection macro. In all other cases: Process macro
+  TEveMacro* macro = NULL;
+  Bool_t isSelectionMacro = kFALSE;
+  Char_t signature[120];
+  memset(signature, '\0', sizeof(Char_t) * 120);
+
+  // Delete ".C" from filename
+  Char_t* name = new Char_t[strlen(nameC)];
+  memset(name, '\0', sizeof(Char_t) * strlen(nameC));
+  strncpy(name, nameC, strlen(nameC) - 2);
+  
+  // Create signature
+  sprintf(signature, "Bool_t %s(AliEveTRDTrack", name);
+  
+  macro = new TEveMacro(pathname);
+  if (!macro) {
+    new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
+                 "Cannot access file!", kMBIconExclamation, kMBOk);
+    return;
   }
-  else
-  {
-      new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Warning", "Macro is already in list (won't be added again)!",
-                   kMBIconExclamation, kMBOk);
+  if (macro->TMacro::GetLineWith(signature) != 0)   isSelectionMacro = kTRUE;
+  else                                              isSelectionMacro = kFALSE; 
+  delete macro;
+  macro = 0;
+  
+  // Only add macro, if it is not already in the list
+  if (!isSelectionMacro && fM->macroList->FindObject(entryName) == 0){
+    fM->macroList->Add(new TObjString(entryName));
+    fM->macroList->Sort();
+
+    UpdateMacroList();
+  } else if (isSelectionMacro && fM->macroSelList->FindObject(entryName) == 0) {
+    fM->macroSelList->Add(new TObjString(entryName));
+    fM->macroSelList->Sort();
+
+    UpdateMacroList();
+  } else {
+    new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Warning", "Macro is already in list (won't be added again)!", kMBIconExclamation, kMBOk);
   }
 }
 
+//________________________________________________________
 void AliEveTRDTrackListEditor::ApplyMacros()
 {
   TList* iterator = new TList();
-  //TEveMacro* macro = NULL;
+  TEveMacro* macro = NULL;
   Char_t name[100];
   Char_t path[300];
   Char_t pathname[400];
-  Char_t cmd[430];
+  //Char_t cmd[430];
+
+  // First apply the selection macros
+  tlMacroSelList->GetSelectedEntries(iterator);
+  AliEveTRDTrack* track = 0;
+  //AliTRDtrackV1 *trackv1 = 0;
+  Bool_t selectedByMacro = kFALSE;
+
+  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);
+    
+    // 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) - 1] = '\0';
+    sprintf(pathname, "%s/%s", path, name);
+    
+    TString sPathname(pathname);
+    gSystem->ExpandPathName(sPathname);
+
+    // Load and execute macro
+    macro = new TEveMacro(sPathname);
+
+    // Walk through the list of tracks
+    for (TEveElement::List_i iter = fM->BeginChildren(); iter != fM->EndChildren(); ++iter){
+      track = dynamic_cast<AliEveTRDTrack*>(*iter);
+
+      if (!track) continue;
+  
+      //trackv1 = (AliTRDtrackV1*)track->GetUserData();
+      
+      // Make this track available
+      track->ExportToCINT("automaticTrack");
+      selectedByMacro = (Bool_t)macro->Exec("automaticTrack");
+      track->SetRnrState(selectedByMacro);         
+
+      if (macro != NULL)    delete macro;
+      return;
+    }
+  }  
 
-  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);
+  if (iterator != NULL) delete iterator;  
 
+  // Now apply the process macros
+  iterator = new TList();
   tlMacroList->GetSelectedEntries(iterator);
 
   // Make tracklist availabe
   fM->ExportToCINT("trackList");
-  for (Int_t i = 0; i < iterator->GetEntries(); i++)
-  {
-      // 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) - 1] = '\0';
-      sprintf(pathname, "%s/%s", path, name);
-
-      TString sPathname(pathname);
-      gSystem->ExpandPathName(sPathname);
-      sprintf(cmd, ".x %s(trackList)", pathname);
-      gROOT->ProcessLine(cmd);
-      // Load and execute macro
-      //macro = new TEveMacro(sPathname);
-
-      //macro->Exec("trackList");
-      //if (macro != NULL)    delete 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);
+
+    // 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) - 1] = '\0';
+    sprintf(pathname, "%s/%s", path, name);
+
+    TString sPathname(pathname);
+    gSystem->ExpandPathName(sPathname);
+
+    //sprintf(cmd, ".x %s(trackList)", pathname);
+    //gROOT->ProcessLine(cmd);
+    // Load and execute macro
+    macro = new TEveMacro(sPathname);
+
+    macro->Exec("trackList");
+    if (macro != NULL)    delete macro;
   }
 
   if (iterator != NULL) delete iterator;    
 }
-/*
-void AliEveTRDTrackListEditor::BrowseMacros()
-{
-  new TGFileDialog(gClient->GetRoot(), new TGWindow(), kFDOpen, fileInfo);
-  
-  if (fileInfo->fFilename != 0 && fileInfo->fIniDir != 0)
-  {                            
-    Char_t pathname[300];
-    
-    // Extract filename
-    Char_t* name = strrchr(fileInfo->fFilename, '/');
-    // Delete '"' at the end
-    name[strlen(name)] = '\0';
-    sprintf(pathname, "%s (Path: %s)", name + 1, fileInfo->fIniDir);
-  
-    AddMacro(pathname); 
-  }
-}
-*/
 
+
+//________________________________________________________
 void AliEveTRDTrackListEditor::BrowseMacros()
 {
   new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fileInfo);
   
-  if (fileInfo->fIniDir != 0)
-  {                            
-    Char_t pathname[300];
+  if (fileInfo->fIniDir != 0 && fileInfo->fFileNamesList != 0)
+  {       
+    Char_t entryName[300];
+    memset(entryName, '\0', sizeof(Char_t) * 300);
     
     // Extract filenames
     TObject* iter = fileInfo->fFileNamesList->First();
@@ -164,66 +247,82 @@ void AliEveTRDTrackListEditor::BrowseMacros()
       name = strrchr(iter->GetName(), '/');
       // Delete '"' at the end
       name[strlen(name)] = '\0';
-      sprintf(pathname, "%s (Path: %s)", name + 1, fileInfo->fIniDir);
-  
-      AddMacro(pathname); 
+      sprintf(entryName, "%s (Path: %s)", name + 1, fileInfo->fIniDir);
+        
+      AddMacro(entryName, name + 1, iter->GetName()); 
       iter = (TObjString*)fileInfo->fFileNamesList->After(iter);
     }
   }
+
+  // Some error occurs, when one ends the filedialog with "cancel": fileInfo->fFileNamesList is set to 0x0, but
+  // in the next launch no new memory is allocated. So do this manually.
+  if (fileInfo->fFileNamesList == 0)  fileInfo->fFileNamesList = new TList();
 }
 
+
+//________________________________________________________
 void AliEveTRDTrackListEditor::HandleMacroPathSet()
 {
-  if (strlen(teField->GetText()) != 0)
-  {                            
+  if (strlen(teField->GetText()) != 0){                                
     // Check if file exists
     FILE* fp = NULL;
 
     fp = fopen(teField->GetText(), "rb");
-    if (fp != NULL)
-    {
-        fclose(fp);
-        Char_t pathname[300];
-    
-        // Extract filename
-        Char_t* name = strrchr(teField->GetText(), '/');
-
-        // Current path
-        if (name == NULL)
-        {
-            sprintf(pathname, "%s (Path: .)", teField->GetText());
-        }
-        // Different path
-        else
-        {
-            // Extract path
-            Char_t* path = new Char_t[240];
-            memset(path, '\0', sizeof(Char_t) * 240);
-            strncpy(path, teField->GetText(), strlen(teField->GetText()) - strlen(name));
-            sprintf(pathname, "%s (Path: %s)", name + 1, path);
-
-            if (path != NULL)  delete path;
-        }
-
-        AddMacro(pathname);   
-    }
-    else
-    {
-        new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
-                     "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
+    if (fp != NULL){
+      fclose(fp);
+      Char_t entryName[300];
+      memset(entryName, '\0', sizeof(Char_t) * 300);
+  
+      // Extract filename
+      Char_t* name = strrchr(teField->GetText(), '/');
+
+      // Current path
+      if (name == NULL){
+        sprintf(entryName, "%s (Path: .)", teField->GetText());
+        sprintf(name, "%s", teField->GetText());
+
+        // Add path to textfield
+        Char_t pathname[100];
+        memset(pathname, '\0', sizeof(Char_t) * 100);
+        sprintf(pathname, "./%s", teField->GetText());
+        teField->SetText(pathname);
+      } else {// Different path
+        // Extract path
+        Char_t* path = new Char_t[240];
+        memset(path, '\0', sizeof(Char_t) * 240);
+        strncpy(path, teField->GetText(), strlen(teField->GetText()) - strlen(name));
+        sprintf(entryName, "%s (Path: %s)", name + 1, path);
+
+        if (path != NULL)  delete path;
+
+        // Ignore the slash "/" in the following
+        name++;
+      }
+      AddMacro(entryName, name, teField->GetText());   
+    } else {
+      new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
+      "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
     }
   }
 }
 
+
+//________________________________________________________
 void AliEveTRDTrackListEditor::RemoveMacros()
 {
   TList* iterator = new TList();
   
   tlMacroList->GetSelectedEntries(iterator);
 
+  for (Int_t i = 0; i < iterator->GetEntries(); i++){
+      fM->macroList->Remove(fM->macroList->FindObject(iterator->At(i)->GetTitle()));
+  }
+
+  tlMacroSelList->GetSelectedEntries(iterator);
+
   for (Int_t i = 0; i < iterator->GetEntries(); i++)
   {
-      fM->macroList->Remove(fM->macroList->FindObject(iterator->At(i)->GetTitle()));
+      fM->macroSelList->Remove(fM->macroSelList->FindObject(iterator->At(i)->GetTitle()));
   }
 
   UpdateMacroList();
@@ -236,10 +335,16 @@ void AliEveTRDTrackListEditor::SetModel(TObject* obj)
 
   // Add members to a list
   tvMemberList->Clear();
-  for (TEveElement::List_i iterator = fM->BeginChildren(); iterator != fM->EndChildren(); ++iterator)
+  // In order to prevent the first line from being empty, do the following:
+  TEveElement::List_i iterator = fM->BeginChildren();
+  if (iterator != fM->EndChildren())
   {
-    tvMemberList->AddLineFast(((AliEveTRDTrack*)(*iterator))->GetName());
-  }  
+    tvMemberList->SetText(new TGText(((AliEveTRDTrack*)(*iterator))->GetName()));
+    iterator++;
+    for ( ; iterator != fM->EndChildren(); ++iterator)
+            tvMemberList->AddLineFast(((AliEveTRDTrack*)(*iterator))->GetName());
+  }
+  
   tvMemberList->ShowTop();
   tvMemberList->Update();
 
@@ -259,4 +364,17 @@ void AliEveTRDTrackListEditor::UpdateMacroList()
   }
 
   tlMacroList->SortByName();
+
+
+  tlMacroSelList->RemoveAll();
+  iter = (TObjString*)fM->macroSelList->First();
+
+  while (iter != 0)
+  {
+    tlMacroSelList->AddEntry(iter->GetName(), -1);
+    iter = (TObjString*)fM->macroSelList->After(iter);
+  }
+
+  tlMacroSelList->SortByName();  
 }
index c3ba05593d561428300aff1c5b48bf46881fdfe9..53f7f938e39f27447192042733b41cdb409db0ce 100644 (file)
@@ -8,10 +8,13 @@
 #include <TGTextView.h>
 #include <TGListBox.h>
 #include <TGMsgBox.h>
-//#include <TEveMacro.h>
+#include <TGLabel.h>
+#include <TG3DLine.h>
+#include <TEveMacro.h>
 #include <TObjString.h>
 #include <TSystem.h>
 #include <TROOT.h>
+#include <AliTRDtrackV1.h>
 #include <EveDet/AliEveTRDTrackList.h>
 
 class AliEveTRDTrackListEditor: public TGedFrame
@@ -23,37 +26,45 @@ public:
 
   virtual void SetModel(TObject* obj);
 
-  void ApplyMacros();         // Apply macros
-  void BrowseMacros();        // Browse macros
-  void HandleMacroPathSet();  // Handle "macro path set"-event 
-  void RemoveMacros();        // Remove macros
+  void ApplyMacros();               // Apply macros
+  void BrowseMacros();              // Browse macros
+  void HandleMacroPathSet();        // Handle "macro path set"-event 
+  void RemoveMacros();              // Remove macros
 
 protected:
-  AliEveTRDTrackList* fM;     // Model object.
+  AliEveTRDTrackList* fM;           // Model object.
 
 private:
   AliEveTRDTrackListEditor(const AliEveTRDTrackListEditor&);            // Not implemented
   AliEveTRDTrackListEditor& operator=(const AliEveTRDTrackListEditor&); // Not implemented 
 
-  void AddMacro(const Char_t* pathname);   // Add macro to the macro list
-  void UpdateMacroList();                  // Updates the macro list
+  void AddMacro(const Char_t* Entryame, const Char_t* name,     // Add macro to the macro list
+                const Char_t* pathname);
+  void UpdateMacroList();                                       // Updates the macro list
 
 
-  TGVerticalFrame*  fMainFrame; // Top frame for macro functionality.
-  TGVerticalFrame*  fMemberFrame; // Top frame for member list
-  TGHorizontalFrame* fBrowseFrame; // For searching macros
+  TGVerticalFrame*  fMainFrame;             // Top frame for macro functionality.
+  TGVerticalFrame*  fMemberFrame;           // Top frame for member list
+  TGHorizontalFrame* fBrowseFrame;          // For searching macros
 
-  TGTextButton*   bBrowse; // Browse button
-  TGTextButton*   bApplyMacros; // Apply macros button
-  TGTextButton*   bRemoveMacros; // Remove macros button
-  TGTextEntry*    teField; // Text field to insert macro path manually
-  TGTextView*     tvMemberList; // To display the list of members
-  TGListBox*      tlMacroList; // To display the list of macros
+  TGTextButton*   bBrowse;                  // Browse button
+  TGTextButton*   bApplyMacros;             // Apply macros button
+  TGTextButton*   bRemoveMacros;            // Remove macros button
+  TGTextEntry*    teField;                  // Text field to insert macro path manually
+  TGTextView*     tvMemberList;             // To display the list of members
+  TGListBox*      tlMacroList;              // To display the list of (process) macros
+  TGListBox*      tlMacroSelList;           // To display the list of (selection) macros
 
-  TGFileInfo*     fileInfo; // Holds data about opening macros
-  Char_t**    fileTypes; // File types (for macros)
+  TGFileInfo*     fileInfo;                 // Holds data about opening macros
+  Char_t**    fileTypes;                    // File types (for macros)
 
-  ClassDef(AliEveTRDTrackListEditor, 0); // Editor for AliEveTRDTrackList.
+  // Some labels
+  TGLabel *fLabel1, *fLabel2, *fLabel3;
+  
+  // Some lines
+  TGHorizontal3DLine *fLine1, *fLine2, *fLine3;
+
+  ClassDef(AliEveTRDTrackListEditor, 0)    // Editor for AliEveTRDTrackList.
 };
 
 #endif