]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/MUON/AliHLTMUONProcessor.cxx
Update From Debojit
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONProcessor.cxx
index f3281426de57a9e8fefd7a1e1b62927ccb731def..bff4bc3cdca699e39c83b6d783dec84119460528 100644 (file)
 ///
 
 #include "AliHLTMUONProcessor.h"
+#include "AliHLTMUONConstants.h"
+#include "AliHLTMisc.h"
 #include "AliMUONRecoParam.h"
 #include "AliCDBManager.h"
 #include "AliCDBStorage.h"
 #include "AliCDBEntry.h"
+#include "AliGRPManager.h"
+#include "AliGRPObject.h"
+#include "AliMagF.h"
 #include "AliMpCDB.h"
 #include "AliMpDDLStore.h"
 #include "AliMpDEStore.h"
+#include "TGeoGlobalMagField.h"
 #include "TMap.h"
 #include "TObjString.h"
 #include "TString.h"
@@ -285,13 +291,34 @@ int AliHLTMUONProcessor::FetchMappingStores() const
        Int_t runUsed = cdbManager->GetRun();
        
        // Now we can try load the DDL and DE store objects.
+       if (AliHLTMisc::Instance().LoadOCDBEntry("MUON/Calib/MappingData", runUsed) == NULL)
+       {
+               HLTError("Could not find entry in CDB path '%s/MUON/Calib/MappingData' and run no. %d.",
+                       cdbPathUsed, runUsed
+               );
+               return -ENOENT;
+       }
+       if (AliHLTMisc::Instance().LoadOCDBEntry("MUON/Calib/Gains", runUsed) == NULL)
+       {
+               HLTError("Could not find entry in CDB path '%s/MUON/Calib/Gains' and run no. %d.",
+                       cdbPathUsed, runUsed
+               );
+               return -ENOENT;
+       }
+       if (AliHLTMisc::Instance().LoadOCDBEntry("MUON/Calib/Pedestals", runUsed) == NULL)
+       {
+               HLTError("Could not find entry in CDB path '%s/MUON/Calib/Pedestals' and run no. %d.",
+                       cdbPathUsed, runUsed
+               );
+               return -ENOENT;
+       }
        if (not AliMpCDB::LoadDDLStore(warn))
        {
                HLTError("Failed to load DDL or detector element store specified"
                         " for CDB path '%s' and run no. %d.",
                        cdbPathUsed, runUsed
                );
-               return -ENOENT;
+               return -EIO;
        }
        
        if (AliMpDDLStore::Instance(warn) == NULL or AliMpDEStore::Instance(warn) == NULL)
@@ -307,31 +334,13 @@ int AliHLTMUONProcessor::FetchMappingStores() const
 int AliHLTMUONProcessor::FetchTMapFromCDB(const char* pathToEntry, TMap*& map) const
 {
        /// Fetches a TMap object from the CDB.
-       /// [in] \param pathToEntry  The relative path to the entry in the CDB to fetch.
-       /// [out] \param map  This will be filled with the TMap object found if
+       /// \param [in] pathToEntry  The relative path to the entry in the CDB to fetch.
+       /// \param [out] map  This will be filled with the TMap object found if
        ///      a successful status code is returned. Otherwise it will be unchanged.
        /// \return Zero if the object could be found. Otherwise an error code,
        ///      which is compatible with the HLT framework, is returned.
        
-       assert(AliCDBManager::Instance() != NULL);
-       
-       AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
-       if (store == NULL)
-       {
-               HLTError("Could not get the the default storage for the CDB.");
-               return -EIO;
-       }
-
-       Int_t version = store->GetLatestVersion(pathToEntry, GetRunNo());
-       Int_t subVersion = store->GetLatestSubVersion(pathToEntry, GetRunNo(), version);
-       AliCDBEntry* entry = AliCDBManager::Instance()->Get(pathToEntry, GetRunNo(), version, subVersion);
-       if (entry == NULL)
-       {
-               HLTError("Could not get the CDB entry for \"%s\".", pathToEntry);
-               return -EIO;
-       }
-       
-       TObject* obj = entry->GetObject();
+       TObject* obj = LoadAndExtractOCDBObject(pathToEntry);
        if (obj == NULL)
        {
                HLTError("Configuration object for \"%s\" is missing.", pathToEntry);
@@ -345,7 +354,7 @@ int AliHLTMUONProcessor::FetchTMapFromCDB(const char* pathToEntry, TMap*& map) c
                );
                return -EPROTO;
        }
