//End_Html
// //
///////////////////////////////////////////////////////////////////////////////
+
#include <TNode.h>
#include <TObjArray.h>
+#include <TClonesArray.h>
+#include <TTree.h>
#include <TSystem.h>
+#include <TDirectory.h>
+#include <TVirtualMC.h>
+#include "AliLog.h"
+#include "AliConfig.h"
+#include "AliLoader.h"
+#include "AliMagF.h"
#include "AliModule.h"
#include "AliRun.h"
-#include "AliMagF.h"
-#include "AliConfig.h"
+#include "AliTrackReference.h"
+#include "AliMC.h"
+#include "../RAW/AliRawDataHeader.h"
ClassImp(AliModule)
fHistograms(0),
fNodes(0),
fDebug(0),
- fEnable(1)
+ fEnable(1),
+ fTrackReferences(0),
+ fMaxIterTrackRef(0),
+ fCurrentIterTrackRef(0),
+ fRunLoader(0)
{
//
// Default constructor for the AliModule class
fHistograms(new TList()),
fNodes(new TList()),
fDebug(0),
- fEnable(1)
+ fEnable(1),
+ fTrackReferences(new TClonesArray("AliTrackReference", 100)),
+ fMaxIterTrackRef(0),
+ fCurrentIterTrackRef(0),
+ fRunLoader(0)
{
//
// Normal constructor invoked by all Modules.
Int_t id = gAlice->GetModuleID(name);
if (id>=0) {
// Module already added !
- Warning("Ctor","Module: %s already present at %d\n",name,id);
+ AliWarning(Form("Module: %s already present at %d",name,id));
return;
}
//
// Add this Module to the list of Modules
- gAlice->Modules()->Add(this);
- //
- //
+
+ gAlice->AddModule(this);
+
SetMarkerColor(3);
//
// Clear space for tracking media and material indexes
for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
-
- AliConfig::Instance()->Add(this);
-
- SetDebug(gAlice->GetDebug());
}
//_______________________________________________________________________
fHistograms(0),
fNodes(0),
fDebug(0),
- fEnable(0)
+ fEnable(0),
+ fTrackReferences(0),
+ fMaxIterTrackRef(0),
+ fCurrentIterTrackRef(0),
+ fRunLoader(0)
{
//
// Copy constructor
//
// Remove this Module from the list of Modules
- gAlice->Modules()->Remove(this);
-
+ if (gAlice) {
+ TObjArray * modules = gAlice->Modules();
+ if (modules) modules->Remove(this);
+ }
// Delete ROOT geometry
if(fNodes) {
fNodes->Clear();
delete fNodes;
+ fNodes = 0;
+ }
+ // Delete histograms
+ if(fHistograms) {
+ fHistograms->Clear();
+ delete fHistograms;
+ fHistograms = 0;
+ }
+ // Delete track references
+ if (fTrackReferences) {
+ fTrackReferences->Delete();
+ delete fTrackReferences;
+ fTrackReferences = 0;
}
- //
// Delete TArray objects
delete fIdtmed;
delete fIdmate;
+
}
//_______________________________________________________________________
-void AliModule::Copy(AliModule & /* mod */) const
+void AliModule::Copy(TObject & /* mod */) const
{
//
// Copy *this onto mod, not implemented for AliModule
//
- Fatal("Copy","Not implemented!\n");
+ AliFatal("Not implemented!");
}
//_______________________________________________________________________
}
}
-//_______________________________________________________________________
-Int_t AliModule::DistancetoPrimitive(Int_t, Int_t) const
-{
- //
- // Return distance from mouse pointer to object
- // Dummy routine for the moment
- //
- return 9999;
-}
-
//_______________________________________________________________________
void AliModule::Enable()
{
lun=fopen(filtmp,"r");
delete [] filtmp;
if(!lun) {
- Error("ReadEuclid","Could not open file %s\n",filnam);
+ AliError(Form("Could not open file %s",filnam));
return;
}
//* --- definition of rotation matrix 0 ---
if (!strcmp(key,"TMED")) {
sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
if( itmed<0 || itmed>=100 ) {
- Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
+ AliError(Form("TMED illegal medium number %d for %s",itmed,natmed));
exit(1);
}
//Pad the string with blanks
natmed[i]='\0';
//
if( idtmed[itmed]<=0 ) {
- Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
+ AliError(Form("TMED undefined medium number %d for %s",itmed,natmed));
exit(1);
}
gMC->Gckmat(idtmed[itmed],natmed);
} else if (!strcmp(key,"ROTM")) {
sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
if( irot<=0 || irot>=kMaxRot ) {
- Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
+ AliError(Form("ROTM rotation matrix number %d illegal",irot));
exit(1);
}
AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
flag=0;
for(i=1;i<=nvol;i++) {
if (istop[i] && flag) {
- Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
+ AliWarning(Form(" %s is another possible top volume",volst[i]));
}
if (istop[i] && !flag) {
strcpy(topvol,volst[i]);
- if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
+ AliDebug(2, Form("volume %s taken as a top volume",topvol));
flag=1;
}
}
if (!flag) {
- Warning("ReadEuclid","top volume not found\n");
+ AliWarning("top volume not found");
}
fclose (lun);
//*
//* commented out only for the not cernlib version
- if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
+ AliDebug(1, Form("file: %s is now read in",filnam));
//
return;
//*
L20:
- Error("ReadEuclid","reading error or premature end of file\n");
+ AliError("reading error or premature end of file");
}
//_______________________________________________________________________
}
//
// *** The input filnam name will be with extension '.euc'
- if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
+ AliDebug(1, Form("The file name is %s",filnam)); //Debug
filtmp=gSystem->ExpandPathName(filnam);
lun=fopen(filtmp,"r");
delete [] filtmp;
if(!lun) {
- Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
+ AliWarning(Form("Could not open file %s",filnam));
return;
}
//
fclose (lun);
//*
//* commented out only for the not cernlib version
- if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
- ClassName(),filnam);
+ AliDebug(1, Form("file %s is now read in",filnam));
//*
return;
//*
L20:
- Warning("ReadEuclidMedia","reading error or premature end of file\n");
+ AliWarning("reading error or premature end of file");
}
+
+//_______________________________________________________________________
+void AliModule::RemapTrackReferencesIDs(Int_t *map)
+{
+ //
+ // Remapping track reference
+ // Called at finish primary
+ //
+ if (!fTrackReferences) return;
+ for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
+ AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
+ if (ref) {
+ Int_t newID = map[ref->GetTrack()];
+ if (newID>=0) ref->SetTrack(newID);
+ else {
+ //ref->SetTrack(-1);
+ ref->SetBit(kNotDeleted,kFALSE);
+ fTrackReferences->RemoveAt(i);
+ }
+ }
+ }
+ fTrackReferences->Compress();
+
+}
+
+
+//_______________________________________________________________________
+AliTrackReference* AliModule::FirstTrackReference(Int_t track)
+{
+ //
+ // Initialise the hit iterator
+ // Return the address of the first hit for track
+ // If track>=0 the track is read from disk
+ // while if track<0 the first hit of the current
+ // track is returned
+ //
+ if(track>=0)
+ {
+ if (fRunLoader == 0x0)
+ AliFatal("AliRunLoader not initialized. Can not proceed");
+ fRunLoader->GetAliRun()->GetMCApp()->ResetTrackReferences();
+ fRunLoader->TreeTR()->GetEvent(track);
+ }
+ //
+ fMaxIterTrackRef = fTrackReferences->GetEntriesFast();
+ fCurrentIterTrackRef = 0;
+ if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
+ else return 0;
+}
+
+//_______________________________________________________________________
+AliTrackReference* AliModule::NextTrackReference()
+{
+ //
+ // Return the next hit for the current track
+ //
+ if(fMaxIterTrackRef) {
+ if(++fCurrentIterTrackRef<fMaxIterTrackRef)
+ return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
+ else
+ return 0;
+ } else {
+ AliWarning("Iterator called without calling FistTrackReference before");
+ return 0;
+ }
+}
+
+
+//_______________________________________________________________________
+void AliModule::ResetTrackReferences()
+{
+ //
+ // Reset number of hits and the hits array
+ //
+ fMaxIterTrackRef = 0;
+ if (fTrackReferences) fTrackReferences->Clear();
+}
+//_____________________________________________________________________________
+
+AliLoader* AliModule::MakeLoader(const char* /*topfoldername*/)
+{
+ return 0x0;
+}
+//PH Merged with v3-09-08 |
+// V
+//_____________________________________________________________________________
+
+void AliModule::SetTreeAddress()
+{
+ //
+ // Set branch address for track reference Tree
+ //
+
+ TBranch *branch;
+
+ // Branch address for track reference tree
+ TTree *treeTR = TreeTR();
+
+ if (treeTR && fTrackReferences) {
+ branch = treeTR->GetBranch(GetName());
+ if (branch)
+ {
+ AliDebug(3, Form("(%s) Setting for TrackRefs",GetName()));
+ branch->SetAddress(&fTrackReferences);
+ }
+ else
+ {
+ //can be called before MakeBranch and than does not make sense to issue the warning
+ AliDebug(1, Form("(%s) Failed for Track References. Can not find branch in tree.",
+ GetName()));
+ }
+ }
+}
+
+//_____________________________________________________________________________
+void AliModule::AddTrackReference(Int_t label){
+ //
+ // add a trackrefernce to the list
+ if (!fTrackReferences) {
+ AliError("Container trackrefernce not active");
+ return;
+ }
+ Int_t nref = fTrackReferences->GetEntriesFast();
+ TClonesArray &lref = *fTrackReferences;
+ new(lref[nref]) AliTrackReference(label);
+}
+
+
+//_____________________________________________________________________________
+void AliModule::MakeBranchTR(Option_t */*option*/)
+{
+ //
+ // Makes branch in treeTR
+ //
+ AliDebug(2,Form("Making Track Refs. Branch for %s",GetName()));
+ TTree * tree = TreeTR();
+ if (fTrackReferences && tree)
+ {
+ TBranch *branch = tree->GetBranch(GetName());
+ if (branch)
+ {
+ AliDebug(2,Form("Branch %s is already in tree.",GetName()));
+ return;
+ }
+
+ branch = tree->Branch(GetName(),&fTrackReferences);
+ }
+ else
+ {
+ AliDebug(2,Form("FAILED for %s: tree=%#x fTrackReferences=%#x",
+ GetName(),tree,fTrackReferences));
+ }
+}
+
+//_____________________________________________________________________________
+TTree* AliModule::TreeTR()
+{
+ //
+ // Return TR tree pointer
+ //
+ if ( fRunLoader == 0x0)
+ {
+ AliError("Can not get the run loader");
+ return 0x0;
+ }
+
+ TTree* tree = fRunLoader->TreeTR();
+ return tree;
+}
+
+
+//_____________________________________________________________________________
+void AliModule::Digits2Raw()
+{
+// This is a dummy version that just copies the digits file contents
+// to a raw data file.
+
+ AliWarning(Form("Dummy version called for %s", GetName()));
+
+ const Int_t kNDetectors = 17;
+ const char* kDetectors[kNDetectors] = {"TPC", "ITSSPD", "ITSSDD", "ITSSSD", "TRD", "TOF", "PHOS", "RICH", "EMCAL", "MUON", "MUTR", "ZDC", "PMD", "START", "VZERO", "CRT", "FMD"};
+ const Int_t kDetectorDDLs[kNDetectors] = {216, 20, 12, 16, 18, 72, 20, 20, 22, 20, 2, 1, 6, 1, 1, 1, 3};
+ Int_t nDDLs = 1;
+ Int_t ddlOffset = 0;
+ for (Int_t i = 0; i < kNDetectors; i++) {
+ if (strcmp(GetName(), kDetectors[i]) == 0) {
+ nDDLs = kDetectorDDLs[i];
+ ddlOffset = 0x100 * i;
+ }
+ }
+
+ if (!GetLoader()) return;
+ fstream digitsFile(GetLoader()->GetDigitsFileName(), ios::in);
+ if (!digitsFile) return;
+
+ digitsFile.seekg(0, ios::end);
+ UInt_t size = digitsFile.tellg();
+ UInt_t ddlSize = 4 * (size / (4*nDDLs));
+ Char_t* buffer = new Char_t[ddlSize+1];
+
+ for (Int_t iDDL = 0; iDDL < nDDLs; iDDL++) {
+ char fileName[20];
+ sprintf(fileName, "%s_%d.ddl", GetName(), iDDL + ddlOffset);
+ fstream rawFile(fileName, ios::out);
+ if (!rawFile) return;
+
+ AliRawDataHeader header;
+ header.fSize = ddlSize + sizeof(header);
+ rawFile.write((char*) &header, sizeof(header));
+
+ digitsFile.read(buffer, ddlSize);
+ rawFile.write(buffer, ddlSize);
+ rawFile.close();
+ }
+
+ digitsFile.close();
+ delete[] buffer;
+}
+
+
+//_____________________________________________________________________________
+Int_t AliModule::GetDebug() const
+{
+ AliWarning("Don't use this method any more, use AliDebug instead");
+ return 0;
+}