]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliModule.cxx
Using AliPHOSLoader instead of AliPHOSGetter
[u/mrichter/AliRoot.git] / STEER / AliModule.cxx
index 57afb02446db132fbf062e2671add8ea370ca99b..fc3a2545df164fbf578b8c8be232231960db678b 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.11  2000/07/12 08:56:25  fca
-Coding convention correction and warning removal
-
-Revision 1.10  2000/07/11 18:24:59  fca
-Coding convention corrections + few minor bug fixes
-
-Revision 1.9  2000/05/16 08:45:08  fca
-Correct dtor, thanks to J.Belikov
-
-Revision 1.8  2000/02/23 16:25:22  fca
-AliVMC and AliGeant3 classes introduced
-ReadEuclid moved from AliRun to AliModule
-
-Revision 1.7  1999/09/29 09:24:29  fca
-Introduction of the Copyright and cvs Log
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -50,109 +32,135 @@ Introduction of the Copyright and cvs Log
 //End_Html
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
-#include <TClass.h>
+
 #include <TNode.h>
-#include <TRandom.h>
-#include "TSystem.h"
+#include <TObjArray.h>
+#include <TClonesArray.h>
+#include <TTree.h>
+#include <TSystem.h>
+#include <TDirectory.h>
+#include <TVirtualMC.h>
+#include <TGeoManager.h>
+#include <TString.h>
 
+#include "AliLog.h"
+#include "AliConfig.h"
+#include "AliLoader.h"
+#include "AliMagF.h"
 #include "AliModule.h"
 #include "AliRun.h"
-#include "AliHit.h"
-#include "AliPoints.h"
-#include "AliMagF.h"
+#include "AliTrackReference.h"
 #include "AliMC.h"
+#include "AliRawDataHeader.h"
+
+#include "AliDAQ.h"
 
 ClassImp(AliModule)
  
-//_____________________________________________________________________________
-AliModule::AliModule()
+Float_t AliModule::fgDensityFactor = 1.0;
+//_______________________________________________________________________
+AliModule::AliModule():
+  fEuclidMaterial(""),
+  fEuclidGeometry(""),
+  fIdtmed(0),
+  fIdmate(0),
+  fLoMedium(0),
+  fHiMedium(0),
+  fActive(0),
+  fHistograms(0),
+  fNodes(0),
+  fEnable(1),
+  fTrackReferences(0),
+  fMaxIterTrackRef(0),
+  fCurrentIterTrackRef(0),
+  fRunLoader(0)
 {
   //
   // Default constructor for the AliModule class
   //
-  fHistograms = 0;
-  fNodes      = 0;
-  fIdtmed     = 0;
-  fIdmate     = 0;
 }
  
-//_____________________________________________________________________________
-AliModule::AliModule(const char* name,const char *title):TNamed(name,title)
+//_______________________________________________________________________
+AliModule::AliModule(const char* name,const char *title):
+  TNamed(name,title),
+  fEuclidMaterial(""),
+  fEuclidGeometry(""),
+  fIdtmed(new TArrayI(100)),
+  fIdmate(new TArrayI(100)),
+  fLoMedium(65536),
+  fHiMedium(0),
+  fActive(0),
+  fHistograms(new TList()),
+  fNodes(new TList()),
+  fEnable(1),
+  fTrackReferences(new TClonesArray("AliTrackReference", 100)),
+  fMaxIterTrackRef(0),
+  fCurrentIterTrackRef(0),
+  fRunLoader(0)
 {
   //
   // Normal constructor invoked by all Modules.
   // Create the list for Module specific histograms
   // Add this Module to the global list of Modules in Run.
   //
-  //
-  // Initialises the histogram list
-  fHistograms = new TList();
-  //
-  // Initialises the list of ROOT TNodes
-  fNodes      = new TList();
-  //  
   // Get the Module numeric ID
+
   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);
-  //
-  //
-  SetMarkerColor(3);
+
+  gAlice->AddModule(this);
+
+  //PH  SetMarkerColor(3);
   //
-  // Allocate space for tracking media and material indexes
-  fIdtmed = new TArrayI(100);
-  fIdmate  = new TArrayI(100);
+  // Clear space for tracking media and material indexes
+
   for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
-  //
-  // Prepare to find the tracking media range
-  fLoMedium = 65536;
-  fHiMedium = 0;
 }
  
