/*
$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
// 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
// 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("");
//
////////////////////////////////////////////////////////////////////////
#include "TFile.h"
#include "TTree.h"
+#include "TList.h"
// AliROOT includes
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) {
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;
}
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;
}
AliRunDigitizer::~AliRunDigitizer() {
// dtor
- if (fInputFiles) {
- delete fInputFiles;
- fInputFiles = 0;
- }
if (fInputStreams) {
delete fInputStreams;
fInputStreams = 0;
}
}
-
////////////////////////////////////////////////////////////////////////
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()) {
}
////////////////////////////////////////////////////////////////////////
-void AliRunDigitizer::Digitize()
+void AliRunDigitizer::Digitize(Option_t* option)
{
// get a new combination of inputs, connect input trees and loop
// over all digitizers
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();
// 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);
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;
{
// 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.");
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);
+ }
}
////////////////////////////////////////////////////////////////////////
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++;
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();
// 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
return 0;
*/
}
+
////////////////////////////////////////////////////////////////////////
+void AliRunDigitizer::ExecuteTask(Option_t* option)
+{
+// overwrite ExecuteTask to do Digitize only
+ if (!IsActive()) return;
+ Digitize(option);
+ fHasExecuted = kTRUE;
+ return;
+}
#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;}
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);
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
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
void FinishGlobal();
Int_t fDebug; //! specifies debug level, 0 is min
- ClassDef(AliRunDigitizer,1)
+ ClassDef(AliRunDigitizer,2)
};
#endif // ALIRUNDIGITIZER_H