]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliModule.cxx
Restored functionality
[u/mrichter/AliRoot.git] / STEER / AliModule.cxx
index e2fb9fc9cb5378e701db3bca902d77486d1b41a4..f11805c475b7ce967c1d8ab1e706e82a19b1a906 100644 (file)
 //End_Html
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
+
 #include <TNode.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 "AliMagF.h"
-#include "AliConfig.h"
 #include "AliTrackReference.h"
+#include "AliMC.h"
+#include "AliRawDataHeader.h"
+
+#include "AliDAQ.h"
 
 ClassImp(AliModule)
  
@@ -58,11 +68,11 @@ AliModule::AliModule():
   fActive(0),
   fHistograms(0),
   fNodes(0),
-  fDebug(0),
   fEnable(1),
   fTrackReferences(0),
   fMaxIterTrackRef(0),
-  fCurrentIterTrackRef(0)
+  fCurrentIterTrackRef(0),
+  fRunLoader(0)
 {
   //
   // Default constructor for the AliModule class
@@ -81,11 +91,11 @@ AliModule::AliModule(const char* name,const char *title):
   fActive(0),
   fHistograms(new TList()),
   fNodes(new TList()),
-  fDebug(0),
   fEnable(1),
   fTrackReferences(new TClonesArray("AliTrackReference", 100)),
   fMaxIterTrackRef(0),
-  fCurrentIterTrackRef(0)
+  fCurrentIterTrackRef(0),
+  fRunLoader(0)
 {
   //
   // Normal constructor invoked by all Modules.
@@ -93,55 +103,25 @@ AliModule::AliModule(const char* name,const char *title):
   // Add this Module to the global list of Modules in Run.
   //
   // 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);
   //
   // 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());
 }
  
-//_______________________________________________________________________
-AliModule::AliModule(const AliModule &mod):
-  TNamed(mod),
-  TAttLine(mod),
-  TAttMarker(mod),
-  AliRndm(mod),
-  fEuclidMaterial(""),
-  fEuclidGeometry(""),
-  fIdtmed(0),
-  fIdmate(0),
-  fLoMedium(0),
-  fHiMedium(0),
-  fActive(0),
-  fHistograms(0),
-  fNodes(0),
-  fDebug(0),
-  fEnable(0),
-  fTrackReferences(0),
-  fMaxIterTrackRef(0),
-  fCurrentIterTrackRef(0)
-{
-  //
-  // Copy constructor
-  //
-  mod.Copy(*this);
-}
-
 //_______________________________________________________________________
 AliModule::~AliModule()
 {
@@ -158,27 +138,26 @@ AliModule::~AliModule()
   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()
 {
@@ -196,16 +175,6 @@ void AliModule::Disable()
   }   
 }
 
-//_______________________________________________________________________
-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()
 {
@@ -242,8 +211,19 @@ 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{
+    gMC->Material(kmat, uniquename.Data(), a, z, dens, radl, absl, buf, nwbuf);
+    (*fIdmate)[imat]=kmat;
+  }
 }
   
 //_______________________________________________________________________
@@ -297,8 +277,19 @@ 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{
+    gMC->Mixture(kmat, uniquename.Data(), a, z, dens, nlmat, wmat);
+    (*fIdmate)[imat]=kmat;
+  }
 } 
  
 //_______________________________________________________________________
@@ -330,9 +321,20 @@ 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;
+  }
 } 
  
 //_______________________________________________________________________
@@ -422,7 +424,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 ---  
@@ -441,7 +443,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
@@ -451,7 +453,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);
@@ -459,7 +461,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);
@@ -535,26 +537,26 @@ 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]);
-      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");
 }
 
 //_______________________________________________________________________
@@ -587,12 +589,12 @@ void AliModule::ReadEuclidMedia(const char* filnam)
   }
   //
   // *** 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;
   }
   //
@@ -642,145 +644,132 @@ void AliModule::ReadEuclidMedia(const char* filnam)
   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)
+void AliModule::AddAlignableVolumes() const
 {
   // 
-  // 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);
-      
-    }
-  }
+  if (IsActive())
+    AliWarning(Form(" %s still has to implement the AddAlignableVolumes method!",GetName()));
 }
 
