]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructorComponent.cxx
Made changes to the trigger reconstructor component algorithm to interpret raw DDL...
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONTriggerReconstructorComponent.cxx
index 3730af0e815f6d830eae370ac794a5d1a312ccf5..60d62d1cb91e24a0fe4a82b6c16f39a769df4e82 100644 (file)
@@ -20,7 +20,7 @@
 ///
 /// @file   AliHLTMUONTriggerReconstructorComponent.cxx
 /// @author Indranil Das <indra.das@saha.ac.in>, Artur Szostak <artursz@iafrica.com>
-/// @date
+/// @date   18 Sep 2007
 /// @brief  Implementation of the trigger DDL reconstructor component.
 ///
 
@@ -30,6 +30,7 @@
 #include "AliHLTMUONConstants.h"
 #include "AliHLTMUONUtils.h"
 #include "AliHLTMUONDataBlockWriter.h"
+#include "AliRawDataHeader.h"
 #include "AliCDBManager.h"
 #include "AliCDBStorage.h"
 #include "AliGeomManager.h"
@@ -54,11 +55,12 @@ ClassImp(AliHLTMUONTriggerReconstructorComponent)
 
 
 AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent() :
-       AliHLTProcessor(),
+       AliHLTMUONProcessor(),
        fTrigRec(NULL),
        fDDL(-1),
        fWarnForUnexpecedBlock(false),
