3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Oystein Djuvsland <oysteind@ift.uib.no> *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
19 #include "AliHLTPHOSClusterizerComponent.h"
20 #include "AliHLTPHOSClusterizer.h"
21 #include "AliHLTPHOSRecPointDataStruct.h"
22 #include "AliHLTPHOSRecPointHeaderStruct.h"
23 #include "AliHLTPHOSDigitDataStruct.h"
24 #include "AliHLTPHOSDigitContainerDataStruct.h"
28 /** @file AliHLTPHOSClusterizerComponent.cxx
29 @author Oystein Djuvsland
31 @brief A clusterizer component for PHOS HLT
34 // see header file for class documentation
36 // refer to README to build package
38 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
40 AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent;
42 AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent():
43 AliHLTPHOSProcessor(),
49 //See headerfile for documentation
52 AliHLTPHOSClusterizerComponent::~AliHLTPHOSClusterizerComponent()
54 //See headerfile for documentation
58 delete fClusterizerPtr;
70 AliHLTPHOSClusterizerComponent::Deinit()
72 //See headerfile for documentation
76 delete fClusterizerPtr;
84 AliHLTPHOSClusterizerComponent::GetComponentID()
86 //See headerfile for documentation
87 return "PhosClusterizer";
91 AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
93 //See headerfile for documentation
95 list.push_back(AliHLTPHOSDefinitions::fgkDigitDataType);
98 AliHLTComponentDataType
99 AliHLTPHOSClusterizerComponent::GetOutputDataType()
101 //See headerfile for documentation
102 return AliHLTPHOSDefinitions::fgkRecPointDataType;
106 AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
109 //See headerfile for documentation
110 constBase = sizeof(AliHLTPHOSRecPointHeaderStruct) + sizeof(AliHLTPHOSRecPointDataStruct) + (sizeof(AliHLTPHOSDigitDataStruct) << 7); //Reasonable estimate... ;
111 inputMultiplier = 1.5;
115 AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
116 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
117 std::vector<AliHLTComponentBlockData>& outputBlocks)
119 //See headerfile for documentation
121 if(blocks == 0) return 0;
125 Int_t nRecPoints = 0;
128 UInt_t availableSize = size;
129 AliHLTUInt8_t* outBPtr;
131 const AliHLTComponentBlockData* iter = 0;
134 UInt_t specification = 0;
136 AliHLTPHOSDigitHeaderStruct *digitHeaderPtr = 0;
137 AliHLTPHOSDigitHeaderStruct *outputDigitHeaderPtr = reinterpret_cast<AliHLTPHOSDigitHeaderStruct*>(outBPtr);
139 // HLTError("Header pointer before screwing around: 0x%x", outputDigitHeaderPtr);
141 AliHLTPHOSDigitDataStruct *firstDigitPtr = 0;
142 AliHLTPHOSDigitDataStruct *lastDigitPtr = 0;
144 // Adding together all the digits, should be put in standalone method
145 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
148 if (iter->fDataType == AliHLTPHOSDefinitions::fgkDigitDataType)
150 // Get the digit header
151 digitHeaderPtr = reinterpret_cast<AliHLTPHOSDigitHeaderStruct*>(iter->fPtr);
153 // Update the number of digits
154 nDigits += digitHeaderPtr->fNDigits;
156 // Get the specification
157 specification = specification|iter->fSpecification;
159 // Check if we have the first buffer in the event
162 if(availableSize < digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct) + sizeof(AliHLTPHOSDigitHeaderStruct))
164 // HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
165 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", mysize, size);
168 // If so, lets copy the header and the corresponding digits to the output
169 memcpy(outBPtr, iter->fPtr, digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct) + sizeof(AliHLTPHOSDigitHeaderStruct));
171 // Set the pointer to the first digit in the list
172 // firstDigitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outBPtr + sizeof(AliHLTPHOSDigitHeaderStruct) + digitHeaderPtr->fFirstDigitOffset);
173 firstDigitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outBPtr + digitHeaderPtr->fFirstDigitOffset);
175 // lastDigitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outBPtr + sizeof(AliHLTPHOSDigitHeaderStruct) + digitHeaderPtr->fLastDigitOffset);
176 lastDigitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outBPtr + digitHeaderPtr->fLastDigitOffset);
178 // Update the amount of the output buffer we have used
179 mysize += digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct) + sizeof(AliHLTPHOSDigitHeaderStruct);
183 // Check if we have space for
184 if(availableSize < digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct))
186 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", mysize, size);
190 // If we already have copied the first buffer to the output copy only the digits
191 memcpy(outBPtr, reinterpret_cast<const void*>(reinterpret_cast<UChar_t*>(iter->fPtr)+sizeof(AliHLTPHOSDigitHeaderStruct)), digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct));
193 // Check if the first digit in this buffer has a ID less than the first digit in the previous
194 // if(firstDigitPtr->fID > reinterpret_cast<AliHLTPHOSDigitDataStruct*>(reinterpret_cast<UChar_t*>(iter->fPtr) + sizeof(AliHLTPHOSDigitDataStruct) + digitHeaderPtr->fFirstDigitOffset)->fID)
195 AliHLTPHOSDigitDataStruct *thisFirst =
196 reinterpret_cast<AliHLTPHOSDigitDataStruct*>(reinterpret_cast<UChar_t*>(iter->fPtr) + digitHeaderPtr->fFirstDigitOffset);
197 if(firstDigitPtr->fID > thisFirst->fID)
199 // If that is the case we have to take care of the ordering
201 HLTError("Re-ordering digit blocks...");
202 // The last digit in the current buffer has to link to the first digit in the previous buffer
203 // AliHLTPHOSDigitDataStruct *thisLast = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outBPtr + sizeof(AliHLTPHOSDigitHeaderStruct) + digitHeaderPtr->fLastDigitOffset);
204 AliHLTPHOSDigitDataStruct *thisLast = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outBPtr - sizeof(AliHLTPHOSDigitHeaderStruct) + digitHeaderPtr->fLastDigitOffset);
205 thisLast->fMemOffsetNext = reinterpret_cast<Long_t>(firstDigitPtr) - reinterpret_cast<Long_t>(thisLast);
207 // Setting the pointer to the new first digit
208 firstDigitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outBPtr + digitHeaderPtr->fFirstDigitOffset - sizeof(AliHLTPHOSDigitHeaderStruct));
212 // Previous last digit need to link to the current first digit
213 lastDigitPtr->fMemOffsetNext = reinterpret_cast<Long_t>(lastDigitPtr) - (reinterpret_cast<Long_t>(outBPtr) + digitHeaderPtr->fFirstDigitOffset - sizeof(AliHLTPHOSDigitHeaderStruct));
215 // We need to change the last digit pointer
216 lastDigitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(reinterpret_cast<Long_t>(outBPtr) + digitHeaderPtr->fLastDigitOffset - sizeof(AliHLTPHOSDigitHeaderStruct));
218 // Update the amount of the output buffer we have used
219 mysize += digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct);
226 // The digit header in the output needs to know about the position of the new first digit
227 // outputDigitHeaderPtr->fFirstDigitOffset = reinterpret_cast<Long_t>(firstDigitPtr) - reinterpret_cast<Long_t>(outputDigitHeaderPtr) + sizeof(AliHLTPHOSDigitHeaderStruct);
228 outputDigitHeaderPtr->fFirstDigitOffset = reinterpret_cast<Long_t>(firstDigitPtr) - reinterpret_cast<Long_t>(outputDigitHeaderPtr);
230 // The digit header in the output needs to know about the position of the new last digit
231 // outputDigitHeaderPtr->fLastDigitOffset = reinterpret_cast<Long_t>(lastDigitPtr) - reinterpret_cast<Long_t>(outputDigitHeaderPtr) + sizeof(AliHLTPHOSDigitHeaderStruct);
232 outputDigitHeaderPtr->fLastDigitOffset = reinterpret_cast<Long_t>(lastDigitPtr) - reinterpret_cast<Long_t>(outputDigitHeaderPtr);
235 // HLTError("Header pointer after screwing around: 0x%x", outputDigitHeaderPtr);
236 // HLTError("First/last offset: %d / %d, first digit ID: %d, energy: %f", outputDigitHeaderPtr->fFirstDigitOffset, outputDigitHeaderPtr->fLastDigitOffset, firstDigitPtr->fID, firstDigitPtr->fEnergy);
239 HLTDebug("Number of digits: %d", nDigits);
244 AliHLTPHOSRecPointHeaderStruct* recPointHeaderPtr = reinterpret_cast<AliHLTPHOSRecPointHeaderStruct*>(outBPtr);
246 fClusterizerPtr->SetRecPointDataPtr(reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(outBPtr+sizeof(AliHLTPHOSRecPointHeaderStruct)));
248 nRecPoints = fClusterizerPtr->ClusterizeEvent(outputDigitHeaderPtr, availableSize, mysize);
249 recPointHeaderPtr->fNRecPoints = nRecPoints;
251 mysize += sizeof(AliHLTPHOSRecPointHeaderStruct);
253 HLTDebug("Number of clusters: %d", nRecPoints);
255 AliHLTComponentBlockData clusterBd;
256 FillBlockData( clusterBd );
257 clusterBd.fOffset = offset;
258 clusterBd.fSize = mysize;
259 clusterBd.fDataType = AliHLTPHOSDefinitions::fgkRecPointDataType;
260 clusterBd.fSpecification = specification;
261 outputBlocks.push_back( clusterBd );
265 AliHLTComponentBlockData digitBd;
266 FillBlockData(digitBd);
275 AliHLTPHOSClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
277 // see header file for class documentation
279 const char* path="HLT/ConfigPHOS/ClusterizerComponent";
281 if (cdbEntry) path = cdbEntry;
283 return ConfigureFromCDBTObjString(cdbEntry);
287 AliHLTPHOSClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv)
289 //See header file for documentation
291 if(argc <= 0) return 0;
295 TString argument=argv[i];
297 if (argument.CompareTo("-digitthreshold") == 0)
299 if (++i >= argc) return -EPROTO;
301 fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof());
305 if (argument.CompareTo("-recpointthreshold") == 0)
307 if (++i >= argc) return -EPROTO;
309 fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof());
316 AliHLTPHOSClusterizerComponent::DoInit(int argc, const char** argv )
318 //See headerfile for documentation
320 fAllDigitsPtr = new AliHLTPHOSDigitContainerDataStruct();
321 fClusterizerPtr = new AliHLTPHOSClusterizer();
322 fClusterizerPtr->SetDigitContainer(fAllDigitsPtr);
323 fNoCrazyness = false;
326 // const char *path = "HLT/ConfigPHOS/ClusterizerComponent";
328 // ConfigureFromCDBTObjString(path);
330 for (int i = 0; i < argc; i++)
332 ScanConfigurationArgument(i, argv);
339 AliHLTPHOSClusterizerComponent::Spawn()
341 //See headerfile for documentation
343 return new AliHLTPHOSClusterizerComponent();