]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
The trigger reconstructor component now generates the correct data format.
authorszostak <szostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 21 Sep 2007 18:33:22 +0000 (18:33 +0000)
committerszostak <szostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 21 Sep 2007 18:33:22 +0000 (18:33 +0000)
Also cleaned up the code, removed some unecessary memory copies and fixed some potencial bugs.
Artur Szostak

HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructor.cxx
HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructor.h
HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructorComponent.cxx
HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructorComponent.h

index fa7e945cd02c75c62117662885882fd4a14d7897..35f6ed3561df35d2d01145467b0c9639cb9f9b41 100644 (file)
@@ -136,12 +136,17 @@ bool AliHLTMUONTriggerReconstructor::LoadLookUpTable(AliHLTMUONHitReconstructor:
   return true;
 }
 
-bool AliHLTMUONTriggerReconstructor::Run(int *rawData, int *rawDataSize, AliHLTMUONTriggerRecordStruct trigRecord[], int *nofTrigRec)
+bool AliHLTMUONTriggerReconstructor::Run(
+               const AliHLTUInt32_t* rawData,
+               AliHLTUInt32_t rawDataSize,
+               AliHLTMUONTriggerRecordStruct* trigRecord,
+               AliHLTUInt32_t& nofTrigRec
+       )
 {
 
-  fRecPoints = &trigRecord[0];
-  fMaxRecPointsCount = *nofTrigRec;
-  fRecPointsCount = nofTrigRec;
+  fRecPoints = trigRecord;
+  fMaxRecPointsCount = nofTrigRec;
+  fRecPointsCount = &nofTrigRec;
   *fRecPointsCount = 0;
   fMaxFiredPerDetElem.clear();
   fDetElemToDataId.clear();
@@ -158,7 +163,7 @@ bool AliHLTMUONTriggerReconstructor::Run(int *rawData, int *rawDataSize, AliHLTM
   fPadData[0].fPcbZone = -1 ;
   fPadData[0].fCharge = 0 ;
   
-  if(!ReadDDL(rawData,rawDataSize)){
+  if(!ReadDDL(rawData, rawDataSize)){
     HLTError("Failed to read the complete DDL file\n");
     return false;
   }
@@ -172,7 +177,10 @@ bool AliHLTMUONTriggerReconstructor::Run(int *rawData, int *rawDataSize, AliHLTM
 }
 
 
-bool AliHLTMUONTriggerReconstructor::ReadDDL(int *rawData, int *rawDataSize)
+bool AliHLTMUONTriggerReconstructor::ReadDDL(
+               const AliHLTUInt32_t* rawData,
+               AliHLTUInt32_t rawDataSize
+       )
 {
 
   int idManuChannel ;
index fae00079b0bd4f2162b70e45353d450619522584..e3dac532844adde65607f2ccc7e4ceb111e84aa0 100644 (file)
@@ -28,8 +28,7 @@
 
 #include <vector>
 
-#include <AliHLTLogging.h>
-
+#include "AliHLTLogging.h"
 #include "AliHLTMUONTriggerRecordsBlockStruct.h"
 #include "AliHLTMUONHitReconstructor.h"
 
@@ -58,8 +57,7 @@ class AliHLTMUONTriggerReconstructor : public AliHLTLogging
   bool LoadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookUpTableData, int lookUpTableId);
   
   bool SetRegToLocCardMap(RegToLoc* regToLoc);
-  //bool Run(int iEvent, int iDDL, AliHLTMUONTriggerRecordStruct trigRecord, int *nofTrigRec); // for Reading using rawreader
-  bool Run(int *rawData, int *rawDataSize, AliHLTMUONTriggerRecordStruct trigRecord[], int *nofTrigRec);
+  bool Run(const AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize, AliHLTMUONTriggerRecordStruct* trigRecord, AliHLTUInt32_t& nofTrigRec);
 
   int GetLutLine(){return fgkLutLine ;}
 
@@ -97,8 +95,8 @@ class AliHLTMUONTriggerReconstructor : public AliHLTLogging
   AliHLTMUONHitReconstructor::DHLTLut* fLookUpTableData;                  // pointer to the array of Lookuptable data
   
   AliHLTMUONTriggerRecordStruct *fRecPoints;    // Reconstructed hits
-  int *fRecPointsCount;                       // nof reconstructed hit  
-  int fMaxRecPointsCount;                    // max nof reconstructed hit  
+  AliHLTUInt32_t *fRecPointsCount;                       // nof reconstructed hit  
+  AliHLTUInt32_t fMaxRecPointsCount;                    // max nof reconstructed hit  
 
   //104 correspond to maximum nuber of x indices a nonbending side of detelem may have (i.e. 1101) 
   //and 64 corresponds to the maximum number of y indices occurs in bending side of detelem (i.e 1100)
@@ -114,7 +112,7 @@ class AliHLTMUONTriggerReconstructor : public AliHLTLogging
   bool MergeTrigHits(DataIdIndex& dataIndex);
   bool FindTrigHits() ;
 
-  bool ReadDDL(int *rawData, int *rawDataSize);
+  bool ReadDDL(const AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize);
 };
 
 #endif // AliHLTMUONTRIGGERRECONSTRUCTOR_H
index 480ca15b40437a8e5e63fc296488ac5dbee455e6..55728f0de22cca20913747c7b71681dbec194e4b 100644 (file)
     @date   
     @brief  Implementation of the trigger DDL reconstructor component. */
 
-#if __GNUC__ >= 3
-using namespace std;
-#endif
-
-#include "AliHLTSystem.h"
 #include "AliHLTMUONTriggerReconstructorComponent.h"
 #include "AliHLTMUONTriggerReconstructor.h"
 #include "AliHLTMUONHitReconstructor.h"
 #include "AliHLTMUONConstants.h"
-
-#include <stdlib.h>
-#include <errno.h>
+#include "AliHLTMUONDataBlockWriter.h"
+#include <cstdlib>
+#include <cerrno>
 
 namespace
 {
        // This is a global object used for automatic component registration,
        // do not use this for calculation.
        AliHLTMUONTriggerReconstructorComponent gAliHLTMUONTriggerReconstructorComponent;
+
 } // end of namespace
 
 
 ClassImp(AliHLTMUONTriggerReconstructorComponent)
     
     
-AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent()
-  :
-  fTrigRec(NULL),
-  fDDLDir(""),
-  fDDL(0)
+AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent() :
+       fTrigRec(NULL),
+       fDDLDir(""),
+       fDDL(0)
 {
 }
 
@@ -61,40 +56,42 @@ AliHLTMUONTriggerReconstructorComponent::~AliHLTMUONTriggerReconstructorComponen
 
 const char* AliHLTMUONTriggerReconstructorComponent::GetComponentID()
 {
-  return "MUONTrigRec"; // The ID of this component
+       return AliHLTMUONConstants::TriggerReconstructorId();
 }
 
 
 void AliHLTMUONTriggerReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list)
 {
-  list.clear();
-  list.push_back( AliHLTMUONConstants::TriggerDDLRawDataType() );
+       list.clear();
+       list.push_back( AliHLTMUONConstants::TriggerDDLRawDataType() );
 }
 
 
 AliHLTComponentDataType AliHLTMUONTriggerReconstructorComponent::GetOutputDataType()
 {
-  return AliHLTMUONConstants::TriggerRecordsBlockDataType();
+       return AliHLTMUONConstants::TriggerRecordsBlockDataType();
 }
 
 
-void AliHLTMUONTriggerReconstructorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+void AliHLTMUONTriggerReconstructorComponent::GetOutputDataSize(
+               unsigned long& constBase, double& inputMultiplier
+       )
 {
-  constBase = 0;
-  inputMultiplier = 1;
+       constBase = sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType);
+       inputMultiplier = 1;
 }
 
 
