1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * ALICE Experiment at CERN, All rights reserved. *
5 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
6 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
7 * for The ALICE HLT Project. *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
18 /** @file AliHLTEMCALClusterizerComponent.cxx
19 @author Mateusz Ploskon
21 @brief EMCAL clusterizer component for HLT. */
27 #include "AliHLTEMCALClusterizerComponent.h"
28 #include "AliHLTEMCALDefinitions.h"
29 #include "AliHLTEMCALUtils.h"
32 #include "TObjString.h"
33 #include "TObjArray.h"
35 #include "AliCDBEntry.h"
36 #include "AliCDBManager.h"
37 #include "AliRawReaderMemory.h"
39 // this is a global object used for automatic component registration, do not use this
40 AliHLTEMCALClusterizerComponent gAliHLTEMCALClusterizerComponent;
42 /** ROOT macro for the implementation of ROOT specific class methods */
43 ClassImp(AliHLTEMCALClusterizerComponent)
45 AliHLTEMCALClusterizerComponent::AliHLTEMCALClusterizerComponent()
47 , fOutputPercentage(100)
48 , fStorageDBpath("local://$ALICE_ROOT/OCDB")
50 , fGeometryFileName("")
52 // see header file for class documentation
54 // refer to README to build package
56 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
59 AliHLTEMCALClusterizerComponent::AliHLTEMCALClusterizerComponent(const AliHLTEMCALClusterizerComponent &/*c*/)
61 , fOutputPercentage(100)
62 , fStorageDBpath("local://$ALICE_ROOT/OCDB")
64 , fGeometryFileName("")
66 // may not use the copy contructor
67 HLTError("May not use.");
70 AliHLTEMCALClusterizerComponent& AliHLTEMCALClusterizerComponent::operator=(const AliHLTEMCALClusterizerComponent&)
72 // may not use the copy contructor
73 HLTError("May not use.");
77 AliHLTEMCALClusterizerComponent::~AliHLTEMCALClusterizerComponent()
79 // see header file for class documentation
82 AliHLTComponentDataType AliHLTEMCALClusterizerComponent::GetOutputDataType()
84 //return AliHLTEMCALDefinitions::fgkClusterDataType | AliHLTEMCALDefinitions::fgkDigitDataType;
85 return AliHLTEMCALDefinitions::fgkClusterDataType;
88 const char* AliHLTEMCALClusterizerComponent::GetComponentID()
90 return "EMCALClusterizer";
93 void AliHLTEMCALClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
95 list.push_back(kAliHLTAnyDataType);
98 void AliHLTEMCALClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
101 inputMultiplier = ((double)fOutputPercentage)/100.0;
104 int AliHLTEMCALClusterizerComponent::DoInit( int argc, const char** argv )
106 // see header file for class documentation
108 HLTInfo("parsing %d arguments", argc);
111 TString configuration="";
113 bool bHaveMandatory1=false;
114 bool bHaveMandatory2=false;
118 for (int i=0; i<argc && iResult>=0; i++)
121 if (argument.IsNull()) continue;
124 if (argument.CompareTo("-cdb")==0)
127 if ((bMissingParam=(++i>=argc))) break;
128 HLTInfo("got \'-cdb\' argument: %s", argv[i]);
129 fStorageDBpath = argv[i];
130 HLTInfo("CDB path is: %s", fStorageDBpath.c_str());
133 else if (argument.CompareTo("-geometry")==0)
136 if ((bMissingParam=(++i>=argc))) break;
137 HLTInfo("got \'-geometry\' argument");
138 fGeometryFileName = argv[i];
139 HLTInfo("Geometry file is: %s", fGeometryFileName.c_str());
142 else if (argument.CompareTo("-output_percentage")==0)
144 if ((bMissingParam=(++i>=argc))) break;
145 HLTInfo("got \'-output_percentage\' argument: %s", argv[i]);
146 fOutputPercentage = strtoul(argv[i], &cpErr, 0);
149 HLTError("Unable to convert ouput_percentage to a number %s", argv[i]);
155 // the remaining arguments are treated as configuration
156 if (!configuration.IsNull()) configuration+=" ";
157 configuration+=argument;
163 HLTError("missing parameter for argument %s", argument.Data());
167 if (iResult>=0 && !bHaveMandatory1)
169 HLTError("mandatory argument \'-cdb\' missing");
173 if (iResult>=0 && !bHaveMandatory2)
175 HLTError("mandatory argument \'-geometry\' missing");
179 if (iResult>=0 && !configuration.IsNull())
181 iResult=Configure(configuration.Data());
185 iResult=Reconfigure(NULL, NULL);
192 if (AliHLTEMCALUtils::GetGeometry() == NULL)
194 HLTError("unable to init geometry");
200 // clusterizer and raw utils
201 if (AliHLTEMCALUtils::GetRawUtils() == NULL)
203 HLTError("unable to init rawutils");
207 if (AliHLTEMCALUtils::GetRawUtils() == NULL)
209 HLTError("unable to init rawutils");
213 if (AliHLTEMCALUtils::GetRecParam() == NULL)
215 HLTError("unable to init reco params");
219 if (AliHLTEMCALUtils::GetClusterizer() == NULL)
221 HLTError("unable to init clusterizer");
228 int AliHLTEMCALClusterizerComponent::DoDeinit()
230 // see header file for class documentation
231 AliHLTEMCALUtils::Cleanup();
232 HLTInfo("processing cleanup");
236 int AliHLTEMCALClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
237 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
238 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks ) {
239 // see header file for class documentation
240 // check if the input data are there at all - empty events possible
241 HLTDebug("processing data");
242 if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0 &&
243 outputPtr==0 && size==0)
245 outputBlocks.clear();
246 // this is just to get rid of the warning "unused parameter"
251 ULong_t buffSize = 0;
252 Int_t eqID = 4608; //fixed for the moment - get this one from the input data
253 TString recoOption = "";
254 AliHLTUInt32_t dBlockSpecification = 0;
256 // Loop over all input blocks in the event
257 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
259 //if (blocks[i].fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginEMCAL))
260 if (blocks[i].fDataType != (kAliHLTDataTypeDDLRaw)) // for the moment until we have the EMCAL in the publisher setup
262 HLTWarning("COMPARE FAILED received type=%d expected-or-type=%d",
263 blocks[i].fDataType, kAliHLTDataTypeDDLRaw | kAliHLTDataOriginEMCAL);
267 dBlockSpecification = blocks[i].fSpecification;
268 unsigned long blockSize = blocks[i].fSize;
269 buffSize += blockSize;
272 buffer = (UChar_t*)calloc(buffSize, 1);
273 AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)buffer;
276 HLTError("Unable to allocate %lu bytes", buffSize);
280 // Make the memory continous
281 unsigned long copied = 0;
282 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
284 // we process only the raw data from TRD
285 if ( blocks[i].fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginEMCAL) )
288 void *pos = (void*)(pBuf + copied);
289 void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize);
292 HLTError("MEMORY Unable to copy %lu bytes", blocks[i].fSize);
295 copied += blocks[i].fSize;
298 // do it all function RAW->ClusterTree
299 // TTree* AliHLTEMCALUtils::RawBuffer2Clusters(UChar_t *buffer, ULong_t buffSize,
301 // Option_t* sDigitsOption)
303 AliHLTEMCALUtils::ResetReconstructionTrees();
304 TTree* outputTree = AliHLTEMCALUtils::RawBuffer2Clusters(buffer, buffSize, eqID, recoOption.Data());
305 PushBack(outputTree, AliHLTEMCALDefinitions::fgkClusterDataType);
307 TTree *digitsTree = AliHLTEMCALUtils::GetDigitsTree();
308 PushBack(digitsTree, AliHLTEMCALDefinitions::fgkDigitDataType);
315 int AliHLTEMCALClusterizerComponent::Configure(const char* arguments)
317 // see header file for class documentation
319 if (!arguments) return iResult;
320 HLTInfo("parsing configuration string \'%s\'", arguments);
322 TString allArgs = arguments;
326 TObjArray* pTokens = allArgs.Tokenize(" ");
329 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++)
331 argument=((TObjString*)pTokens->At(i))->GetString();
332 if (argument.IsNull()) continue;
333 HLTInfo("processing argument %\n", argument.Data());
335 if (argument.CompareTo("-cdb")==0)
337 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
338 HLTInfo("got \'-cdb\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
341 else if (argument.CompareTo("-geometry")==0)
343 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
344 HLTInfo("got \'-geometry\'");
346 else if (argument.CompareTo("-output_percentage")==0)
348 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
349 HLTInfo("got \'-output_percentage\'");
353 HLTError("unknown argument %s", argument.Data());
363 HLTError("missing parameter for argument %s", argument.Data());
370 int AliHLTEMCALClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
372 // see header file for class documentation
374 const char* path="HLT/ConfigEMCAL/EMCALClusterizerComponent";
375 const char* defaultNotify="";
379 defaultNotify=" (default)";
383 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
384 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
387 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
390 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
391 iResult=Configure(pString->GetString().Data());
394 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
399 HLTError("can not fetch object \"%s\" from CDB", path);
405 int AliHLTEMCALClusterizerComponent::ReadPreprocessorValues(const char* modules)
407 // see header file for class documentation
409 TString detectors(modules!=NULL?modules:"");
410 HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());