LCOV - code coverage report
Current view: top level - EVGEN - AliGenReaderTreeK.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 104 1.9 %
Date: 2016-06-14 17:26:59 Functions: 2 18 11.1 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : //
      18             : // Realisation of AliGenReader to be used with AliGenExtFile
      19             : // It reads events from a kinematics TreeK.
      20             : // NextEvent() is used to loop over events 
      21             : // and NextParticle() to loop over particles.  
      22             : // Author: andreas.morsch@cern.ch
      23             : //
      24             : #include <TFile.h>
      25             : #include <TTree.h>
      26             : #include <TParticle.h>
      27             : #include <TObjString.h>
      28             : #include <TObjArray.h>
      29             : 
      30             : #include "AliGenReaderTreeK.h"
      31             : #include "AliHeader.h"
      32             : #include "AliRun.h"
      33             : #include "AliStack.h"
      34             : #include "AliRunLoader.h"
      35             : 
      36           6 : ClassImp(AliGenReaderTreeK)
      37             : 
      38           6 : const TString AliGenReaderTreeK::fgkEventFolderName("GenReaderTreeK");
      39             : 
      40             : AliGenReaderTreeK::AliGenReaderTreeK():
      41           0 :     AliGenReader(),
      42           0 :     fNcurrent(0),
      43           0 :     fNparticle(0),
      44           0 :     fNp(0),
      45           0 :     fInRunLoader(0),
      46           0 :     fBaseFile(0),
      47           0 :     fStack(0),
      48           0 :     fOnlyPrimaries(kFALSE),
      49           0 :     fDirs(0x0),
      50           0 :     fCurrentDir(0)
      51           0 : {
      52             : //  Default constructor
      53           0 : }
      54             : 
      55             : AliGenReaderTreeK::AliGenReaderTreeK(const AliGenReaderTreeK &reader):
      56           0 :     AliGenReader(reader),
      57           0 :     fNcurrent(0),
      58           0 :     fNparticle(0),
      59           0 :     fNp(0),
      60           0 :     fInRunLoader(0),
      61           0 :     fBaseFile(0),
      62           0 :     fStack(0),
      63           0 :     fOnlyPrimaries(kFALSE),
      64           0 :     fDirs(0x0),
      65           0 :     fCurrentDir(0)
      66           0 : {
      67           0 :     reader.Copy(*this);
      68           0 : }
      69             : 
      70             : 
      71             : AliGenReaderTreeK::~AliGenReaderTreeK() 
      72           0 : {
      73             : // Destructor
      74           0 :     delete fInRunLoader;//it cleans all the loaded data
      75           0 :     delete fDirs;
      76           0 : }
      77             : 
      78             : void AliGenReaderTreeK::Init() 
      79             : {
      80             : // Initialization
      81             : // Connect base file and file to read from
      82             : 
      83           0 :     TTree *ali = AliRunLoader::Instance()->TreeE();
      84           0 :     if (ali) {
      85           0 :       fBaseFile = ali->GetCurrentFile();
      86           0 :     } else {
      87           0 :       printf("\n Warning: Basefile cannot be found !\n");
      88             :     }
      89             :     //if (!fFile) fFile  = new TFile(fFileName);
      90           0 :     if (fInRunLoader == 0x0) 
      91             :      {
      92           0 :        fInRunLoader = AliRunLoader::Open((GetDirName(fCurrentDir++)+"/")+fFileName,fgkEventFolderName);
      93           0 :        fInRunLoader->LoadHeader();
      94           0 :        fInRunLoader->LoadKinematics("READ");
      95           0 :      }
      96           0 : }
      97             : 
      98             : Int_t AliGenReaderTreeK::NextEvent() 
      99             : {
     100             : //  Read the next event  
     101             : //  cd to file with old kine tree    
     102           0 :     if (!fBaseFile) Init();
     103             : //  Get next event
     104             :     
     105           0 :     if (fNcurrent >= fInRunLoader->GetNumberOfEvents())
     106             :      {
     107           0 :       if (fCurrentDir >= fDirs->GetEntries())
     108             :        {
     109           0 :          Warning("NextEvent","No more events");
     110           0 :          return 0;
     111             :        }
     112           0 :       delete fInRunLoader;
     113           0 :       fInRunLoader = AliRunLoader::Open((GetDirName(fCurrentDir++)+"/")+fFileName,fgkEventFolderName);
     114           0 :       fInRunLoader->LoadHeader();
     115           0 :       fInRunLoader->LoadKinematics("READ");
     116           0 :       fNcurrent = 0;
     117           0 :      }
     118           0 :     fInRunLoader->GetEvent(fNcurrent);
     119           0 :     fStack = fInRunLoader->Stack();
     120             :     
     121             : //  cd back to base file
     122           0 :     fBaseFile->cd();
     123             : //
     124           0 :     fNcurrent++;
     125           0 :     fNparticle = 0;
     126           0 :     fNp =  fStack->GetNtrack();
     127           0 :     printf("\n Next event contains %d particles", fNp);
     128             : //    
     129           0 :     return  fNp;
     130           0 : }
     131             : 
     132             : TParticle* AliGenReaderTreeK::NextParticle() 
     133             : {
     134             : //Return next particle
     135           0 :   TParticle* part = GetParticle(fNparticle++);
     136           0 :   if (part == 0x0) return 0x0;
     137             :   //if only primaries are to be read, and this particle is not primary enter loop  
     138           0 :   if (fOnlyPrimaries && ( part->GetFirstMother() > -1) ) 
     139             :    for (;;)
     140             :     { //look for a primary
     141           0 :       part = GetParticle(fNparticle++);
     142           0 :       if (part == 0x0) return 0x0;
     143           0 :       if (part->GetFirstMother() == -1) return part;
     144             :     }
     145             : 
     146           0 :   return part;
     147           0 : }
     148             : 
     149             : void AliGenReaderTreeK::RewindEvent()
     150             : {
     151             :   // Go back to the first particle of the event
     152           0 :   fNparticle = 0;
     153           0 : }
     154             : 
     155             : 
     156             : AliGenReaderTreeK& AliGenReaderTreeK::operator=(const  AliGenReaderTreeK& rhs)
     157             : {
     158             : // Assignment operator
     159           0 :     rhs.Copy(*this);
     160           0 :     return *this;
     161             : }
     162             : 
     163             : void AliGenReaderTreeK::Copy(TObject&) const
     164             : {
     165             :     //
     166             :     // Copy 
     167             :     //
     168           0 :     Fatal("Copy","Not implemented!\n");
     169           0 : }
     170             : 
     171             : 
     172             : 
     173             : TString& AliGenReaderTreeK::GetDirName(Int_t entry)
     174             :  {
     175             : // Get the current directory name
     176             : 
     177             :    TString* retval;//return value
     178           0 :    if (fDirs ==  0x0)
     179             :     {
     180           0 :       retval = new TString(".");
     181           0 :       return *retval;
     182             :     }
     183             :    
     184           0 :    if ( (entry>fDirs->GetEntries()) || (entry<0))//if out of bounds return empty string
     185             :     {                                            //note that entry==0 is accepted even if array is empty (size=0)
     186           0 :       Error("GetDirName","Name out of bounds");
     187           0 :       retval = new TString();
     188           0 :       return *retval;
     189             :     }
     190             :    
     191           0 :    if (fDirs->GetEntries() == 0)
     192             :     { 
     193           0 :       retval = new TString(".");
     194           0 :       return *retval;
     195             :     }
     196             :    
     197           0 :    TObjString *dir = dynamic_cast<TObjString*>(fDirs->At(entry));
     198           0 :    if(dir == 0x0)
     199             :     {
     200           0 :       Error("GetDirName","Object in TObjArray is not a TObjString or its descendant");
     201           0 :       retval = new TString();
     202           0 :       return *retval;
     203             :     }
     204           0 :    if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data());
     205           0 :    return dir->String();
     206           0 :  }
     207             :  
     208             : void AliGenReaderTreeK::AddDir(const char* dirname)
     209             : {
     210             :   //adds a directory to the list of directories where data are looked for
     211           0 :   if(fDirs == 0x0) 
     212             :    {
     213           0 :      fDirs = new TObjArray();
     214           0 :      fDirs->SetOwner(kTRUE);
     215           0 :    }
     216           0 :   TObjString *odir= new TObjString(dirname);
     217           0 :   fDirs->Add(odir);
     218           0 : }
     219             : 
     220             : TParticle* AliGenReaderTreeK::GetParticle(Int_t i)
     221             :  {
     222           0 :   if (fStack && i<fNp) return fStack->Particle(i);
     223           0 :   return 0x0;
     224           0 :  }

Generated by: LCOV version 1.11