From: jchudoba Date: Thu, 4 Oct 2001 15:56:34 +0000 (+0000) Subject: TTask inheritance X-Git-Url: http://git.uio.no/git/?a=commitdiff_plain;h=8d5e634550dca9c1555e8c20acff4d7b9aa9c97e;p=u%2Fmrichter%2FAliRoot.git TTask inheritance --- diff --git a/STEER/AliDigitizer.cxx b/STEER/AliDigitizer.cxx index 33f45896e55..4a1edc44283 100644 --- a/STEER/AliDigitizer.cxx +++ b/STEER/AliDigitizer.cxx @@ -23,6 +23,9 @@ /* $Log$ +Revision 1.1 2001/07/27 13:02:06 jchudoba +ABC for detector digits merging/digitization + */ // system includes @@ -36,17 +39,17 @@ $Log$ ClassImp(AliDigitizer) -AliDigitizer::AliDigitizer() :TNamed("AliDigitizer","") +AliDigitizer::AliDigitizer() :TTask("AliDigitizer","") { // dummy default ctor - ; + fManager = 0; } AliDigitizer::AliDigitizer(AliRunDigitizer* manager) - :TNamed("AliDigitizer","") + :TTask("AliDigitizer","") { + fManager = manager; manager->AddDigitizer(this); - fDebug=1; } AliDigitizer::~AliDigitizer() {;} diff --git a/STEER/AliDigitizer.h b/STEER/AliDigitizer.h index 07ca4e88931..e5a053531c8 100644 --- a/STEER/AliDigitizer.h +++ b/STEER/AliDigitizer.h @@ -7,30 +7,28 @@ //////////////////////////////////////////////////////////////////////// // -// Abstract Base Class for Detector specific Merging/Digitization +// Base Class for Detector specific Merging/Digitization // // Author: Jiri Chudoba (CERN) // //////////////////////////////////////////////////////////////////////// -#include "TNamed.h" +#include "TTask.h" + class AliRunDigitizer; -class AliDigitizer: public TNamed { +class AliDigitizer: public TTask { public: AliDigitizer(); // default ctor - dummy AliDigitizer(AliRunDigitizer *manager); // ctor to be used virtual ~AliDigitizer(); - virtual Bool_t Init() = 0; - virtual void Digitize() = 0; - Int_t GetDebug() {return fDebug;} // get debug level - void SetDebug(Int_t level){fDebug = level;} // set debug level - -private: - - Int_t fDebug; // debug level + virtual Bool_t Init() {return kTRUE;} +// virtual void Digitize() = 0; + protected: + AliRunDigitizer *fManager; + ClassDef(AliDigitizer,1) }; diff --git a/STEER/AliRunDigitizer.cxx b/STEER/AliRunDigitizer.cxx index fb07f41dc68..8584fcd6999 100644 --- a/STEER/AliRunDigitizer.cxx +++ b/STEER/AliRunDigitizer.cxx @@ -15,9 +15,6 @@ /* $Log$ -Revision 1.5 2001/09/20 14:35:25 jchudoba -Temporary disable GetParticle and GetNParticles functions - Revision 1.4 2001/09/19 06:23:50 jchudoba Move some tasks to AliStream and AliMergeCombi classes @@ -62,6 +59,9 @@ Manager class for merging/digitization // manager->SetFirstOutputEventNr(Int_t) method. The particle numbers // in the output are shifted by MASK, which is taken from manager. // +// The default output is to the signal file (stream 0). This can be +// changed with the SetOutputFile(TString fn) method. +// // Single input file is permitted. Maximum MAXSTREAMSTOMERGE can be merged. // Input from the memory (on-the-fly merging) is not yet // supported, as well as access to the input data by invoking methods @@ -76,11 +76,10 @@ Manager class for merging/digitization // AliRunDigitizer * manager = new AliRunDigitizer(2,1); // manager->SetInputStream(0,"1track_10events_phi45_60.root"); // manager->SetInputStream(1,"1track_10events_phi120_135.root"); -// manager->SetOutputDir("/tmp"); // manager->SetOutputFile("digits.root"); // AliMUONDigitizer *dMUON = new AliMUONDigitizer(manager); // manager->SetNrOfEventsToWrite(1); -// manager->Digitize(); +// manager->Exec(""); // //////////////////////////////////////////////////////////////////////// @@ -92,6 +91,7 @@ Manager class for merging/digitization #include "TFile.h" #include "TTree.h" +#include "TList.h" // AliROOT includes @@ -106,20 +106,7 @@ Manager class for merging/digitization ClassImp(AliRunDigitizer) //////////////////////////////////////////////////////////////////////// - -AliRunDigitizer::AliRunDigitizer() : TNamed("AliRunDigitizer","") -{ -// default ctor - cerr<<"Don't use"<2) cerr<<"AliRunDigitizer::AliRunDigitizer() called"<= MAXDETECTORS) { - cerr<<"Too many detectors to digitize. Increase value of MAXDETECTORS" - <<" constant in AliRunDigitizer.h and recompile or decrease the" - <<" the number of detectors"<Add(digitizer); } - //////////////////////////////////////////////////////////////////////// - void AliRunDigitizer::SetInputStream(Int_t i, char *inputFile) { if (i > fInputStreams->GetLast()) { @@ -205,7 +177,7 @@ void AliRunDigitizer::SetInputStream(Int_t i, char *inputFile) } //////////////////////////////////////////////////////////////////////// -void AliRunDigitizer::Digitize() +void AliRunDigitizer::Digitize(Option_t* option) { // get a new combination of inputs, connect input trees and loop // over all digitizers @@ -222,14 +194,13 @@ void AliRunDigitizer::Digitize() return; } Int_t eventsCreated = 0; - while (eventsCreated++ < fNrOfEventsToWrite) { -// if (GetDebug()>2) PrintCombination(); - ConnectInputTrees(); +// loop until there is anything on the input in case fNrOfEventsToWrite < 0 + while ((eventsCreated++ < fNrOfEventsToWrite) || (fNrOfEventsToWrite < 0)) { + if (!ConnectInputTrees()) break; InitEvent(); // loop over all registered digitizers and let them do the work - for (Int_t i=0;iDigitize(); - } + ExecuteTasks(""); + CleanTasks(); FinishEvent(); } FinishGlobal(); @@ -243,7 +214,7 @@ Bool_t AliRunDigitizer::ConnectInputTrees() // null pointers can be in the output, AliDigitizer has to check it TTree *tree; - char treeName[20]; + char treeName[50]; Int_t serialNr; Int_t eventNr[MAXSTREAMSTOMERGE], delta[MAXSTREAMSTOMERGE]; fCombi->Combination(eventNr, delta); @@ -251,6 +222,7 @@ Bool_t AliRunDigitizer::ConnectInputTrees() if (delta[i] == 1) { AliStream *iStream = static_cast(fInputStreams->At(i)); if (!iStream->NextEventInStream(serialNr)) return kFALSE; + fInputFiles[i]=iStream->CurrentFile(); sprintf(treeName,"TreeS%d",serialNr); tree = static_cast(iStream->CurrentFile()->Get(treeName)); fArrayTreeS[i] = tree; @@ -273,24 +245,33 @@ Bool_t AliRunDigitizer::InitGlobal() { // called once before Digitize() is called, initialize digitizers and output - if (!InitOutputGlobal()) return kFALSE; - for (Int_t i=0;iInit()) return kFALSE; - } + TList* subTasks = this->GetListOfTasks(); + if (subTasks) { + subTasks->ForEach(AliDigitizer,Init)(); + } return kTRUE; } +//////////////////////////////////////////////////////////////////////// + +void AliRunDigitizer::SetOutputFile(TString fn) +// the output will be to separate file, not to the signal file +{ + fOutputFileName = fn; + (static_cast(fInputStreams->At(0)))->ChangeMode("READ"); + InitOutputGlobal(); +} + //////////////////////////////////////////////////////////////////////// Bool_t AliRunDigitizer::InitOutputGlobal() { -// Creates the output file, called once by InitGlobal() +// Creates the output file, called by InitEvent() TString fn; fn = fOutputDirName + '/' + fOutputFileName; fOutput = new TFile(fn,"recreate"); if (GetDebug()>2) { - cerr<<"file "<2) cerr<<"AliRunDigitizer::InitEvent: fEvent = "<(fInputStreams->At(0)))->CurrentFile(); + } fOutput->cd(); - char hname[30]; - sprintf(hname,"TreeD%d",fEvent); - fTreeD = new TTree(hname,"Digits"); - fTreeD->Write(); // Do I have to write it here??? + char treeName[30]; + sprintf(treeName,"TreeD%d",fEvent); + fTreeD = static_cast(fOutput->Get(treeName)); + if (!fTreeD) { + fTreeD = new TTree(treeName,"Digits"); + fTreeD->Write(0,TObject::kOverwrite); + } } //////////////////////////////////////////////////////////////////////// @@ -323,9 +312,9 @@ void AliRunDigitizer::FinishEvent() char treeName[20]; Int_t i = fCopyTreesFromInput; sprintf(treeName,"TreeK%d",fCombination[i]); - ((TFile*)fInputFiles->At(i))->Get(treeName)->Clone()->Write(); + fInputFiles[i]->Get(treeName)->Clone()->Write(); sprintf(treeName,"TreeH%d",fCombination[i]); - ((TFile*)fInputFiles->At(i))->Get(treeName)->Clone()->Write(); + fInputFiles[i]->Get(treeName)->Clone()->Write(); } fEvent++; fNrOfEventsWritten++; @@ -343,8 +332,7 @@ void AliRunDigitizer::FinishGlobal() fOutput->cd(); this->Write(); if (fCopyTreesFromInput > -1) { - ((TFile*)fInputFiles->At(fCopyTreesFromInput))->Get("TE") - ->Clone()->Write(); + fInputFiles[fCopyTreesFromInput]->Get("TE")->Clone()->Write(); gAlice->Write(); } fOutput->Close(); @@ -445,7 +433,7 @@ TParticle* AliRunDigitizer::GetParticle(Int_t i, Int_t input, Int_t event) // return pointer to particle with index i in the input file input // (index without mask) // event is the event number in the file input -// return 0 if it does not exist +// return 0 i fit does not exist // Must be revised in the version with AliStream @@ -498,5 +486,14 @@ TParticle* AliRunDigitizer::GetParticle(Int_t i, Int_t input, Int_t event) return 0; */ } + //////////////////////////////////////////////////////////////////////// +void AliRunDigitizer::ExecuteTask(Option_t* option) +{ +// overwrite ExecuteTask to do Digitize only + if (!IsActive()) return; + Digitize(option); + fHasExecuted = kTRUE; + return; +} diff --git a/STEER/AliRunDigitizer.h b/STEER/AliRunDigitizer.h index 3083f5947b1..63ec6269e98 100644 --- a/STEER/AliRunDigitizer.h +++ b/STEER/AliRunDigitizer.h @@ -20,6 +20,7 @@ #include "TClonesArray.h" #include "TTree.h" #include "TParticle.h" +#include "TTask.h" #define MAXDETECTORS 20 #define MAXSTREAMSTOMERGE 4 @@ -29,14 +30,13 @@ class AliDigitizer; class AliMergeCombi; -class AliRunDigitizer: public TNamed { +class AliRunDigitizer: public TTask { public: - AliRunDigitizer(); - AliRunDigitizer(Int_t nInputStream, Int_t sperb); + AliRunDigitizer(Int_t nInputStream=1, Int_t sperb=1); virtual ~AliRunDigitizer(); void AddDigitizer(AliDigitizer *digitizer); - void SetOutputFile(TString fn) {fOutputFileName = fn;} + void SetOutputFile(TString fn); TString GetOutputFile() {return fOutputFileName;} void SetOutputDir(TString dn) {fOutputDirName = dn;} TString GetOutputDir() {return fOutputDirName;} @@ -54,8 +54,11 @@ public: TTree* GetInputTreeH(Int_t i) const {return fArrayTreeH[i];} TTree* GetInputTreeTPCS(Int_t i) const {return fArrayTreeTPCS[i];} TTree* GetTreeD() const {return fTreeD;} - void Digitize(); + void Digitize(Option_t* option = 0); + void Exec(Option_t *option) {this->Digitize();} + void ExecuteTask(Option_t* option = 0); + // Nr of particles in all input files for a given event // (as numbered in the output file) Int_t GetNParticles(Int_t event); @@ -84,10 +87,6 @@ public: void SetDebug(Int_t level) {fDebug = level;} private: - AliDigitizer * fDigitizers[MAXDETECTORS]; //! pointers to registered - // digitizers -// the constant 20 corresponds to MAXDETECTORS = 20 - could be done better - Int_t fNDigitizers; //! nr. of registered digitizers Int_t fkMASK[MAXSTREAMSTOMERGE]; //! masks for track ids from // different source files Int_t fkMASKSTEP; // step to increase MASK for @@ -104,7 +103,7 @@ private: Int_t fNinputs; // nr of input streams - can be taken from the TClonesArray dimension Int_t fNinputsGiven; // nr of input streams given by user TClonesArray * fInputStreams; // input streams - TClonesArray * fInputFiles; // current input files + TFile * fInputFiles[MAXSTREAMSTOMERGE]; //! p. to current input files TTree * fArrayTreeS[MAXSTREAMSTOMERGE]; //! array with p. to TreeS TTree * fArrayTreeTPCS[MAXSTREAMSTOMERGE]; //! array with p. to TreeD_75x40_100x60_x (TPC Sdigits) TTree * fArrayTreeH[MAXSTREAMSTOMERGE]; //! array with p. to TreeH @@ -120,7 +119,7 @@ private: void FinishGlobal(); Int_t fDebug; //! specifies debug level, 0 is min - ClassDef(AliRunDigitizer,1) + ClassDef(AliRunDigitizer,2) }; #endif // ALIRUNDIGITIZER_H