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. */
28 #include "AliHLTTRDClusterizerComponent.h"
29 #include "AliHLTTRDDefinitions.h"
31 #include "AliCDBManager.h"
32 #include "AliTRDclusterizerV1HLT.h"
33 #include "AliRawReaderMemory.h"
42 // this is a global object used for automatic component registration, do not use this
43 AliHLTTRDClusterizerComponent gAliHLTTRDClusterizerComponent;
45 ClassImp(AliHLTTRDClusterizerComponent);
47 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent()
49 , fOutputPercentage(100) // By default we copy to the output exactly what we got as input
50 , fStrorageDBpath("local://$ALICE_ROOT")
55 // Default constructor
58 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
64 const char* AliHLTTRDClusterizerComponent::GetComponentID()
66 // Return the component ID const char *
67 return "TRDClusterizer"; // The ID of this component
70 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
72 // Get the list of input data
73 list.clear(); // We do not have any requirements for our input data type(s).
74 list.push_back( AliHLTTRDDefinitions::fgkDDLRawDataType );
77 AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
79 // Get the output data type
80 return AliHLTTRDDefinitions::fgkClusterDataType;
83 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
85 // Get the output data size
87 inputMultiplier = ((double)fOutputPercentage)/100.0;
90 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
92 // Spawn function, return new instance of this class
93 return new AliHLTTRDClusterizerComponent;
96 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
98 // perform initialization. We check whether our relative output size is specified in the arguments.
99 fOutputPercentage = 100;
100 Int_t fRawDataVersion = 2;
105 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
106 if ( !strcmp( argv[i], "output_percentage" ) )
110 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing output_percentage parameter");
113 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
114 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
117 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
120 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
125 if ( strcmp( argv[i], "-cdb" ) == 0)
129 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -cdb argument");
132 fStrorageDBpath = argv[i+1];
133 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );
138 if ( strcmp( argv[i], "-rawver" ) == 0)
142 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -rawver argument");
145 fRawDataVersion = atoi( argv[i+1] );
146 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Raw Data", "Version is %d", fRawDataVersion );
151 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
155 fCDB = AliCDBManager::Instance();
158 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get CDB instance", "fCDB 0x%x", fCDB);
162 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
163 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
164 Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "CDB instance", "fCDB 0x%x", fCDB);
167 fMemReader = new AliRawReaderMemory;
168 fClusterizer = new AliTRDclusterizerV1HLT("TRDCclusterizer", "TRDCclusterizer");
169 fClusterizer->SetRawDataVersion(fRawDataVersion);
170 fClusterizer->InitClusterTree();
174 int AliHLTTRDClusterizerComponent::DoDeinit()
176 // Deinitialization of the component
185 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "fCDB");
191 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks,
192 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
193 AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
196 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
197 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
199 unsigned long totalSize = 0;
200 AliHLTUInt32_t fDblock_Specification = 0;
202 // Loop over all input blocks in the event
203 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
205 char tmp1[14], tmp2[14];
206 DataType2Text( blocks[i].fDataType, tmp1 );
207 DataType2Text( AliHLTTRDDefinitions::fgkDDLRawDataType, tmp2 );
208 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoEvent", "Event received",
209 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
210 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
212 if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType )
214 Logging (kHLTLogError, "HLT::TRDClusterizer::DoEvent", "COMPARE FAILED", "type=%d is type=%d",
215 blocks[i].fDataType, AliHLTTRDDefinitions::fgkDDLRawDataType);
218 fDblock_Specification = blocks[i].fSpecification;
219 unsigned long blockSize = blocks[i].fSize;
220 totalSize += blockSize;
223 void *memBufIn = calloc(totalSize, 1);
224 AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)memBufIn;
225 if (memBufIn == NULL)
227 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "MEMORY", "Unable to allocate %lu bytes", totalSize);
231 // Make the memory continuous
232 unsigned long copied = 0;
233 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
235 if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType )
238 void *pos = (void*)(pBuf + copied);
239 void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize);
242 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "MEMORY", "Unable to copy %lu bytes", blocks[i].fSize);
245 copied += blocks[i].fSize;
248 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "COPY STATS", "total=%lu copied=%lu", totalSize, copied);
251 fMemReader->SetMemory((UChar_t*)memBufIn, totalSize);
252 //fMemReader->Reset();
253 Bool_t ihead = fMemReader->ReadHeader();
256 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read successfully");
260 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read ERROR");
261 //return -1; -- not FATAL
264 fClusterizer->ResetTree();
265 Bool_t ireadD = fClusterizer->ReadDigits(fMemReader);
268 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "DIGITS", "Digits read successfully");
272 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "DIGITS", "Digits read ERROR");
276 Bool_t iclustered = fClusterizer->MakeClusters();
277 if (iclustered == kTRUE)
279 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustered successfully");
283 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustering ERROR");
289 //UInt_t memBufOutSize = 0;
290 // void *memBufOut = fClusterizer->WriteClustersToMemory(memBufOut, memBufOutSize);
291 Int_t iNclusters = fClusterizer->GetNclusters();
292 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "COUNT", "N of Clusters = %d", iNclusters);
294 // put the tree into output blocks of TObjArrays
295 TTree *fcTree = fClusterizer->GetClusterTree();
296 TList *lt = (TList*)fcTree->GetListOfBranches();
300 while ((tb = (TBranch*)it.Next()) != 0)
302 TObjArray *clusters = 0;
303 tb->SetAddress(&clusters);
304 for (Int_t icb = 0; icb < tb->GetEntries(); icb++)
307 PushBack(clusters, AliHLTTRDDefinitions::fgkClusterDataType, fDblock_Specification);