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. */
32 #include "AliHLTTRDClusterizerComponent.h"
33 #include "AliHLTTRDDefinitions.h"
35 #include "AliCDBManager.h"
36 #include "AliTRDclusterizerHLT.h"
37 #include "AliRawReaderMemory.h"
43 // this is a global object used for automatic component registration, do not use this
44 AliHLTTRDClusterizerComponent gAliHLTTRDClusterizerComponent;
46 ClassImp(AliHLTTRDClusterizerComponent);
48 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent()
50 , fOutputPercentage(100) // By default we copy to the output exactly what we got as input
51 , fStrorageDBpath("local://$ALICE_ROOT")
55 , fGeometryFileName("")
59 // Default constructor
61 fGeometryFileName = getenv("ALICE_ROOT");
62 fGeometryFileName += "/HLT/TRD/geometry.root";
65 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
71 const char* AliHLTTRDClusterizerComponent::GetComponentID()
73 // Return the component ID const char *
74 return "TRDClusterizer"; // The ID of this component
77 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
79 // Get the list of input data
80 list.clear(); // We do not have any requirements for our input data type(s).
81 list.push_back( AliHLTTRDDefinitions::fgkDDLRawDataType );
84 AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
86 // Get the output data type
87 return AliHLTTRDDefinitions::fgkClusterDataType;
90 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
92 // Get the output data size
94 inputMultiplier = ((double)fOutputPercentage)/100.0;
97 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
99 // Spawn function, return new instance of this class
100 return new AliHLTTRDClusterizerComponent;
103 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
105 // perform initialization. We check whether our relative output size is specified in the arguments.
106 fOutputPercentage = 100;
107 Int_t fRawDataVersion = 2;
112 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
113 if ( !strcmp( argv[i], "output_percentage" ) )
117 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing output_percentage parameter");
120 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
121 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
124 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
127 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
132 if ( strcmp( argv[i], "-cdb" ) == 0)
136 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -cdb argument");
139 fStrorageDBpath = argv[i+1];
140 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );
145 if ( strcmp( argv[i], "-rawver" ) == 0)
149 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -rawver argument");
152 fRawDataVersion = atoi( argv[i+1] );
153 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Raw Data", "Version is %d", fRawDataVersion );
158 if ( strcmp( argv[i], "-geometry" ) == 0)
162 Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing -geometry argument");
165 fGeometryFileName = argv[i+1];
166 Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "GeomFile storage set", "GeomFile storage is %s",
167 fGeometryFileName.c_str() );
172 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
176 fCDB = AliCDBManager::Instance();
179 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get CDB instance", "fCDB 0x%x", fCDB);
183 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
184 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
185 Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "CDB instance", "fCDB 0x%x", fCDB);
188 fGeometryFile = TFile::Open(fGeometryFileName.c_str());
191 fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
195 Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "fGeometryFile", "Unable to open file. FATAL!");
199 fMemReader = new AliRawReaderMemory;
201 fClusterizer = new AliTRDclusterizerHLT("TRDCclusterizer", "TRDCclusterizer");
202 fClusterizer->SetRawVersion(fRawDataVersion);
203 fClusterizer->InitClusterTree();
207 int AliHLTTRDClusterizerComponent::DoDeinit()
209 // Deinitialization of the component
218 fGeometryFile->Close();
219 delete fGeometryFile;
225 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "fCDB");
231 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks,
232 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
233 AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
236 // Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
237 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
239 unsigned long totalSize = 0;
240 AliHLTUInt32_t fDblock_Specification = 0;
242 //implement a usage of the following
243 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
244 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
245 // void *triggerData = trigData.fData;
246 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoEvent", "Trigger data received",
247 "Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
248 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoEvent", "Output status",
249 "Output pointer at 0x%x Output vector blocks at 0x%x", outputPtr, &outputBlocks);
251 // Loop over all input blocks in the event
252 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
254 char tmp1[14], tmp2[14];
255 DataType2Text( blocks[i].fDataType, tmp1 );
256 DataType2Text( AliHLTTRDDefinitions::fgkDDLRawDataType, tmp2 );
257 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoEvent", "Event received",
258 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
259 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
261 if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType )
263 Logging (kHLTLogError, "HLT::TRDClusterizer::DoEvent", "COMPARE FAILED", "type=%d is type=%d",
264 blocks[i].fDataType, AliHLTTRDDefinitions::fgkDDLRawDataType);
267 fDblock_Specification = blocks[i].fSpecification;
268 // Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "CHECKSPEC", "fDblock_Spec %d %d", i, fDblock_Specification);
269 unsigned long blockSize = blocks[i].fSize;
270 totalSize += blockSize;
273 void *memBufIn = calloc(totalSize, 1);
274 AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)memBufIn;
275 if (memBufIn == NULL)
277 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "MEMORY", "Unable to allocate %lu bytes", totalSize);
281 // Make the memory continuous
282 unsigned long copied = 0;
283 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
285 if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType )
288 void *pos = (void*)(pBuf + copied);
289 void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize);
292 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "MEMORY", "Unable to copy %lu bytes", blocks[i].fSize);
295 copied += blocks[i].fSize;
298 // Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "COPY STATS", "total=%lu copied=%lu", totalSize, copied);
301 fMemReader->SetMemory((UChar_t*)memBufIn, totalSize);
302 //fMemReader->SelectEquipment(0, 1024, 1041);
303 fMemReader->SetEquipmentID(1024);
304 //fMemReader->Reset();
305 // Bool_t ihead = fMemReader->ReadHeader();
306 // if (ihead == kTRUE)
308 // Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read successfully");
312 // Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read ERROR");
313 // //return -1; -- not FATAL
316 fClusterizer->ResetTree();
317 Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
318 if (iclustered == kTRUE)
320 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustered successfully");
324 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustering ERROR");
328 // AliRawReaderMemory reader;
330 // reader.SetMemory((UChar_t*)memBufIn, totalSize);
331 // //reader->Reset();
332 // Bool_t ihead = reader.ReadHeader();
333 // // if (ihead == kTRUE)
335 // // Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read successfully");
339 // // Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read ERROR");
340 // // //return -1; -- not FATAL
343 // fClusterizer->ResetTree();
345 // Bool_t iclustered = fClusterizer->Raw2ClustersChamber(&reader);
346 // if (iclustered == kTRUE)
348 // Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustered successfully");
352 // Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustering ERROR");
358 // put the tree into output blocks of TObjArrays
359 TTree *fcTree = fClusterizer->GetClusterTree();
361 PushBack(fcTree, AliHLTTRDDefinitions::fgkClusterDataType, fDblock_Specification);
363 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "DONE", "Output size %d", size);