]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONDataInterface.cxx
Correcting MUONGenerateGeometryData.C macro description
[u/mrichter/AliRoot.git] / MUON / AliMUONDataInterface.cxx
index 68ede878c8c252b7d52cffe1262f7d1fbbc55155..4ca6f7df80404356b47ac869d966c9b54645274d 100644 (file)
 #include "AliMUONRawCluster.h"
 #include "AliLog.h"
 
+#include <iostream>
+using std::endl;
+using std::cout;
+
 
 ClassImp(AliMUONDataInterface)
 
@@ -37,11 +41,11 @@ AliMUONDataInterface::AliMUONDataInterface(const AliMUONDataInterface& rhs)
 
 AliMUONDataInterface::~AliMUONDataInterface()
 {
-// Delete the runloader when done.
+// Delete the runloader if we created it.
 // If the runloader is not to be deleted then call Reset just before 
 // the destructor is called.
 
-       if (fRunloader != NULL)
+       if (fRunloader != NULL && fCreatedRunLoader)
                delete fRunloader;
 }
 
@@ -64,6 +68,7 @@ void AliMUONDataInterface::Reset()
 // Note: No resources are released!
 // Specificaly AliRunLoader is not deleted.
 
+       fCreatedRunLoader = kFALSE;
        fRunloader = NULL;
        fMuonloader = NULL;
        fEventnumber = -1;
@@ -78,6 +83,46 @@ void AliMUONDataInterface::Reset()
 }
 
 
+Bool_t AliMUONDataInterface::UseCurrentRunLoader()
+{
+// Tries to fetch the current runloader with AliRunLoader::GetRunLoader. If nothing is
+// currently loaded then kFALSE is returned and AliMUONDataInterface is reset.
+
+       Reset();
+       fRunloader = AliRunLoader::GetRunLoader();
+       if (fRunloader == NULL) return kFALSE;
+       // Fetch the current file name, folder name and event number.
+       fFilename = fRunloader->GetFileName();
+       fFoldername = fRunloader->GetEventFolder()->GetName();
+       fEventnumber = fRunloader->GetEventNumber();
+
+       if ( ! FetchMuonLoader(fFilename.Data(), fFoldername.Data()) )
+       {
+               Reset();
+               return kFALSE;
+       }               
+
+       return kTRUE;
+}
+
+
+Bool_t AliMUONDataInterface::FetchMuonLoader(TString filename, TString foldername)
+{
+       fMuonloader = fRunloader->GetLoader("MUONLoader");
+       if (fMuonloader == NULL)
+       {
+               AliError(Form("Could not find the MUON loader in file: %s and folder: %s", 
+                       (const char*)filename, (const char*)foldername));
+               return kFALSE;
+       }
+       
+       // Need to connect the muon loader to the AliMUONData object,
+       // else class to fData will return NULL.
+       fData.SetLoader(fMuonloader);
+       return kTRUE;
+}
+
+
 Bool_t AliMUONDataInterface::LoadLoaders(TString filename, TString foldername)
 {
 // Load the run and muon loaders from the specified file and folder.
@@ -90,19 +135,13 @@ Bool_t AliMUONDataInterface::LoadLoaders(TString filename, TString foldername)
                        (const char*)filename, (const char*)foldername));
                return kFALSE;
        }
-       fMuonloader = fRunloader->GetLoader("MUONLoader");
-       if (fMuonloader == NULL)
+       fCreatedRunLoader = kTRUE;
+       if ( ! FetchMuonLoader(filename, foldername) )
        {
-               AliError(Form("Could not find the MUON loader in file: %s and folder: %s", 
-                       (const char*)filename, (const char*)foldername));
                fRunloader = NULL;
                return kFALSE;
        }
        
-       // Need to connect the muon loader to the AliMUONData object,
-       // else class to fData will return NULL.
-       fData.SetLoader(fMuonloader);
-       
        fFilename = filename;
        fFoldername = foldername;
        fEventnumber = -1;  // Reset the event number to force the event to be loaded.
@@ -123,6 +162,17 @@ Bool_t AliMUONDataInterface::FetchLoaders(TString filename, TString foldername)
                fRunloader = AliRunLoader::GetRunLoader();
                if (fRunloader == NULL)
                        return LoadLoaders(filename, foldername);
+               else
+               {
+                       if (fMuonloader == NULL)
+                       {
+                               if ( ! FetchMuonLoader(filename, foldername) )
+                               {
+                                       fRunloader = NULL;
+                                       return kFALSE;
+                               }
+                       }
+               }
                
                // Fetch the current file and folder names.
                fFilename = fRunloader->GetFileName();