-//_____________________________________________________________________________
-AliModule::AliModule(const AliModule &mod)
-{
-  //
-  // Copy constructor
-  //
-  mod.Copy(*this);
-}
-
-//_____________________________________________________________________________
+//_______________________________________________________________________
 AliModule::~AliModule()
 {
   //
   // Destructor
   //
-  fHistograms = 0;
-  //
+
+  // Remove this Module from the list of Modules
+  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
-{
-  //
-  // Copy *this onto mod, not implemented for AliModule
-  //
-  Fatal("Copy","Not implemented!\n");
-}
-
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::Disable()
 {
   //
@@ -164,22 +172,12 @@ void AliModule::Disable()
   //
   // Loop through geometry to disable all
   // nodes for this Module
-  while((node = (TNode*)next())) {
-    node->SetVisibility(0);
+  while((node = dynamic_cast<TNode*>(next()))) {
+    node->SetVisibility(-1);
   }   
 }
 
-//_____________________________________________________________________________
-Int_t AliModule::DistancetoPrimitive(Int_t, Int_t)
-{
-  //
-  // Return distance from mouse pointer to object
-  // Dummy routine for the moment
-  //
-  return 9999;
-}
-
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::Enable()
 {
   //
@@ -191,15 +189,15 @@ void AliModule::Enable()
   //
   // Loop through geometry to enable all
   // nodes for this Module
-  while((node = (TNode*)next())) {
-    node->SetVisibility(1);
+  while((node = dynamic_cast<TNode*>(next()))) {
+    node->SetVisibility(3);
   }   
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a, 
-                             Float_t z, Float_t dens, Float_t radl,
-                             Float_t absl, Float_t *buf, Int_t nwbuf) const
+                            Float_t z, Float_t dens, Float_t radl,
+                            Float_t absl, Float_t *buf, Int_t nwbuf) const
 {
   //
   // Store the parameters for a material
@@ -215,14 +213,27 @@ void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
   // nwbuf       number of user words
   //
   Int_t kmat;
-  gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
-  (*fIdmate)[imat]=kmat;
+  //Build the string uniquename as "DET_materialname"
+  TString uniquename = GetName();
+  uniquename.Append("_");
+  uniquename.Append(name);
+  //if geometry loaded from file only fill fIdmate, else create material too
+  if(gAlice->IsRootGeometry()){
+    TGeoMaterial *mat = gGeoManager->GetMaterial(uniquename.Data());
+    kmat = mat->GetUniqueID();
+    (*fIdmate)[imat]=kmat;
+  }else{
+    if (fgDensityFactor != 1.0)
+      AliWarning(Form("Material density multiplied by %.2f!", fgDensityFactor));
+    gMC->Material(kmat, uniquename.Data(), a, z, dens * fgDensityFactor, radl, absl, buf, nwbuf);
+    (*fIdmate)[imat]=kmat;
+  }
 }
   
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a, 
-                             Float_t &z, Float_t &dens, Float_t &radl,
-                             Float_t &absl)
+                               Float_t &z, Float_t &dens, Float_t &radl,
+                               Float_t &absl) const
 {
   //
   // Store the parameters for a material
@@ -245,10 +256,10 @@ void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
 }
   
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
-                            Float_t *z, Float_t dens, Int_t nlmat,
-                            Float_t *wmat) const
+                           Float_t *z, Float_t dens, Int_t nlmat,
+                           Float_t *wmat) const
 { 
   //
   // Defines mixture or compound imat as composed by 
@@ -270,16 +281,29 @@ void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
   // wmat        array of concentrations
   //
   Int_t kmat;
-  gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
-  (*fIdmate)[imat]=kmat;
+  //Build the string uniquename as "DET_mixturename"
+  TString uniquename = GetName();
+  uniquename.Append("_");
+  uniquename.Append(name);
+  //if geometry loaded from file only fill fIdmate, else create mixture too
+  if(gAlice->IsRootGeometry()){
+    TGeoMaterial *mat = gGeoManager->GetMaterial(uniquename.Data());
+    kmat = mat->GetUniqueID();
+    (*fIdmate)[imat]=kmat;
+  }else{
+    if (fgDensityFactor != 1.0)
+      AliWarning(Form("Material density multiplied by %.2f!", fgDensityFactor));
+    gMC->Mixture(kmat, uniquename.Data(), a, z, dens * fgDensityFactor, nlmat, wmat);
+    (*fIdmate)[imat]=kmat;
+  }
 } 
  
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
-                           Int_t isvol, Int_t ifield, Float_t fieldm,
-                           Float_t tmaxfd, Float_t stemax, Float_t deemax,
-                           Float_t epsil, Float_t stmin, Float_t *ubuf,
-                           Int_t nbuf) const
+                          Int_t isvol, Int_t ifield, Float_t fieldm,
+                          Float_t tmaxfd, Float_t stemax, Float_t deemax,
+                          Float_t epsil, Float_t stmin, Float_t *ubuf,
+                          Int_t nbuf) const
 { 
   //
   // Store the parameters of a tracking medium
@@ -303,15 +327,26 @@ void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
   //        =  3       constant magnetic field along z
   //  
   Int_t kmed;
-  gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
-                        tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf); 
-  (*fIdtmed)[numed]=kmed;
+  //Build the string uniquename as "DET_mediumname"
+  TString uniquename = GetName();
+  uniquename.Append("_");
+  uniquename.Append(name);
+  //if geometry loaded from file only fill fIdtmed, else create medium too
+  if(gAlice->IsRootGeometry()){
+    TGeoMedium *med = gGeoManager->GetMedium(uniquename.Data());
+    kmed = med->GetId();
+    (*fIdtmed)[numed]=kmed;
+  }else{
+    gMC->Medium(kmed, uniquename.Data(), (*fIdmate)[nmat], isvol, ifield,
+                fieldm, tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
+    (*fIdtmed)[numed]=kmed;
+  }
 } 
  
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
-                           Float_t theta2, Float_t phi2, Float_t theta3,
-                           Float_t phi3) const
+                          Float_t theta2, Float_t phi2, Float_t theta3,
+                          Float_t phi3) const
 {
   // 
   // Define a rotation matrix. Angles are in degrees.
@@ -327,14 +362,19 @@ void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
   gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3); 
 } 
 
