]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Protection when a nonexistent event is asked for (J.Chudoba)
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 2 Jul 2001 07:23:11 +0000 (07:23 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 2 Jul 2001 07:23:11 +0000 (07:23 +0000)
STEER/AliRun.cxx
STEER/AliStack.cxx
STEER/AliStack.h

index 0e1df686247ebc4ee56e34669f6b27d36ee6ed64..275c95bd94d28e44dd76fb9281cc15739d09dbbb 100644 (file)
 
 /*
 $Log$
 
 /*
 $Log$
-Revision 1.69  2001/06/28 16:27:50  morsch
-AliReco() with user control of event range.
-
-Revision 1.68  2001/06/11 13:14:40  morsch
-SetAliGenEventHeader() method added.
-
-Revision 1.67  2001/06/07 18:24:50  buncic
-Removed compilation warning in AliConfig initialisation.
-
 Revision 1.66  2001/05/22 14:32:40  hristov
 Weird inline removed
 
 Revision 1.66  2001/05/22 14:32:40  hristov
 Weird inline removed
 
@@ -203,6 +194,7 @@ Introduction of the Copyright and cvs Log
 #include <TFile.h>
 #include <TRandom.h>
 #include <TBRIK.h> 
 #include <TFile.h>
 #include <TRandom.h>
 #include <TBRIK.h> 
+#include <TNode.h> 
 #include <TCint.h> 
 #include <TSystem.h>
 #include <TObjectTable.h>
 #include <TCint.h> 
 #include <TSystem.h>
 #include <TObjectTable.h>
@@ -211,7 +203,6 @@ Introduction of the Copyright and cvs Log
 #include <TROOT.h>
 #include <TBrowser.h>
 #include <TFolder.h>
 #include <TROOT.h>
 #include <TBrowser.h>
 #include <TFolder.h>
-#include <TNode.h>
 
 #include "TParticle.h"
 #include "AliRun.h"
 
 #include "TParticle.h"
 #include "AliRun.h"
@@ -800,10 +791,10 @@ Int_t AliRun::GetEvent(Int_t event)
   ResetSDigits();
   
   // Delete Trees already connected
   ResetSDigits();
   
   // Delete Trees already connected
-  if (fTreeH) delete fTreeH;
-  if (fTreeD) delete fTreeD;
-  if (fTreeR) delete fTreeR;
-  if (fTreeS) delete fTreeS;
+  if (fTreeH) { delete fTreeH; fTreeH = 0;}
+  if (fTreeD) { delete fTreeD; fTreeD = 0;}
+  if (fTreeR) { delete fTreeR; fTreeR = 0;}
+  if (fTreeS) { delete fTreeS; fTreeS = 0;}
 
  // Create the particle stack
   if (fHeader) delete fHeader; 
 
  // Create the particle stack
   if (fHeader) delete fHeader; 
@@ -812,15 +803,25 @@ Int_t AliRun::GetEvent(Int_t event)
   // Get header from file
   if(fTreeE) {
       fTreeE->SetBranchAddress("Header", &fHeader);
   // Get header from file
   if(fTreeE) {
       fTreeE->SetBranchAddress("Header", &fHeader);
-      fTreeE->GetEntry(event);
+
+      if (!fTreeE->GetEntry(event)) {
+       Error("GetEvent","Cannot find event:%d\n",event);
+       return -1;
+      }
   }  
   }  
-  else 
+  else {
       Error("GetEvent","Cannot find Header Tree (TE)\n");
       Error("GetEvent","Cannot find Header Tree (TE)\n");
+      return -1;
+  }
 
 
-  // Get the stack from the header
+  // Get the stack from the header, set fStack to 0 if it 
+  // fails to get event
   if (fStack) delete fStack;
   fStack = fHeader->Stack();
   if (fStack) delete fStack;
   fStack = fHeader->Stack();
-  fStack->GetEvent(event);
+  if (fStack) {
+    if (!fStack->GetEvent(event,0)) fStack = 0;
+  }
+
   //
   TFile *file = fTreeE->GetCurrentFile();
   char treeName[20];
   //
   TFile *file = fTreeE->GetCurrentFile();
   char treeName[20];
@@ -980,7 +981,7 @@ void AliRun::InitMC(const char *setup)
 
    fMCQA = new AliMCQA(fNdets);
 
 
    fMCQA = new AliMCQA(fNdets);
 
-   AliConfig::Instance();
+   AliConfig *config = AliConfig::Instance();
    //
    // Save stuff at the beginning of the file to avoid file corruption
    Write();
    //
    // Save stuff at the beginning of the file to avoid file corruption
    Write();
@@ -1424,17 +1425,12 @@ void AliRun::RunMC(Int_t nevent, const char *setup)
 }
 
 //_____________________________________________________________________________
 }
 
 //_____________________________________________________________________________
-void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
+void AliRun::RunReco(const char *selected)
 {
   //
   // Main function to be called to reconstruct Alice event
 {
   //
   // Main function to be called to reconstruct Alice event
-  // 
-   cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
-   Int_t nFirst = first;
-   Int_t nLast  = (last < 0)? (Int_t) gAlice->TreeE()->GetEntries() : last;
-   
-   for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
-     cout << "Processing event "<< nevent << endl;
+  //  
+   for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
      GetEvent(nevent);
      // MakeTree("R");
      Digits2Reco(selected);
      GetEvent(nevent);
      // MakeTree("R");
      Digits2Reco(selected);
@@ -1753,9 +1749,3 @@ TTree* AliRun::TreeK() {
   //
   return fStack->TreeK();
 }
   //
   return fStack->TreeK();
 }
-
-
-void AliRun::SetGenEventHeader(AliGenEventHeader* header)
-{
-    fHeader->SetGenEventHeader(header);
-}
index e8d41a2e1fce45b3cf865ec08743121f709f6395..6b420abeadf0022df299e286bfbd7d15c39f7a05 100644 (file)
@@ -69,11 +69,11 @@ AliStack::AliStack(Int_t size)
   fParticles      = new TClonesArray("TParticle",1000);
   fParticleMap    = new TObjArray(size);
   fParticleBuffer = 0;
   fParticles      = new TClonesArray("TParticle",1000);
   fParticleMap    = new TObjArray(size);
   fParticleBuffer = 0;
-  fNtrack         =  0;
-  fNprimary       0;
+  fNtrack         = 0;
+  fNprimary       = 0;
   fCurrent        = -1;
   fCurrentPrimary = -1;
   fCurrent        = -1;
   fCurrentPrimary = -1;
-  fTreeK          =  0;
+  fTreeK          = 0;
 }
 
 
 }
 
 
@@ -88,11 +88,11 @@ AliStack::AliStack()
   fParticles      = new TClonesArray("TParticle",1000);
   fParticleMap    = new TObjArray(10000);
   fParticleBuffer = 0;
   fParticles      = new TClonesArray("TParticle",1000);
   fParticleMap    = new TObjArray(10000);
   fParticleBuffer = 0;
-  fNtrack         =  0;
+  fNtrack         = 0;
   fCurrent        = -1;
   fCurrent        = -1;
-  fNprimary       0;
+  fNprimary       = 0;
   fCurrentPrimary = -1;
   fCurrentPrimary = -1;
-  fTreeK          =  0;
+  fTreeK          = 0;
 }
 
 
 }
 
 
@@ -153,9 +153,9 @@ void AliStack::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
   Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
                        pmom[1]*pmom[1]+pmom[2]*pmom[2]);
   
   Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
                        pmom[1]*pmom[1]+pmom[2]*pmom[2]);
   
-//  printf("Loading  mass %f ene %f No %d ip %d parent %d done %d pos %f %f %f mom %f %f %f kS %d m \n",
-//  mass,e,fNtrack,pdg,parent,done,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS);
-
+//    printf("Loading  mass %f ene %f No %d ip %d parent %d done %d pos %f %f %f mom %f %f %f kS %d m \n",
+//        mass,e,fNtrack,pdg,parent,done,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS);
+  
   TClonesArray &particles = *fParticles;
   TParticle* particle
    = new(particles[fLoadPoint++]) 
   TClonesArray &particles = *fParticles;
   TParticle* particle
    = new(particles[fLoadPoint++]) 
@@ -267,7 +267,7 @@ void AliStack::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
   
 
   TParticle* track = GetNextParticle();
   
 
   TParticle* track = GetNextParticle();
-//  cout << "GetNextTrack():" << fCurrent << fNprimary << endl;
+//    cout << "GetNextTrack():" << fCurrent << fNprimary << endl;
 
   if(track) {
     mtrack=fCurrent;
 
   if(track) {
     mtrack=fCurrent;
@@ -286,7 +286,7 @@ void AliStack::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
     polar[2]=pol.Z();
     tof=track->T();
     track->SetBit(kDoneBit);
     polar[2]=pol.Z();
     tof=track->T();
     track->SetBit(kDoneBit);
-    //cout << "Filled params" << endl;
+//      cout << "Filled params" << endl;
   }
   else 
     mtrack=-1;
   }
   else 
     mtrack=-1;
@@ -468,7 +468,7 @@ void AliStack::FinishEvent()
         // To be removed later and replaced with break.
       if(!allFilled) allFilled = kTRUE;
     } 
         // To be removed later and replaced with break.
       if(!allFilled) allFilled = kTRUE;
     } 
-  //cout << "Nof particles: " << fNtrack << endl;
+//    cout << "Nof particles: " << fNtrack << endl;
   //Reset();   
 } 
 
   //Reset();   
 } 
 
@@ -555,7 +555,7 @@ TParticle* AliStack::Particle(Int_t i)
   // Return particle with specified ID
   
   if(!(*fParticleMap)[i]) {
   // Return particle with specified ID
   
   if(!(*fParticleMap)[i]) {
-    Int_t nentries = fParticles->GetEntriesFast();
+    Int_t nentries = fParticles->GetEntries();
     // algorithmic way of getting entry index
     // (primary particles are filled after secondaries)
     Int_t entry;
     // algorithmic way of getting entry index
     // (primary particles are filled after secondaries)
     Int_t entry;
@@ -739,7 +739,7 @@ void AliStack::MakeTree(Int_t event, const char *file)
   TBranch *branch=0;
   // Make Kinematics Tree
   char hname[30];
   TBranch *branch=0;
   // Make Kinematics Tree
   char hname[30];
-  //    printf("\n MakeTree called %d", event);
+//    printf("\n MakeTree called %d", event);
   if (!fTreeK) {
     sprintf(hname,"TreeK%d",event);
     fTreeK = new TTree(hname,"Kinematics");
   if (!fTreeK) {
     sprintf(hname,"TreeK%d",event);
     fTreeK = new TTree(hname,"Kinematics");
@@ -776,10 +776,11 @@ void AliStack::FinishRun()
 }
 
 //_____________________________________________________________________________
 }
 
 //_____________________________________________________________________________
-void AliStack::GetEvent(Int_t event)
+Bool_t AliStack::GetEvent(Int_t event)
 {
 //
 // Get new event from TreeK
 {
 //
 // Get new event from TreeK
+
     // Reset/Create the particle stack
     if (fTreeK) delete fTreeK;
     
     // Reset/Create the particle stack
     if (fTreeK) delete fTreeK;
     
@@ -788,14 +789,18 @@ void AliStack::GetEvent(Int_t event)
     sprintf(treeName,"TreeK%d",event);
     fTreeK = (TTree*)gDirectory->Get(treeName);
 
     sprintf(treeName,"TreeK%d",event);
     fTreeK = (TTree*)gDirectory->Get(treeName);
 
-    if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticleBuffer);
-
-  else    
+    if (fTreeK) 
+      fTreeK->SetBranchAddress("Particles", &fParticleBuffer);
+    else {
       Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
       Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
-//
-//    printf("\n primaries %d", fNprimary);
-//    printf("\n tracks    %d", fNtrack);    
-//
+      return kFALSE;
+    }
+//      printf("\n primaries %d", fNprimary);
+//      printf("\n tracks    %d", fNtrack);    
+      
     Int_t size = (Int_t)fTreeK->GetEntries();
     ResetArrays(size);
     Int_t size = (Int_t)fTreeK->GetEntries();
     ResetArrays(size);
+    return kTRUE;
 }
 }
+
+//----------------------------------------------------------------------
index 094288bb748339080e8d69be290285beaff152c8..8823f70451e4cf08401346d63e30841cf27c8849 100644 (file)
@@ -32,7 +32,7 @@ class AliStack : public TObject
     void  MakeTree(Int_t event, const char *file);
     void  BeginEvent(Int_t event);
     void  FinishRun();
     void  MakeTree(Int_t event, const char *file);
     void  BeginEvent(Int_t event);
     void  FinishRun();
-    void  GetEvent(Int_t nevent);
+    Bool_t GetEvent(Int_t nevent);
     void  SetTrack(Int_t done, Int_t parent, Int_t pdg, 
                   Float_t *pmom, Float_t *vpos, Float_t *polar, 
                    Float_t tof, AliMCProcess mech, Int_t &ntr,
     void  SetTrack(Int_t done, Int_t parent, Int_t pdg, 
                   Float_t *pmom, Float_t *vpos, Float_t *polar, 
                    Float_t tof, AliMCProcess mech, Int_t &ntr,
@@ -86,7 +86,7 @@ class AliStack : public TObject
     Int_t          fHgwmk;             //! Last track purified
     Int_t          fLoadPoint;         //! Next free position in the particle buffer
     TStopwatch     fTimer;             //! Timer object
     Int_t          fHgwmk;             //! Last track purified
     Int_t          fLoadPoint;         //! Next free position in the particle buffer
     TStopwatch     fTimer;             //! Timer object
-    ClassDef(AliStack,1) //Particles stack
+    ClassDef(AliStack,2) //Particles stack
 };
 
 // inline
 };
 
 // inline
@@ -109,4 +109,9 @@ inline Int_t AliStack::CurrentTrack() const
 inline TObjArray* AliStack::Particles() const
 { return fParticleMap; }
 
 inline TObjArray* AliStack::Particles() const
 { return fParticleMap; }
 
+inline Int_t AliStack::GetDebug() const
+{ return fDebug; }
+
+inline void  AliStack::SetDebug(Int_t level)
+{ fDebug = level; }
 #endif //ALI_STACK_H
 #endif //ALI_STACK_H