@@ -144,6 +194,8 @@ Bool_t AliMUONDataInterface::FetchEvent(Int_t event)
 {
 // Fetch the specified event from the runloader and reset all the track, cathode
 // and address flags to force them to be reloaded.
+// If a negative event number is specified then the current runloader event
+// number is used.
 
        if (fEventnumber < 0)
        {
@@ -401,7 +453,7 @@ Int_t AliMUONDataInterface::NumberOfSDigits(
        if ( fSCathode != cathode )
        {
                fData.ResetSDigits();
-               fData.GetCathodeS(cathode);
+               fData.GetSDigits();
                fSCathode = cathode;
        }
        return fData.SDigits(chamber)->GetEntriesFast();
@@ -426,7 +478,7 @@ AliMUONDigit* AliMUONDataInterface::SDigit(
        if ( fSCathode != cathode )
        {
                fData.ResetSDigits();
-               fData.GetCathodeS(cathode);
+               fData.GetSDigits();
                fSCathode = cathode;
        }
        return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
@@ -450,7 +502,7 @@ Int_t AliMUONDataInterface::NumberOfDigits(
        if ( fCathode != cathode )
        {
                fData.ResetDigits();
-               fData.GetCathode(cathode);
+               fData.GetDigits();
                fCathode = cathode;
        }
        return fData.Digits(chamber)->GetEntriesFast();
@@ -475,7 +527,7 @@ AliMUONDigit* AliMUONDataInterface::Digit(
        if ( fCathode != cathode )
        {
                fData.ResetDigits();
-               fData.GetCathode(cathode);
+               fData.GetDigits();
                fCathode = cathode;
        }
        return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
@@ -536,13 +588,13 @@ Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString filename, TString fold
 
        if ( ! FetchLoaders(filename, foldername) ) return -1;
        if ( ! FetchEvent(event) ) return -1;
-       if ( ! FetchTreeR() ) return -1;
+       if ( ! FetchTreeD() ) return -1;
        if ( ! fTriggerAddressSet )
        {
                // If the local trigger address in TreeR is not set yet then set it now.
                fData.SetTreeAddress("GLT");
                fData.ResetTrigger();
-               fData.GetTrigger();
+               fData.GetTriggerD();
                fTriggerAddressSet = kTRUE;
        }
        return fData.LocalTrigger()->GetEntriesFast();
@@ -558,13 +610,13 @@ AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(
 
        if ( ! FetchLoaders(filename, foldername) ) return NULL;
        if ( ! FetchEvent(event) ) return NULL;
-       if ( ! FetchTreeR() ) return NULL;
+       if ( ! FetchTreeD() ) return NULL;
        if ( ! fTriggerAddressSet )
        {
                // If the local trigger address in TreeR is not set yet then set it now.
                fData.SetTreeAddress("GLT");
                fData.ResetTrigger();
-               fData.GetTrigger();
+               fData.GetTriggerD();
                fTriggerAddressSet = kTRUE;
        }
        return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );
@@ -743,7 +795,7 @@ Int_t AliMUONDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
        if ( fSCathode != cathode )
        {
                fData.ResetSDigits();
-               fData.GetCathodeS(cathode);
+               fData.GetSDigits();
                fSCathode = cathode;
        }
        return fData.SDigits(chamber)->GetEntriesFast();
@@ -773,7 +825,7 @@ AliMUONDigit* AliMUONDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t s
        if ( fSCathode != cathode )
        {
                fData.ResetSDigits();
-               fData.GetCathodeS(cathode);
+               fData.GetSDigits();
                fSCathode = cathode;
        }
        return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
@@ -803,7 +855,7 @@ Int_t AliMUONDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
        if ( fCathode != cathode )
        {
                fData.ResetDigits();
-               fData.GetCathode(cathode);
+               fData.GetDigits();
                fCathode = cathode;
        }
        return fData.Digits(chamber)->GetEntriesFast();
@@ -833,7 +885,7 @@ AliMUONDigit* AliMUONDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t di
        if ( fCathode != cathode )
        {
                fData.ResetDigits();
-               fData.GetCathode(cathode);
+               fData.GetDigits();
                fCathode = cathode;
        }
        return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
@@ -916,12 +968,12 @@ Int_t AliMUONDataInterface::NumberOfLocalTriggers()
                return -1;
        }
 
-       if ( ! FetchTreeR() ) return -1;
+       if ( ! FetchTreeD() ) return -1;
        if ( ! fTriggerAddressSet )
        {
                fData.SetTreeAddress("GLT");
                fData.ResetTrigger();
-               fData.GetTrigger();
+               fData.GetTriggerD();
                fTriggerAddressSet = kTRUE;
        }
        return fData.LocalTrigger()->GetEntriesFast();
@@ -944,12 +996,12 @@ AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t trigger)
                return NULL;
        }
 
-       if ( ! FetchTreeR() ) return NULL;
+       if ( ! FetchTreeD() ) return NULL;
        if ( ! fTriggerAddressSet )
        {
                fData.SetTreeAddress("GLT");
                fData.ResetTrigger();
-               fData.GetTrigger();
+               fData.GetTriggerD();
                fTriggerAddressSet = kTRUE;
        }
        return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );