]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
TTask inheritance
authorjchudoba <jchudoba@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 4 Oct 2001 15:56:34 +0000 (15:56 +0000)
committerjchudoba <jchudoba@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 4 Oct 2001 15:56:34 +0000 (15:56 +0000)
STEER/AliDigitizer.cxx
STEER/AliDigitizer.h
STEER/AliRunDigitizer.cxx
STEER/AliRunDigitizer.h

index 33f45896e5536db93abf6822af8b7085bd812f4f..4a1edc44283ca4f6700354f6ab7004ade84ca3e1 100644 (file)
@@ -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() {;}
index 07ca4e88931d9d984c60b12a9b2678c948c87ad1..e5a053531c8b6f0b48994263030d1c66df4de3b7 100644 (file)
@@ -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)
 };
 
index fb07f41dc684a80f75779a8c75020f13259f5d66..8584fcd6999581cd2c0425cb3dd7b955a3a95f76 100644 (file)
@@ -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"<<endl;
-  fCombi = 0;
-  fInputFiles = 0;
-  fNDigitizers = 0;
-  fNinputs = 0;
-  fInputStreams = 0;
-}
-
-////////////////////////////////////////////////////////////////////////
-AliRunDigitizer::AliRunDigitizer(Int_t nInputStreams, Int_t sperb) : TNamed("AliRunDigitizer","")
+AliRunDigitizer::AliRunDigitizer(Int_t nInputStreams, Int_t sperb) : TTask("AliRunDigitizer","The manager for Merging")
 {
 // default ctor
   if (nInputStreams == 0) {
@@ -127,11 +114,9 @@ AliRunDigitizer::AliRunDigitizer(Int_t nInputStreams, Int_t sperb) : TNamed("Ali
     return;
   }
   Int_t i;
-  for (i=0;i<MAXDETECTORS;i++) fDigitizers[i]=0;
-  fNDigitizers = 0;
   fNinputs = nInputStreams;
-  fOutputFileName = "digits.root";
-  fOutputDirName = "/tmp/";
+  fOutputFileName = "";
+  fOutputDirName = ".";
   fCombination.Set(MAXSTREAMSTOMERGE);
   for (i=0;i<MAXSTREAMSTOMERGE;i++) {
     fArrayTreeS[i]=fArrayTreeH[i]=fArrayTreeTPCS[i]=NULL;
@@ -144,17 +129,18 @@ AliRunDigitizer::AliRunDigitizer(Int_t nInputStreams, Int_t sperb) : TNamed("Ali
   }
   fInputStreams = new TClonesArray("AliStream",nInputStreams);
   TClonesArray &lInputStreams = *fInputStreams;
-  for (i=0;i<nInputStreams;i++) {
+// the first Input is open RW to be output as well
+  new(lInputStreams[0]) AliStream("UPDATE");
+  for (i=1;i<nInputStreams;i++) {
     new(lInputStreams[i]) AliStream();
   }
-  fInputFiles = new TClonesArray("TFile",1);
   fOutput = 0;
   fEvent = 0;
-  fNrOfEventsToWrite = 0;
+  fNrOfEventsToWrite = -1;
   fNrOfEventsWritten = 0;
   fCopyTreesFromInput = -1;
   fCombi = new AliMergeCombi(nInputStreams,sperb);
-  fDebug = 3;
+  fDebug = 0;
   if (GetDebug()>2) 
     cerr<<"AliRunDigitizer::AliRunDigitizer() called"<<endl;
 }
@@ -164,10 +150,6 @@ AliRunDigitizer::AliRunDigitizer(Int_t nInputStreams, Int_t sperb) : TNamed("Ali
 AliRunDigitizer::~AliRunDigitizer() {
 // dtor
 
-  if (fInputFiles) {
-    delete fInputFiles;
-    fInputFiles = 0;
-  }
   if (fInputStreams) {
     delete fInputStreams;
     fInputStreams = 0;
@@ -178,23 +160,13 @@ AliRunDigitizer::~AliRunDigitizer() {
   }
 
 }
-
 ////////////////////////////////////////////////////////////////////////
 void AliRunDigitizer::AddDigitizer(AliDigitizer *digitizer)
 {
 // add digitizer to the list of active digitizers
-
-  if (fNDigitizers >= MAXDETECTORS) {
-    cerr<<"Too many detectors to digitize. Increase value of MAXDETECTORS"
-       <<" constant in AliRunDigitizer.h and recompile or decrease the"
-       <<" the number of detectors"<<endl;
-  } else {
-    fDigitizers[fNDigitizers++] = digitizer;
-  }
+  this->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;i<fNDigitizers; i++) {
-      fDigitizers[i]->Digitize();
-    }
+    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<AliStream*>(fInputStreams->At(i));
       if (!iStream->NextEventInStream(serialNr)) return kFALSE;
+      fInputFiles[i]=iStream->CurrentFile();
       sprintf(treeName,"TreeS%d",serialNr);
       tree = static_cast<TTree*>(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;i<fNDigitizers; i++) {
-    if (!fDigitizers[i]->Init()) 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<AliStream*>(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 "<<fn.Data()<<" was opened"<<endl;
-    cerr<<"fOutput = "<<fOutput<<endl;
+    cerr<<"AliRunDigitizer::InitOutputGlobal(): file "<<fn.Data()<<" was opened"<<endl;
   }
   if (fOutput) return kTRUE;
   Error("InitOutputGlobal","Could not create output file.");
@@ -306,11 +287,19 @@ void AliRunDigitizer::InitEvent()
 
   if (GetDebug()>2) 
     cerr<<"AliRunDigitizer::InitEvent: fEvent = "<<fEvent<<endl;
+
+// if fOutputFileName was not given, write output to signal file
+  if (fOutputFileName == "") {
+    fOutput = (static_cast<AliStream*>(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<TTree*>(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 iit 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;
+}
index 3083f5947b13cef51f1bf2db4108549e4a87ec21..63ec6269e987a843be0f39711828a74495fe76b7 100644 (file)
@@ -20,6 +20,7 @@
 #include "TClonesArray.h"
 #include "TTree.h"
 #include "TParticle.h"
+#include "TTask.h"
 
 #define MAXDETECTORS 20
 #define MAXSTREAMSTOMERGE  4
 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