X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=STEER%2FAliRun.cxx;h=d185070f9d7c1d3fb62947007bef364d7f46744b;hb=5cab551d37e064277494543a9980c60ffb59b461;hp=e41fb2903ff1470b3b74efcffa1a0d4f2abaad5f;hpb=7683c6957a0d4f9251cd71d8303ac103fbf80fbf;p=u%2Fmrichter%2FAliRoot.git diff --git a/STEER/AliRun.cxx b/STEER/AliRun.cxx index e41fb2903ff..d185070f9d7 100644 --- a/STEER/AliRun.cxx +++ b/STEER/AliRun.cxx @@ -40,38 +40,31 @@ // // /////////////////////////////////////////////////////////////////////////////// -#include -#include -#include - -#include "Riostream.h" -#include "TBRIK.h" -#include "TBrowser.h" -#include "TCint.h" -#include "TFile.h" -#include "TFolder.h" -#include "TGeometry.h" -#include "TNode.h" -#include "TParticle.h" -#include "TRandom3.h" -#include "TROOT.h" -#include "TSystem.h" -#include "TTree.h" - -#include "AliConfig.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include "AliLog.h" #include "AliDetector.h" #include "AliDisplay.h" -#include "AliGenerator.h" #include "AliHeader.h" #include "AliLego.h" #include "AliLegoGenerator.h" -#include "AliMCQA.h" +#include "AliMC.h" #include "AliMagFC.h" #include "AliMagFCM.h" #include "AliMagFDM.h" #include "AliPDG.h" #include "AliRun.h" #include "AliStack.h" +#include "AliAlignObj.h" AliRun *gAlice; @@ -83,95 +76,53 @@ AliRun::AliRun(): fEvent(0), fEventNrInRun(0), fEventsPerRun(0), - fDebug(0), - fHeader(0), - fTreeD(0), - fTreeS(0), - fTreeH(0), - fTreeTR(0), - fTreeE(0), - fTreeR(0), fModules(0), fGeometry(0), + fMCApp(0), fDisplay(0), - fTimer(), fField(0), - fMC(0), - fImedia(0), fNdets(0), - fTrRmax(1.e10), - fTrZmax(1.e10), - fGenerator(0), fInitDone(kFALSE), fLego(0), fPDGDB(0), //Particle factory object - fHitLists(0), - fEventEnergy(0), - fSummEnergy(0), - fSum2Energy(0), - fConfigFunction("\0"), + fConfigFunction(""), fRandom(0), - fMCQA(0), - fTransParName("\0"), - fBaseFileName("\0"), - fStack(0), - fTreeDFileName(""), - fTreeDFile(0), - fTreeSFileName(""), - fTreeSFile(0), - fTreeRFileName(""), - fTreeRFile(0) + fBaseFileName(""), + fIsRootGeometry(kFALSE), + fGeometryFileName(""), + fTriggerDescriptor(""), + fRunLoader(0x0) { // // Default constructor for AliRun // + AliConfig::Instance();//skowron 29 Feb 2002 + //ensures that the folder structure is build } //_______________________________________________________________________ AliRun::AliRun(const AliRun& arun): - TVirtualMCApplication(arun), + TNamed(arun), fRun(0), fEvent(0), fEventNrInRun(0), fEventsPerRun(0), - fDebug(0), - fHeader(0), - fTreeD(0), - fTreeS(0), - fTreeH(0), - fTreeTR(0), - fTreeE(0), - fTreeR(0), fModules(0), fGeometry(0), + fMCApp(0), fDisplay(0), - fTimer(), fField(0), - fMC(0), - fImedia(0), fNdets(0), - fTrRmax(1.e10), - fTrZmax(1.e10), - fGenerator(0), fInitDone(kFALSE), fLego(0), fPDGDB(0), //Particle factory object - fHitLists(0), - fEventEnergy(0), - fSummEnergy(0), - fSum2Energy(0), fConfigFunction("\0"), fRandom(0), - fMCQA(0), - fTransParName("\0"), - fBaseFileName("\0"), - fStack(0), - fTreeDFileName(""), - fTreeDFile(0), - fTreeSFileName(""), - fTreeSFile(0), - fTreeRFileName(""), - fTreeRFile(0) + fBaseFileName(""), + fIsRootGeometry(kFALSE), + fGeometryFileName(""), + fTriggerDescriptor(""), + fRunLoader(0x0) { // // Copy constructor for AliRun @@ -181,49 +132,27 @@ AliRun::AliRun(const AliRun& arun): //_____________________________________________________________________________ AliRun::AliRun(const char *name, const char *title): - TVirtualMCApplication(name,title), + TNamed(name,title), fRun(0), fEvent(0), fEventNrInRun(0), fEventsPerRun(0), - fDebug(0), - fHeader(new AliHeader()), - fTreeD(0), - fTreeS(0), - fTreeH(0), - fTreeTR(0), - fTreeE(0), - fTreeR(0), fModules(new TObjArray(77)), // Support list for the Detectors fGeometry(0), + fMCApp(0), fDisplay(0), - fTimer(), fField(0), - fMC(gMC), - fImedia(new TArrayI(1000)), fNdets(0), - fTrRmax(1.e10), - fTrZmax(1.e10), - fGenerator(0), fInitDone(kFALSE), fLego(0), fPDGDB(TDatabasePDG::Instance()), //Particle factory object! - fHitLists(new TList()), // Create HitLists list - fEventEnergy(0), - fSummEnergy(0), - fSum2Energy(0), fConfigFunction("Config();"), fRandom(new TRandom3()), - fMCQA(0), - fTransParName("\0"), - fBaseFileName("\0"), - fStack(new AliStack(10000)), //Particle stack - fTreeDFileName(""), - fTreeDFile(0), - fTreeSFileName(""), - fTreeSFile(0), - fTreeRFileName(""), - fTreeRFile(0) + fBaseFileName(""), + fIsRootGeometry(kFALSE), + fGeometryFileName(""), + fTriggerDescriptor(""), + fRunLoader(0x0) { // // Constructor for the main processor. @@ -243,21 +172,13 @@ AliRun::AliRun(const char *name, const char *title): // Add to list of browsable gROOT->GetListOfBrowsables()->Add(this,name); - - // Create the TNode geometry for the event display - BuildSimpleGeometry(); // Create default mag field SetField(); - // Prepare the tracking medium lists - for(Int_t i=0;i<1000;i++) (*fImedia)[i]=-99; - // Add particle list to configuration AliConfig::Instance()->Add(fPDGDB); - // Set transport parameters - SetTransPar(); } @@ -267,110 +188,39 @@ AliRun::~AliRun() // // Default AliRun destructor // - TFile *curfil =0; - if(fTreeE)curfil=fTreeE->GetCurrentFile(); - delete fImedia; + gROOT->GetListOfBrowsables()->Remove(this); + + if (fRunLoader) + { + TFolder* evfold = fRunLoader->GetEventFolder(); + TFolder* modfold = dynamic_cast(evfold->FindObjectAny(AliConfig::GetModulesFolderName())); + TIter next(fModules); + AliModule *mod; + while((mod = (AliModule*)next())) + { + modfold->Remove(mod); + } + } + + delete fField; - delete fMC; + delete fMCApp; + delete gMC; gMC=0; delete fGeometry; delete fDisplay; - delete fGenerator; delete fLego; - delete fTreeD; - delete fTreeH; - delete fTreeTR; - delete fTreeE; - delete fTreeR; - delete fTreeS; if (fModules) { fModules->Delete(); delete fModules; } - delete fStack; - delete fHitLists; + delete fPDGDB; - delete fMCQA; - delete fHeader; - // avoid to delete TFile objects not owned by this object - // avoid multiple deletions - if(curfil == fTreeDFile) fTreeDFile=0; - if(curfil == fTreeSFile) fTreeSFile=0; - if(curfil == fTreeRFile) fTreeRFile=0; - if(fTreeSFile == fTreeDFile) fTreeSFile=0; - if(fTreeRFile == fTreeDFile) fTreeRFile=0; - if(fTreeRFile == fTreeSFile) fTreeRFile=0; - if(fTreeDFile){ - if(fTreeDFile->IsOpen())fTreeDFile->Close(); - delete fTreeDFile; - } - if(fTreeSFile){ - if(fTreeSFile->IsOpen())fTreeSFile->Close(); - delete fTreeSFile; - } - if(fTreeRFile){ - if(fTreeRFile->IsOpen())fTreeRFile->Close(); - delete fTreeRFile; - } - if (gROOT->GetListOfBrowsables()) - gROOT->GetListOfBrowsables()->Remove(this); - - gAlice=0; -} - -//_______________________________________________________________________ -void AliRun::Copy(AliRun &) const -{ - // - // Copy method ... not implemented - // - Fatal("Copy","Not implemented!\n"); -} - -//_______________________________________________________________________ -void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const -{ - // - // Add a hit to detector id - // - TObjArray &dets = *fModules; - if(dets[id]) dynamic_cast(dets[id])->AddHit(track,vol,hits); -} - -//_______________________________________________________________________ -void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const -{ - // - // Add digit to detector id - // - TObjArray &dets = *fModules; - if(dets[id]) dynamic_cast(dets[id])->AddDigit(tracks,digits); } //_______________________________________________________________________ -void AliRun::Browse(TBrowser *b) +void AliRun::Copy(TObject &) const { - // - // Called when the item "Run" is clicked on the left pane - // of the Root browser. - // It displays the Root Trees and all detectors. - // - if(!fStack) fStack=fHeader->Stack(); - TTree* pTreeK = fStack->TreeK(); - - if (pTreeK) b->Add(pTreeK,pTreeK->GetName()); - if (fTreeH) b->Add(fTreeH,fTreeH->GetName()); - if (fTreeTR) b->Add(fTreeTR,fTreeH->GetName()); - if (fTreeD) b->Add(fTreeD,fTreeD->GetName()); - if (fTreeE) b->Add(fTreeE,fTreeE->GetName()); - if (fTreeR) b->Add(fTreeR,fTreeR->GetName()); - if (fTreeS) b->Add(fTreeS,fTreeS->GetName()); - - TIter next(fModules); - AliModule *detector; - while((detector = dynamic_cast(next()))) { - b->Add(detector,detector->GetName()); - } - b->Add(fMCQA,"AliMCQA"); + AliFatal("Not implemented!"); } //_______________________________________________________________________ @@ -403,52 +253,41 @@ void AliRun::CleanDetectors() // // Clean Detectors at the end of event // - TIter next(fModules); - AliModule *detector; - while((detector = dynamic_cast(next()))) { - detector->FinishEvent(); - } + fRunLoader->CleanDetectors(); } //_______________________________________________________________________ -Int_t AliRun::DistancetoPrimitive(Int_t, Int_t) const +void AliRun::ResetHits() { - // - // Return the distance from the mouse to the AliRun object - // Dummy routine - // - return 9999; + fMCApp->ResetHits(); } //_______________________________________________________________________ -void AliRun::DumpPart (Int_t i) const +AliGenerator* AliRun::Generator() const { - // - // Dumps particle i in the stack - // - fStack->DumpPart(i); + return fMCApp->Generator(); } //_______________________________________________________________________ -void AliRun::DumpPStack () const +void AliRun::SetField(AliMagF* magField) { // - // Dumps the particle stack + // Set Magnetic Field Map // - fStack->DumpPStack(); + fField = magField; + fField->ReadField(); } //_______________________________________________________________________ -void AliRun::SetField(AliMagF* magField) +void AliRun::SetRootGeometry(Bool_t flag) { - // Set Magnetic Field Map - fField = magField; - fField->ReadField(); +// Instruct application that the geometry is to be retreived from a root file. + fIsRootGeometry = flag; + if (flag) gMC->SetRootGeometry(); } - //_______________________________________________________________________ void AliRun::SetField(Int_t type, Int_t version, Float_t scale, - Float_t maxField, char* filename) + Float_t maxField, const char* filename) { // // Set magnetic field parameters @@ -469,139 +308,68 @@ void AliRun::SetField(Int_t type, Int_t version, Float_t scale, fField = new AliMagFDM("Map4",filename,type,scale,maxField); fField->ReadField(); } else { - Warning("SetField","Invalid map %d\n",version); + AliWarning(Form("Invalid map %d",version)); } } - -//_______________________________________________________________________ + +//_____________________________________________________________________________ + +void AliRun::InitLoaders() +{ + //creates list of getters + AliDebug(1, ""); + TIter next(fModules); + AliModule *mod; + while((mod = (AliModule*)next())) + { + mod->SetRunLoader(fRunLoader); + AliDetector *det = dynamic_cast(mod); + if (det) + { + AliDebug(2, Form("Adding %s", det->GetName())); + fRunLoader->AddLoader(det); + } + } + AliDebug(1, "Done"); +} +//_____________________________________________________________________________ + void AliRun::FinishRun() { // // Called at the end of the run. // - - // - if(fLego) fLego->FinishRun(); + + if(fLego) + { + AliDebug(1, "Finish Lego"); + fRunLoader->CdGAFile(); + fLego->FinishRun(); + } // Clean detector information TIter next(fModules); AliModule *detector; while((detector = dynamic_cast(next()))) { + AliDebug(2, Form("%s->FinishRun()", detector->GetName())); detector->FinishRun(); } - //Output energy summary tables - EnergySummary(); + AliDebug(1, "fRunLoader->WriteHeader(OVERWRITE)"); + fRunLoader->WriteHeader("OVERWRITE"); - TFile *file = fTreeE->GetCurrentFile(); - - file->cd(); - - fTreeE->Write(0,TObject::kOverwrite); - // Write AliRun info and all detectors parameters - Write(0,TObject::kOverwrite); - - // Clean tree information - - fStack->FinishRun(); - - if (fTreeH) { - delete fTreeH; fTreeH = 0; - } - if (fTreeTR) { - delete fTreeTR; fTreeTR = 0; - } - if (fTreeD) { - delete fTreeD; fTreeD = 0; - } - if (fTreeR) { - delete fTreeR; fTreeR = 0; - } -// if (fTreeE) { -// delete fTreeE; fTreeE = 0; -// } - if (fTreeS) { - delete fTreeS; fTreeS = 0; - } - fGenerator->FinishRun(); + fRunLoader->CdGAFile(); + Write(0,TObject::kOverwrite);//write AliRun + fRunLoader->Write(0,TObject::kOverwrite);//write RunLoader itself - // Close output file - file->Write(); -} + // Clean tree information + AliDebug(1, "fRunLoader->Stack()->FinishRun()"); + fRunLoader->Stack()->FinishRun(); -//_______________________________________________________________________ -void AliRun::FlagTrack(Int_t track) -{ - // Delegate to stack - // - fStack->FlagTrack(track); -} - -//_______________________________________________________________________ -void AliRun::EnergySummary() -{ - // - // Print summary of deposited energy - // + if(fMCApp) fMCApp->FinishRun(); - Int_t ndep=0; - Float_t edtot=0; - Float_t ed, ed2; - Int_t kn, i, left, j, id; - const Float_t kzero=0; - Int_t ievent=fHeader->GetEvent()+1; - // - // Energy loss information - if(ievent) { - printf("***************** Energy Loss Information per event (GEV) *****************\n"); - for(kn=1;kn0) { - fEventEnergy[ndep]=kn; - if(ievent>1) { - ed=ed/ievent; - ed2=fSum2Energy[kn]; - ed2=ed2/ievent; - ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed; - } else - ed2=99; - fSummEnergy[ndep]=ed; - fSum2Energy[ndep]=TMath::Min(static_cast(99.),TMath::Max(ed2,kzero)); - edtot+=ed; - ndep++; - } - } - for(kn=0;kn<(ndep-1)/3+1;kn++) { - left=ndep-kn*3; - for(i=0;i<(3VolName(id),fSummEnergy[j],fSum2Energy[j]); - } - printf("\n"); - } - // - // Relative energy loss in different detectors - printf("******************** Relative Energy Loss per event ********************\n"); - printf("Total energy loss per event %10.3f GeV\n",edtot); - for(kn=0;kn<(ndep-1)/5+1;kn++) { - left=ndep-kn*5; - for(i=0;i<(5VolName(id),100*fSummEnergy[j]/edtot); - } - printf("\n"); - } - for(kn=0;kn<75;kn++) printf("*"); - printf("\n"); - } - // - // Reset the TArray's - // fEventEnergy.Set(0); - // fSummEnergy.Set(0); - // fSum2Energy.Set(0); + fRunLoader->Synchronize(); } //_______________________________________________________________________ @@ -615,7 +383,7 @@ void AliRun::Announce() const printf("%6s","*");printf("%64s","*\n"); printf("%6s","*"); - printf(" You are running AliRoot version v3-09-06\n"); + printf(" You are running AliRoot version NewIO\n"); printf("%6s","*"); printf(" The cvs tag for the current program is $Name$\n"); @@ -658,667 +426,199 @@ Int_t AliRun::GetModuleID(const char *name) const //_______________________________________________________________________ Int_t AliRun::GetEvent(Int_t event) { - // - // Connect the Trees Kinematics and Hits for event # event - // Set branch addresses - // - - // Reset existing structures - ResetHits(); - ResetTrackReferences(); +// +// Reloads data containers in folders # event +// Set branch addresses +// + if (fRunLoader == 0x0) + { + AliError("RunLoader is not set. Can not load data."); + return -1; + } +/*****************************************/ +/**** P R E R E L O A D I N G ****/ +/*****************************************/ +// Reset existing structures + fMCApp->ResetHits(); + fMCApp->ResetTrackReferences(); ResetDigits(); ResetSDigits(); - - // Delete Trees already connected - if (fTreeH) { delete fTreeH; fTreeH = 0;} - if (fTreeTR) { delete fTreeTR; fTreeTR = 0;} - if (fTreeD) { delete fTreeD; fTreeD = 0;} - if (fTreeR) { delete fTreeR; fTreeR = 0;} - if (fTreeS) { delete fTreeS; fTreeS = 0;} - - // Create the particle stack - if (fHeader) delete fHeader; - fHeader = 0; - - // Get header from file - if(fTreeE) { - fTreeE->SetBranchAddress("Header", &fHeader); - - if (!fTreeE->GetEntry(event)) { - Error("GetEvent","Cannot find event:%d\n",event); - return -1; - } - } - else { - Error("GetEvent","Cannot find Header Tree (TE)\n"); - return -1; - } - - // Get the stack from the header, set fStack to 0 if it - // fails to get event - // - TFile *file = fTreeE->GetCurrentFile(); - char treeName[20]; - - file->cd(); - - if (fStack) delete fStack; - fStack = fHeader->Stack(); - if (fStack) { - if (!fStack->GetEvent(event)) fStack = 0; - } - - // Get Hits Tree header from file - sprintf(treeName,"TreeH%d",event); - fTreeH = dynamic_cast(gDirectory->Get(treeName)); - if (!fTreeH) { - Warning("GetEvent","cannot find Hits Tree for event:%d\n",event); - } - - // Get TracReferences Tree header from file - sprintf(treeName,"TreeTR%d",event); - fTreeTR = dynamic_cast(gDirectory->Get(treeName)); - if (!fTreeTR) { - Warning("GetEvent","cannot find TrackReferences Tree for event:%d\n",event); - } - - // get current file name and compare with names containing trees S,D,R - TString curfilname=static_cast(fTreeE->GetCurrentFile()->GetName()); - if(fTreeDFileName==curfilname)fTreeDFileName=""; - if(fTreeSFileName==curfilname)fTreeSFileName=""; - if(fTreeRFileName==curfilname)fTreeRFileName=""; - - // Get Digits Tree header from file - sprintf(treeName,"TreeD%d",event); - if (!fTreeDFile && fTreeDFileName != "") { - InitTreeFile("D",fTreeDFileName); - } - if (fTreeDFile) { - fTreeD = dynamic_cast(fTreeDFile->Get(treeName)); - } else { - fTreeD = dynamic_cast(file->Get(treeName)); - } - if (!fTreeD) { - // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event); - } - if(fTreeDFileName != ""){ - if(fTreeDFileName==fTreeSFileName) { - fTreeSFileName = ""; - fTreeSFile = fTreeDFile; - } - if(fTreeDFileName==fTreeRFileName) { - fTreeRFileName = ""; - fTreeRFile = fTreeDFile; - } - } - - file->cd(); - - // Get SDigits Tree header from file - sprintf(treeName,"TreeS%d",event); - if (!fTreeSFile && fTreeSFileName != "") { - InitTreeFile("S",fTreeSFileName); - } - if (fTreeSFile) { - fTreeS = dynamic_cast(fTreeSFile->Get(treeName)); - } else { - fTreeS = dynamic_cast(gDirectory->Get(treeName)); - } - if (!fTreeS) { - // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event); - } +/*****************************************/ +/**** R E L O A D ****/ +/*****************************************/ - if(fTreeSFileName != ""){ - if(fTreeSFileName==fTreeRFileName){ - fTreeRFileName = ""; - fTreeRFile = fTreeSFile; - } - } + fRunLoader->GetEvent(event); - file->cd(); - - // Get Reconstruct Tree header from file - sprintf(treeName,"TreeR%d",event); - if (!fTreeRFile && fTreeRFileName != "") { - InitTreeFile("R",fTreeRFileName); - } - if(fTreeRFile) { - fTreeR = dynamic_cast(fTreeRFile->Get(treeName)); - } else { - fTreeR = dynamic_cast(gDirectory->Get(treeName)); - } - if (!fTreeR) { - // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event); - } +/*****************************************/ +/**** P O S T R E L O A D I N G ****/ +/*****************************************/ - file->cd(); - // Set Trees branch addresses TIter next(fModules); AliModule *detector; - while((detector = dynamic_cast(next()))) { - detector->SetTreeAddress(); - } - - fEvent=event; //MI change - - return fHeader->GetNtrack(); + while((detector = dynamic_cast(next()))) + { + detector->SetTreeAddress(); + } + + return fRunLoader->GetHeader()->GetNtrack(); } //_______________________________________________________________________ TGeometry *AliRun::GetGeometry() { - // - // Import Alice geometry from current file - // Return pointer to geometry object - // - if (!fGeometry) fGeometry = dynamic_cast(gDirectory->Get("AliceGeom")); - // - // Unlink and relink nodes in detectors - // This is bad and there must be a better way... - // + // Create the TNode geometry for the event display + if (!fGeometry) { + BuildSimpleGeometry(); + // + // Unlink and relink nodes in detectors + // This is bad and there must be a better way... + // - TIter next(fModules); - AliModule *detector; - while((detector = dynamic_cast(next()))) { - TList *dnodes=detector->Nodes(); - Int_t j; - TNode *node, *node1; - for ( j=0; jGetSize(); j++) { - node = dynamic_cast(dnodes->At(j)); - node1 = fGeometry->GetNode(node->GetName()); - dnodes->Remove(node); - dnodes->AddAt(node1,j); + TIter next(fModules); + AliModule *detector; + while((detector = dynamic_cast(next()))) { + detector->BuildGeometry(); + TList *dnodes=detector->Nodes(); + Int_t j; + TNode *node, *node1; + for ( j=0; jGetSize(); j++) { + node = dynamic_cast(dnodes->At(j)); + node1 = fGeometry->GetNode(node->GetName()); + dnodes->Remove(node); + dnodes->AddAt(node1,j); + } } } return fGeometry; } //_______________________________________________________________________ -Int_t AliRun::GetPrimary(Int_t track) const +void AliRun::SetBaseFile(const char *filename) { - // - // return number of primary that has generated track - // - return fStack->GetPrimary(track); + fBaseFileName = filename; } - + //_______________________________________________________________________ -void AliRun::MediaTable() +void AliRun::ResetDigits() { // - // Built media table to get from the media number to - // the detector id - // - Int_t kz, nz, idt, lz, i, k, ind; - // Int_t ibeg; - TObjArray &dets = *gAlice->Detectors(); - AliModule *det; - // - // For all detectors - for (kz=0;kz(dets[kz]))) { - TArrayI &idtmed = *(det->GetIdtmed()); - for(nz=0;nz<100;nz++) { - // Find max and min material number - if((idt=idtmed[nz])) { - det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt; - det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt; - } - } - if(det->LoMedium() > det->HiMedium()) { - det->LoMedium() = 0; - det->HiMedium() = 0; - } else { - if(det->HiMedium() > fImedia->GetSize()) { - Error("MediaTable","Increase fImedia from %d to %d", - fImedia->GetSize(),det->HiMedium()); - return; - } - // Tag all materials in rage as belonging to detector kz - for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) { - (*fImedia)[lz]=kz; - } - } - } - } + // Reset all Detectors digits // - // Print summary table - printf(" Traking media ranges:\n"); - for(i=0;i<(fNdets-1)/6+1;i++) { - for(k=0;k< (6(dets[ind]); - if(det) - printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(), - det->HiMedium()); - else - printf(" %6s: %3d -> %3d;","NULL",0,0); - } - printf("\n"); + TIter next(fModules); + AliModule *detector; + while((detector = dynamic_cast(next()))) { + detector->ResetDigits(); } } //_______________________________________________________________________ -void AliRun::SetGenerator(AliGenerator *generator) +void AliRun::ResetSDigits() { // - // Load the event generator + // Reset all Detectors digits // - if(!fGenerator) fGenerator = generator; + TIter next(fModules); + AliModule *detector; + while((detector = dynamic_cast(next()))) { + detector->ResetSDigits(); + } } -//_______________________________________________________________________ -void AliRun::ResetGenerator(AliGenerator *generator) -{ - // - // Load the event generator - // - if(fGenerator) - if(generator) - Warning("ResetGenerator","Replacing generator %s with %s\n", - fGenerator->GetName(),generator->GetName()); - else - Warning("ResetGenerator","Replacing generator %s with NULL\n", - fGenerator->GetName()); - fGenerator = generator; -} //_______________________________________________________________________ -void AliRun::SetTransPar(const char *filename) + +void AliRun::ResetPoints() { // - // Sets the file name for transport parameters + // Reset all Detectors points // - fTransParName = filename; + TIter next(fModules); + AliModule *detector; + while((detector = dynamic_cast(next()))) { + detector->ResetPoints(); + } } - //_______________________________________________________________________ -void AliRun::SetBaseFile(const char *filename) -{ - fBaseFileName = filename; -} -//_______________________________________________________________________ -void AliRun::ReadTransPar() +void AliRun::InitMC(const char *setup) { // - // Read filename to set the transport parameters + // Initialize ALICE Simulation run // + Announce(); - - const Int_t kncuts=10; - const Int_t knflags=11; - const Int_t knpars=kncuts+knflags; - const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO", - "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI", - "BREM","COMP","DCAY","DRAY","HADR","LOSS", - "MULS","PAIR","PHOT","RAYL"}; - char line[256]; - char detName[7]; - char* filtmp; - Float_t cut[kncuts]; - Int_t flag[knflags]; - Int_t i, itmed, iret, ktmed, kz; - FILE *lun; - // - // See whether the file is there - filtmp=gSystem->ExpandPathName(fTransParName.Data()); - lun=fopen(filtmp,"r"); - delete [] filtmp; - if(!lun) { - Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data()); + if(fInitDone) { + AliWarning("Cannot initialise AliRun twice!"); return; } - // - if(fDebug) { - printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n"); - printf(" *%59s\n","*"); - printf(" * Please check carefully what you are doing!%10s\n","*"); - printf(" *%59s\n","*"); - } - // - while(1) { - // Initialise cuts and flags - for(i=0;iGetIdtmed(); - // Check that the tracking medium code is valid - if(0<=itmed && itmed < 100) { - ktmed=idtmed[itmed]; - if(!ktmed) { - Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName()); - continue; - } - // Set energy thresholds - for(kz=0;kz=0) { - if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n", - kpars[kz],cut[kz],itmed,mod->GetName()); - gMC->Gstpar(ktmed,kpars[kz],cut[kz]); - } - } - // Set transport mechanisms - for(kz=0;kz=0) { - if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n", - kpars[kncuts+kz],flag[kz],itmed,mod->GetName()); - gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz])); - } - } - } else { - Warning("ReadTransPar","Invalid medium code %d *\n",itmed); - continue; + + if (!fMCApp) + fMCApp=new AliMC(GetName(),GetTitle()); + + gROOT->LoadMacro(setup); + gInterpreter->ProcessLine(fConfigFunction.Data()); + + fRunLoader->CdGAFile(); + + AliPDG::AddParticlesToPdgDataBase(); + + fNdets = fModules->GetLast()+1; + + TIter next(fModules); + for(Int_t i=0; i(fModules->At(i)); + objlast = gDirectory->GetList()->Last(); + + // Add Detector histograms in Detector list of histograms + if (objlast) objfirst = gDirectory->GetList()->After(objlast); + else objfirst = gDirectory->GetList()->First(); + while (objfirst) + { + detector->Histograms()->Add(objfirst); + objfirst = gDirectory->GetList()->After(objfirst); } - } else { - if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName); - continue; + } + + fMCApp->Init(); + + //Must be here because some MCs (G4) adds detectors here and not in Config.C + InitLoaders(); + fRunLoader->MakeTree("E"); + if (fLego == 0x0) + { + fRunLoader->LoadKinematics("RECREATE"); + fRunLoader->LoadTrackRefs("RECREATE"); + fRunLoader->LoadHits("all","RECREATE"); } - } + fInitDone = kTRUE; + // + // Save stuff at the beginning of the file to avoid file corruption + fRunLoader->CdGAFile(); + Write(); + fEventNrInRun = -1; //important - we start Begin event from increasing current number in run } - //_______________________________________________________________________ -void AliRun::MakeTree(Option_t *option, const char *file) + +void AliRun::RunMC(Int_t nevent, const char *setup) { // - // Create the ROOT trees - // Loop on all detectors to create the Root branch (if any) + // Main function to be called to process a galice run + // example + // Root > gAlice.Run(); + // a positive number of events will cause the finish routine + // to be called // - - char hname[30]; - // - // Analyse options - const char *oK = strstr(option,"K"); - const char *oH = strstr(option,"H"); - const char *oTR = strstr(option,"T"); - const char *oE = strstr(option,"E"); - const char *oD = strstr(option,"D"); - const char *oR = strstr(option,"R"); - const char *oS = strstr(option,"S"); - // - - TDirectory *cwd = gDirectory; - - TBranch *branch = 0; - - if (oK) fStack->MakeTree(fEvent, file); - - if (oE && !fTreeE) { - fTreeE = new TTree("TE","Header"); - // branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0); - branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0); - branch->SetAutoDelete(kFALSE); - TFolder *folder = dynamic_cast(gROOT->FindObjectAny("/Folders/RunMC/Event/Header")); - if (folder) folder->Add(fHeader); -// branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0); -// branch->SetAutoDelete(kFALSE); -// if (folder) folder->Add(fStack); - fTreeE->Write(0,TObject::kOverwrite); - } - - if (file && branch) { - char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2]; - sprintf(outFile,"%s/%s",GetBaseFile(),file); - branch->SetFile(outFile); - TIter next( branch->GetListOfBranches()); - while ((branch=dynamic_cast(next()))) { - branch->SetFile(outFile); - } - if (GetDebug()>1) - printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file); - cwd->cd(); - delete outFile; - } - - if (oH && !fTreeH) { - sprintf(hname,"TreeH%d",fEvent); - fTreeH = new TTree(hname,"Hits"); - fTreeH->SetAutoSave(1000000000); //no autosave - fTreeH->Write(0,TObject::kOverwrite); - } - - if (oTR && !fTreeTR) { - sprintf(hname,"TreeTR%d",fEvent); - fTreeTR = new TTree(hname,"TrackReferences"); - fTreeTR->SetAutoSave(1000000000); //no autosave - fTreeTR->Write(0,TObject::kOverwrite); - } - - if (oD && !fTreeD) { - sprintf(hname,"TreeD%d",fEvent); - fTreeD = new TTree(hname,"Digits"); - fTreeD->Write(0,TObject::kOverwrite); - } - if (oS && !fTreeS) { - sprintf(hname,"TreeS%d",fEvent); - fTreeS = new TTree(hname,"SDigits"); - fTreeS->Write(0,TObject::kOverwrite); - } - if (oR && !fTreeR) { - sprintf(hname,"TreeR%d",fEvent); - fTreeR = new TTree(hname,"Reconstruction"); - fTreeR->Write(0,TObject::kOverwrite); - } - - // - // Create a branch for hits/digits for each detector - // Each branch is a TClonesArray. Each data member of the Hits classes - // will be in turn a subbranch of the detector master branch - TIter next(fModules); - AliModule *detector; - while((detector = dynamic_cast(next()))) { - if (oH) detector->MakeBranch(option,file); - if (oTR) detector->MakeBranchTR(option,file); - } -} - -//_______________________________________________________________________ -TParticle* AliRun::Particle(Int_t i) const -{ - // - // Returns particle i on the simulation stack - // - return fStack->Particle(i); -} - -//_______________________________________________________________________ -void AliRun::ResetDigits() -{ - // - // Reset all Detectors digits - // - TIter next(fModules); - AliModule *detector; - while((detector = dynamic_cast(next()))) { - detector->ResetDigits(); - } -} - -//_______________________________________________________________________ -void AliRun::ResetSDigits() -{ - // - // Reset all Detectors digits - // - TIter next(fModules); - AliModule *detector; - while((detector = dynamic_cast(next()))) { - detector->ResetSDigits(); - } -} - -//_______________________________________________________________________ -void AliRun::ResetHits() -{ - // - // Reset all Detectors hits - // - TIter next(fModules); - AliModule *detector; - while((detector = dynamic_cast(next()))) { - detector->ResetHits(); - } -} - -//_______________________________________________________________________ -void AliRun::ResetTrackReferences() -{ - // - // Reset all Detectors hits - // - TIter next(fModules); - AliModule *detector; - while((detector = dynamic_cast(next()))) { - detector->ResetTrackReferences(); - } -} - -//_______________________________________________________________________ -void AliRun::ResetPoints() -{ - // - // Reset all Detectors points - // - TIter next(fModules); - AliModule *detector; - while((detector = dynamic_cast(next()))) { - detector->ResetPoints(); - } -} - -//_______________________________________________________________________ -void AliRun::InitMC(const char *setup) -{ - // - // Initialize the Alice setup - // - - Announce(); - - if(fInitDone) { - Warning("Init","Cannot initialise AliRun twice!\n"); - return; - } - - gROOT->LoadMacro(setup); - gInterpreter->ProcessLine(fConfigFunction.Data()); - - // Register MC in configuration - AliConfig::Instance()->Add(gMC); - gMC->SetStack(fStack); - - gMC->DefineParticles(); //Create standard MC particles - AliPDG::AddParticlesToPdgDataBase(); - - TObject *objfirst, *objlast; - - fNdets = fModules->GetLast()+1; - - // - //=================Create Materials and geometry - gMC->Init(); - - // Added also after in case of interactive initialisation of modules - fNdets = fModules->GetLast()+1; - - TIter next(fModules); - AliModule *detector; - while((detector = dynamic_cast(next()))) { - detector->SetTreeAddress(); - objlast = gDirectory->GetList()->Last(); - - // Add Detector histograms in Detector list of histograms - if (objlast) objfirst = gDirectory->GetList()->After(objlast); - else objfirst = gDirectory->GetList()->First(); - while (objfirst) { - detector->Histograms()->Add(objfirst); - objfirst = gDirectory->GetList()->After(objfirst); - } - } - ReadTransPar(); //Read the cuts for all materials - - MediaTable(); //Build the special IMEDIA table - - //Initialise geometry deposition table - fEventEnergy.Set(gMC->NofVolumes()+1); - fSummEnergy.Set(gMC->NofVolumes()+1); - fSum2Energy.Set(gMC->NofVolumes()+1); - - //Compute cross-sections - gMC->BuildPhysics(); - - //Write Geometry object to current file. - fGeometry->Write(); - - fInitDone = kTRUE; - - fMCQA = new AliMCQA(fNdets); - - AliConfig::Instance(); - // - // Save stuff at the beginning of the file to avoid file corruption - Write(); -} - -//_______________________________________________________________________ -void AliRun::RunMC(Int_t nevent, const char *setup) -{ - // - // Main function to be called to process a galice run - // example - // Root > gAlice.Run(); - // a positive number of events will cause the finish routine - // to be called - // - fEventsPerRun = nevent; + fEventsPerRun = nevent; // check if initialisation has been done if (!fInitDone) InitMC(setup); // Create the Root Tree with one branch per detector - - MakeTree("ESDRT"); - - if (gSystem->Getenv("CONFIG_SPLIT_FILE")) { - MakeTree("K","Kine.root"); - MakeTree("H","Hits.root"); - } else { - MakeTree("KH"); - } + //Hits moved to begin event -> now we are crating separate tree for each event gMC->ProcessRun(nevent); @@ -1332,14 +632,14 @@ void AliRun::RunReco(const char *selected, Int_t first, Int_t last) // // Main function to be called to reconstruct Alice event // - cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl; + Int_t nev = fRunLoader->GetNumberOfEvents(); + AliDebug(1, Form("Found %d events", nev)); Int_t nFirst = first; - Int_t nLast = (last < 0)? static_cast(gAlice->TreeE()->GetEntries()) : last; + Int_t nLast = (last < 0)? nev : last; for (Int_t nevent = nFirst; nevent <= nLast; nevent++) { - cout << "Processing event "<< nevent << endl; + AliDebug(1, Form("Processing event %d", nevent)); GetEvent(nevent); - // MakeTree("R"); Digits2Reco(selected); } } @@ -1353,7 +653,6 @@ void AliRun::Hits2Digits(const char *selected) // for (Int_t nevent=0; neventTreeE()->GetEntries(); nevent++) { GetEvent(nevent); - // MakeTree("D"); Hits2SDigits(selected); SDigits2Digits(selected); } @@ -1386,53 +685,51 @@ void AliRun::Tree2Tree(Option_t *option, const char *selected) AliDetector *detector = 0; - TDirectory *cwd = gDirectory; - - TObject *obj; - - char outFile[32]; - - while((obj = next())) { - if (!dynamic_cast(obj)) - Fatal("Tree2Tree","Wrong type in fModules array\n"); - if (!(detector = dynamic_cast(obj))) continue; + while((detector = dynamic_cast(next()))) { if (selected) if (strcmp(detector->GetName(),selected)) continue; - if (!detector->IsActive()) continue; - if (gSystem->Getenv("CONFIG_SPLIT_FILE")) { - if (oS) { - sprintf(outFile,"SDigits.%s.root",detector->GetName()); - detector->MakeBranch("S",outFile); - } - if (oD) { - sprintf(outFile,"Digits.%s.root",detector->GetName()); - detector->MakeBranch("D",outFile); - } - if (oR) { - sprintf(outFile,"Reco.%s.root",detector->GetName()); - detector->MakeBranch("R",outFile); - } - } else { - detector->MakeBranch(option); - } - - cwd->cd(); - - if (oS) { - cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl; - detector->Hits2SDigits(); - } - if (oD) { - cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl; - detector->SDigits2Digits(); - } - if (oR) { - cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl; - detector->Digits2Reco(); - } - - cwd->cd(); - } + if (detector->IsActive()) + { + + AliLoader* loader = detector->GetLoader(); + if (loader == 0x0) continue; + + if (oS) + { + AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName())); + loader->LoadHits("read"); + if (loader->TreeS() == 0x0) loader->MakeTree("S"); + detector->MakeBranch(option); + detector->SetTreeAddress(); + detector->Hits2SDigits(); + loader->UnloadHits(); + loader->UnloadSDigits(); + } + if (oD) + { + AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName())); + loader->LoadSDigits("read"); + if (loader->TreeD() == 0x0) loader->MakeTree("D"); + detector->MakeBranch(option); + detector->SetTreeAddress(); + detector->SDigits2Digits(); + loader->UnloadSDigits(); + loader->UnloadDigits(); + } + if (oR) + { + AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName())); + loader->LoadDigits("read"); + if (loader->TreeR() == 0x0) loader->MakeTree("R"); + detector->MakeBranch(option); + detector->SetTreeAddress(); + detector->Digits2Reco(); + loader->UnloadDigits(); + loader->UnloadRecPoints(); + + } + } + } } //_______________________________________________________________________ @@ -1479,13 +776,10 @@ void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min, // // check if initialisation has been done - if (!fInitDone) InitMC(setup); - //Save current generator - AliGenerator *gen=Generator(); + // If runloader has been initialized, set the number of events per file to nc1 * nc2 // Set new generator if (!gener) gener = new AliLegoGenerator(); - ResetGenerator(gener); // // Configure Generator gener->SetRadiusRange(rmin, rmax); @@ -1497,21 +791,24 @@ void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min, //Create Lego object fLego = new AliLego("lego",gener); + if (!fInitDone) InitMC(setup); + //Save current generator + + AliGenerator *gen=fMCApp->Generator(); + fMCApp->ResetGenerator(gener); //Prepare MC for Lego Run gMC->InitLego(); //Run Lego Object + if (fRunLoader) fRunLoader->SetNumberOfEventsPerFile(nc1 * nc2); //gMC->ProcessRun(nc1*nc2+1); gMC->ProcessRun(nc1*nc2); - // Create only the Root event Tree - MakeTree("E"); - // End of this run, close files FinishRun(); // Restore current generator - ResetGenerator(gen); + fMCApp->ResetGenerator(gen); // Delete Lego Object delete fLego; fLego=0; } @@ -1526,337 +823,15 @@ void AliRun::SetConfigFunction(const char * config) fConfigFunction=config; } -//_______________________________________________________________________ -void AliRun::SetCurrentTrack(Int_t track) -{ - // - // Set current track number - // - fStack->SetCurrentTrack(track); -} - -//_______________________________________________________________________ -void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom, - Float_t *vpos, Float_t *polar, Float_t tof, - TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is) -{ -// Delegate to stack -// - - fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof, - mech, ntr, weight, is); -} - -//_______________________________________________________________________ -void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, - Double_t px, Double_t py, Double_t pz, Double_t e, - Double_t vx, Double_t vy, Double_t vz, Double_t tof, - Double_t polx, Double_t poly, Double_t polz, - TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is) -{ - // Delegate to stack - // - fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof, - polx, poly, polz, mech, ntr, weight, is); - -} - -//_______________________________________________________________________ -void AliRun::SetHighWaterMark(const Int_t nt) -{ - // - // Set high water mark for last track in event - fStack->SetHighWaterMark(nt); -} - -//_______________________________________________________________________ -void AliRun::KeepTrack(const Int_t track) -{ - // - // Delegate to stack - // - fStack->KeepTrack(track); -} - // // MC Application // -//_______________________________________________________________________ -void AliRun::ConstructGeometry() -{ - // - // Create modules, materials, geometry - // - - TStopwatch stw; - TIter next(fModules); - AliModule *detector; - printf("Geometry creation:\n"); - while((detector = dynamic_cast(next()))) { - stw.Start(); - // Initialise detector materials and geometry - detector->CreateMaterials(); - detector->CreateGeometry(); - printf("%10s R:%.2fs C:%.2fs\n", - detector->GetName(),stw.RealTime(),stw.CpuTime()); - } -} - -//_______________________________________________________________________ -void AliRun::InitGeometry() -{ - // - // Initialize detectors and display geometry - // - - printf("Initialisation:\n"); - TStopwatch stw; - TIter next(fModules); - AliModule *detector; - while((detector = dynamic_cast(next()))) { - stw.Start(); - // Initialise detector and display geometry - detector->Init(); - detector->BuildGeometry(); - printf("%10s R:%.2fs C:%.2fs\n", - detector->GetName(),stw.RealTime(),stw.CpuTime()); - } - -} - -//_______________________________________________________________________ -void AliRun::GeneratePrimaries() -{ - // - // Generate primary particles and fill them in the stack. - // - - Generator()->Generate(); -} - -//_______________________________________________________________________ -void AliRun::BeginEvent() -{ - // Clean-up previous event - // Energy scores - fEventEnergy.Reset(); - // Clean detector information - CleanDetectors(); - // Reset stack info - fStack->Reset(); - - - // - // Reset all Detectors & kinematics & trees - // - char hname[30]; - // - // Initialise event header - fHeader->Reset(fRun,fEvent,fEventNrInRun); - // - fStack->BeginEvent(fEvent); - - // - if(fLego) { - fLego->BeginEvent(); - return; - } - - // - - ResetHits(); - ResetTrackReferences(); - ResetDigits(); - ResetSDigits(); - - - if(fTreeH) { - fTreeH->Reset(); - sprintf(hname,"TreeH%d",fEvent); - fTreeH->SetName(hname); - } - - if(fTreeTR) { - fTreeTR->Reset(); - sprintf(hname,"TreeTR%d",fEvent); - fTreeTR->SetName(hname); - } - - if(fTreeD) { - fTreeD->Reset(); - sprintf(hname,"TreeD%d",fEvent); - fTreeD->SetName(hname); - fTreeD->Write(0,TObject::kOverwrite); - } - if(fTreeS) { - fTreeS->Reset(); - sprintf(hname,"TreeS%d",fEvent); - fTreeS->SetName(hname); - fTreeS->Write(0,TObject::kOverwrite); - } - if(fTreeR) { - fTreeR->Reset(); - sprintf(hname,"TreeR%d",fEvent); - fTreeR->SetName(hname); - fTreeR->Write(0,TObject::kOverwrite); - } -} - -//_______________________________________________________________________ -void AliRun::BeginPrimary() -{ - // - // Called at the beginning of each primary track - // - - // Reset Hits info - gAlice->ResetHits(); - gAlice->ResetTrackReferences(); - -} - -//_______________________________________________________________________ -void AliRun::PreTrack() -{ - // - // Method called before each track - // - TObjArray &dets = *fModules; - AliModule *module; - - for(Int_t i=0; i<=fNdets; i++) - if((module = dynamic_cast(dets[i]))) - module->PreTrack(); - - fMCQA->PreTrack(); -} - -//_______________________________________________________________________ -void AliRun::Stepping() -{ - // - // Called at every step during transport - // - - Int_t id = DetFromMate(gMC->GetMedium()); - if (id < 0) return; - - // - // --- If lego option, do it and leave - if (fLego) - fLego->StepManager(); - else { - Int_t copy; - //Update energy deposition tables - AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep()); - - //Call the appropriate stepping routine; - AliModule *det = dynamic_cast(fModules->At(id)); - if(det && det->StepManagerIsEnabled()) { - fMCQA->StepManager(id); - det->StepManager(); - } - } -} - -//_______________________________________________________________________ -void AliRun::PostTrack() -{ - // - // Called after a track has been trasported - // - TObjArray &dets = *fModules; - AliModule *module; - - for(Int_t i=0; i<=fNdets; i++) - if((module = dynamic_cast(dets[i]))) - module->PostTrack(); -} - -//_______________________________________________________________________ -void AliRun::FinishPrimary() -{ - // - // Called at the end of each primary track - // - - // static Int_t count=0; - // const Int_t times=10; - // This primary is finished, purify stack - fStack->PurifyKine(); - - TIter next(fModules); - AliModule *detector; - while((detector = dynamic_cast(next()))) { - detector->FinishPrimary(); - } - - // Write out hits if any - if (gAlice->TreeH()) { - gAlice->TreeH()->Fill(); - } - - // Write out hits if any - if (gAlice->TreeTR()) { - gAlice->TreeTR()->Fill(); - } - - // - // if(++count%times==1) gObjectTable->Print(); -} - -//_______________________________________________________________________ -void AliRun::FinishEvent() -{ - // - // Called at the end of the event. - // - - // - if(fLego) fLego->FinishEvent(); - - //Update the energy deposit tables - Int_t i; - for(i=0;iSetNprimary(fStack->GetNprimary()); - fHeader->SetNtrack(fStack->GetNtrack()); - - - // Write out the kinematics - fStack->FinishEvent(); - - // Write out the event Header information - if (fTreeE) { - fHeader->SetStack(fStack); - fTreeE->Fill(); - } - - - // Write Tree headers - TTree* pTreeK = fStack->TreeK(); - if (pTreeK) pTreeK->Write(0,TObject::kOverwrite); - if (fTreeH) fTreeH->Write(0,TObject::kOverwrite); - if (fTreeTR) fTreeTR->Write(0,TObject::kOverwrite); - - ++fEvent; - ++fEventNrInRun; -} - //_______________________________________________________________________ void AliRun::Field(const Double_t* x, Double_t *b) const { // - // Returns the magnetic field at point x[3] - // Units are kGauss + // Return the value of the magnetic field // Float_t xfloat[3]; for (Int_t i=0; i<3; i++) xfloat[i] = x[i]; @@ -1867,10 +842,9 @@ void AliRun::Field(const Double_t* x, Double_t *b) const for (Int_t j=0; j<3; j++) b[j] = bfloat[j]; } else { - printf("No mag field defined!\n"); + AliError("No mag field defined!"); b[0]=b[1]=b[2]=0.; } - } // @@ -1884,315 +858,110 @@ void AliRun::Streamer(TBuffer &R__b) if (R__b.IsReading()) { if (!gAlice) gAlice = this; - AliRun::Class()->ReadBuffer(R__b, this); - // gROOT->GetListOfBrowsables()->Add(this,"Run"); - fTreeE = dynamic_cast(gDirectory->Get("TE")); - if (fTreeE) { - fTreeE->SetBranchAddress("Header", &fHeader); - } - else Error("Streamer","cannot find Header Tree\n"); - - fTreeE->GetEntry(0); gRandom = fRandom; } else { AliRun::Class()->WriteBuffer(R__b, this); } } - - -//_______________________________________________________________________ -Int_t AliRun::CurrentTrack() const { - // - // Returns current track - // - return fStack->CurrentTrack(); -} - -//_______________________________________________________________________ -Int_t AliRun::GetNtrack() const { - // - // Returns number of tracks in stack - // - return fStack->GetNtrack(); -} - //_______________________________________________________________________ -TObjArray* AliRun::Particles() const { - // - // Returns pointer to Particles array - // - return fStack->Particles(); -} -//_______________________________________________________________________ -TTree* AliRun::TreeK() const { - // - // Returns pointer to the TreeK array - // - return fStack->TreeK(); -} - - -//_______________________________________________________________________ void AliRun::SetGenEventHeader(AliGenEventHeader* header) { - fHeader->SetGenEventHeader(header); -} - -//_______________________________________________________________________ -TFile* AliRun::InitFile(TString fileName) -{ -// -// create the file where the whole tree will be saved -// - TDirectory *wd = gDirectory; - TFile* file = TFile::Open(fileName,"update"); - gDirectory = wd; - if (!file->IsOpen()) { - Error("Cannot open file, %s\n",fileName); - return 0; - } - return file; + fRunLoader->GetHeader()->SetGenEventHeader(header); } - //_______________________________________________________________________ -TFile* AliRun::InitTreeFile(Option_t *option, TString fileName) -{ - // - // create the file where one of the following trees will be saved - // trees: S,D,R - // WARNING: by default these trees are saved on the file on which - // hits are stored. If you divert one of these trees, you cannot restore - // it to the original file (usually galice.root) in the same aliroot session - Bool_t oS = (strstr(option,"S")!=0); - Bool_t oR = (strstr(option,"R")!=0); - Bool_t oD = (strstr(option,"D")!=0); - Int_t choice[3]; - for (Int_t i=0; i<3; i++) choice[i] = 0; - if(oS)choice[0] = 1; - if(oD)choice[1] = 1; - if(oR)choice[2] = 1; - - TFile *ptr=0; - - if(!(oS || oR || oD))return ptr; - - Int_t active[3]; - for (Int_t i=0; i<3; i++) active[i] = 0; - if(fTreeSFileName != "") active[0] = 1; - if(fTreeDFileName != "") active[1] = 1; - if(fTreeDFileName != "") active[2] = 1; - - Bool_t alreadyopen1 = kFALSE; - Bool_t alreadyopen2 = kFALSE; - - if(oS){ - // if already active and same name with non-null ptr - if(active[0]==1 && fileName == fTreeSFileName && fTreeSFile){ - Warning("InitTreeFile","File %s already opened",fTreeSFileName.Data()); - ptr = fTreeSFile; - } - else { - // if already active with different name with non-null ptr - if(active[0]==1 && fileName != fTreeSFileName && fTreeSFile){ - // close the active files and also the other possible files in option - CloseTreeFile(option); - } - fTreeSFileName = fileName; - alreadyopen1 = - (active[1] == 1 && fTreeDFileName == fTreeSFileName && fTreeDFile); - alreadyopen2 = - (active[2] == 1 && fTreeRFileName == fTreeSFileName && fTreeRFile); - if(!(alreadyopen1 || alreadyopen2)){ - ptr = InitFile(fileName); - fTreeSFile = ptr; - } - else { - if(alreadyopen1){fTreeSFile = fTreeDFile; ptr = fTreeSFile;} - if(alreadyopen2){fTreeSFile = fTreeRFile; ptr = fTreeSFile;} - } - if(choice[1] == 1) { fTreeDFileName = fileName; fTreeDFile = ptr;} - if(choice[2] == 1) { fTreeRFileName = fileName; fTreeRFile = ptr;} - } - return ptr; - } - if(oD){ - // if already active and same name with non-null ptr - if(active[1]==1 && fileName == fTreeDFileName && fTreeDFile){ - Warning("InitTreeFile","File %s already opened",fTreeDFileName.Data()); - ptr = fTreeDFile; - } - else { - // if already active with different name with non-null ptr - if(active[1]==1 && fileName != fTreeDFileName && fTreeDFile){ - // close the active files and also the other possible files in option - CloseTreeFile(option); - } - fTreeDFileName = fileName; - alreadyopen1 = - (active[0] == 1 && fTreeSFileName == fTreeDFileName && fTreeSFile); - alreadyopen2 = - (active[2] == 1 && fTreeRFileName == fTreeDFileName && fTreeRFile); - if(!(alreadyopen1 || alreadyopen2)){ - ptr = InitFile(fileName); - fTreeDFile = ptr; - } - else { - if(alreadyopen1){fTreeDFile = fTreeSFile; ptr = fTreeDFile;} - if(alreadyopen2){fTreeDFile = fTreeRFile; ptr = fTreeDFile;} - } - if(choice[2] == 1) { fTreeRFileName = fileName; fTreeRFile = ptr;} - } - return ptr; - } +Int_t AliRun::GetEvNumber() const +{ +//Returns number of current event + if (fRunLoader == 0x0) + { + AliError("RunLoader is not set. Can not load data."); + return -1; + } - if(oR){ - // if already active and same name with non-null ptr - if(active[2]==1 && fileName == fTreeRFileName && fTreeRFile){ - Warning("InitTreeFile","File %s already opened",fTreeRFileName.Data()); - ptr = fTreeRFile; - } - else { - // if already active with different name with non-null ptr - if(active[2]==1 && fileName != fTreeRFileName && fTreeRFile){ - // close the active files and also the other possible files in option - CloseTreeFile(option); - } - fTreeRFileName = fileName; - alreadyopen1 = - (active[1] == 1 && fTreeDFileName == fTreeRFileName && fTreeDFile); - alreadyopen2 = - (active[0]== 1 && fTreeSFileName == fTreeRFileName && fTreeSFile); - if(!(alreadyopen1 || alreadyopen2)){ - ptr = InitFile(fileName); - fTreeRFile = ptr; - } - else { - if(alreadyopen1){fTreeRFile = fTreeDFile; ptr = fTreeRFile;} - if(alreadyopen2){fTreeRFile = fTreeSFile; ptr = fTreeRFile;} - } - } - return ptr; - } - return 0; + return fRunLoader->GetEventNumber(); } - //_______________________________________________________________________ -void AliRun::PrintTreeFile() + +void AliRun::SetRunLoader(AliRunLoader* rloader) { // - // prints the file names and pointer associated to S,D,R trees + // Set the loader of the run // - cout<<"===================================================\n"; - TFile *file = fTreeE->GetCurrentFile(); - TString curfilname=""; - if(file)curfilname=static_cast(file->GetName()); - cout<<" Current tree file name: "<IsOpen()){ - fTreeSFile->Close(); - delete fTreeSFile; - } - } - fTreeSFile = 0; - } - if(oD){ - fTreeDFileName = ""; - if(fTreeDFile){ - if(!((fTreeDFile == fTreeRFile) || (fTreeDFile == fTreeSFile)) && - fTreeDFile->IsOpen()){ - fTreeDFile->Close(); - delete fTreeDFile; - } - } - fTreeDFile = 0; - } - if(oR){ - fTreeRFileName = ""; - if(fTreeRFile){ - if(!((fTreeRFile == fTreeSFile) || (fTreeRFile == fTreeDFile)) && - fTreeRFile->IsOpen()){ - fTreeRFile->Close(); - delete fTreeRFile; + fRunLoader = rloader; + if (fRunLoader == 0x0) return; + + TString evfoldname; + TFolder* evfold = fRunLoader->GetEventFolder(); + if (evfold) evfoldname = evfold->GetName(); + else AliWarning("Did not get Event Folder from Run Loader"); + + if ( fRunLoader->GetAliRun() ) + {//if alrun already exists in folder + if (fRunLoader->GetAliRun() != this ) + {//and is different than this - crash + AliFatal("AliRun is already in Folder and it is not this object"); + return;//pro forma + }//else do nothing + } + else + { + evfold->Add(this);//Post this AliRun to Folder + } + + TIter next(fModules); + AliModule *module; + while((module = (AliModule*)next())) + { + if (evfold) AliConfig::Instance()->Add(module,evfoldname); + module->SetRunLoader(fRunLoader); + AliDetector* detector = dynamic_cast(module); + if (detector) + { + AliLoader* loader = fRunLoader->GetLoader(detector); + if (loader == 0x0) + { + AliError(Form("Can not get loader for detector %s", detector->GetName())); + } + else + { + AliDebug(1, Form("Setting loader for detector %s", detector->GetName())); + detector->SetLoader(loader); + } } - } - fTreeRFile = 0; - } + } } -//_______________________________________________________________________ -void AliRun::MakeTree(Option_t *option, TFile *file) +void AliRun::AddModule(AliModule* mod) { // - // Create some trees in the separate file + // Add a module to the module list // - const char *oD = strstr(option,"D"); - const char *oR = strstr(option,"R"); - const char *oS = strstr(option,"S"); - - TDirectory *cwd = gDirectory; - char hname[30]; - - if (oD) { - delete fTreeD; - sprintf(hname,"TreeD%d",fEvent); - file->cd(); - fTreeD = static_cast(file->Get("hname")); - if (!fTreeD) { - fTreeD = new TTree(hname,"Digits"); - fTreeD->Write(0,TObject::kOverwrite); - } - cwd->cd(); - } - if (oS) { - delete fTreeS; - sprintf(hname,"TreeS%d",fEvent); - file->cd(); - fTreeS = static_cast(file->Get("hname")); - if (!fTreeS) { - fTreeS = new TTree(hname,"SDigits"); - fTreeS->Write(0,TObject::kOverwrite); - } - cwd->cd(); - } + if (mod == 0x0) return; + if (strlen(mod->GetName()) == 0) return; + if (GetModuleID(mod->GetName()) >= 0) return; + + AliDebug(1, mod->GetName()); + if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod); + else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName()); - if (oR) { - delete fTreeR; - sprintf(hname,"TreeR%d",fEvent); - file->cd(); - fTreeR = static_cast(file->Get("hname")); - if (!fTreeR) { - fTreeR = new TTree(hname,"RecPoint"); - fTreeR->Write(0,TObject::kOverwrite); - } - cwd->cd(); - } + Modules()->Add(mod); + + fNdets++; +} + +// added by Alberto Colla +//_____________________________________________________________________________ +/*inline*/ Bool_t AliRun::IsFileAccessible(const char* fnam, EAccessMode mode) +{ return !gSystem->AccessPathName(fnam,mode);} + +//______________________________________________________ +/*inline*/ Bool_t AliRun::IsFileAccessible(Char_t* name,EAccessMode mode) +{ + TString str = name; gSystem->ExpandPathName(str); + return !gSystem->AccessPathName(str.Data(),mode); }