-#include "AliRunAnalysis.h"
-//________________________________
-///////////////////////////////////////////////////////////
-//
-// class AliRunAnalysis
-//
-//
-//
-// Piotr.Skowronski@cern.ch
-//
-///////////////////////////////////////////////////////////
-
-#include <stdlib.h>
-
-#include <TString.h>
-#include <TObjString.h>
-#include <TClass.h>
-#include <TFile.h>
-#include <TKey.h>
-#include <TObjArray.h>
-
-#include <AliRun.h>
-#include <AliRunLoader.h>
-#include <AliStack.h>
-#include <AliESDtrack.h>
-#include <AliESD.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$ */
+
+//********************************************************
+// class AliRunAnalysis *
+// Analysis manager *
+// Author: Piotr.Skowronski@cern.ch *
+//********************************************************
+#include "AliRunAnalysis.h"
+#include "AliLog.h"
+#include "AliAnalysis.h"
#include "AliEventCut.h"
+#include "AliReader.h"
-const TString AliRunAnalysis::fgkDefaultRunAnalysisName("RunAnalysis");
ClassImp(AliRunAnalysis)
AliRunAnalysis::AliRunAnalysis():
- TTask(fgkDefaultRunAnalysisName,"Alice Analysis Manager") ,
- fDirs(),
+ TTask("RunAnalysis","Alice Analysis Manager"),
+ fAnalysies(10),
+ fReader(0x0),
fEventCut(0x0),
- fFileName("AliESDs.root"),
- fReadKinematics(kFALSE)
+ fCutOnSim(kFALSE),
+ fCutOnRec(kTRUE)
{
//ctor
}
AliRunAnalysis::~AliRunAnalysis()
{
//dtor
- delete fDirs;
- delete fAnalysies;
+ delete fReader;
delete fEventCut;
}
/*********************************************************/
Int_t AliRunAnalysis::Run()
{
//makes analysis
-
- Int_t currentdir = 0;
- Int_t ndirs;
- if (fDirs) //if array with directories is supplied by user
- {
- ndirs = fDirs->GetEntries(); //get the number if directories
- }
- else
+
+ if (fReader == 0x0)
{
- ndirs = 0; //if the array is not supplied read only from current directory
+ AliError("Reader is not set");
+ return 1;
}
-
+ TDirectory* cwd = gDirectory;
+ Int_t nanal = fAnalysies.GetEntries();
+ AliDebug(1,Form("There are %d analyses",nanal));
/******************************/
/* Init Event */
/******************************/
- if (fAnalysies == 0x0)
- {
- Info("Run","No analysis present");
- return 0;
+ AliDebug(1,"Intializing analyses...");
+ for (Int_t an = 0; an < nanal; an++)
+ {
+ AliAnalysis* analysis = (AliAnalysis*)fAnalysies.At(an);
+ AliDebug(1,Form("Intializing analysis %d,address=%#x, name=%s",
+ an, analysis, analysis->GetName()));
+ analysis->Init();
+ AliDebug(1,Form("Init done for analysis %d",an));
}
+ AliDebug(1,"Intializing analyses... Done.");
- for (Int_t an = 0; an < fAnalysies->GetEntries(); an++)
+ while (fReader->Next() == kFALSE)
{
- AliAnalysis* analysis = (AliAnalysis*)fAnalysies->At(an);
- analysis->Init();
- }
+ AliAOD* eventrec = fReader->GetEventRec();
+ AliAOD* eventsim = fReader->GetEventSim();
- do
- {
- TFile* file = OpenFile(currentdir);
- if (file == 0x0)
+ /******************************/
+ /* Event Cut */
+ /******************************/
+ if ( Rejected(eventrec,eventsim) )
{
- Error("Run","Cannot get File for dir no. %d",currentdir);
- currentdir++;
- continue;
- }
- AliStack* stack = 0x0;
- AliRunLoader* rl = 0x0;
- if (fReadKinematics)
- {
- const TString& dirname = GetDirName(currentdir);
- if (dirname == "")
- {
- Error("Run","Can not get directory name");
- return 0x0;
- }
- TString filename = dirname +"/galice.root";
-
- rl = AliRunLoader::Open(filename);
- if ( rl == 0x0 )
- {
- Error("Run","Can't get Run Loader from dir %s",filename.Data());
- delete file;
- currentdir++;
- continue;
- }
- if( rl->LoadHeader() )
- {
- Error("Run","Error while loading Header from dir %s",filename.Data());
- delete file;
- delete rl;
- currentdir++;
- continue;
- }
- if( rl->LoadKinematics() )
- {
- Error("Run","Error while loading Kinematics from dir %s",filename.Data());
- delete file;
- delete rl;
- currentdir++;
- continue;
- }
- }
-
- file->cd();
- TIter keyiter(file->GetListOfKeys());
- TKey* key;
- while (( key = (TKey*)keyiter.Next() ))
- {
- if (key == 0x0)
- {
- if (GetDebug() > 2 )
- {
- Info("Run","No more keys.");
- }
- break;
- }
-
- TObject* esdobj = key->ReadObj();
- if (esdobj == 0x0)
- {
- if (GetDebug() > 2 )
- {
- Info("ReadNext","Key read NULL. Key Name is %s",key->GetName());
- key->Dump();
- }
- continue;
- }
- if (GetDebug() > 9 ) esdobj->Dump();
- AliESD* esd = dynamic_cast<AliESD*>(esdobj);
-
- if (esd == 0x0)
- {
- if (GetDebug() > 7 )
- {
- Info("ReadNext","It is not an ESD object");
- }
- delete esdobj;
- continue;
- }
-
- if (fReadKinematics)
- {
- TString esdname(esd->GetName());
- esdname.ReplaceAll("ESD","");
- Int_t nev = atoi(esdname);
- Info("Run","ESD name is %s, Event Number is %d",esd->GetName(),nev);
- if (rl->GetEvent(nev))
- {
- Error("Run","Error occured while RunLoader GetEvent %d",nev);
- delete esd;
- continue;
- }
- stack = rl->Stack();
- if (stack == 0x0)
- {
- Error("Run","Can not get stack");
- delete esd;
- continue;
- }
- }
- /******************************/
- /* Event Cut */
- /******************************/
- if (fEventCut)
- {
- if (fEventCut->Pass(esd))
- {
- if (GetDebug()) Info("Run","Event rejected by Event Cut");
- delete esd;
- continue; //Did not pass the
- }
- }
- /******************************/
- /* Process Event */
- /******************************/
- for (Int_t an = 0; an < fAnalysies->GetEntries(); an++)
- {
- AliAnalysis* analysis = (AliAnalysis*)fAnalysies->At(an);
- analysis->ProcessEvent(esd,stack);
- }
- delete esd;
- }//end of loop over keys in file
+ AliDebug(1,"Event rejected by Event Cut");
+ continue; //Did not pass the
+ }
+
+ /******************************/
+ /* Process Event */
+ /******************************/
+ AliDebug(1,Form("There is %d analyses",fAnalysies.GetEntries()));
- delete file;
- delete rl;
- currentdir++;
+ for (Int_t an = 0; an < fAnalysies.GetEntries(); an++)
+ {
+ AliAnalysis* analysis = (AliAnalysis*)fAnalysies.At(an);
+ analysis->ProcessEvent(eventrec,eventsim);
+ }
- }while (currentdir < ndirs);//end of loop over directories
+ }//end of loop over events
/******************************/
/* Finish Event */
/******************************/
- for (Int_t an = 0; an < fAnalysies->GetEntries(); an++)
+ AliDebug(1,Form("Finishing analyses...\n There are %d anlyses",fAnalysies.GetEntries()));
+ if (cwd) cwd->cd();
+ for (Int_t an = 0; an < fAnalysies.GetEntries(); an++)
{
- AliAnalysis* analysis = (AliAnalysis*)fAnalysies->At(an);
- analysis->Init();
+ AliAnalysis* analysis = (AliAnalysis*)fAnalysies.At(an);
+ AliDebug(1,Form("Calling Finish for analysis %d address %#x name=%s",
+ an, analysis,analysis->GetName()));
+ analysis->Finish();
+ AliDebug(1,Form("Called Finish for analysis %d",an));
}
+ AliDebug(1,"Finishing done");
return 0;
}
/*********************************************************/
-TFile* AliRunAnalysis::OpenFile(Int_t n)
+void AliRunAnalysis::Add(AliAnalysis* a)
{
-//opens file with kine tree
-
- const TString& dirname = GetDirName(n);
- if (dirname == "")
- {
- Error("OpenFiles","Can not get directory name");
- return 0x0;
- }
- TString filename = dirname +"/"+ fFileName;
- TFile *ret = TFile::Open(filename.Data());
-
- if ( ret == 0x0)
- {
- Error("OpenFiles","Can't open file %s",filename.Data());
- return 0x0;
- }
- if (!ret->IsOpen())
- {
- Error("OpenFiles","Can't open file %s",filename.Data());
- return 0x0;
- }
-
- return ret;
+ //adds a to the list of analysis
+ fAnalysies.Add(a);
}
/*********************************************************/
-TString& AliRunAnalysis::GetDirName(Int_t entry)
+void AliRunAnalysis::SetEventCut(AliEventCut* evcut)
{
-//returns directory name of next one to read
- TString* retval;//return value
- if (fDirs == 0x0)
- {
- retval = new TString(".");
- return *retval;
- }
-
- 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)
- {
- retval = new TString(".");
- return *retval;
- }
-
- TClass *objclass = fDirs->At(entry)->IsA();
- TClass *stringclass = TObjString::Class();
-
- TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry));
-
- if(dir == 0x0)
- {
- Error("GetDirName","Object in TObjArray is not a TObjString or its descendant");
- retval = new TString();
- return *retval;
- }
- if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data());
- return dir->String();
+//Sets event - makes a private copy
+ delete fEventCut;
+ if (evcut) fEventCut = (AliEventCut*)evcut->Clone();
+ else fEventCut = 0x0;
}
+
/*********************************************************/
-void AliRunAnalysis::Add(AliAnalysis* a)
+Bool_t AliRunAnalysis::Rejected(AliAOD* recevent, AliAOD* simevent)
{
- //adds a to the list of analysis
- if (fAnalysies == 0x0) fAnalysies = new TObjArray();
- fAnalysies->Add(a);
+ //checks the event cut
+ if (fEventCut == 0x0) return kFALSE;
+
+ if (fCutOnRec)
+ if (fEventCut->Rejected(recevent)) return kTRUE;
+
+ if (fCutOnSim)
+ if (fEventCut->Rejected(simevent)) return kTRUE;
+
+ return kFALSE;
}