]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliReader.cxx
Bugfix (thanks to Matevz for finding it)
[u/mrichter/AliRoot.git] / ANALYSIS / AliReader.cxx
index d4ef9488f7595d9288ce915338aec875998ff8c1..df65af7eae1c761ce83bba04a0d4392edd2f22b6 100644 (file)
@@ -1,4 +1,20 @@
-#include "AliReader.h"
+/**************************************************************************
+ * 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$ */
+
 //_________________________________________________________________________
 ///////////////////////////////////////////////////////////////////////////
 //
 //
 ///////////////////////////////////////////////////////////////////////////
 
-#include <TString.h>
-#include <TObjString.h>
-#include <TObjArray.h>
 #include <TClass.h>
-#include <TRandom.h>
+#include <TGliteXmlEventlist.h>
 #include <TH1.h>
+#include <TObjArray.h>
+#include <TObjString.h>
+#include <TRandom.h>
+#include <TString.h>
 
-#include "AliAODParticleCut.h"
 #include "AliAOD.h"
+#include "AliAODParticleCut.h"
 #include "AliAODRun.h"
+#include "AliLog.h"
+#include "AliReader.h"
  
 ClassImp(AliReader)
 //pure virtual
@@ -66,6 +85,7 @@ ClassImp(AliReader)
 /*************************************************************************************/
 
 AliReader::AliReader():
+ fEventList(0x0),
  fCuts(new TObjArray()),
  fDirs(0x0),
  fCurrentEvent(0),
@@ -87,6 +107,7 @@ AliReader::AliReader():
 /*************************************************************************************/
 
 AliReader::AliReader(TObjArray* dirs):
+ fEventList(0x0),
  fCuts(new TObjArray()),
  fDirs(dirs),
  fCurrentEvent(0),
@@ -108,6 +129,7 @@ AliReader::AliReader(TObjArray* dirs):
 /*************************************************************************************/
 AliReader::AliReader(const AliReader& in):
  TNamed(in),
+ fEventList((in.fEventList)?(TGliteXmlEventlist*)in.fEventList->Clone():0x0),
  fCuts((in.fCuts)?(TObjArray*)in.fCuts->Clone():0x0),
  fDirs((in.fDirs)?(TObjArray*)in.fDirs->Clone():0x0),
  fCurrentEvent(0),
@@ -138,6 +160,7 @@ AliReader::~AliReader()
  delete fEventSim;
  delete fEventRec;
  delete fTrackCounter;
+ delete fEventList;
 }
 /*************************************************************************************/
 
@@ -171,7 +194,7 @@ Int_t AliReader::Next()
 //moves to next event
 
   //if asked to read up to event nb. fLast, and it is overcome, report no more events
-  if ((fNEventsRead > fLast) && (fLast > 0) ) return kTRUE;
+  if ((fNEventsRead >= fLast) && (fLast > 0) ) return kTRUE;
   
   if (fTrackCounter == 0x0)//create Track Counter
    {
@@ -346,13 +369,13 @@ Int_t AliReader::Read(AliAODRun* particles, AliAODRun *tracks)
 }      
 /*************************************************************************************/
 
-Bool_t AliReader::Pass(AliVAODParticle* p)
+Bool_t AliReader::Rejected(AliVAODParticle* p)
 {
  //Method examines whether particle meets all cut and particle type criteria
   
    if(p==0x0)//of corse we not pass NULL pointers
     {
-     Warning("Pass()","No Pasaran! We never accept NULL pointers");
+     Warning("Rejected()","No Pasaran! We never accept NULL pointers");
      return kTRUE;
     }
    //if no particle is specified, we pass all particles
@@ -361,14 +384,14 @@ Bool_t AliReader::Pass(AliVAODParticle* p)
   for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)   
    {
      AliAODParticleCut &cut = *((AliAODParticleCut*)fCuts->At(i));
-     if(!cut.Pass(p)) return kFALSE;  //accepted
+     if(!cut.Rejected(p)) return kFALSE;  //accepted
    }
    
   return kTRUE;//not accepted
 }
 /*************************************************************************************/
 
-Bool_t  AliReader::Pass(Int_t pid)
+Bool_t  AliReader::Rejected(Int_t pid)
 {
 //this method checks if any of existing cuts accepts this pid particles
 //or any cuts accepts all particles
@@ -388,29 +411,37 @@ Bool_t  AliReader::Pass(Int_t pid)
 }
 /*************************************************************************************/
 
-TString& AliReader::GetDirName(Int_t entry)
+TString AliReader::GetDirName(Int_t entry)
 {
 //returns directory name of next one to read
-  TString* retval;//return value
+  TString  retval;//return value
   if (fDirs ==  0x0)
-   {
-     retval = new TString(".");
-     return *retval;
+   { 
+     if (entry == 0)
+      {
+       retval = ".";
+       return retval;
+      }
+     else
+      {
+       return retval;
+      }  
    }
-
-  if ( (entry>fDirs->GetEntries()) || (entry<0))//if out of bounds return empty string
+  
+  
+  if ( (entry >= fDirs->GetEntries()) || (entry < 0))//if out of bounds return empty string
    {                                            //note that entry==0 is accepted even if array is empty (size=0)
-     Error("GetDirName","Name out of bounds");
-     retval = new TString();
-     return *retval;
-   }
+    if ( (fDirs->GetEntries() == 0) && (entry == 0) )
+      { 
+        retval = ".";
+        return retval;
+      }
+     AliDebug(1,Form("Index %d out of bounds",entry));
 
-  if (fDirs->GetEntries() == 0)
-   { 
-     retval = new TString(".");
-     return *retval;
+     return retval;
    }
 
+
   TClass *objclass = fDirs->At(entry)->IsA();
   TClass *stringclass = TObjString::Class();
 
@@ -419,11 +450,11 @@ TString& AliReader::GetDirName(Int_t entry)
   if(dir == 0x0)
    {
      Error("GetDirName","Object in TObjArray is not a TObjString or its descendant");
-     retval = new TString();
-     return *retval;
+     return retval;
    }
-  if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data());
-  return dir->String();
+  AliDebug(1,Form("Returned ok %s",dir->String().Data()));
+  retval = dir->String();
+  return retval;
 }
 /*************************************************************************************/
 
@@ -433,13 +464,26 @@ void AliReader::Blend()
   //is used to check if some distributions (of many particle properties) 
   //depend on the order of particles
   //(tracking gives particles Pt sorted)
-  
-  if (fEventSim == 0x0) return;
-  
-  for (Int_t i = 2; i < fEventSim->GetNumberOfParticles(); i++)
+  Int_t npart = 0;
+
+  if (fEventSim ) 
+   {
+     npart = fEventSim->GetNumberOfParticles();
+    } 
+  else 
+    if (fEventRec ) 
+     {
+        npart = fEventRec->GetNumberOfParticles();
+     }
+    else
+     {
+       return;
+     }
+  for (Int_t i = 2;  i < npart; i++)
    {
      Int_t with = gRandom->Integer(i);
-     fEventSim->SwapParticles(i,with);
+//     Info("Blend","%d %d",i, with);
+     if (fEventSim) fEventSim->SwapParticles(i,with);
      if (fEventRec) fEventRec->SwapParticles(i,with);
    }
 }