]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliRunDigitizer.cxx
Replacing Header with Id
[u/mrichter/AliRoot.git] / STEER / AliRunDigitizer.cxx
index 32eace15eaaa099cd7238955e8d3202c2a95508a..f263d0c317ee597c8abf2598b965c90dc93a324a 100644 (file)
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/
 
-/*
-$Log$
-Revision 1.15  2002/04/09 13:38:47  jchudoba
-Add const to the filename argument
-
-Revision 1.14  2002/04/04 09:28:04  jchudoba
-Change default names of TPC trees. Use update instead of recreate for the output file. Overwrite the AliRunDigitizer object in the output if it exists.
-
-Revision 1.13  2002/02/13 09:03:32  jchudoba
-Pass option to subtasks. Delete input TTrees. Use gAlice from memory if it is present (user must delete the default one created by aliroot if he/she wants to use gAlice from the input file!). Add new data member to store name of the special TPC TTrees.
-
-Revision 1.12  2001/12/10 16:40:52  jchudoba
-Import gAlice from the signal file before InitGlobal() to allow detectors to use it during initialization
-
-Revision 1.11  2001/12/03 07:10:13  jchudoba
-Default ctor cannot create new objects, create dummy default ctor which leaves object in not well defined state - to be used only by root for I/O
-
-Revision 1.10  2001/11/15 11:07:25  jchudoba
-Set to zero new pointers to TPC and TRD special trees in the default ctor. Add const to all Get functions. Remove unused constant, rename constant according coding rules.
-
-Revision 1.9  2001/11/15 09:00:11  jchudoba
-Add special treatment for TPC and TRD, they use different trees than other detectors
-
-Revision 1.8  2001/10/21 18:38:43  hristov
-Several pointers were set to zero in the default constructors to avoid memory management problems
-
-Revision 1.7  2001/10/04 15:56:07  jchudoba
-TTask inheritance
-
-Revision 1.4  2001/09/19 06:23:50  jchudoba
-Move some tasks to AliStream and AliMergeCombi classes
-
-Revision 1.3  2001/07/30 14:04:18  jchudoba
-correct bug in the initialization
-
-Revision 1.2  2001/07/28 10:44:32  hristov
-Loop variable declared once; typos corrected
-
-Revision 1.1  2001/07/27 12:59:00  jchudoba
-Manager class for merging/digitization
-
-*/
+/* $Id$ */
 
 ////////////////////////////////////////////////////////////////////////
 //
@@ -131,117 +90,172 @@ Manager class for merging/digitization
 
 // system includes
 
-#include <iostream.h>
+#include <Riostream.h>
 
 // ROOT includes
 
 #include "TFile.h"
-#include "TTree.h"
 #include "TList.h"
+#include "TTree.h"
 
 // AliROOT includes
 
-#include "AliRunDigitizer.h"
 #include "AliDigitizer.h"
+#include "AliMergeCombi.h"
 #include "AliRun.h"
-#include "AliHeader.h"
-#include "TParticle.h"
+#include "AliRunDigitizer.h"
 #include "AliStream.h"
-#include "AliMergeCombi.h"
 
 ClassImp(AliRunDigitizer)
 
