]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Adding AliSelector, AliSelectorRL to ESD, STEER that can be used as base classes
authorjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 2 Oct 2006 12:01:18 +0000 (12:01 +0000)
committerjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 2 Oct 2006 12:01:18 +0000 (12:01 +0000)
for selector based distributed analysis

STEER/AliSelector.cxx [new file with mode: 0644]
STEER/AliSelector.h [new file with mode: 0644]
STEER/AliSelectorRL.cxx [new file with mode: 0644]
STEER/AliSelectorRL.h [new file with mode: 0644]
STEER/ESDLinkDef.h
STEER/STEERLinkDef.h
STEER/libESD.pkg
STEER/libSTEER.pkg

diff --git a/STEER/AliSelector.cxx b/STEER/AliSelector.cxx
new file mode 100644 (file)
index 0000000..621c92e
--- /dev/null
@@ -0,0 +1,237 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+
+// Selector base class for analysis based on ESD
+// Please derive your selector-based analysis from this class, if you just want to use
+// information from the ESD.
+//
+// The ESD is available as member fESD
+//
+// The following methods can be overrriden. Please do not forgot to call the base class function.
+//
+//    Begin():        called everytime a loop on the tree starts,
+//                    a convenient place to create your histograms.
+//    SlaveBegin():   called after Begin(), when on PROOF called only on the
+//                    slave servers.
+//    Init():         called for each new tree. Enable/Disable branches here.
+//    Process():      called for each event, in this function you decide what
+//                    to read and fill your histograms.
+//    SlaveTerminate: called at the end of the loop on the tree, when on PROOF
+//                    called only on the slave servers.
+//    Terminate():    called at the end of the loop on the tree,
+//                    a convenient place to draw/fit your histograms.
+//
+//  Author: Jan.Fiete.Grosse-Oetringhaus@cern.ch
+
+#include "AliSelector.h"
+
+#include <TStyle.h>
+#include <TSystem.h>
+#include <TCanvas.h>
+#include <TRegexp.h>
+#include <TTime.h>
+#include <TFriendElement.h>
+#include <TTree.h>
+#include <TChain.h>
+#include <TFile.h>
+#include <TTimeStamp.h>
+
+#include <AliLog.h>
+#include <AliESD.h>
+
+ClassImp(AliSelector)
+
+AliSelector::AliSelector() :
+  TSelector(),
+  fTree(0),
+  fESD(0),
+  fCountFiles(0)
+{
+  //
+  // Constructor. Initialization of pointers
+  //
+}
+
+AliSelector::~AliSelector()
+{
+  //
+  // Destructor
+  //
+
+ if (fTree)
+   fTree->ResetBranchAddresses();
+
+ if (fESD)
+ {
+   delete fESD;
+   fESD = 0;
+ }
+}
+
+void AliSelector::CheckOptions()
+{
+  // checks the option string for the debug flag
+
+  AliLog::SetClassDebugLevel(ClassName(), AliLog::kInfo);
+
+  TString option = GetOption();
+
+  if (option.Contains("moredebug"))
+  {
+    printf("Enabling verbose debug mode for %s\n", ClassName());
+    AliLog::SetClassDebugLevel(ClassName(), AliLog::kDebug+1);
+    AliInfo(Form("Called with option %s.", option.Data()));
+  }
+  else if (option.Contains("debug"))
+  {
+    printf("Enabling debug mode for %s\n", ClassName());
+    AliLog::SetClassDebugLevel(ClassName(), AliLog::kDebug);
+    AliInfo(Form("Called with option %s.", option.Data()));
+  }
+}
+
+void AliSelector::Begin(TTree*)
+{
+  // The Begin() function is called at the start of the query.
+  // When running with PROOF Begin() is only called on the client.
+  // The tree argument is deprecated (on PROOF 0 is passed).
+
+  CheckOptions();
+
+  AliDebug(AliLog::kDebug, "============BEGIN===========");
+}
+
+void AliSelector::SlaveBegin(TTree* tree)
+{
+  // The SlaveBegin() function is called after the Begin() function.
+  // When running with PROOF SlaveBegin() is called on each slave server.
+  // The tree argument is deprecated (on PROOF 0 is passed).
+
+  CheckOptions();
+
+  AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
+  AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
+  AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
+
+  if (tree != 0)
+    Init(tree);
+}
+
+void AliSelector::Init(TTree *tree)
+{
+  // The Init() function is called when the selector needs to initialize
+  // a new tree or chain. Typically here the branch addresses of the tree
+  // will be set. It is normaly not necessary to make changes to the
+  // generated code, but the routine can be extended by the user if needed.
+  // Init() will be called many times when running with PROOF.
+
+  AliDebug(AliLog::kDebug, "=========Init==========");
+
+  fTree = tree;
+
+  if (fTree == 0)
+  {
+    AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
+    return;
+  }
+
+  // Set branch address
+  fTree->SetBranchAddress("ESD", &fESD);
+  if (fESD != 0)
+    AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
+}
+
+Bool_t AliSelector::Notify()
+{
+  // The Notify() function is called when a new file is opened. This
+  // can be either for a new TTree in a TChain or when when a new TTree
+  // is started when using PROOF. Typically here the branch pointers
+  // will be retrieved. It is normaly not necessary to make changes
+  // to the generated code, but the routine can be extended by the
+  // user if needed.
+
+  AliDebug(AliLog::kDebug, "=========NOTIFY==========");
+  AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
+  AliDebug(AliLog::kDebug, Form("Time: %s", TTimeStamp(time(0)).AsString()));
+
+  ++fCountFiles;
+  if (fTree)
+  {
+    TFile *f = fTree->GetCurrentFile();
+    AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
+  }
+  else
+  {
+    AliDebug(AliLog::kError, "fTree not available");
+  }
+
+  return kTRUE;
+}
+
+Bool_t AliSelector::Process(Long64_t entry)
+{
+  // The Process() function is called for each entry in the tree (or possibly
+  // keyed object in the case of PROOF) to be processed. The entry argument
+  // specifies which entry in the currently loaded tree is to be processed.
+  // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
+  // to read either all or the required parts of the data. When processing
+  // keyed objects with PROOF, the object is already loaded and is available
+  // via the fObject pointer.
+  //
+  // This function should contain the "body" of the analysis. It can contain
+  // simple or elaborate selection criteria, run algorithms on the data
+  // of the event and typically fill histograms.
+
+  // WARNING when a selector is used with a TChain, you must use
+  //  the pointer to the current TTree to call GetEntry(entry).
+  //  The entry is always the local entry number in the current tree.
+  //  Assuming that fTree is the pointer to the TChain being processed,
+  //  use fTree->GetTree()->GetEntry(entry).
+
+  AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
+
+  if (!fTree)
+  {
+    AliDebug(AliLog::kError, "ERROR: fTree is 0.");
+    return kFALSE;
+  }
+
+  fTree->GetTree()->GetEntry(entry);
+
+  if (fESD)
+    AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
+
+  return kTRUE;
+}
+
+void AliSelector::SlaveTerminate()
+{
+  // The SlaveTerminate() function is called after all entries or objects
+  // have been processed. When running with PROOF SlaveTerminate() is called
+  // on each slave server.
+
+  AliDebug(AliLog::kDebug, "=======SLAVETERMINATE=======");
+}
+
+void AliSelector::Terminate()
+{
+  // The Terminate() function is the last function to be called during
+  // a query. It always runs on the client, it can be used to present
+  // the results graphically or save the results to file.
+
+  AliDebug(AliLog::kDebug, "=========TERMINATE==========");
+}
diff --git a/STEER/AliSelector.h b/STEER/AliSelector.h
new file mode 100644 (file)
index 0000000..720a2ed
--- /dev/null
@@ -0,0 +1,44 @@
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+#ifndef ALISELECTOR_H
+#define ALISELECTOR_H
+
+// This selector is only dependent on the ESD library, if you need the whole of AliROOT use AliSelectorRL
+
+#include <TSelector.h>
+
+class TTree;
+class AliESD;
+
+class AliSelector : public TSelector {
+  public:
+    AliSelector();
+    virtual ~AliSelector();
+
+    virtual Int_t   Version() const {return 1;}
+    virtual void    Begin(TTree*);
+    virtual void    SlaveBegin(TTree* tree);
+    virtual void    Init(TTree *tree);
+    virtual Bool_t  Notify();
+    virtual Bool_t  Process(Long64_t entry);
+    virtual void    SlaveTerminate();
+    virtual void    Terminate();
+
+ protected:
+    void CheckOptions();
+
+    TTree          *fTree;     //! pointer to the TTree containing the events
+    AliESD*          fESD;     //! "ESD" branch in fChain
+    Int_t fCountFiles;         // number of processed file
+
+ private:
+    AliSelector(const AliSelector&);
+    AliSelector& operator=(const AliSelector&);
+
+  ClassDef(AliSelector,0);
+};
+
+#endif
diff --git a/STEER/AliSelectorRL.cxx b/STEER/AliSelectorRL.cxx
new file mode 100644 (file)
index 0000000..ac867b0
--- /dev/null
@@ -0,0 +1,153 @@
+/* $Id$ */
+
+#include "AliSelectorRL.h"
+
+#include <AliLog.h>
+#include <AliRunLoader.h>
+
+#include <TTree.h>
+#include <TFile.h>
+
+//
+// This selector depends on the RunLoader, therefore to use it you have to have the whole AliRoot available
+// The benefit is that you can use the RunLoader to access everything in the data structure
+// If you only have the ESD library use AliSelector instead
+//
+
+ClassImp(AliSelectorRL)
+
+AliSelectorRL::AliSelectorRL() :
+  AliSelector(),
+  fRunLoader(0),
+  fKinematicsLoaded(kFALSE),
+  fHeaderLoaded(kFALSE)
+{
+  //
+  // Constructor. Initialization of pointers
+  //
+}
+
+AliSelectorRL::~AliSelectorRL()
+{
+  //
+  // Destructor
+  //
+
+  // histograms are in the output list and deleted when the output
+  // list is deleted by the TSelector dtor
+}
+
+Bool_t AliSelectorRL::Notify()
+{
+  // Calls base class Notify
+  // On top of that run loader is closed, because we change the input file
+
+  if (AliSelector::Notify() == kFALSE)
+    return kFALSE;
+
+  DeleteRunLoader();
+
+  return kTRUE;
+}
+
+Bool_t AliSelectorRL::Process(Long64_t entry)
+{
+  // Call the baseclass Process and set event number in runLoader (if loaded)
+
+  if (AliSelector::Process(entry) == kFALSE)
+    return kFALSE;
+
+  if (fRunLoader)
+  {
+    if (fRunLoader->GetEvent(entry) != 0)
+      return kFALSE;
+  }
+
+  return kTRUE;
+}
+
+void AliSelectorRL::SlaveTerminate()
+{
+  // removes runloader
+
+  AliSelector::SlaveTerminate();
+
+  DeleteRunLoader();
+}
+
+AliRunLoader* AliSelectorRL::GetRunLoader()
+{
+  // Returns AliRun instance corresponding to current ESD active in fTree
+  // Loads galice.root, the file is identified by replacing "AliESDs" to
+  // "galice" in the file path of the ESD file. 
+
+  if (!fRunLoader)
+  {
+    if (!fTree->GetCurrentFile())
+      return 0;
+
+    TString fileName(fTree->GetCurrentFile()->GetName());
+    fileName.ReplaceAll("AliESDs", "galice");
+
+    // temporary workaround for PROOF bug #18505
+    fileName.ReplaceAll("#galice.root#galice.root", "#galice.root");
+
+    fRunLoader = AliRunLoader::Open(fileName);
+    if (!fRunLoader)
+      return 0;
+
+    fRunLoader->GetEvent(fTree->GetTree()->GetReadEntry());
+  }
+
+  return fRunLoader;
+}
+
+void AliSelectorRL::DeleteRunLoader()
+{
+  //
+  // deletes the runloader
+  //
+
+  if (fRunLoader)
+  {
+    fRunLoader->Delete();
+    fRunLoader = 0;
+  }
+
+  fKinematicsLoaded = kFALSE;
+  fHeaderLoaded = kFALSE;
+}
+
+AliHeader* AliSelectorRL::GetHeader()
+{
+  // Returns header retrieved from RunLoader
+
+  AliRunLoader* runLoader = GetRunLoader();
+  if (!runLoader)
+    return 0;
+
+  if (fHeaderLoaded == kFALSE)
+    if (runLoader->LoadHeader() != 0)
+      return 0;
+
+  fHeaderLoaded = kTRUE;
+
+  return runLoader->GetHeader();
+}
+
+AliStack* AliSelectorRL::GetStack()
+{
+  // Returns stack retrieved from RunLoader
+
+  AliRunLoader* runLoader = GetRunLoader();
+  if (!runLoader)
+    return 0;
+
+  if (fKinematicsLoaded == kFALSE)
+    if (runLoader->LoadKinematics() != 0)
+      return 0;
+
+  fKinematicsLoaded = kTRUE;
+
+  return runLoader->Stack();
+}
diff --git a/STEER/AliSelectorRL.h b/STEER/AliSelectorRL.h
new file mode 100644 (file)
index 0000000..43de4dd
--- /dev/null
@@ -0,0 +1,44 @@
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+#ifndef ALISELECTORRL_H
+#define ALISELECTORRL_H
+
+// Use this selector, if you have AliROOT installed (at the moment only ESD, STEER + deps)
+
+#include "AliSelector.h"
+
+class AliRunLoader;
+class AliHeader;
+class AliStack;
+
+class AliSelectorRL : public AliSelector {
+  public:
+    AliSelectorRL();
+    virtual ~AliSelectorRL();
+
+    virtual Bool_t  Notify();
+    virtual Bool_t  Process(Long64_t entry);
+    virtual void    SlaveTerminate();
+
+ protected:
+    AliRunLoader* GetRunLoader();
+    AliHeader* GetHeader();
+    AliStack* GetStack();
+
+ private:
+    void DeleteRunLoader();
+
+    AliRunLoader* fRunLoader;    //! pointer to the RunLoader if galice.root was opened
+    Bool_t fKinematicsLoaded;    // determines if the stack is properly loaded (AliRunLoader::LoadKinematics() succeeded), this is needed because the GetStack returnes a invalid stack object when the function failed
+    Bool_t fHeaderLoaded;        // determines if the header is properly loaded
+
+    AliSelectorRL(const AliSelectorRL&);
+    AliSelectorRL& operator=(const AliSelectorRL&);
+
+    ClassDef(AliSelectorRL,0);
+};
+
+#endif
index 4d20002dd7a8aa12404837503939ba784d8b4d21..b8088ef102a58b62b575b41cede1557fddf4bcd7 100644 (file)
@@ -54,6 +54,9 @@
 
 #pragma link C++ class  AliESDMultITS+;
 #pragma link C++ class  AliMultiplicity+;
