]>
Commit | Line | Data |
---|---|---|
b0201cbe | 1 | /************************************************************************** |
960d54ad | 2 | * This file is property of and copyright by the ALICE HLT Project * |
3 | * All rights reserved. * | |
b0201cbe | 4 | * * |
960d54ad | 5 | * Primary Authors: * |
6 | * Indranil Das <indra.das@saha.ac.in> * | |
b0201cbe | 7 | * * |
8 | * Permission to use, copy, modify and distribute this software and its * | |
9 | * documentation strictly for non-commercial purposes is hereby granted * | |
10 | * without fee, provided that the above copyright notice appears in all * | |
11 | * copies and that both the copyright notice and this permission notice * | |
12 | * appear in the supporting documentation. The authors make no claims * | |
960d54ad | 13 | * about the suitability of this software for any purpose. It is * |
b0201cbe | 14 | * provided "as is" without express or implied warranty. * |
15 | **************************************************************************/ | |
16 | ||
17 | /* $Id$ */ | |
18 | ||
baff881d | 19 | ///* |
20 | // | |
21 | // The HitRec Component is designed to deal the rawdata inputfiles to findout the | |
22 | // the reconstructed hits. The output is send to the output block for further | |
23 | // processing. | |
24 | // | |
25 | // Author : Indranil Das ( indra.das@saha.ac.in || indra.ehep@gmail.com ) | |
26 | // | |
27 | //*/ | |
b0201cbe | 28 | |
960d54ad | 29 | #include "AliHLTMUONRecHitsBlockStruct.h" |
b0201cbe | 30 | #include "AliHLTMUONHitReconstructorComponent.h" |
b12fe461 | 31 | #include "AliHLTMUONHitReconstructor.h" |
960d54ad | 32 | #include "AliHLTMUONConstants.h" |
5ff5f960 | 33 | #include "AliHLTMUONDataBlockWriter.h" |
b0201cbe | 34 | #include "AliHLTLogging.h" |
35 | #include "AliHLTSystem.h" | |
36 | #include "AliHLTDefinitions.h" | |
29486e5a | 37 | #include <cstdlib> |
38 | #include <cerrno> | |
39 | #include <cassert> | |
b0201cbe | 40 | |
41 | namespace | |
42 | { | |
43 | // The global object used for automatic component registration, | |
44 | // Note DO NOT use this component for calculation! | |
45 | AliHLTMUONHitReconstructorComponent gAliHLTMUONHitReconstructorComponent; | |
46 | } | |
47 | ||
b0201cbe | 48 | ClassImp(AliHLTMUONHitReconstructorComponent) |
49 | ||
50 | ||
29486e5a | 51 | AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent() : |
52 | fHitRec(NULL), | |
53 | fDDLDir(""), | |
54 | fDDL(0), | |
55 | fReaderType(false), | |
56 | fWarnForUnexpecedBlock(false) | |
b0201cbe | 57 | { |
b0201cbe | 58 | } |
59 | ||
960d54ad | 60 | |
b0201cbe | 61 | AliHLTMUONHitReconstructorComponent::~AliHLTMUONHitReconstructorComponent() |
62 | { | |
960d54ad | 63 | } |
b0201cbe | 64 | |
960d54ad | 65 | const char* AliHLTMUONHitReconstructorComponent::GetComponentID() |
66 | { | |
29486e5a | 67 | return AliHLTMUONConstants::HitReconstructorId(); |
b0201cbe | 68 | } |
69 | ||
b0201cbe | 70 | |
960d54ad | 71 | void AliHLTMUONHitReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list) |
72 | { | |
29486e5a | 73 | list.clear(); |
74 | list.push_back( AliHLTMUONConstants::TrackingDDLRawDataType() ); | |
960d54ad | 75 | } |
b0201cbe | 76 | |
b0201cbe | 77 | |
960d54ad | 78 | AliHLTComponentDataType AliHLTMUONHitReconstructorComponent::GetOutputDataType() |
79 | { | |
29486e5a | 80 | return AliHLTMUONConstants::RecHitsBlockDataType(); |
960d54ad | 81 | } |
b0201cbe | 82 | |
b0201cbe | 83 | |
960d54ad | 84 | void AliHLTMUONHitReconstructorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) |
85 | { | |
13f09bc1 | 86 | constBase = sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType); |
29486e5a | 87 | inputMultiplier = 1; |
960d54ad | 88 | } |
b0201cbe | 89 | |
b0201cbe | 90 | |
960d54ad | 91 | // Spawn function, return new instance of this class |
92 | AliHLTComponent* AliHLTMUONHitReconstructorComponent::Spawn() | |
93 | { | |
29486e5a | 94 | return new AliHLTMUONHitReconstructorComponent; |
960d54ad | 95 | } |
b0201cbe | 96 | |
b0201cbe | 97 | |
29486e5a | 98 | int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv) |
960d54ad | 99 | { |
100 | // perform initialization. We check whether our relative output size is specified in the arguments. | |
101 | ||
102 | HLTInfo("Initialising DHLT HitReconstruction Component"); | |
b0201cbe | 103 | |
960d54ad | 104 | fHitRec = new AliHLTMUONHitReconstructor(); |
29486e5a | 105 | fWarnForUnexpecedBlock = false; |
b0201cbe | 106 | |
960d54ad | 107 | // this is to get rid of the warning "unused parameter" |
108 | if (argc==0 && argv==NULL) { | |
109 | HLTError("Arguments missing", " no arguments" ); | |
110 | } | |
b0201cbe | 111 | |
960d54ad | 112 | char lutFileName[500],buspatchFileName[500]; |
b0201cbe | 113 | |
960d54ad | 114 | int i = 0; |
115 | char* cpErr; | |
116 | while ( i < argc ) | |
117 | { | |
118 | HLTDebug("argv[%d] == %s", i, argv[i] ); | |
119 | ||
b8d467da | 120 | if ( !strcmp( argv[i], "-lut" ) ) { |
960d54ad | 121 | if ( argc <= i+1 ) { |
122 | HLTError("LookupTable filename not specified" ); | |
123 | return EINVAL; /* Invalid argument */ | |
124 | } | |
125 | ||
126 | sprintf(lutFileName,"%s",argv[i+1]); | |
127 | ||
128 | i += 2; | |
129 | continue; | |
130 | }// lut argument | |
131 | ||
132 | ||
b8d467da | 133 | if ( !strcmp( argv[i], "-ddl" ) ) { |
960d54ad | 134 | if ( argc <= i+1 ) { |
135 | HLTError("DDL number not specified" ); | |
136 | return EINVAL; /* Invalid argument */ | |
137 | } | |
138 | ||
b8d467da | 139 | unsigned long num = strtoul( argv[i+1], &cpErr, 0 ); |
140 | if (cpErr == NULL or *cpErr != '\0') | |
960d54ad | 141 | { |
142 | HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] ); | |
143 | return EINVAL; | |
144 | } | |
b8d467da | 145 | if (num < 13 or 20 < num) |
146 | { | |
147 | HLTError("The DDL number must be in the range [13..20]."); | |
148 | return EINVAL; | |
149 | } | |
150 | fDDL = num - 1; | |
960d54ad | 151 | |
152 | i += 2; | |
153 | continue; | |
154 | }// ddl argument | |
155 | ||
156 | ||
b8d467da | 157 | if ( !strcmp( argv[i], "-rawdir" ) ) { |
960d54ad | 158 | if ( argc <= i+1 ) { |
159 | HLTError("DDL directory not specified" ); | |
160 | return EINVAL; /* Invalid argument */ | |
161 | } | |
162 | ||
163 | fDDLDir = argv[i+1] ; | |
164 | ||
165 | i += 2; | |
166 | continue; | |
167 | }// ddl directory argument | |
168 | ||
169 | ||
b8d467da | 170 | if ( !strcmp( argv[i], "-buspatchmap" ) ) { |
960d54ad | 171 | if ( argc <= i+1 ) { |
172 | HLTError("Buspatch filename not specified" ); | |
173 | return EINVAL; /* Invalid argument */ | |
174 | } | |
175 | ||
176 | sprintf(buspatchFileName,"%s",argv[i+1]); | |
177 | ||
178 | i += 2; | |
179 | continue; | |
180 | }// buspatch argument | |
181 | ||
b8d467da | 182 | if ( !strcmp( argv[i], "-rawreader" ) ) { |
960d54ad | 183 | fReaderType = true; // true when using rawreader for standalone it is set to false. |
184 | i += 1; | |
185 | continue; | |
186 | } | |
29486e5a | 187 | |
188 | if ( !strcmp( argv[i], "-warn_on_unexpected_block" ) ) { | |
189 | fWarnForUnexpecedBlock = true; | |
190 | i++; | |
191 | continue; | |
192 | } | |
960d54ad | 193 | |
194 | HLTError("Unknown option '%s'", argv[i] ); | |
195 | return EINVAL; | |
196 | ||
197 | }//while loop | |
198 | ||
199 | int lutline = fHitRec->GetLutLine(fDDL); | |
baff881d | 200 | AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline]; |
960d54ad | 201 | if(!ReadLookUpTable(lookupTable,lutFileName)){ |
202 | HLTError("Failed to read lut, lut cannot be read, DoInit"); | |
b0201cbe | 203 | return ENOENT ; /* No such file or directory */ |
204 | }else{ | |
960d54ad | 205 | |
b0201cbe | 206 | BusToDetElem busToDetElem; |
960d54ad | 207 | BusToDDL busToDDL; |
208 | if(!ReadBusPatchToDetElemFile(busToDetElem,busToDDL,buspatchFileName)){ | |
209 | HLTError("Failed to read buspatchmap, buspatchmap cannot be read, DoInit"); | |
b0201cbe | 210 | return ENOENT ; /* No such file or directory */ |
211 | } | |
960d54ad | 212 | |
b0201cbe | 213 | fHitRec->SetBusToDetMap(busToDetElem); |
960d54ad | 214 | fHitRec->SetBusToDDLMap(busToDDL); |
215 | fHitRec->LoadLookUpTable(lookupTable,fDDL); | |
216 | ||
b0201cbe | 217 | }// reading lut |
218 | ||
960d54ad | 219 | delete []lookupTable; |
220 | ||
221 | HLTInfo("Initialisation of DHLT HitReconstruction Component is done"); | |
222 | ||
b0201cbe | 223 | return 0; |
224 | } | |
225 | ||
960d54ad | 226 | |
227 | int AliHLTMUONHitReconstructorComponent::DoDeinit() | |
228 | { | |
b0201cbe | 229 | if(fHitRec) |
230 | delete fHitRec; | |
960d54ad | 231 | |
232 | HLTInfo(" Deinitialising DHLT HitReconstruction Component"); | |
233 | ||
b0201cbe | 234 | return 0; |
235 | } | |
236 | ||
b0201cbe | 237 | |
960d54ad | 238 | int AliHLTMUONHitReconstructorComponent::DoEvent( |
239 | const AliHLTComponentEventData& evtData, | |
b8d467da | 240 | const AliHLTComponentBlockData* blocks, |
241 | AliHLTComponentTriggerData& /*trigData*/, | |
242 | AliHLTUInt8_t* outputPtr, | |
960d54ad | 243 | AliHLTUInt32_t& size, |
244 | std::vector<AliHLTComponentBlockData>& outputBlocks | |
245 | ) | |
246 | { | |
29486e5a | 247 | // Process an event |
248 | unsigned long totalSize = 0; // Amount of memory currently consumed in bytes. | |
b0201cbe | 249 | |
29486e5a | 250 | HLTDebug("Processing event %llu with %u input data blocks.", |
251 | evtData.fEventID, evtData.fBlockCnt | |
252 | ); | |
253 | ||
254 | // Loop over all input blocks in the event | |
255 | for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ ) | |
5ff5f960 | 256 | { |
29486e5a | 257 | #ifdef __DEBUG |
258 | char id[kAliHLTComponentDataTypefIDsize+1]; | |
259 | for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) | |
260 | id[i] = blocks[n].fDataType.fID[i]; | |
261 | id[kAliHLTComponentDataTypefIDsize] = '\0'; | |
262 | char origin[kAliHLTComponentDataTypefOriginSize+1]; | |
263 | for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) | |
264 | origin[i] = blocks[n].fDataType.fOrigin[i]; | |
265 | origin[kAliHLTComponentDataTypefOriginSize] = '\0'; | |
266 | #endif // __DEBUG | |
267 | HLTDebug("Handling block: %u, with fDataType.fID = '%s'," | |
268 | " fDataType.fID = '%s', fPtr = %p and fSize = %u bytes.", | |
269 | n, static_cast<char*>(id), static_cast<char*>(origin), | |
270 | blocks[n].fPtr, blocks[n].fSize | |
5ff5f960 | 271 | ); |
29486e5a | 272 | |
273 | if (blocks[n].fDataType != AliHLTMUONConstants::TrackingDDLRawDataType()) | |
274 | { | |
275 | // Log a message indicating that we got a data block that we | |
276 | // do not know how to handle. | |
277 | char id[kAliHLTComponentDataTypefIDsize+1]; | |
278 | for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) | |
279 | id[i] = blocks[n].fDataType.fID[i]; | |
280 | id[kAliHLTComponentDataTypefIDsize] = '\0'; | |
281 | char origin[kAliHLTComponentDataTypefOriginSize+1]; | |
282 | for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) | |
283 | origin[i] = blocks[n].fDataType.fOrigin[i]; | |
284 | origin[kAliHLTComponentDataTypefOriginSize] = '\0'; | |
285 | ||
286 | if (fWarnForUnexpecedBlock) | |
d42549e3 | 287 | HLTWarning("Received a data block of a type we cannot handle: '%s' origin: '%s'", |
29486e5a | 288 | static_cast<char*>(id), static_cast<char*>(origin) |
289 | ); | |
290 | else | |
d42549e3 | 291 | HLTDebug("Received a data block of a type we cannot handle: '%s' origin: '%s'", |
29486e5a | 292 | static_cast<char*>(id), static_cast<char*>(origin) |
293 | ); | |
294 | ||
295 | continue; | |
296 | } | |
297 | ||
298 | // Create a new output data block and initialise the header. | |
299 | AliHLTMUONRecHitsBlockWriter block(outputPtr+totalSize, size-totalSize); | |
300 | if (not block.InitCommonHeader()) | |
301 | { | |
302 | HLTError("There is not enough space in the output buffer for the new data block.", | |
303 | " We require at least %u bytes, but have %u bytes left.", | |
304 | sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType), | |
305 | block.BufferSize() | |
306 | ); | |
307 | break; | |
308 | } | |
309 | ||
310 | AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t); | |
311 | AliHLTUInt32_t ddlRawDataSize = totalDDLSize - fHitRec->GetkDDLHeaderSize(); | |
312 | AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr) | |
313 | + fHitRec->GetkDDLHeaderSize(); | |
314 | AliHLTUInt32_t nofHit = block.MaxNumberOfEntries(); | |
315 | ||
316 | HLTDebug("=========== Dumping DDL payload buffer =========="); | |
317 | for (AliHLTUInt32_t j = 0; j < totalDDLSize; j++) | |
318 | HLTDebug("buffer[%d] : %x",j,buffer[j]); | |
319 | HLTDebug("================== End of dump ================="); | |
320 | ||
321 | if (not fHitRec->Run(buffer, ddlRawDataSize, block.GetArray(), nofHit)) | |
322 | { | |
323 | HLTError("Error while processing of hit reconstruction algorithm."); | |
324 | size = totalSize; // Must tell the framework how much buffer space was used. | |
325 | return EIO; | |
326 | } | |
327 | ||
328 | // nofHit should now contain the number of reconstructed hits actually found | |
329 | // and filled into the output data block, so we can set this number. | |
330 | assert( nofHit <= block.MaxNumberOfEntries() ); | |
331 | block.SetNumberOfEntries(nofHit); | |
332 | ||
333 | HLTDebug("Number of reconstructed hits found is %d", nofHit); | |
334 | ||
335 | // Fill a block data structure for our output block. | |
336 | AliHLTComponentBlockData bd; | |
337 | FillBlockData(bd); | |
338 | bd.fPtr = outputPtr; | |
339 | // This block's start (offset) is after all other blocks written so far. | |
340 | bd.fOffset = totalSize; | |
341 | bd.fSize = block.BytesUsed(); | |
342 | bd.fDataType = AliHLTMUONConstants::RecHitsBlockDataType(); | |
343 | bd.fSpecification = blocks[n].fSpecification; | |
344 | outputBlocks.push_back(bd); | |
345 | ||
346 | // Increase the total amount of data written so far to our output memory | |
347 | totalSize += block.BytesUsed(); | |
5ff5f960 | 348 | } |
29486e5a | 349 | // Finally we set the total size of output memory we consumed. |
350 | size = totalSize; | |
351 | ||
352 | return 0; | |
b0201cbe | 353 | } |
354 | ||
355 | ||
960d54ad | 356 | bool AliHLTMUONHitReconstructorComponent::ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath) |
b0201cbe | 357 | { |
960d54ad | 358 | if (fDDL < AliHLTMUONHitReconstructor::GetkDDLOffSet() || |
359 | fDDL >= AliHLTMUONHitReconstructor::GetkDDLOffSet() + AliHLTMUONHitReconstructor::GetkNofDDL()){ | |
360 | HLTError("DDL number is out of range"); | |
361 | return false; | |
362 | } | |
363 | ||
364 | int lutLine = fHitRec->GetLutLine(fDDL); | |
365 | ||
366 | FILE* fin = fopen(lutpath, "r"); | |
367 | if (fin == NULL){ | |
368 | HLTError("Failed to open file: %s",lutpath); | |
369 | return false; | |
370 | } | |
371 | ||
372 | for(int i=0;i<lutLine;i++){ | |
373 | fscanf( | |
374 | fin, | |
375 | "%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n", | |
376 | &lookupTable[i].fIdManuChannel, | |
377 | &lookupTable[i].fIX, | |
378 | &lookupTable[i].fIY, | |
379 | &lookupTable[i].fRealX, | |
380 | &lookupTable[i].fRealY, | |
381 | &lookupTable[i].fRealZ, | |
382 | &lookupTable[i].fPcbZone, | |
383 | &lookupTable[i].fPlane | |
384 | ); | |
385 | } | |
386 | ||
387 | fclose(fin); | |
388 | return true; | |
b0201cbe | 389 | } |
390 | ||
b0201cbe | 391 | |
960d54ad | 392 | bool AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile(BusToDetElem& busToDetElem, BusToDDL& busToDDL, const char* buspatchmappath) |
b0201cbe | 393 | { |
960d54ad | 394 | char getLine[80]; |
395 | char temp; | |
396 | int detElem, minBusPatch, maxBusPatch, ddl; | |
397 | ||
398 | FILE* fin = fopen(buspatchmappath, "r"); | |
399 | if (fin == NULL){ | |
400 | HLTError("Failed to open file: %s",buspatchmappath); | |
401 | return false; | |
402 | } | |
403 | ||
404 | while (feof(fin)==0){ | |
405 | fgets(getLine,80,fin); | |
406 | sscanf(getLine, "%d\t%d %c %d\t%d", &detElem, &minBusPatch, &temp, &maxBusPatch,&ddl); | |
407 | if (detElem >= 700 && detElem <= 1025){ | |
408 | ||
409 | for(int i = minBusPatch; i <= maxBusPatch; i++){ | |
410 | busToDetElem[i] = detElem; | |
411 | busToDDL[i] = ddl; | |
412 | }//for loop | |
413 | } // detElem condn | |
414 | } // while loop for file | |
415 | ||
416 | fclose(fin); | |
417 | return true; | |
b0201cbe | 418 | } |