-// Spawn function, return new instance of this class
 AliHLTComponent* AliHLTMUONTriggerReconstructorComponent::Spawn()
 {
-  return new AliHLTMUONTriggerReconstructorComponent;
+       return new AliHLTMUONTriggerReconstructorComponent;
 }
 
 
 int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
 {
-  // perform initialization. We check whether our relative output size is specified in the arguments.
+  // perform initialization. We check whether our relative output size is
+  // specified in the arguments.
   
   HLTInfo("Initialising DHLT Trigger Record Component");
 
@@ -105,7 +102,6 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
     HLTError("Arguments missing, no arguments" );
   }
 
-
   char lutFileName[500],reglocFileName[500];
 
   int i = 0;
@@ -204,14 +200,17 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
 
 int AliHLTMUONTriggerReconstructorComponent::DoDeinit()
 {
-  if(fTrigRec)
-    delete fTrigRec;
-  
-  HLTInfo(" Deinitialising DHLT Trigger Record Component");
-  
-  return 0;
+       HLTInfo("Deinitialising DHLT Trigger Record Component");
+
+       if(fTrigRec)
+       {
+               delete fTrigRec;
+               fTrigRec = NULL;
+       }
+       return 0;
 }
 
+
 int AliHLTMUONTriggerReconstructorComponent::DoEvent(
                const AliHLTComponentEventData& evtData,
                const AliHLTComponentBlockData* blocks, 
@@ -221,93 +220,106 @@ int AliHLTMUONTriggerReconstructorComponent::DoEvent(
                std::vector<AliHLTComponentBlockData>& outputBlocks
        )
 {
-  // Process an event
-  unsigned long totalSize = 0;
-  HLTDebug("Output percentage set to %lu and totalSize %lu",fOutputPercentage,totalSize );
-    
-  HLTDebug("Event : %d has : %lu  blocks",(int)evtData.fEventID,evtData.fBlockCnt);
-  // Loop over all input blocks in the event
-  for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
-    {
-
-      HLTDebug("block : %d, block rawData : %p, block.fSize (bytes) : %d, blocks.fDataType.fID : %s, blocks.fDataType.fOrigin  : %s, required type : %s\n",
-              n,blocks[n].fPtr,blocks[n].fSize,(char *)(blocks[n].fDataType.fID),
-             (char *)(blocks[n].fDataType.fOrigin,(char *)(AliHLTMUONConstants::TriggerDDLRawDataType().fID)));
-      
-
-      if(strncmp((char *)(blocks[n].fDataType.fID),(char *)(AliHLTMUONConstants::TriggerDDLRawDataType().fID),kAliHLTComponentDataTypefIDsize)) continue;
-
-      if ( totalSize > size )
-       break;
-      
-      int totalDDLSize = blocks[n].fSize/sizeof(int);
-      int  ddlRawDataSize = totalDDLSize - fTrigRec->GetkDDLHeaderSize();
+       // Process an event
+       unsigned long totalSize = 0; // Amount of memory currently consumed in bytes.
 
-      int *buffer = (int *)((int *)blocks[n].fPtr + fTrigRec->GetkDDLHeaderSize()) ;
-      
-      AliHLTMUONTriggerRecordStruct trigRecord[300];
-      int nofTrigRec = 300;
+       HLTDebug("Processing event %llu with %u input data blocks.",
+               evtData.fEventID, evtData.fBlockCnt
+       );
        
-      if(! (fTrigRec->Run(buffer,&ddlRawDataSize,&trigRecord[0],&nofTrigRec))){
-       HLTError("ERROR In Processing of TrigRec Algo ");
-       return EIO;
-      }
-      
-      //       if(! (fTrigRec->Run((int)evtData.fEventID,fDDL,trigRecord,&nofTrigRec))){
-      //         HLTError("ERROR In Processing of TrigRec Algo ");
-      //         return EIO;
-      //       }
-       
-      unsigned long mySize = sizeof(AliHLTMUONTriggerRecordStruct)*nofTrigRec;
-    
-      HLTDebug("Number record found is %d",nofTrigRec);
-//       for(int ihit=0;ihit<nofTrigRec;ihit++)
-//     cout<<"\tdetelem : "<<trigRecord[ihit].fId
-//         <<"\t"<<trigRecord[ihit].fHit[0].fX
-//         <<"\t"<<trigRecord[ihit].fHit[0].fY
-//         <<"\t"<<trigRecord[ihit].fHit[0].fZ
-//         <<endl;
-
-       // Check how much space we have left and adapt this output block's size accordingly.
-       if ( totalSize + mySize > size )
-           mySize = size-totalSize;
-
-       Logging( kHLTLogDebug, "AliHLTMUONTriggerReconstructor::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu", 
-                mySize, totalSize, size );
-
-       if ( mySize<=0 )
-           continue; // No room left to write a further block.
-
-       // Now copy the input block
-       unsigned long copied = 0;
-       // First copy all full multiples of the input block
-
-       // And the copy the remaining fragment of the block
-       Logging( kHLTLogDebug, "AliHLTMUONTriggerReconstructor::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B", 
-                mySize-copied, copied, totalSize );
-       //memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, mySize-copied );
-       memcpy( outputPtr+totalSize+copied, &trigRecord[0], mySize);
-       Logging( kHLTLogDebug, "AliHLTMUONTriggerReconstructor::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B", 
-                copied, totalSize );
-       
-       // Fill a block data structure for our output block.
-       AliHLTComponentBlockData bd;
-       FillBlockData(bd);
-       bd.fPtr = outputPtr;
-       // This block's start (offset) is after all other blocks written so far.
-       bd.fOffset = totalSize;
-       bd.fSize = mySize;
-       bd.fDataType = AliHLTMUONConstants::TriggerRecordsBlockDataType();
-       bd.fSpecification = blocks[n].fSpecification;
-       outputBlocks.push_back(bd);
+       // Loop over all input blocks in the event and run the trigger DDL
+       // reconstruction algorithm on the raw data.
+       for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
+       {
+               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';
+               
+               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
+               );
+
+               if (blocks[n].fDataType != AliHLTMUONConstants::TriggerDDLRawDataType())
+               {
+                       // 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';
+                       
+                       HLTError("Received a data block of an unexpected type: %s origin %s",
+                               static_cast<char*>(id), static_cast<char*>(origin)
+                       );
+                       continue;
+               }
+               
+               // Create a new output data block and initialise the header.
+               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.",
+                                " We require at least %u bytes, but have %u bytes left.",
+                               sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType),
+                               block.BufferSize()
+                       );
+                       break;
+               }
+
+               AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t);
+               AliHLTUInt32_t ddlRawDataSize = totalDDLSize - fTrigRec->GetkDDLHeaderSize();
+               AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr)
+                       + fTrigRec->GetkDDLHeaderSize();
+               AliHLTUInt32_t nofTrigRec = block.MaxNumberOfEntries();
+
+               if (not fTrigRec->Run(buffer, ddlRawDataSize, block.GetArray(), nofTrigRec))
+               {
+                       HLTError("Error while processing of trigger DDL reconstruction algorithm.");
+                       size = totalSize; // Must tell the framework how much buffer space was used.
+                       return EIO;
+               }
+               
+               // nofTrigRec should now contain the number of triggers actually found
+               // and filled into the output data block, so we can set this number.
+               assert( nofTrigRec <= block.MaxNumberOfEntries() );
+               block.SetNumberOfEntries(nofTrigRec);
+               
+               HLTDebug("Number of trigger records found is %d", nofTrigRec);
+               
+               // Fill a block data structure for our output block.
+               AliHLTComponentBlockData bd;
+               FillBlockData(bd);
+               bd.fPtr = outputPtr;
+               // This block's start (offset) is after all other blocks written so far.
+               bd.fOffset = totalSize;
+               bd.fSize = block.BytesUsed();
+               bd.fDataType = AliHLTMUONConstants::TriggerRecordsBlockDataType();
+               bd.fSpecification = blocks[n].fSpecification;
+               outputBlocks.push_back(bd);
+               
+               HLTDebug("Created a new output data block at fPtr = %p,"
+                         " with fOffset = %u (0x%.X) and fSize = %u bytes.", 
+                       bd.fPtr, bd.fOffset, bd.fOffset, bd.fSize
+               );
+               
+               // Increase the total amount of data written so far to our output memory.
+               totalSize += block.BytesUsed();
+       }
        
