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
53 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
57 const char* AliHLTTRDClusterizerComponent::GetComponentID()
59 return "TRDClusterizer"; // The ID of this component
62 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
64 list.clear(); // We do not have any requirements for our input data type(s).
65 list.push_back( AliHLTTRDDefinitions::fgkDDLRawDataType );
68 AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
70 return AliHLTTRDDefinitions::fgkClusterDataType;
73 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
76 inputMultiplier = ((double)fOutputPercentage)/100.0;
81 // Spawn function, return new instance of this class
82 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
84 return new AliHLTTRDClusterizerComponent;
87 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
89 // perform initialization. We check whether our relative output size is specified in the arguments.
90 fOutputPercentage = 100;
91 Int_t fRawDataVersion = 2;
96 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
97 if ( !strcmp( argv[i], "output_percentage" ) )
101 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing output_percentage parameter");
104 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
105 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
108 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
111 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
116 if ( strcmp( argv[i], "-cdb" ) == 0)
120 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -cdb argument");
123 fStrorageDBpath = argv[i+1];
124 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );
129 if ( strcmp( argv[i], "-rawver" ) == 0)
133 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -rawver argument");
136 fRawDataVersion = atoi( argv[i+1] );
137 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Raw Data", "Version is %d", fRawDataVersion );
142 Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
146 cdb = AliCDBManager::Instance();
149 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get CDB instance", "cdb 0x%x", cdb);
153 cdb->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
154 cdb->SetDefaultStorage(fStrorageDBpath.c_str());
155 Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "CDB instance", "cdb 0x%x", cdb);
158 rmem = new AliRawReaderMemory;
159 clusterizer = new AliTRDclusterizerV1HLT("TRDCclusterizer", "TRDCclusterizer");
160 clusterizer->SetRawDataVersion(fRawDataVersion);
161 clusterizer->InitClusterTree();
165 int AliHLTTRDClusterizerComponent::DoDeinit()
175 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "cdb");
181 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks,
182 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
183 AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
185 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
186 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
188 unsigned long totalSize = 0;
189 AliHLTUInt32_t fDblock_Specification = 0;
191 // Loop over all input blocks in the event
192 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
194 char tmp1[14], tmp2[14];
195 DataType2Text( blocks[i].fDataType, tmp1 );
196 DataType2Text( AliHLTTRDDefinitions::fgkDDLRawDataType, tmp2 );
197 Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoEvent", "Event received",
198 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
199 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
201 if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType )
203 Logging (kHLTLogError, "HLT::TRDClusterizer::DoEvent", "COMPARE FAILED", "type=%d is type=%d",
204 blocks[i].fDataType, AliHLTTRDDefinitions::fgkDDLRawDataType);
207 fDblock_Specification = blocks[i].fSpecification;
208 unsigned long blockSize = blocks[i].fSize;
209 totalSize += blockSize;
212 void *memBufIn = calloc(totalSize, 1);
213 AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)memBufIn;
214 if (memBufIn == NULL)
216 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "MEMORY", "Unable to allocate %lu bytes", totalSize);
220 // Make the memory continuous
221 unsigned long copied = 0;
222 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
224 if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType )
227 void *pos = (void*)(pBuf + copied);
228 void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize);
231 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "MEMORY", "Unable to copy %lu bytes", blocks[i].fSize);
234 copied += blocks[i].fSize;
237 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "COPY STATS", "total=%lu copied=%lu", totalSize, copied);
240 rmem->SetMemory((UChar_t*)memBufIn, totalSize);
242 Bool_t ihead = rmem->ReadHeader();
245 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read successfully");
249 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read ERROR");
250 //return -1; -- not FATAL
253 clusterizer->ResetTree();
254 Bool_t ireadD = clusterizer->ReadDigits(rmem);
257 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "DIGITS", "Digits read successfully");
261 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "DIGITS", "Digits read ERROR");
265 Bool_t iclustered = clusterizer->MakeClusters();
266 if (iclustered == kTRUE)
268 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustered successfully");
272 Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustering ERROR");
278 UInt_t memBufOutSize = 0;
279 // void *memBufOut = clusterizer->WriteClustersToMemory(memBufOut, memBufOutSize);
280 Int_t iNclusters = clusterizer->GetNclusters();
281 Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "COUNT", "N of Clusters = %d", iNclusters);
283 // put the tree into output blocks of TObjArrays
284 TTree *fcTree = clusterizer->GetClusterTree();
285 TList *lt = (TList*)fcTree->GetListOfBranches();
289 while ((tb = (TBranch*)it.Next()) != 0)
291 TObjArray *clusters = 0;
292 tb->SetAddress(&clusters);
293 for (Int_t icb = 0; icb < tb->GetEntries(); icb++)
296 PushBack(clusters, AliHLTTRDDefinitions::fgkClusterDataType, fDblock_Specification);