+
+#pragma link C++ class  AliSelector+;
+
 #endif
 
 
index a2dc81afe198f1a99d777037dd4519c578722497..d6bcf3fdde56cb1c5a5b3b42bd68eafa385c985c 100644 (file)
 #pragma link C++ class  AliV0+;
 #pragma link C++ class  AliKink+;
 
+#pragma link C++ class  AliSelectorRL+;
+
 #endif
index 4aa615997839cb8697edd8b482c92f8874379a19..7e34ff6cb67fc7168e092783d4f4bc8b03df4644 100644 (file)
@@ -11,7 +11,8 @@ SRCS = AliESD.cxx AliESDfriend.cxx\
        AliTrackPointArray.cxx \
        AliESDFMD.cxx AliFMDMap.cxx AliFMDFloatMap.cxx \
        AliESDMultITS.cxx \
-       AliMultiplicity.cxx AliXMLCollection.cxx
+       AliMultiplicity.cxx AliXMLCollection.cxx \
+       AliSelector.cxx
 
 
 HDRS:= $(SRCS:.cxx=.h) 
index 5be9f56e7a3df850b8a77d2e8c078628216142c9..5efa0b8ce10382c9c531c82c260362b15cec2330 100644 (file)
@@ -32,7 +32,8 @@ AliAlignmentTracks.cxx \
 AliExpression.cxx \
 AliCTPRawData.cxx AliCTPRawStream.cxx \
 AliMathBase.cxx AliSignalProcesor.cxx \
-AliTracker.cxx AliCluster.cxx AliHelix.cxx AliV0.cxx AliKink.cxx
+AliTracker.cxx AliCluster.cxx AliHelix.cxx AliV0.cxx AliKink.cxx \
+AliSelectorRL.cxx
 
 HDRS:= $(SRCS:.cxx=.h)