-//_____________________________________________________________________________
-AliModule& AliModule::operator=(const AliModule &mod)
+//_______________________________________________________________________
+Float_t AliModule::ZMin() const
 {
-  mod.Copy(*this);
-  return (*this);
+  return -500;
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
+Float_t AliModule::ZMax() const
+{
+  return 500;
+}
+
+//_______________________________________________________________________
 void AliModule::SetEuclidFile(char* material, char* geometry)
 {
   //
@@ -352,7 +392,7 @@ void AliModule::SetEuclidFile(char* material, char* geometry)
   }
 }
  
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::ReadEuclid(const char* filnam, char* topvol)
 {
   //                                                                     
@@ -378,7 +418,7 @@ void AliModule::ReadEuclid(const char* filnam, char* topvol)
   char key[5], card[77], natmed[21];
   char name[5], mother[5], shape[5], konly[5], volst[7000][5];
   char *filtmp;
-  Float_t par[50];
+  Float_t par[100];
   Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
   Float_t xo, yo, zo;
   const Int_t kMaxRot=5000;
@@ -390,7 +430,7 @@ void AliModule::ReadEuclid(const char* filnam, char* topvol)
   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 ---  
@@ -409,7 +449,7 @@ void AliModule::ReadEuclid(const char* filnam, char* topvol)
   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
@@ -419,7 +459,7 @@ void AliModule::ReadEuclid(const char* filnam, char* topvol)
     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);
@@ -427,7 +467,7 @@ void AliModule::ReadEuclid(const char* filnam, char* topvol)
   } 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);
@@ -503,29 +543,29 @@ void AliModule::ReadEuclid(const char* filnam, char* topvol)
   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]);
-      printf(" *** GREUCL *** volume %s taken as a top volume\n",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
-  printf(" *** GREUCL *** file: %s is now read in\n",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");
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::ReadEuclidMedia(const char* filnam)
 {
   //                                                                     
@@ -555,12 +595,12 @@ void AliModule::ReadEuclidMedia(const char* filnam)
   }
   //
   // *** The input filnam name will be with extension '.euc'
-  printf("The file name is %s\n",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;
   }
   //
@@ -610,44 +650,132 @@ void AliModule::ReadEuclidMedia(const char* filnam)
   fclose (lun);
   //*
   //*     commented out only for the not cernlib version
-  Warning("ReadEuclidMedia","file: %s is now read in\n",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::AddAlignableVolumes() const
+{
+  // 
+  if (IsActive())
+    AliWarning(Form(" %s still has to implement the AddAlignableVolumes method!",GetName()));
+}
+
+//_______________________________________________________________________
+
+AliLoader*  AliModule::MakeLoader(const char* /*topfoldername*/)
+{
+  return 0x0;
+}
  
+
 //_____________________________________________________________________________
-void AliModule::Streamer(TBuffer &R__b)
-{
+AliTrackReference*  AliModule::AddTrackReference(Int_t label, Int_t id){
   //
-  // Stream an object of class Module.
-  //
-  if (R__b.IsReading()) {
-    Version_t R__v = R__b.ReadVersion(); if (R__v) { }
-    TNamed::Streamer(R__b);
-    TAttLine::Streamer(R__b);
-    TAttMarker::Streamer(R__b);
-    fEuclidMaterial.Streamer(R__b);
-    fEuclidGeometry.Streamer(R__b);
-    R__b >> fActive;
-    R__b >> fHistograms;
+  // add a trackrefernce to the list
+    return (gAlice->GetMCApp()->AddTrackReference(label, id));
+}
+
+ //_______________________________________________________________________
+AliTrackReference* AliModule::FirstTrackReference(Int_t track)
+{
     //
-    // Stream the pointers but not the TClonesArrays
-    R__b >> fNodes; // diff
-  } else {
-    R__b.WriteVersion(AliModule::IsA());
-    TNamed::Streamer(R__b);
-    TAttLine::Streamer(R__b);
-    TAttMarker::Streamer(R__b);
-    fEuclidMaterial.Streamer(R__b);
-    fEuclidGeometry.Streamer(R__b);
-    R__b << fActive;
-    R__b << fHistograms;
+    // Initialise the hit iterator
+    // Return the address of the first hit for track
+    // If track>=0 the track is read from disk
+    // while if track0 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()
+{
     //
-    // Stream the pointers but not the TClonesArrays
-    R__b << fNodes; // diff
+    // 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;
+    }
+}
+
+
+
+
+//_____________________________________________________________________________
+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()));
+
+  Int_t nDDLs = AliDAQ::NumberOfDdls(GetName());
+
+  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];
+    strcpy(fileName,AliDAQ::DdlFileName(GetName(),iDDL));
+    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;
 }