1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
6 * Indranil Das <indra.das@saha.ac.in> *
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 *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
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
25 // Author : Indranil Das ( indra.das@saha.ac.in || indra.ehep@gmail.com )
29 #include "AliHLTMUONRecHitsBlockStruct.h"
30 #include "AliHLTMUONHitReconstructorComponent.h"
31 #include "AliHLTMUONHitReconstructor.h"
32 #include "AliHLTMUONConstants.h"
33 #include "AliHLTMUONDataBlockWriter.h"
34 #include "AliHLTLogging.h"
35 #include "AliHLTSystem.h"
36 #include "AliHLTDefinitions.h"
43 // The global object used for automatic component registration,
44 // Note DO NOT use this component for calculation!
45 AliHLTMUONHitReconstructorComponent gAliHLTMUONHitReconstructorComponent;
48 ClassImp(AliHLTMUONHitReconstructorComponent)
51 AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent() :
56 fWarnForUnexpecedBlock(false)
61 AliHLTMUONHitReconstructorComponent::~AliHLTMUONHitReconstructorComponent()
65 const char* AliHLTMUONHitReconstructorComponent::GetComponentID()
67 return AliHLTMUONConstants::HitReconstructorId();
71 void AliHLTMUONHitReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list)
74 list.push_back( AliHLTMUONConstants::TrackingDDLRawDataType() );
78 AliHLTComponentDataType AliHLTMUONHitReconstructorComponent::GetOutputDataType()
80 return AliHLTMUONConstants::RecHitsBlockDataType();
84 void AliHLTMUONHitReconstructorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
86 constBase = sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType);
91 // Spawn function, return new instance of this class
92 AliHLTComponent* AliHLTMUONHitReconstructorComponent::Spawn()
94 return new AliHLTMUONHitReconstructorComponent;
98 int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
100 // perform initialization. We check whether our relative output size is specified in the arguments.
102 HLTInfo("Initialising DHLT HitReconstruction Component");
104 fHitRec = new AliHLTMUONHitReconstructor();
105 fWarnForUnexpecedBlock = false;
107 // this is to get rid of the warning "unused parameter"
108 if (argc==0 && argv==NULL) {
109 HLTError("Arguments missing", " no arguments" );
112 char lutFileName[500],buspatchFileName[500];
118 HLTDebug("argv[%d] == %s", i, argv[i] );
120 if ( !strcmp( argv[i], "-lut" ) ) {
122 HLTError("LookupTable filename not specified" );
123 return EINVAL; /* Invalid argument */
126 sprintf(lutFileName,"%s",argv[i+1]);
133 if ( !strcmp( argv[i], "-ddl" ) ) {
135 HLTError("DDL number not specified" );
136 return EINVAL; /* Invalid argument */
139 unsigned long num = strtoul( argv[i+1], &cpErr, 0 );
140 if (cpErr == NULL or *cpErr != '\0')
142 HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] );
145 if (num < 13 or 20 < num)
147 HLTError("The DDL number must be in the range [13..20].");
157 if ( !strcmp( argv[i], "-rawdir" ) ) {
159 HLTError("DDL directory not specified" );
160 return EINVAL; /* Invalid argument */
163 fDDLDir = argv[i+1] ;
167 }// ddl directory argument
170 if ( !strcmp( argv[i], "-buspatchmap" ) ) {
172 HLTError("Buspatch filename not specified" );
173 return EINVAL; /* Invalid argument */
176 sprintf(buspatchFileName,"%s",argv[i+1]);
180 }// buspatch argument
182 if ( !strcmp( argv[i], "-rawreader" ) ) {
183 fReaderType = true; // true when using rawreader for standalone it is set to false.
188 if ( !strcmp( argv[i], "-warn_on_unexpected_block" ) ) {
189 fWarnForUnexpecedBlock = true;
194 HLTError("Unknown option '%s'", argv[i] );
199 int lutline = fHitRec->GetLutLine(fDDL);
200 AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline];
201 if(!ReadLookUpTable(lookupTable,lutFileName)){
202 HLTError("Failed to read lut, lut cannot be read, DoInit");
203 return ENOENT ; /* No such file or directory */
206 BusToDetElem busToDetElem;
208 if(!ReadBusPatchToDetElemFile(busToDetElem,busToDDL,buspatchFileName)){
209 HLTError("Failed to read buspatchmap, buspatchmap cannot be read, DoInit");
210 return ENOENT ; /* No such file or directory */
213 fHitRec->SetBusToDetMap(busToDetElem);
214 fHitRec->SetBusToDDLMap(busToDDL);
215 fHitRec->LoadLookUpTable(lookupTable,fDDL);
219 delete []lookupTable;
221 HLTInfo("Initialisation of DHLT HitReconstruction Component is done");
227 int AliHLTMUONHitReconstructorComponent::DoDeinit()
232 HLTInfo(" Deinitialising DHLT HitReconstruction Component");
238 int AliHLTMUONHitReconstructorComponent::DoEvent(
239 const AliHLTComponentEventData& evtData,
240 const AliHLTComponentBlockData* blocks,
241 AliHLTComponentTriggerData& /*trigData*/,
242 AliHLTUInt8_t* outputPtr,
243 AliHLTUInt32_t& size,
244 std::vector<AliHLTComponentBlockData>& outputBlocks
248 unsigned long totalSize = 0; // Amount of memory currently consumed in bytes.
250 HLTDebug("Processing event %llu with %u input data blocks.",
251 evtData.fEventID, evtData.fBlockCnt
254 // Loop over all input blocks in the event
255 for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
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';
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
273 if (blocks[n].fDataType != AliHLTMUONConstants::TrackingDDLRawDataType())
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';
286 if (fWarnForUnexpecedBlock)
287 HLTWarning("Received a data block of a type we cannot handle: '%s' origin: '%s'",
288 static_cast<char*>(id), static_cast<char*>(origin)
291 HLTDebug("Received a data block of a type we cannot handle: '%s' origin: '%s'",
292 static_cast<char*>(id), static_cast<char*>(origin)
298 // Create a new output data block and initialise the header.
299 AliHLTMUONRecHitsBlockWriter block(outputPtr+totalSize, size-totalSize);
300 if (not block.InitCommonHeader())
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),
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();
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 =================");
321 if (not fHitRec->Run(buffer, ddlRawDataSize, block.GetArray(), nofHit))
323 HLTError("Error while processing of hit reconstruction algorithm.");
324 size = totalSize; // Must tell the framework how much buffer space was used.
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);
333 HLTDebug("Number of reconstructed hits found is %d", nofHit);
335 // Fill a block data structure for our output block.
336 AliHLTComponentBlockData bd;
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);
346 // Increase the total amount of data written so far to our output memory
347 totalSize += block.BytesUsed();
349 // Finally we set the total size of output memory we consumed.
356 bool AliHLTMUONHitReconstructorComponent::ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath)
358 if (fDDL < AliHLTMUONHitReconstructor::GetkDDLOffSet() ||
359 fDDL >= AliHLTMUONHitReconstructor::GetkDDLOffSet() + AliHLTMUONHitReconstructor::GetkNofDDL()){
360 HLTError("DDL number is out of range");
364 int lutLine = fHitRec->GetLutLine(fDDL);
366 FILE* fin = fopen(lutpath, "r");
368 HLTError("Failed to open file: %s",lutpath);
372 for(int i=0;i<lutLine;i++){
375 "%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",
376 &lookupTable[i].fIdManuChannel,
379 &lookupTable[i].fRealX,
380 &lookupTable[i].fRealY,
381 &lookupTable[i].fRealZ,
382 &lookupTable[i].fPcbZone,
383 &lookupTable[i].fPlane
392 bool AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile(BusToDetElem& busToDetElem, BusToDDL& busToDDL, const char* buspatchmappath)
396 int detElem, minBusPatch, maxBusPatch, ddl;
398 FILE* fin = fopen(buspatchmappath, "r");
400 HLTError("Failed to open file: %s",buspatchmappath);
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){
409 for(int i = minBusPatch; i <= maxBusPatch; i++){
410 busToDetElem[i] = detElem;
414 } // while loop for file