-       fSuppressPartialTrigs(false)
+       fStopOnOverflow(false),
+       fUseCrateId(true)
 {
        ///
        /// Default constructor.
@@ -160,12 +162,15 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
        
        fDDL = -1;
        fWarnForUnexpecedBlock = false;
-       fSuppressPartialTrigs = false;
+       fStopOnOverflow = false;
+       fUseCrateId = true;
        
        const char* lutFileName = NULL;
        const char* cdbPath = NULL;
        Int_t run = -1;
        bool useCDB = false;
+       bool suppressPartialTrigs = true;
+       bool tryRecover = false;
        
        for (int i = 0; i < argc; i++)
        {
@@ -201,7 +206,7 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
                        unsigned long num = strtoul(argv[i+1], &cpErr, 0);
                        if (cpErr == NULL or *cpErr != '\0')
                        {
-                               HLTError("Cannot convert '%s' to a DDL Number.", argv[i+1] );\
+                               HLTError("Cannot convert '%s' to a DDL Number.", argv[i+1]);
                                // Make sure to delete fTrigRec to avoid partial initialisation.
                                delete fTrigRec;
                                fTrigRec = NULL;
@@ -209,7 +214,7 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
                        }
                        if (num < 21 or 22 < num)
                        {
-                               HLTError("The DDL ID number must be in the range [21..22].");
+                               HLTError("The DDL number must be in the range [21..22].");
                                // Make sure to delete fTrigRec to avoid partial initialisation.
                                delete fTrigRec;
                                fTrigRec = NULL;
@@ -221,6 +226,41 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
                        continue;
                }
                
+               if (strcmp( argv[i], "-ddlid" ) == 0)
+               {
+                       if ( argc <= i+1 )
+                       {
+                               HLTError("DDL equipment ID number not specified. It must be in the range [2816..2817]" );
+                               // Make sure to delete fTrigRec to avoid partial initialisation.
+                               delete fTrigRec;
+                               fTrigRec = NULL;
+                               return -EINVAL;
+                       }
+               
+                       char* cpErr = NULL;
+                       unsigned long num = strtoul(argv[i+1], &cpErr, 0);
+                       if (cpErr == NULL or *cpErr != '\0')
+                       {
+                               HLTError("Cannot convert '%s' to a DDL equipment ID Number.", argv[i+1]);
+                               // Make sure to delete fTrigRec to avoid partial initialisation.
+                               delete fTrigRec;
+                               fTrigRec = NULL;
+                               return -EINVAL;
+                       }
+                       fDDL = AliHLTMUONUtils::EquipIdToDDLNumber(num); // Convert to DDL number in the range 0..21
+                       if (fDDL < 20 or 21 < fDDL)
+                       {
+                               HLTError("The DDL equipment ID number must be in the range [2816..2817].");
+                               // Make sure to delete fTrigRec to avoid partial initialisation.
+                               delete fTrigRec;
+                               fTrigRec = NULL;
+                               return -EINVAL;
+                       }
+                       
+                       i++;
+                       continue;
+               }
+               
                if (strcmp( argv[i], "-cdb" ) == 0)
                {
                        useCDB = true;
@@ -279,7 +319,31 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
                
                if (strcmp( argv[i], "-suppress_partial_triggers" ) == 0)
                {
-                       fSuppressPartialTrigs = true;
+                       suppressPartialTrigs = true;
+                       continue;
+               }
+               
+               if (strcmp( argv[i], "-generate_partial_triggers" ) == 0)
+               {
+                       suppressPartialTrigs = false;
+                       continue;
+               }
+               
+               if (strcmp( argv[i], "-stop_on_buffer_overflow" ) == 0)
+               {
+                       fStopOnOverflow = true;
+                       continue;
+               }
+               
+               if (strcmp( argv[i], "-tryrecover" ) == 0)
+               {
+                       tryRecover = true;
+                       continue;
+               }
+               
+               if (strcmp( argv[i], "-dont_use_crateid" ) == 0)
+               {
+                       fUseCrateId = false;
                        continue;
                }
                
@@ -301,7 +365,9 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
        int result = 0;
        if (useCDB)
        {
-               HLTInfo("Loading lookup table information from CDB for DDL %d.", fDDL+1);
+               HLTInfo("Loading lookup table information from CDB for DDL %d (ID = %d).",
+                       fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL)
+               );
                if (fDDL == -1)
                        HLTWarning("DDL number not specified. The lookup table loaded from CDB will be empty!");
                result = ReadCDB(cdbPath, run);
@@ -321,6 +387,10 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
                return result;
        }
        
+       fTrigRec->SuppressPartialTriggers(suppressPartialTrigs);
+       fTrigRec->TryRecover(tryRecover);
+       fTrigRec->UseCrateId(fUseCrateId);
+       
        return 0;
 }
 
@@ -366,20 +436,8 @@ int AliHLTMUONTriggerReconstructorComponent::DoEvent(
        // reconstruction algorithm on the raw data.
        for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
        {
-#ifdef __DEBUG
-               char id[kAliHLTComponentDataTypefIDsize+1];
-               for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
-                       id[i] = blocks[n].fDataType.fID[i];
-               id[kAliHLTComponentDataTypefIDsize] = '\0';
-               char origin[kAliHLTComponentDataTypefOriginSize+1];
-               for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
-                       origin[i] = blocks[n].fDataType.fOrigin[i];
-               origin[kAliHLTComponentDataTypefOriginSize] = '\0';
-#endif // __DEBUG
-               HLTDebug("Handling block: %u, with fDataType.fID = '%s',"
-                         " fDataType.fID = '%s', fPtr = %p and fSize = %u bytes.",
-                       n, static_cast<char*>(id), static_cast<char*>(origin),
-                       blocks[n].fPtr, blocks[n].fSize
+               HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
+                       n, DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fPtr, blocks[n].fSize
                );
 
                if (blocks[n].fDataType != AliHLTMUONConstants::DDLRawDataType()
@@ -388,34 +446,28 @@ int AliHLTMUONTriggerReconstructorComponent::DoEvent(
                {
                        // Log a message indicating that we got a data block that we
                        // do not know how to handle.
-                       char id[kAliHLTComponentDataTypefIDsize+1];
-                       for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
-                               id[i] = blocks[n].fDataType.fID[i];
-                       id[kAliHLTComponentDataTypefIDsize] = '\0';
-                       char origin[kAliHLTComponentDataTypefOriginSize+1];
-                       for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
-                               origin[i] = blocks[n].fDataType.fOrigin[i];
-                       origin[kAliHLTComponentDataTypefOriginSize] = '\0';
-                       
                        if (fWarnForUnexpecedBlock)
-                               HLTWarning("Received a data block of a type we cannot handle: '%s' origin: '%s' spec: 0x%X",
-                                       static_cast<char*>(id), static_cast<char*>(origin), blocks[n].fSpecification
+                               HLTWarning("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
+                                       DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification
                                );
                        else
-                               HLTDebug("Received a data block of a type we cannot handle: '%s' origin: '%s' spec: 0x%X",
-                                       static_cast<char*>(id), static_cast<char*>(origin), blocks[n].fSpecification
+                               HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
+                                       DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification
                                );
                        
                        continue;
                }
                
+               AliHLTInt32_t receivedDDL = AliHLTMUONUtils::SpecToDDLNumber(blocks[n].fSpecification);
                if (fDDL != -1)
                {
-                       bool ddl[22];
-                       AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl);
-                       if (not ddl[fDDL])
+                       if (receivedDDL != fDDL)
                        {
-                               HLTWarning("Received raw data from an unexpected DDL.");
+                               HLTWarning("Received raw data from DDL %d (ID = %d),"
+                                       " but expect data only from DDL %d (ID = %d).",
+                                       receivedDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(receivedDDL),
+                                       fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL)
+                               );
                        }
                }
                
@@ -423,7 +475,7 @@ int AliHLTMUONTriggerReconstructorComponent::DoEvent(
                AliHLTMUONTriggerRecordsBlockWriter block(outputPtr+totalSize, size-totalSize);
                if (not block.InitCommonHeader())
                {
-                       HLTError("There is not enough space in the output buffer for the new data block.",
+                       HLTError("There is not enough space in the output buffer for the new data block."
                                 " We require at least %ufTrigRec->GetkDDLHeaderSize() bytes, but have %u bytes left.",
                                sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType),
                                block.BufferSize()
@@ -431,21 +483,42 @@ int AliHLTMUONTriggerReconstructorComponent::DoEvent(
                        break;
                }
 
-               AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t);
-               AliHLTUInt32_t ddlRawDataSize = totalDDLSize - 8;
-               AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr) + 8;
+               AliHLTUInt32_t totalDDLSize = blocks[n].fSize;
+               if (totalDDLSize < sizeof(AliRawDataHeader))
+               {
+                       HLTError("Raw data block %d is %d bytes in size and is too short to"
+                                " possibly contain valid DDL raw data. We expect it to have"
+                                " at least %d bytes for the commond data header.",
+                               n, totalDDLSize, sizeof(AliRawDataHeader)
+                       );
+                       continue;
+               }
+               AliRawDataHeader* header = reinterpret_cast<AliRawDataHeader*>(blocks[n].fPtr);
+               AliHLTUInt32_t payloadSize = totalDDLSize - sizeof(AliRawDataHeader);
+               AliHLTUInt8_t* buffer = reinterpret_cast<AliHLTUInt8_t*>(header + 1);
                AliHLTUInt32_t nofTrigRec = block.MaxNumberOfEntries();
-
+               
+               // Decode if this is a scalar event or not.
+               bool scalarEvent = ((header->GetL1TriggerMessage() & 0x1) == 0x1);
+               
+               // Remember: the following does NOT change the mapping!
+               // It is just to generate unique trigger record IDs.
+               fTrigRec->SetDDL(receivedDDL);
+               
                bool runOk = fTrigRec->Run(
-                               buffer, ddlRawDataSize,
-                               block.GetArray(), nofTrigRec,
-                               fSuppressPartialTrigs
+                               buffer, payloadSize, scalarEvent,
+                               block.GetArray(), nofTrigRec
                        );
                if (not runOk)
                {
-                       HLTError("Error while processing of trigger DDL reconstruction algorithm.");
-                       size = totalSize; // Must tell the framework how much buffer space was used.
-                       return -EIO;
+                       HLTError("Error while processing the trigger DDL reconstruction algorithm.");
+                       if (not fTrigRec->OverflowedOutputBuffer()
+                           or (fTrigRec->OverflowedOutputBuffer() and fStopOnOverflow)
+                          )
+                       {
+                               size = totalSize; // Must tell the framework how much buffer space was used.
+                               return -EIO;
+                       }
                }
                
                // nofTrigRec should now contain the number of triggers actually found
@@ -532,43 +605,11 @@ int AliHLTMUONTriggerReconstructorComponent::ReadCDB(const char* cdbPath, Int_t
                return -EINVAL;
        }
 
-       Bool_t warn = kFALSE;
-       
-       AliCDBManager* cdbManager = AliCDBManager::Instance();
-       if (cdbManager == NULL)
-       {
-               HLTError("CDB manager instance does not exist.");
-               return -EIO;
-       }
-       
-       const char* cdbPathUsed = "unknown (not set)";
-       if (cdbPath != NULL)
-       {
-               cdbManager->SetDefaultStorage(cdbPath);
-               cdbPathUsed = cdbPath;
-       }
-       else
-       {
-               AliCDBStorage* store = cdbManager->GetDefaultStorage();
-               if (store != NULL) cdbPathUsed = store->GetURI().Data();
-       }
-       
-       if (run != -1) cdbManager->SetRun(run);
-       Int_t runUsed = cdbManager->GetRun();
-       
-       if (not AliMpCDB::LoadDDLStore(warn))
-       {
-               HLTError("Failed to load DDL store specified for CDB path '%s' and run no. %d",
-                       cdbPathUsed, runUsed
-               );
-               return -ENOENT;
-       }
+       int result = FetchMappingStores(cdbPath, run);
+       // Error message already generated in FetchMappingStores.
+       if (result != 0) return result;
        AliMpDDLStore* ddlStore = AliMpDDLStore::Instance();
-       if (ddlStore == NULL)
-       {
-               HLTError("Could not find DDL store instance.");
-               return -EIO;
-       }
+       
        AliMpSegmentation* segmentation = AliMpSegmentation::Instance();
        if (segmentation == NULL)
        {
@@ -576,7 +617,11 @@ int AliHLTMUONTriggerReconstructorComponent::ReadCDB(const char* cdbPath, Int_t
                return -EIO;
        }
        
-       AliGeomManager::LoadGeometry();
+       // Only load geometry if not already loaded.
+       if (AliGeomManager::GetGeometry() == NULL)
+       {
+               AliGeomManager::LoadGeometry();
+       }
        AliMUONGeometryTransformer transformer;
        if (not transformer.LoadGeometryData())
        {
@@ -586,12 +631,13 @@ int AliHLTMUONTriggerReconstructorComponent::ReadCDB(const char* cdbPath, Int_t
        
        AliHLTMUONTriggerRecoLookupTable* lookupTable = fTrigRec->LookupTableBuffer();
        
-       for (Int_t i = 0; i < 8; i++)
+       for (Int_t i = 0; i < 16; i++)
        for (Int_t j = 0; j < 16; j++)
        for (Int_t k = 0; k < 4; k++)
        for (Int_t n = 0; n < 2; n++)
        for (Int_t m = 0; m < 16; m++)
        {
+               lookupTable->fRow[i][j][k][n][m].fIdFlags = 0x0;
                lookupTable->fRow[i][j][k][n][m].fX = 0;
                lookupTable->fRow[i][j][k][n][m].fY = 0;
                lookupTable->fRow[i][j][k][n][m].fZ = 0;
@@ -603,8 +649,22 @@ int AliHLTMUONTriggerReconstructorComponent::ReadCDB(const char* cdbPath, Int_t
                AliMpTriggerCrate* crate = ddlStore->GetTriggerCrate(fDDL, iReg);
                if (crate == NULL)
                {
-                       cerr << "ERROR: Could not get crate for regional header = " << iReg
-                               << ", and DDL ID = " << fDDL << endl;
+                       HLTError("Could not get crate mapping for regional header = %d"
+                               " and DDL %d (ID = %d).",
+                               iReg, fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL)
+                       );
+                       continue;
+               }
+               // Depending on the value of fUseCrateId, use either the crate ID as would
+               // be found in the regional header structures or the sequencial index number
+               // of the structure.
+               UInt_t crateId = (fUseCrateId ? crate->GetId() : iReg);
+               if (crateId >= 16)
+               {
+                       HLTError("The crate ID number (%d) for regional header = %d and"
+                               " DDL %d (ID = %d) is too big. It should be in the range [0..15]",
+                               crateId, iReg, fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL)
+                       );
                        continue;
                }
                
@@ -616,7 +676,7 @@ int AliHLTMUONTriggerReconstructorComponent::ReadCDB(const char* cdbPath, Int_t
                        AliMpLocalBoard* localBoard = ddlStore->GetLocalBoard(boardId);
                        if (localBoard == NULL)
                        {
-                               cerr << "ERROR: Could not get loacl board: " << boardId << endl;
+                               HLTError("Could not get local board: %d.", boardId);
                                continue;
                        }
 
@@ -627,11 +687,15 @@ int AliHLTMUONTriggerReconstructorComponent::ReadCDB(const char* cdbPath, Int_t
                        {
                                Int_t detElemId = ddlStore->GetDEfromLocalBoard(boardId, iChamber);
                                
+                               AliHLTUInt32_t idflags = AliHLTMUONUtils::PackRecHitFlags(iChamber+10, detElemId);
+                               
                                const AliMUONGeometryDetElement* detElemTransform = transformer.GetDetElement(detElemId);
                                if (detElemTransform == NULL)
                                {
-                                       cerr << "ERROR: Got NULL pointer for geometry transformer for detection element ID = "
-                                               << detElemId << endl;
+                                       HLTError("Got NULL pointer for geometry transformer"
+                                               " for detection element ID = %d.",
+                                               detElemId
+                                       );
                                        continue;
                                }
                                
@@ -661,15 +725,16 @@ int AliHLTMUONTriggerReconstructorComponent::ReadCDB(const char* cdbPath, Int_t
                                                detElemTransform->Local2Global(lx, ly, 0, gx, gy, gz);
                                                
                                                // Fill the LUT
-                                               lookupTable->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fX = gx;
-                                               lookupTable->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fY = gy;
-                                               lookupTable->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fZ = gz;
+                                               lookupTable->fRow[crateId][iLocBoard][iChamber][iCathode][bitxy].fIdFlags = idflags;
+                                               lookupTable->fRow[crateId][iLocBoard][iChamber][iCathode][bitxy].fX = gx;
+                                               lookupTable->fRow[crateId][iLocBoard][iChamber][iCathode][bitxy].fY = gy;
+                                               lookupTable->fRow[crateId][iLocBoard][iChamber][iCathode][bitxy].fZ = gz;
                                        }
                                }
                        }
                }
        }
-
+       
        return 0;
 }
 
@@ -677,6 +742,7 @@ int AliHLTMUONTriggerReconstructorComponent::ReadCDB(const char* cdbPath, Int_t
 bool AliHLTMUONTriggerReconstructorComponent::GenerateLookupTable(
                AliHLTInt32_t ddl, const char* filename,
                const char* cdbPath, Int_t run
+               //TODO add option fCrateId
        )
 {
        /// Generates a binary file containing the lookup table (LUT) from the
@@ -721,7 +787,7 @@ bool AliHLTMUONTriggerReconstructorComponent::GenerateLookupTable(
                );
        if (not file)
        {
-               cerr << "ERROR: There was a problem writing to the file: " << filename << endl;
+               std::cerr << "ERROR: There was a problem writing to the file: " << filename << std::endl;
                return false;
        }
        file.close();