-////////////////////////////////////////////////////////////////////////
-AliRunDigitizer::AliRunDigitizer()
+//_______________________________________________________________________
+AliRunDigitizer::AliRunDigitizer():
+  fkMASKSTEP(0),
+  fOutputFileName(0),
+  fOutputDirName(0),
+  fOutput(0),
+  fEvent(0),
+  fNrOfEventsToWrite(0),
+  fNrOfEventsWritten(0),
+  fCopyTreesFromInput(0),
+  fTreeD(0),
+  fTreeDTPC(0),
+  fTreeDTRD(0),
+  fTreeR(0),
+  fNinputs(0),
+  fNinputsGiven(0),
+  fInputStreams(0),
+  fTreeDTPCBaseName(0),
+  fTreeTPCSBaseName(0),
+  fCombi(0),
+  fCombination(0),
+  fCombinationFileName(0),
+  fDebug(0)
 {
-// root requires default ctor, where no new objects can be created
-// do not use this ctor, it is supplied only for root needs
-  
-// just set all pointers - data members to 0
-  fOutput = 0;
-  fTreeD = 0;
-  fTreeR = 0;
-  fTreeDTPC = 0;
-  fTreeDTRD = 0;
-  fInputStreams = 0;
+  //
+  // default ctor, where no new objects can be created
+  // do not use this ctor, it is supplied only for root needs
+  //
   for (Int_t i=0;i<kMaxStreamsToMerge;i++) {
     fArrayTreeS[i]=fArrayTreeH[i]=fArrayTreeTPCS[i]=fArrayTreeTRDS[i]=NULL;
     fInputFiles[i]=0;
   }
-  fCombi = 0;
+}
+
+//_______________________________________________________________________
+AliRunDigitizer::AliRunDigitizer(const AliRunDigitizer& dig):
+  TTask(dig),
+  fkMASKSTEP(0),
+  fOutputFileName(0),
+  fOutputDirName(0),
+  fOutput(0),
+  fEvent(0),
+  fNrOfEventsToWrite(0),
+  fNrOfEventsWritten(0),
+  fCopyTreesFromInput(0),
+  fTreeD(0),
+  fTreeDTPC(0),
+  fTreeDTRD(0),
+  fTreeR(0),
+  fNinputs(0),
+  fNinputsGiven(0),
+  fInputStreams(0),
+  fTreeDTPCBaseName(0),
+  fTreeTPCSBaseName(0),
+  fCombi(0),
+  fCombination(0),
+  fCombinationFileName(0),
+  fDebug(0)
+{
+  //
+  // Copy ctor
+  //
+  dig.Copy(*this);
+}
 
+//_______________________________________________________________________
+void AliRunDigitizer::Copy(AliRunDigitizer&) const
+{
+  Fatal("Copy","Not installed\n");
 }
 