-
 //_______________________________________________________________________
-AliTrackReference* AliModule::FirstTrackReference(Int_t track)
+
+AliLoader*  AliModule::MakeLoader(const char* /*topfoldername*/)
 {
+  return 0x0;
+}
+
+//_____________________________________________________________________________
+AliTrackReference*  AliModule::AddTrackReference(Int_t label, Int_t id){
   //
-  // 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) {
-    gAlice->ResetTrackReferences();
-    gAlice->TreeTR()->GetEvent(track);
-  }
-  //
-  fMaxIterTrackRef     = fTrackReferences->GetEntriesFast();
-  fCurrentIterTrackRef = 0;
-  if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
-  else            return 0;
+  // add a trackrefernce to the list
+    return (gAlice->GetMCApp()->AddTrackReference(label, id));
 }
 
-//_______________________________________________________________________
+ //_______________________________________________________________________
+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 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()
 {
-  //
-  // Return the next hit for the current track
-  //
-  if(fMaxIterTrackRef) {
-    if(++fCurrentIterTrackRef<fMaxIterTrackRef) 
-      return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
-    else        
-      return 0;
-  } else {
-    printf("* AliDetector::NextTrackReference * TrackReference  Iterator called without calling FistTrackReference before\n");
-    return 0;
-  }
+    //
+    // 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()
+
+
+//_____________________________________________________________________________
+TTree* AliModule::TreeTR()
 {
   //
-  // Reset number of hits and the hits array
+  // Return TR tree pointer
   //
-  fMaxIterTrackRef   = 0;
-  if (fTrackReferences)   fTrackReferences->Clear();
+  if ( fRunLoader == 0x0)
+   {
+     AliError("Can not get the run loader");
+     return 0x0;
+   }
+
+  TTree* tree = fRunLoader->TreeTR();
+  return tree;
 }
 
-void AliModule::SetTreeAddress()
+
+//_____________________________________________________________________________
+void AliModule::Digits2Raw()
 {
-  //
-  // Set branch address for the Hits and Digits Trees
-  //
-    TBranch *branch;
-    char branchname[20];
-    sprintf(branchname,"%s",GetName());
-    // Branch address for track reference tree
-    TTree *treeTR = gAlice->TreeTR();
-    if (treeTR && fTrackReferences) {
-       branch = treeTR->GetBranch(branchname);
-       if (branch) branch->SetAddress(&fTrackReferences);
-    }
-}
+// This is a dummy version that just copies the digits file contents
+// to a raw data file.
 
-void  AliModule::AddTrackReference(Int_t label){
-  //
-  // add a trackrefernce to the list
-  if (!fTrackReferences) {
-    cerr<<"Container trackrefernce not active\n";
-    return;
-  }
-  Int_t nref = fTrackReferences->GetEntriesFast();
-  TClonesArray &lref = *fTrackReferences;
-  new(lref[nref]) AliTrackReference(label);
-}
+  AliWarning(Form("Dummy version called for %s", GetName()));
 
+  Int_t nDDLs = AliDAQ::NumberOfDdls(GetName());
 
-void AliModule::MakeBranchTR(Option_t *option, const char *file)
-{ 
-    //
-    // Makes branch in treeTR
-    //  
-    char name[10];
-    sprintf(name,"%s",GetName());
-
-    if (GetDebug()>1)
-       printf("* MakeBranch * Making Branch %s \n",name);
-    
-    TDirectory *cwd = gDirectory;
-    TBranch *branch = 0;
-    TTree* tree = gAlice->TreeTR();
-    if (tree) {
-       branch = tree->Branch(name, &fTrackReferences, 1600);
-       if (file) {
-           char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
-           sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
-           branch->SetFile(outFile);
-           TIter next( branch->GetListOfBranches());
-           while ((branch=dynamic_cast<TBranch*>(next()))) {
-               branch->SetFile(outFile);
-           } 
-           delete outFile;
-           
-           cwd->cd();
-           
-           if (GetDebug()>1)
-               printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
-       }
-    }
+  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;
 }