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 "AliRawReaderMemory.h"
49 // this is a global object used for automatic component registration, do not use this
50 AliHLTTRDClusterizerComponent gAliHLTTRDClusterizerComponent;
52 ClassImp(AliHLTTRDClusterizerComponent);
54 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent()
56 , fOutputPercentage(100) // By default we copy to the output exactly what we got as input
57 , fStrorageDBpath("local://$ALICE_ROOT")
61 , fGeometryFileName("")
65 // Default constructor
67 fGeometryFileName = getenv("ALICE_ROOT");
68 fGeometryFileName += "/HLT/TRD/geometry.root";
71 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
77 const char* AliHLTTRDClusterizerComponent::GetComponentID()
79 // Return the component ID const char *
80 return "TRDClusterizer"; // The ID of this component
83 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
85 // Get the list of input data
86 list.clear(); // We do not have any requirements for our input data type(s).
87 list.push_back( AliHLTTRDDefinitions::fgkDDLRawDataType );
90 AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
92 // Get the output data type
93 return AliHLTTRDDefinitions::fgkClusterDataType;
96 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
98 // Get the output data size
100 inputMultiplier = ((double)fOutputPercentage)/100.0;
103 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
105 // Spawn function, return new instance of this class
106 return new AliHLTTRDClusterizerComponent;
109 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
111 // perform initialization. We check whether our relative output size is specified in the arguments.
112 fOutputPercentage = 100;
113 Int_t fRawDataVersion = 2;
118 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
119 if ( !strcmp( argv[i], "output_percentage" ) )
123 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing output_percentage parameter");
126 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
127 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
130 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
133 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
138 if ( strcmp( argv[i], "-cdb" ) == 0)
142 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -cdb argument");
145 fStrorageDBpath = argv[i+1];
146 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );
151 if ( strcmp( argv[i], "-rawver" ) == 0)
155 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -rawver argument");
158 fRawDataVersion = atoi( argv[i+1] );
159 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Raw Data", "Version is %d", fRawDataVersion );
164 if ( strcmp( argv[i], "-geometry" ) == 0)
168 Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing -geometry argument");
171 fGeometryFileName = argv[i+1];
172 Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "GeomFile storage set", "GeomFile storage is %s",
173 fGeometryFileName.c_str() );
178 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
182 fCDB = AliCDBManager::Instance();
185 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get CDB instance", "fCDB 0x%x", fCDB);
189 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
190 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
191 Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "CDB instance", "fCDB 0x%x", fCDB);
194 fGeometryFile = TFile::Open(fGeometryFileName.c_str());
197 fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
201 Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "fGeometryFile", "Unable to open file. FATAL!");
205 fMemReader = new AliRawReaderMemory;
207 fClusterizer = new AliTRDclusterizerHLT("TRDCclusterizer", "TRDCclusterizer");
208 fClusterizer->SetRawVersion(fRawDataVersion);
209 fClusterizer->InitClusterTree();
213 int AliHLTTRDClusterizerComponent::DoDeinit()
215 // Deinitialization of the component
224 fGeometryFile->Close();
225 delete fGeometryFile;
231 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "fCDB");
237 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks,
238 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
239 AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
242 // Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
243 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
245 unsigned long totalSize = 0;
246 AliHLTUInt32_t dBlockSpecification = 0;
248 //implement a usage of the following
249 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
250 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
251 // void *triggerData = trigData.fData;
252 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoEvent", "Trigger data received",
253 "Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
254 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoEvent", "Output status",
255 "Output pointer at 0x%x Output vector blocks at 0x%x", outputPtr, &outputBlocks);
257 // Loop over all input blocks in the event
258 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
260 char tmp1[14], tmp2[14];
261 DataType2Text( blocks[i].fDataType, tmp1 );
262 DataType2Text( AliHLTTRDDefinitions::fgkDDLRawDataType, tmp2 );
263 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoEvent", "Event received",
264 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
265 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
267 if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType )
269 Logging (kHLTLogError, "HLT::TRDClusterizer::DoEvent", "COMPARE FAILED", "type=%d is type=%d",
270 blocks[i].fDataType, AliHLTTRDDefinitions::fgkDDLRawDataType);
273 dBlockSpecification = blocks[i].fSpecification;
274 // Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "CHECKSPEC", "fDblock_Spec %d %d", i, dBlockSpecification);
275 unsigned long blockSize = blocks[i].fSize;
276 totalSize += blockSize;
279 void *memBufIn = calloc(totalSize, 1);
280 AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)memBufIn;
281 if (memBufIn == NULL)
283 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "MEMORY", "Unable to allocate %lu bytes", totalSize);
287 // Make the memory continuous
288 unsigned long copied = 0;
289 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
291 if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType )
294 void *pos = (void*)(pBuf + copied);
295 void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize);
298 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "MEMORY", "Unable to copy %lu bytes", blocks[i].fSize);
301 copied += blocks[i].fSize;
304 // Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "COPY STATS", "total=%lu copied=%lu", totalSize, copied);
307 fMemReader->SetMemory((UChar_t*)memBufIn, totalSize);
308 //fMemReader->SelectEquipment(0, 1024, 1041);
309 fMemReader->SetEquipmentID(1024);
310 //fMemReader->Reset();
311 // Bool_t ihead = fMemReader->ReadHeader();
312 // if (ihead == kTRUE)
314 // Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read successfully");
318 // Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read ERROR");
319 // //return -1; -- not FATAL
322 fClusterizer->ResetTree();
323 Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
324 if (iclustered == kTRUE)
326 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustered successfully");
330 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustering ERROR");
334 // AliRawReaderMemory reader;
336 // reader.SetMemory((UChar_t*)memBufIn, totalSize);
337 // //reader->Reset();
338 // Bool_t ihead = reader.ReadHeader();
339 // // if (ihead == kTRUE)
341 // // Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read successfully");
345 // // Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read ERROR");
346 // // //return -1; -- not FATAL
349 // fClusterizer->ResetTree();
351 // Bool_t iclustered = fClusterizer->Raw2ClustersChamber(&reader);
352 // if (iclustered == kTRUE)
354 // Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustered successfully");
358 // Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustering ERROR");
364 // put the tree into output blocks of TObjArrays
365 TTree *fcTree = fClusterizer->GetClusterTree();
367 PushBack(fcTree, AliHLTTRDDefinitions::fgkClusterDataType, dBlockSpecification);
369 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "DONE", "Output size %d", size);