-////////////////////////////////////////////////////////////////////////
-AliRunDigitizer::AliRunDigitizer(Int_t nInputStreams, Int_t sperb) : TTask("AliRunDigitizer","The manager for Merging")
+
+//_______________________________________________________________________
+AliRunDigitizer::AliRunDigitizer(Int_t nInputStreams, Int_t sperb):
+  TTask("AliRunDigitizer","The manager for Merging"),
+  fkMASKSTEP(10000000),
+  fOutputFileName(""),
+  fOutputDirName("."),
+  fOutput(0),
+  fEvent(0),
+  fNrOfEventsToWrite(-1),
+  fNrOfEventsWritten(0),
+  fCopyTreesFromInput(-1),
+  fTreeD(0),
+  fTreeDTPC(0),
+  fTreeDTRD(0),
+  fTreeR(0),
+  fNinputs(nInputStreams),
+  fNinputsGiven(0),
+  fInputStreams(new TClonesArray("AliStream",nInputStreams)),
+  fTreeDTPCBaseName("TreeD_75x40_100x60_150x60_"),
+  fTreeTPCSBaseName("TreeS_75x40_100x60_150x60_"),
+  fCombi(new AliMergeCombi(nInputStreams,sperb)),
+  fCombination(kMaxStreamsToMerge),
+  fCombinationFileName(0),
+  fDebug(0)
 {
-// ctor which should be used to create a manager for merging/digitization
+  //
+  // ctor which should be used to create a manager for merging/digitization
+  //
   if (nInputStreams == 0) {
     Error("AliRunDigitizer","Specify nr of input streams");
     return;
   }
-  Int_t i;
-  fNinputs = nInputStreams;
-  fOutputFileName = "";
-  fOutputDirName = ".";
-  fCombination.Set(kMaxStreamsToMerge);
-  for (i=0;i<kMaxStreamsToMerge;i++) {
+  for (Int_t i=0;i<kMaxStreamsToMerge;i++) {
     fArrayTreeS[i]=fArrayTreeH[i]=fArrayTreeTPCS[i]=fArrayTreeTRDS[i]=NULL;
     fCombination[i]=-1;
   }
-  fkMASKSTEP = 10000000;
   fkMASK[0] = 0;
-  for (i=1;i<kMaxStreamsToMerge;i++) {
+  for (Int_t i=1;i<kMaxStreamsToMerge;i++) {
     fkMASK[i] = fkMASK[i-1] + fkMASKSTEP;
   }
-  fInputStreams = new TClonesArray("AliStream",nInputStreams);
+
   TClonesArray &lInputStreams = *fInputStreams;
 // the first Input is open RW to be output as well
   new(lInputStreams[0]) AliStream("UPDATE");
-  for (i=1;i<nInputStreams;i++) {
+  for (Int_t i=1;i<nInputStreams;i++) {
     new(lInputStreams[i]) AliStream("READ");
   }
-  fOutput = 0;
-  fEvent = 0;
-  fNrOfEventsToWrite = -1;
-  fNrOfEventsWritten = 0;
-  fCopyTreesFromInput = -1;
-  fCombi = new AliMergeCombi(nInputStreams,sperb);
-  fDebug = 0;
-  fTreeD = 0;
-  fTreeR = 0;
-  fTreeDTPC = 0;
-  fTreeDTRD = 0;
-  fTreeDTPCBaseName = "TreeD_75x40_100x60_150x60_";
-  fTreeTPCSBaseName = "TreeS_75x40_100x60_150x60_";
-
-  for (i=0; i<kMaxStreamsToMerge; i++) fInputFiles[i]=0;
-}
 
-////////////////////////////////////////////////////////////////////////
+  for (Int_t i=0; i<kMaxStreamsToMerge; i++) fInputFiles[i]=0;
+}
 
+//_______________________________________________________________________
 AliRunDigitizer::~AliRunDigitizer() {
 // dtor
 
-  if (fInputStreams) {
+// do not delete subtasks, let the creator delete them
+  if (GetListOfTasks()) 
+    GetListOfTasks()->Clear("nodelete");
+  
     delete fInputStreams;
-    fInputStreams = 0;
-  }
-  if (fCombi) {
     delete fCombi;
-    fCombi = 0;
-  }
-
 }
-////////////////////////////////////////////////////////////////////////
+
+//_______________________________________________________________________
 void AliRunDigitizer::AddDigitizer(AliDigitizer *digitizer)
 {
 // add digitizer to the list of active digitizers
   this->Add(digitizer);
 }
-////////////////////////////////////////////////////////////////////////
+
+//_______________________________________________________________________
 void AliRunDigitizer::SetInputStream(Int_t i, const char *inputFile)
 {
+  //
+  // Sets the name of the input file
+  //
   if (i > fInputStreams->GetLast()) {
     Error("SetInputStream","Input stream number too high");
     return;
@@ -249,7 +263,7 @@ void AliRunDigitizer::SetInputStream(Int_t i, const char *inputFile)
   static_cast<AliStream*>(fInputStreams->At(i))->AddFile(inputFile);
 }
 
-////////////////////////////////////////////////////////////////////////
+//_______________________________________________________________________
 void AliRunDigitizer::Digitize(Option_t* option)
 {
 // get a new combination of inputs, connect input trees and loop 
@@ -282,7 +296,7 @@ void AliRunDigitizer::Digitize(Option_t* option)
   FinishGlobal();
 }
 
-////////////////////////////////////////////////////////////////////////
+//_______________________________________________________________________
 Bool_t AliRunDigitizer::ConnectInputTrees()
 {
 // fill arrays fArrayTreeS, fArrayTreeH and fArrayTreeTPCS with 
@@ -335,29 +349,28 @@ Bool_t AliRunDigitizer::ConnectInputTrees()
   return kTRUE;
 }
 
-////////////////////////////////////////////////////////////////////////
+//_______________________________________________________________________
 Bool_t AliRunDigitizer::InitGlobal()
 {
 // called once before Digitize() is called, initialize digitizers and output
 
-  TList* subTasks = this->GetListOfTasks();
+  TList* subTasks = 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
 {
+  // 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 by InitEvent()
@@ -374,7 +387,7 @@ Bool_t AliRunDigitizer::InitOutputGlobal()
 }
 
 
-////////////////////////////////////////////////////////////////////////
+//_______________________________________________________________________
 void AliRunDigitizer::InitEvent()
 {
 // Creates TreeDxx in the output file, called from Digitize() once for 
@@ -422,7 +435,7 @@ void AliRunDigitizer::InitEvent()
 
 }
 
-////////////////////////////////////////////////////////////////////////
+//_______________________________________________________________________
 void AliRunDigitizer::FinishEvent()
 {
 // called at the end of loop over digitizers
@@ -456,7 +469,8 @@ void AliRunDigitizer::FinishEvent()
     fTreeDTRD = 0;
   }
 }
-////////////////////////////////////////////////////////////////////////
+
+//_______________________________________________________________________
 void AliRunDigitizer::FinishGlobal()
 {
 // called at the end of Exec
@@ -468,11 +482,11 @@ void AliRunDigitizer::FinishGlobal()
     fInputFiles[fCopyTreesFromInput]->Get("TE")->Clone()->Write();
     gAlice->Write();
   }
-  fOutput->Close();
+  fOutput->Write();
 }
 
 
-////////////////////////////////////////////////////////////////////////
+//_______________________________________________________________________
 Int_t  AliRunDigitizer::GetNParticles(Int_t event) const
 {
 // return number of particles in all input files for a given
@@ -489,8 +503,8 @@ Int_t  AliRunDigitizer::GetNParticles(Int_t event) const
   return sum;
 }
 
-////////////////////////////////////////////////////////////////////////
-Int_t  AliRunDigitizer::GetNParticles(Int_t event, Int_t input) const
+//_______________________________________________________________________
+Int_t  AliRunDigitizer::GetNParticles(Int_t /* event */, Int_t /* input */) const
 {
 // return number of particles in input file input for a given
 // event (as numbered in this input file)
@@ -528,7 +542,7 @@ Int_t  AliRunDigitizer::GetNParticles(Int_t event, Int_t input) const
 */
 }
 
-////////////////////////////////////////////////////////////////////////
+//_______________________________________________________________________
 Int_t* AliRunDigitizer::GetInputEventNumbers(Int_t event) const
 {
 // return pointer to an int array with input event numbers which were
@@ -541,8 +555,9 @@ Int_t* AliRunDigitizer::GetInputEventNumbers(Int_t event) const
   }
   return a;
 }
-////////////////////////////////////////////////////////////////////////
-Int_t AliRunDigitizer::GetInputEventNumber(Int_t event, Int_t input) const
+
+//_______________________________________________________________________
+Int_t AliRunDigitizer::GetInputEventNumber(Int_t event, Int_t /* input */) const
 {
 // return an event number of an eventInput from input file input
 // which was merged to create output event event
@@ -550,7 +565,8 @@ Int_t AliRunDigitizer::GetInputEventNumber(Int_t event, Int_t input) const
 // simplified for now, implement later
   return event;
 }
-////////////////////////////////////////////////////////////////////////
+
+//_______________________________________________________________________
 TParticle* AliRunDigitizer::GetParticle(Int_t i, Int_t event) const
 {
 // return pointer to particle with index i (index with mask)
@@ -560,8 +576,9 @@ TParticle* AliRunDigitizer::GetParticle(Int_t i, Int_t event) const
   return GetParticle(i,input,GetInputEventNumber(event,input));
 }
 
-////////////////////////////////////////////////////////////////////////
-TParticle* AliRunDigitizer::GetParticle(Int_t i, Int_t input, Int_t event) const
+//_______________________________________________________________________
+TParticle* AliRunDigitizer::GetParticle(Int_t /* i */, Int_t /* input */, 
+                                        Int_t /* event */) const
 {
 // return pointer to particle with index i in the input file input
 // (index without mask)
@@ -620,7 +637,7 @@ TParticle* AliRunDigitizer::GetParticle(Int_t i, Int_t input, Int_t event) const
 */
 }
 
-////////////////////////////////////////////////////////////////////////
+//_______________________________________________________________________
 void AliRunDigitizer::ExecuteTask(Option_t* option)
 {
 // overwrite ExecuteTask to do Digitize only
@@ -630,3 +647,18 @@ void AliRunDigitizer::ExecuteTask(Option_t* option)
   fHasExecuted = kTRUE;
   return;
 }
+
+//_______________________________________________________________________
+TString AliRunDigitizer::GetInputFileName(const Int_t input, const Int_t order) const 
+{
+// returns file name of the order-th file in the input stream input
+// returns empty string if such file does not exist
+// first input stream is 0
+// first file in the input stream is 0
+  TString fileName("");
+  if (input >= fNinputs) return fileName;
+  AliStream * stream = static_cast<AliStream*>(fInputStreams->At(input));
+  if (order > stream->GetNInputFiles()) return fileName;
+  fileName = stream->GetFileName(order);
+  return fileName;
+}