3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /** @file AliHLTTRDClusterizerComponent.cxx
20 @author Timm Steinbeck, Matthias Richter
22 @brief A TRDClusterizer processing component for the HLT. */
24 // see header file for class documentation //
26 // refer to README to build package //
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt //
38 #include "AliHLTTRDClusterizerComponent.h"
39 #include "AliHLTTRDDefinitions.h"
41 #include "AliCDBManager.h"
42 #include "AliTRDclusterizerHLT.h"
43 #include "AliTRDReconstructor.h"
44 #include "AliTRDrecoParam.h"
45 #include "AliTRDrawStreamBase.h"
47 #include "AliRawReaderMemory.h"
53 // this is a global object used for automatic component registration, do not use this
54 AliHLTTRDClusterizerComponent gAliHLTTRDClusterizerComponent;
56 ClassImp(AliHLTTRDClusterizerComponent);
58 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent()
60 , fOutputPercentage(100) // By default we copy to the output exactly what we got as input
61 , fStrorageDBpath("local://$ALICE_ROOT")
66 , fGeometryFileName("")
70 // Default constructor
72 fGeometryFileName = getenv("ALICE_ROOT");
73 fGeometryFileName += "/HLT/TRD/geometry.root";
76 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
82 const char* AliHLTTRDClusterizerComponent::GetComponentID()
84 // Return the component ID const char *
85 return "TRDClusterizer"; // The ID of this component
88 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
90 // Get the list of input data
91 list.clear(); // We do not have any requirements for our input data type(s).
92 list.push_back( AliHLTTRDDefinitions::fgkDDLRawDataType );
95 AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
97 // Get the output data type
98 return AliHLTTRDDefinitions::fgkClusterDataType;
101 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
103 // Get the output data size
105 inputMultiplier = ((double)fOutputPercentage)/100.0;
108 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
110 // Spawn function, return new instance of this class
111 return new AliHLTTRDClusterizerComponent;
114 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
116 // perform initialization. We check whether our relative output size is specified in the arguments.
117 fOutputPercentage = 100;
118 Int_t iRawDataVersion = 2;
122 Int_t iRecoParamType = -1; // default will be the low flux
124 // the data type will become obsolete as soon as the formats are established
125 Int_t iRecoDataType = -1; // default will be simulation
129 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
130 if ( !strcmp( argv[i], "output_percentage" ) )
134 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing output_percentage parameter");
137 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
138 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
141 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
144 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
149 if ( strcmp( argv[i], "-cdb" ) == 0)
153 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -cdb argument");
156 fStrorageDBpath = argv[i+1];
157 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );
162 // the flux parametrizations
163 if ( strcmp( argv[i], "-lowflux" ) == 0)
166 HLTDebug("Low flux reco selected.");
171 if ( strcmp( argv[i], "-highflux" ) == 0)
174 HLTDebug("Low flux reco selected.");
179 // raw data type - sim or experiment
180 if ( strcmp( argv[i], "-simulation" ) == 0)
187 if ( strcmp( argv[i], "-experiment" ) == 0)
194 if ( strcmp( argv[i], "-rawver" ) == 0)
198 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -rawver argument");
201 iRawDataVersion = atoi( argv[i+1] );
202 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Raw Data", "Version is %d", iRawDataVersion );
207 if ( strcmp( argv[i], "-geometry" ) == 0)
211 Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing -geometry argument");
214 fGeometryFileName = argv[i+1];
215 Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "GeomFile storage set", "GeomFile storage is %s",
216 fGeometryFileName.c_str() );
221 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
225 // THE "REAL" INIT COMES HERE
227 if (iRecoParamType < 0 || iRecoParamType > 1)
229 HLTWarning("No reco param selected. Use -lowflux or -highflux flag. Defaulting to low flux.");
233 if (iRecoParamType == 0)
235 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
236 HLTDebug("Low flux params init.");
239 if (iRecoParamType == 1)
241 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
242 HLTDebug("High flux params init.");
247 HLTError("No reco params initialized. Sniffing big trouble!");
251 AliTRDReconstructor::SetRecoParam(fRecoParam);
253 // init the raw data type to be used...
254 // the switch here will become obsolete as soon as the data structures is fixed
255 // both: in sim and reality
256 if (iRecoDataType < 0 || iRecoDataType > 1)
258 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
262 if (iRecoDataType == 0)
264 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
265 HLTDebug("Data type expected is SIMULATION!");
268 if (iRecoDataType == 1)
270 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
271 HLTDebug("Data type expected is EXPERIMENT!");
274 // the DATA BASE STUFF
275 fCDB = AliCDBManager::Instance();
278 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get CDB instance", "fCDB 0x%x", fCDB);
282 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
283 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
284 Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "CDB instance", "fCDB 0x%x", fCDB);
287 fGeometryFile = TFile::Open(fGeometryFileName.c_str());
290 fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
294 Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "fGeometryFile", "Unable to open file. FATAL!");
298 fMemReader = new AliRawReaderMemory;
300 fClusterizer = new AliTRDclusterizerHLT("TRDCclusterizer", "TRDCclusterizer");
301 fClusterizer->SetRawVersion(iRawDataVersion);
302 fClusterizer->InitClusterTree();
306 int AliHLTTRDClusterizerComponent::DoDeinit()
308 // Deinitialization of the component
317 fGeometryFile->Close();
318 delete fGeometryFile;
324 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "fCDB");
331 HLTDebug("Deleting fRecoParam");
337 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponent_EventData& evtData,
338 const AliHLTComponent_BlockData* blocks,
339 AliHLTComponent_TriggerData& trigData,
340 AliHLTUInt8_t* /*outputPtr*/,
341 AliHLTUInt32_t& size,
342 vector<AliHLTComponent_BlockData>& /*outputBlocks*/ )
345 HLTDebug("NofBlocks %lu", evtData.fBlockCnt );
347 unsigned long totalSize = 0;
348 AliHLTUInt32_t dBlockSpecification = 0;
350 //implement a usage of the following
351 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
352 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
353 // void *triggerData = trigData.fData;
354 HLTDebug("Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
356 // Loop over all input blocks in the event
357 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
359 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
360 // which is depreciated - we use HLT global defs instead
361 if ( blocks[i].fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
363 HLTWarning("COMPARE FAILED received type=%d expected-or-type=%d",
364 blocks[i].fDataType, kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
368 dBlockSpecification = blocks[i].fSpecification;
369 unsigned long blockSize = blocks[i].fSize;
370 totalSize += blockSize;
373 void *memBufIn = calloc(totalSize, 1);
374 AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)memBufIn;
375 if (memBufIn == NULL)
377 HLTError("Unable to allocate %lu bytes", totalSize);
381 // Make the memory continuous
382 unsigned long copied = 0;
383 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
385 // we process only the raw data from TRD
386 if ( blocks[i].fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
389 void *pos = (void*)(pBuf + copied);
390 void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize);
393 //Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "MEMORY", "Unable to copy %lu bytes", blocks[i].fSize);
394 // so here i am not sure which log scheme finaly to use...
395 HLTError("MEMORY Unable to copy %lu bytes", blocks[i].fSize);
396 // maybe put a reasonable return value here...
399 copied += blocks[i].fSize;
402 // lets see what we copied...
403 HLTDebug("COPY STATS total=%lu copied=%lu", totalSize, copied);
406 fMemReader->SetMemory((UChar_t*)memBufIn, totalSize);
408 //fMemReader->SelectEquipment(0, 1024, 1041);
410 // 1024 is good for SM 0 - it should be good for any other too
411 // but in principle the EquipmentID should come with the data
412 fMemReader->SetEquipmentID(1024);
414 fClusterizer->ResetTree();
415 Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
416 if (iclustered == kTRUE)
418 HLTDebug("Clustered successfully");
422 HLTError("Clustering ERROR");
429 // put the tree into output blocks
430 TTree *fcTree = fClusterizer->GetClusterTree();
432 PushBack(fcTree, AliHLTTRDDefinitions::fgkClusterDataType, dBlockSpecification);
434 size=0; // this function did not write data to the buffer directly