-       // Increase the total amount of data written so far to our output memory
-       totalSize += mySize;
-    }
-    // Finally we set the total size of output memory we consumed.
-    size = totalSize;
-
-    return 0;
+       // Finally we set the total size of output memory we consumed.
+       size = totalSize;
+       return 0;
 }
 
 
index c472ce5c32780ec08500eb487ece325f1e55da03..90c4c07c16d7d6cdb75acbdb25f9fee84f835b5a 100644 (file)
@@ -41,8 +41,8 @@
  * @ingroup alihlt_tutorial
  */
 class AliHLTMUONTriggerReconstructorComponent : public AliHLTProcessor
-    {
-    public:
+{
+public:
        AliHLTMUONTriggerReconstructorComponent();
        virtual ~AliHLTMUONTriggerReconstructorComponent();
 
@@ -54,16 +54,16 @@ class AliHLTMUONTriggerReconstructorComponent : public AliHLTProcessor
        AliHLTComponentDataType GetOutputDataType();
        virtual void GetOutputDataSize(unsigned long& constBase, double& inputMultiplier);
        AliHLTComponent* Spawn();
-       
-    protected:
-       
+
+protected:
+
        // Protected functions to implement AliHLTComponent's interface.
        // These functions provide initialization as well as the actual processing
        // capabilities of the component. 
 
        int DoInit(int argc, const char** argv);
        int DoDeinit();
-       
+
        int DoEvent(
                        const AliHLTComponentEventData& evtData,
                        const AliHLTComponentBlockData* blocks, 
@@ -72,9 +72,9 @@ class AliHLTMUONTriggerReconstructorComponent : public AliHLTProcessor
                        AliHLTUInt32_t& size,
                        std::vector<AliHLTComponentBlockData>& outputBlocks
                );
-       
-    private:
-       
+
+private:
+
        AliHLTMUONTriggerReconstructor* fTrigRec;
 
        bool ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath);
@@ -85,6 +85,6 @@ class AliHLTMUONTriggerReconstructorComponent : public AliHLTProcessor
 
        ClassDef(AliHLTMUONTriggerReconstructorComponent, 0)
 
-    };
+};
     
 #endif // AliHLTMUONTRIGGERRECONSTRUCTORCOMPONENT_H