-       map = dynamic_cast<TMap*>(obj);
+       map = static_cast<TMap*>(obj);
        
        return 0;
 }
@@ -357,13 +366,13 @@ int AliHLTMUONProcessor::GetValueFromTMap(
        ) const
 {
        /// Tries to find the string value associated with a certain parameter in a TMap.
-       /// [in] \param map  The TMap object to search in.
-       /// [in] \param paramName  The name of the parameter to search for.
-       /// [out] \param value  Will be filled with the object found.
-       /// [in] \param pathToEntry  The relative path to the entry in the CDB.
+       /// \param [in] map  The TMap object to search in.
+       /// \param [in] paramName  The name of the parameter to search for.
+       /// \param [out] value  Will be filled with the object found.
+       /// \param [in] pathToEntry  The relative path to the entry in the CDB.
        ///      Used when printing error messages. If set to NULL then a string of
        ///      "(unknown)" is used. (default is NULL).
-       /// [in] \param prettyName  Should be the name of the parameter which will
+       /// \param [in] prettyName  Should be the name of the parameter which will
        ///      be used when printing error messages. If this is set to NULL then
        ///      the paramName will be used instead (default is NULL).
        /// \return Zero if the object could be found. Otherwise an error code,
@@ -389,7 +398,7 @@ int AliHLTMUONProcessor::GetValueFromTMap(
                );
                return -EPROTO;
        }
-       value = dynamic_cast<TObjString*>(valueObj)->GetString();
+       value = static_cast<TObjString*>(valueObj)->GetString();
        
        return 0;
 }
