X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=HLT%2FPHOS%2FAliHLTPHOSClusterizerComponent.cxx;h=a41eef0aa76d5a811860ba6767c4575184cee763;hb=ab846928f114c031ffb722773f10d29f67e1212c;hp=0ba2da303d5cf79f7f46577830a8e80e74688e56;hpb=ab38011bd4f71ce9ac052ac6a9dda0eb20c04d19;p=u%2Fmrichter%2FAliRoot.git diff --git a/HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx b/HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx index 0ba2da303d5..a41eef0aa76 100644 --- a/HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx +++ b/HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx @@ -1,7 +1,9 @@ +// $Id$ + /************************************************************************** * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * * * - * Authors: Øystein Djuvsland * + * Authors: Oystein Djuvsland * * * * Permission to use, copy, modify and distribute this software and its * * documentation strictly for non-commercial purposes is hereby granted * @@ -12,85 +14,62 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ - - +#include #include "AliHLTPHOSClusterizerComponent.h" #include "AliHLTPHOSClusterizer.h" -//#include "AliHLTPHOSPhysicsDefinitions.h" -//#include "AliHLTPHOSDefinitions.h" #include "AliHLTPHOSRecPointDataStruct.h" -#include "AliHLTPHOSClusterDataStruct.h" -#include "AliHLTPHOSRecPointListDataStruct.h" +#include "AliHLTPHOSRecPointHeaderStruct.h" +#include "AliHLTPHOSDigitDataStruct.h" #include "AliHLTPHOSDigitContainerDataStruct.h" -using namespace std; -const AliHLTComponentDataType AliHLTPHOSClusterizerComponent::fgkInputDataTypes[]= - { - kAliHLTVoidDataType,{0,"",""} - }; +/** @file AliHLTPHOSClusterizerComponent.cxx + @author Oystein Djuvsland + @date + @brief A clusterizer component for PHOS HLT +*/ + +// see header file for class documentation +// or +// refer to README to build package +// or +// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent; -//AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSBase(), AliHLTProcessor(), fClusterizerPtr(0), fOutPtr(0), -// fRecPointStructArrayPtr(0), fRecPointListPtr(0) -AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSProcessor(), fClusterizerPtr(0), fOutPtr(0), - fRecPointStructArrayPtr(0), fRecPointListPtr(0) +AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): + AliHLTPHOSProcessor(), + fAllDigitsPtr(0), + fClusterizerPtr(0), + fDigitCount(0), + fNoCrazyness(0) { - //Constructor + //See headerfile for documentation } AliHLTPHOSClusterizerComponent::~AliHLTPHOSClusterizerComponent() { - //Destructor + //See headerfile for documentation - if (fClusterizerPtr) + if(fClusterizerPtr) { delete fClusterizerPtr; fClusterizerPtr = 0; } - - if (fRecPointListPtr) - { - delete fRecPointListPtr; - fRecPointListPtr = 0; - } - - if (fRecPointStructArrayPtr) + if(fAllDigitsPtr) { - for (int i = 0; i < 1000; i++) - { - // fRecPointStructArrayPtr[i].Del(); - } - delete fRecPointStructArrayPtr; - fRecPointStructArrayPtr = 0; + delete fAllDigitsPtr; + fAllDigitsPtr = 0; } - } -/* -int -AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent::Deinit() -{ - ////////// PTH WARNING you should Define a class AliHLTPHOSModuleProcessor -} -*/ - -// PTH AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(const AliHLTPHOSClusterizerComponent &):AliHLTProcessor(), -// fClusterizerPtr(0), -// fOutPtr(0), -// fRecPointStructArrayPtr(0), -// fRecPointListPtr(0) -//{ -//Copy constructor, not implemented -//} int AliHLTPHOSClusterizerComponent::Deinit() { - //Deinitialization + //See headerfile for documentation if (fClusterizerPtr) { @@ -98,72 +77,38 @@ AliHLTPHOSClusterizerComponent::Deinit() fClusterizerPtr = 0; } - if (fRecPointListPtr) - { - delete fRecPointListPtr; - fRecPointListPtr = 0; - } - - for (int i = 0; i < 1000; i++) - { - // fRecPointStructArrayPtr[i].Del(); - } - - if (fRecPointStructArrayPtr) - { - for (int i = 0; i < 1000; i++) - { - // fRecPointStructArrayPtr[i].Del(); - } - delete fRecPointStructArrayPtr; - fRecPointStructArrayPtr = 0; - } - - return 0; -} - -int -AliHLTPHOSClusterizerComponent::DoDeinit() -{ - //Do deinitialization - Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSClusterizerComponent DoDeinit"); - return 0; } - const Char_t* AliHLTPHOSClusterizerComponent::GetComponentID() { - //comment - return "AliHltPhosClusterizer"; + //See headerfile for documentation + return "PhosClusterizer"; } void AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector& list) { - //Get datatypes for input - const AliHLTComponentDataType* pType=fgkInputDataTypes; - while (pType->fID!=0) - { - list.push_back(*pType); - pType++; - } + //See headerfile for documentation + list.clear(); + list.push_back(AliHLTPHOSDefinitions::fgkDigitDataType); } AliHLTComponentDataType AliHLTPHOSClusterizerComponent::GetOutputDataType() { - // return AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType; - return AliHLTPHOSDefinitions::fgkAliHLTClusterDataType; + //See headerfile for documentation + return AliHLTPHOSDefinitions::fgkRecPointDataType; } void AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier ) { - constBase = 30; - inputMultiplier = 0.2; + //See headerfile for documentation + constBase = sizeof(AliHLTPHOSRecPointHeaderStruct) + sizeof(AliHLTPHOSRecPointDataStruct) + (sizeof(AliHLTPHOSDigitDataStruct) << 7); //Reasonable estimate... ; + inputMultiplier = 1.5; } int @@ -171,136 +116,229 @@ AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, std::vector& outputBlocks) { - //Do event + //See headerfile for documentation - UInt_t tSize = 0; + if(blocks == 0) return 0; + UInt_t offset = 0; UInt_t mysize = 0; Int_t nRecPoints = 0; Int_t nDigits = 0; - Int_t index = 0; - Int_t j =0; + UInt_t availableSize = size; AliHLTUInt8_t* outBPtr; outBPtr = outputPtr; const AliHLTComponentBlockData* iter = 0; unsigned long ndx; + + UInt_t specification = 0; + + AliHLTPHOSDigitHeaderStruct *digitHeaderPtr = 0; + AliHLTPHOSDigitHeaderStruct *outputDigitHeaderPtr = reinterpret_cast(outBPtr); + + // HLTError("Header pointer before screwing around: 0x%x", outputDigitHeaderPtr); - AliHLTPHOSDigitContainerDataStruct *digitContainerPtr = 0; + AliHLTPHOSDigitDataStruct *firstDigitPtr = 0; + AliHLTPHOSDigitDataStruct *lastDigitPtr = 0; - //AliHLTPHOSRecPointContainerStruct *recPointContainerPtr = (AliHLTPHOSRecPointContainerStruct*)outBPtr; - fClusterizerPtr->SetRecPointContainer((AliHLTPHOSRecPointContainerStruct*)outBPtr); + // Adding together all the digits, should be put in standalone method for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) { iter = blocks+ndx; - digitContainerPtr = reinterpret_cast(iter->fPtr); - if (iter->fDataType != AliHLTPHOSDefinitions::fgkAliHLTDigitDataType) - { - // cout << "Warning: data type is not fgkAliHLTDigitDataType " << endl; - continue; - } - for (Int_t i = 0; i < digitContainerPtr->fNDigits; i++) - { - if(fNoCrazyness && digitContainerPtr->fDigitDataStruct[i].fCrazyness) - continue; - - fAllDigitsPtr->fDigitDataStruct[j+nDigits].fX = digitContainerPtr->fDigitDataStruct[i].fX; - fAllDigitsPtr->fDigitDataStruct[j+nDigits].fZ = digitContainerPtr->fDigitDataStruct[i].fZ; - fAllDigitsPtr->fDigitDataStruct[j+nDigits].fAmplitude = digitContainerPtr->fDigitDataStruct[i].fAmplitude; - fAllDigitsPtr->fDigitDataStruct[j+nDigits].fTime = digitContainerPtr->fDigitDataStruct[i].fTime; - // fAllDigitsPtr->fDigitDataStruct[i+nDigits].fCrazyness = digitContainerPtr->fDigitDataStruct[i].fCrazyness; - j++; - } - nDigits++; + if (iter->fDataType == AliHLTPHOSDefinitions::fgkDigitDataType) + { + // Get the digit header + digitHeaderPtr = reinterpret_cast(iter->fPtr); + + // Update the number of digits + nDigits += digitHeaderPtr->fNDigits; + + // Get the specification + specification = specification|iter->fSpecification; + + // Check if we have the first buffer in the event + if(!firstDigitPtr) + { + if(availableSize < digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct) + sizeof(AliHLTPHOSDigitHeaderStruct)) + { + // HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size); + HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", mysize, size); + return -1; + } + // If so, lets copy the header and the corresponding digits to the output + memcpy(outBPtr, iter->fPtr, digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct) + sizeof(AliHLTPHOSDigitHeaderStruct)); + + // Set the pointer to the first digit in the list + // firstDigitPtr = reinterpret_cast(outBPtr + sizeof(AliHLTPHOSDigitHeaderStruct) + digitHeaderPtr->fFirstDigitOffset); + firstDigitPtr = reinterpret_cast(outBPtr + digitHeaderPtr->fFirstDigitOffset); + + // lastDigitPtr = reinterpret_cast(outBPtr + sizeof(AliHLTPHOSDigitHeaderStruct) + digitHeaderPtr->fLastDigitOffset); + lastDigitPtr = reinterpret_cast(outBPtr + digitHeaderPtr->fLastDigitOffset); + + // Update the amount of the output buffer we have used + mysize += digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct) + sizeof(AliHLTPHOSDigitHeaderStruct); + } + else + { + // Check if we have space for + if(availableSize < digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct)) + { + HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", mysize, size); + return -1; + } + + // If we already have copied the first buffer to the output copy only the digits + memcpy(outBPtr, reinterpret_cast(reinterpret_cast(iter->fPtr)+sizeof(AliHLTPHOSDigitHeaderStruct)), digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct)); + + // Check if the first digit in this buffer has a ID less than the first digit in the previous + // if(firstDigitPtr->fID > reinterpret_cast(reinterpret_cast(iter->fPtr) + sizeof(AliHLTPHOSDigitDataStruct) + digitHeaderPtr->fFirstDigitOffset)->fID) + AliHLTPHOSDigitDataStruct *thisFirst = + reinterpret_cast(reinterpret_cast(iter->fPtr) + digitHeaderPtr->fFirstDigitOffset); + if(firstDigitPtr->fID > thisFirst->fID) + { + // If that is the case we have to take care of the ordering + + HLTError("Re-ordering digit blocks..."); + // The last digit in the current buffer has to link to the first digit in the previous buffer + // AliHLTPHOSDigitDataStruct *thisLast = reinterpret_cast(outBPtr + sizeof(AliHLTPHOSDigitHeaderStruct) + digitHeaderPtr->fLastDigitOffset); + AliHLTPHOSDigitDataStruct *thisLast = reinterpret_cast(outBPtr - sizeof(AliHLTPHOSDigitHeaderStruct) + digitHeaderPtr->fLastDigitOffset); + thisLast->fMemOffsetNext = reinterpret_cast(firstDigitPtr) - reinterpret_cast(thisLast); + + // Setting the pointer to the new first digit + firstDigitPtr = reinterpret_cast(outBPtr + digitHeaderPtr->fFirstDigitOffset - sizeof(AliHLTPHOSDigitHeaderStruct)); + } + else + { + // Previous last digit need to link to the current first digit + lastDigitPtr->fMemOffsetNext = reinterpret_cast(lastDigitPtr) - (reinterpret_cast(outBPtr) + digitHeaderPtr->fFirstDigitOffset - sizeof(AliHLTPHOSDigitHeaderStruct)); + + // We need to change the last digit pointer + lastDigitPtr = reinterpret_cast(reinterpret_cast(outBPtr) + digitHeaderPtr->fLastDigitOffset - sizeof(AliHLTPHOSDigitHeaderStruct)); + } + // Update the amount of the output buffer we have used + mysize += digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct); + } + + outBPtr += mysize; + } + } + + // The digit header in the output needs to know about the position of the new first digit + // outputDigitHeaderPtr->fFirstDigitOffset = reinterpret_cast(firstDigitPtr) - reinterpret_cast(outputDigitHeaderPtr) + sizeof(AliHLTPHOSDigitHeaderStruct); + outputDigitHeaderPtr->fFirstDigitOffset = reinterpret_cast(firstDigitPtr) - reinterpret_cast(outputDigitHeaderPtr); + + // The digit header in the output needs to know about the position of the new last digit + // outputDigitHeaderPtr->fLastDigitOffset = reinterpret_cast(lastDigitPtr) - reinterpret_cast(outputDigitHeaderPtr) + sizeof(AliHLTPHOSDigitHeaderStruct); + outputDigitHeaderPtr->fLastDigitOffset = reinterpret_cast(lastDigitPtr) - reinterpret_cast(outputDigitHeaderPtr); + if(firstDigitPtr) + { + // HLTError("Header pointer after screwing around: 0x%x", outputDigitHeaderPtr); + // HLTError("First/last offset: %d / %d, first digit ID: %d, energy: %f", outputDigitHeaderPtr->fFirstDigitOffset, outputDigitHeaderPtr->fLastDigitOffset, firstDigitPtr->fID, firstDigitPtr->fEnergy); } -// nRecPoints = fClusterizerPtr->CreateRecPointStructArray(fRecPointStructArrayPtr, fRecPointListPtr, index); - - fOutPtr = (AliHLTPHOSRecPointContainerStruct*)outBPtr; - nRecPoints = fClusterizerPtr->ClusterizeEvent(); - //nRecPoints = fClusterizerPtr->CalculateCenterOfGravity(&fRecPointStructArrayPtr[i]); - cout << "Number of clusters found: " << nRecPoints << " extracted from " << nDigits << " digits" << endl; - - mysize = 0; - offset = tSize; + HLTDebug("Number of digits: %d", nDigits); - // fClusterizerPtr->CalculateMoments(&fRecPointStructArrayPtr[i], 0); - // fClusterizerPtr->ClusterizeStruct(&fRecPointStructArrayPtr[i], fOutPtr); + if(nDigits > 0) + { - mysize += sizeof(AliHLTPHOSClusterDataStruct); + AliHLTPHOSRecPointHeaderStruct* recPointHeaderPtr = reinterpret_cast(outBPtr); - AliHLTComponentBlockData bd; - FillBlockData( bd ); - bd.fOffset = offset; - bd.fSize = mysize; - // PTH bd.fDataType = AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType; - bd.fDataType = AliHLTPHOSDefinitions::fgkAliHLTClusterDataType; - bd.fSpecification = 0xFFFFFFFF; - outputBlocks.push_back( bd ); + fClusterizerPtr->SetRecPointDataPtr(reinterpret_cast(outBPtr+sizeof(AliHLTPHOSRecPointHeaderStruct))); - tSize += mysize; - outBPtr += mysize; + nRecPoints = fClusterizerPtr->ClusterizeEvent(outputDigitHeaderPtr, availableSize, mysize); + recPointHeaderPtr->fNRecPoints = nRecPoints; - if ( tSize > size ) + mysize += sizeof(AliHLTPHOSRecPointHeaderStruct); + + HLTDebug("Number of clusters: %d", nRecPoints); + } + AliHLTComponentBlockData clusterBd; + FillBlockData( clusterBd ); + clusterBd.fOffset = offset; + clusterBd.fSize = mysize; + clusterBd.fDataType = AliHLTPHOSDefinitions::fgkRecPointDataType; + clusterBd.fSpecification = specification; + outputBlocks.push_back( clusterBd ); + + if(false) { - Logging( kHLTLogFatal, "HLT::AliHLTPHOSClusterizerComponent::DoEvent", "Too much data", - "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu." - , tSize, size ); - return EMSGSIZE; + AliHLTComponentBlockData digitBd; + FillBlockData(digitBd); } + + size = mysize; + + return 0; +} +int +AliHLTPHOSClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/) +{ + // see header file for class documentation - size = tSize; -// fClusterizerPtr->ResetCellEnergyArray(); + const char* path="HLT/ConfigPHOS/ClusterizerComponent"; - return 0; + if (cdbEntry) path = cdbEntry; + + return ConfigureFromCDBTObjString(cdbEntry); +} + +int +AliHLTPHOSClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv) +{ + //See header file for documentation + + if(argc <= 0) return 0; + + int i=0; + TString argument=argv[i]; + + if (argument.CompareTo("-digitthreshold") == 0) + { + if (++i >= argc) return -EPROTO; + argument = argv[i]; + fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof()); + return 1; + } + + if (argument.CompareTo("-recpointthreshold") == 0) + { + if (++i >= argc) return -EPROTO; + argument = argv[i]; + fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof()); + return 1; + } + return 0; } int AliHLTPHOSClusterizerComponent::DoInit(int argc, const char** argv ) { - //Do initialization + //See headerfile for documentation + fAllDigitsPtr = new AliHLTPHOSDigitContainerDataStruct(); fClusterizerPtr = new AliHLTPHOSClusterizer(); - //fClusterizerPtr->SetNoCrazyness(true); + fClusterizerPtr->SetDigitContainer(fAllDigitsPtr); + fNoCrazyness = false; // + + // const char *path = "HLT/ConfigPHOS/ClusterizerComponent"; + + // ConfigureFromCDBTObjString(path); + for (int i = 0; i < argc; i++) { - /* - if(!strcmp("-threshold", argv[i])) - fClusterizerPtr->SetThreshold(atof(argv[i+1])); - if(!strcmp("-clusterthreshold", argv[i])) - fClusterizerPtr->SetClusterThreshold(atof(argv[i+1])); - if(!strcmp("-highgain", argv[i])) - fClusterizerPtr->SetHighGainFactor(atof(argv[i+1])); - if(!strcmp("-lowgain", argv[i])) - fClusterizerPtr->SetLowGainFactor(atof(argv[i+1])); - if(!strcmp("-arraysize", argv[i])) - fClusterizerPtr->SetArraySize(atoi(argv[i+1]));*/ + ScanConfigurationArgument(i, argv); } - // fClusterizerPtr->ResetCellEnergyArray(); - fRecPointListPtr = new AliHLTPHOSRecPointListDataStruct[N_ZROWS_MOD*N_XCOLUMNS_MOD]; - fRecPointStructArrayPtr = new AliHLTPHOSRecPointDataStruct[1000]; - for (int i = 0; i < 1000; i++) - { - fRecPointStructArrayPtr[i].fMultiplicity = atoi(argv[4])* atoi(argv[4]); - // fRecPointStructArrayPtr[i].New(); - } - /* - printf("Clusterizer component started with:\n"); - printf(" Cell threshold: %f\n", fClusterizerPtr->GetThreshold()); - printf(" Cluster threshold: %f\n", fClusterizerPtr->GetClusterThreshold()); - printf(" High gain factor: %f\n", fClusterizerPtr->GetHighGainFactor()); - printf(" Low gain factor: %f\n", fClusterizerPtr->GetLowGainFactor()); - printf(" Cluster array size: %d\n\n", fClusterizerPtr->GetArraySize()); - */ + return 0; } AliHLTComponent* AliHLTPHOSClusterizerComponent::Spawn() { - //Spawn a new AliHLTPHOSClusterizerComponent, for HLT framework + //See headerfile for documentation + return new AliHLTPHOSClusterizerComponent(); }