@@ -402,14 +411,14 @@ int AliHLTMUONProcessor::GetIntFromTMap(
 {
        /// Tries to find a certain parameter in the TMap object and convert it to
        /// an integer value.
-       /// [in] \param map  The TMap object to search in.
-       /// [in] \param paramName  The name of the parameter to search for.
-       /// [out] \param value  Will be filled with the integer value for the parameter,
+       /// \param [in] map  The TMap object to search in.
+       /// \param [in] paramName  The name of the parameter to search for.
+       /// \param [out] value  Will be filled with the integer value for the parameter,
        ///       if it was found and it was an integer value.
-       /// [in] \param pathToEntry  The relative path to the entry in the CDB.
+       /// \param [in] pathToEntry  The relative path to the entry in the CDB.
        ///      Used when printing error messages. If set to NULL then a string of
        ///      "(unknown)" is used. (default is NULL).
-       /// [in] \param prettyName  Should be the name of the parameter which will
+       /// \param [in] prettyName  Should be the name of the parameter which will
        ///      be used when printing error messages. If this is set to NULL then
        ///      the paramName will be used instead (default is NULL).
        /// \return Zero if the object could be found and is valid. Otherwise an
@@ -443,14 +452,14 @@ int AliHLTMUONProcessor::GetPositiveIntFromTMap(
 {
        /// Tries to find a certain parameter in the TMap object and convert it to
        /// a positive integer value.
-       /// [in] \param map  The TMap object to search in.
-       /// [in] \param paramName  The name of the parameter to search for.
-       /// [out] \param value  Will be filled with the integer value for the parameter,
+       /// \param [in] map  The TMap object to search in.
+       /// \param [in] paramName  The name of the parameter to search for.
+       /// \param [out] value  Will be filled with the integer value for the parameter,
        ///       if it was found and it was a positive integer value.
-       /// [in] \param pathToEntry  The relative path to the entry in the CDB.
+       /// \param [in] pathToEntry  The relative path to the entry in the CDB.
        ///      Used when printing error messages. If set to NULL then a string of
        ///      "(unknown)" is used. (default is NULL).
-       /// [in] \param prettyName  Should be the name of the parameter which will
+       /// \param [in] prettyName  Should be the name of the parameter which will
        ///      be used when printing error messages. If this is set to NULL then
        ///      the paramName will be used instead (default is NULL).
        /// \return Zero if the object could be found and is valid. Otherwise an
@@ -493,14 +502,14 @@ int AliHLTMUONProcessor::GetFloatFromTMap(
 {
        /// Tries to find a certain parameter in the TMap object and convert it to
        /// an floating point value.
-       /// [in] \param map  The TMap object to search in.
-       /// [in] \param paramName  The name of the parameter to search for.
-       /// [out] \param value  Will be filled with the floating point value for the
+       /// \param [in] map  The TMap object to search in.
+       /// \param [in] paramName  The name of the parameter to search for.
+       /// \param [out] value  Will be filled with the floating point value for the
        ///       parameter, if it was found and it was a floating point value.
-       /// [in] \param pathToEntry  The relative path to the entry in the CDB.
+       /// \param [in] pathToEntry  The relative path to the entry in the CDB.
        ///      Used when printing error messages. If set to NULL then a string of
        ///      "(unknown)" is used. (default is NULL).
-       /// [in] \param prettyName  Should be the name of the parameter which will
+       /// \param [in] prettyName  Should be the name of the parameter which will
        ///      be used when printing error messages. If this is set to NULL then
        ///      the paramName will be used instead (default is NULL).
        /// \return Zero if the object could be found and is valid. Otherwise an
@@ -534,14 +543,14 @@ int AliHLTMUONProcessor::GetPositiveFloatFromTMap(
 {
        /// Tries to find a certain parameter in the TMap object and convert it to
        /// an positive floating point value.
-       /// [in] \param map  The TMap object to search in.
-       /// [in] \param paramName  The name of the parameter to search for.
-       /// [out] \param value  Will be filled with the floating point value for the
+       /// \param [in] map  The TMap object to search in.
+       /// \param [in] paramName  The name of the parameter to search for.
+       /// \param [out] value  Will be filled with the floating point value for the
        ///       parameter, if it was found and it was a positive floating point value.
-       /// [in] \param pathToEntry  The relative path to the entry in the CDB.
+       /// \param [in] pathToEntry  The relative path to the entry in the CDB.
        ///      Used when printing error messages. If set to NULL then a string of
        ///      "(unknown)" is used. (default is NULL).
-       /// [in] \param prettyName  Should be the name of the parameter which will
+       /// \param [in] prettyName  Should be the name of the parameter which will
        ///      be used when printing error messages. If this is set to NULL then
        ///      the paramName will be used instead (default is NULL).
        /// \return Zero if the object could be found and is valid. Otherwise an
@@ -577,35 +586,105 @@ int AliHLTMUONProcessor::GetPositiveFloatFromTMap(
 }
 
 
+int AliHLTMUONProcessor::FetchFieldIntegral(Double_t& bfieldintegral) const
+{
+       // Fetches the correct dipole magnetic field integral to use.
+       
+       Float_t currentL3 = 0;
+       Float_t currentDip = 0;
+       
+       if (TGeoGlobalMagField::Instance() == NULL or
+           (TGeoGlobalMagField::Instance() != NULL and TGeoGlobalMagField::Instance()->GetField() == NULL)
+          )
+       {
+               HLTWarning("The magnetic field has not been set in TGeoGlobalMagField."
+                       " Will try and load the GRP entry directly."
+               );
+               
+               AliGRPManager grpman;
+               if (not grpman.ReadGRPEntry() or grpman.GetGRPData() == NULL)
+               {
+                       HLTError("GRP entry could not be loaded.");
+                       return -EIO;
+               }
+               
+               const AliGRPObject* grp = grpman.GetGRPData();
+               Char_t polarityL3 = grp->GetL3Polarity();
+               Char_t polarityDip = grp->GetDipolePolarity();
+               currentL3 = grp->GetL3Current(AliGRPObject::kMean);
+               currentDip = grp->GetDipoleCurrent(AliGRPObject::kMean);
+               if (polarityL3 == AliGRPObject::GetInvalidChar())
+               {
+                       HLTError("L3 polarity in GRP is invalid.");
+                       return -EPROTO;
+               }
+               if (polarityDip == AliGRPObject::GetInvalidChar())
+               {
+                       HLTError("Dipole polarity in GRP is invalid.");
+                       return -EPROTO;
+               }
+               if (currentL3 == AliGRPObject::GetInvalidFloat())
+               {
+                       HLTError("L3 current in GRP is invalid.");
+                       return -EPROTO;
+               }
+               if (currentDip == AliGRPObject::GetInvalidFloat())
+               {
+                       HLTError("Dipole current in GRP is invalid.");
+                       return -EPROTO;
+               }
+               if (grp->IsPolarityConventionLHC())
+               {
+                       currentL3 *= (polarityL3 ? -1:1);
+                       currentDip *= (polarityDip ? -1:1);
+               }
+               else
+               {
+                       currentL3 *= (polarityL3 ? -1:1);
+                       currentDip *= (polarityDip ? 1:-1);
+               }
+       }
+       else
+       {
+               TVirtualMagField* vfield = TGeoGlobalMagField::Instance()->GetField();
+               AliMagF* field = dynamic_cast<AliMagF*>(vfield);
+               if (vfield->IsA() != AliMagF::Class() or field == NULL)
+               {
+                       HLTError(Form(
+                               "The magnetic field is not of type AliMagF."
+                               " Do not know how to handle class of type '%s'.",
+                               vfield->ClassName()
+                       ));
+                       return -EPROTO;
+               }
+               currentL3 = field->GetCurrentSol();
+               currentDip = field->GetCurrentDip();
+       }
+       
+       const char* path = AliHLTMUONConstants::FieldIntegralsCDBPath();
+       TMap* map = NULL;
+       int result = FetchTMapFromCDB(path, map);
+       if (result != 0) return result;
+       const char* paramName = Form("L3_current=%0.2e;Dipole_current=%0.2e", currentL3, currentDip);
+       Double_t value;
+       result = GetFloatFromTMap(map, paramName, value, path);
+       if (result != 0) return result;
+       bfieldintegral = value;
+       return 0;
+}
+
+
 int AliHLTMUONProcessor::LoadRecoParamsFromCDB(AliMUONRecoParam*& params) const
 {
        /// Fetches the reconstruction parameters object from the CDB for MUON.
-       /// [out] \param params  This will be filled with the reconstruction
+       /// \param [out] params  This will be filled with the reconstruction
        ///      parameters object found if a successful status code is returned.
        ///      Otherwise it will be unchanged.
        /// \return Zero if the object could be found. Otherwise an error code,
        ///      which is compatible with the HLT framework, is returned.
        
-       assert(AliCDBManager::Instance() != NULL);
-
-       AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
-       if (store == NULL)
-       {
-               HLTError("Could not get the the default storage for the CDB.");
-               return -EIO;
-       }
-
        const char* pathToEntry = "MUON/Calib/RecoParam";
-       Int_t version = store->GetLatestVersion(pathToEntry, GetRunNo());
-       Int_t subVersion = store->GetLatestSubVersion(pathToEntry, GetRunNo(), version);
-       AliCDBEntry* entry = AliCDBManager::Instance()->Get(pathToEntry, GetRunNo(), version, subVersion);
-       if (entry == NULL)
-       {
-               HLTError("Could not get the CDB entry for \"%s\".", pathToEntry);
-               return -EIO;
-       }
-       
-       TObject* obj = entry->GetObject();
+       TObject* obj = LoadAndExtractOCDBObject(pathToEntry);
        if (obj == NULL)
        {
                HLTError("Reconstruction parameters object for \"%s\" is missing.", pathToEntry);