/************************************************************************** * This file is property of and copyright by the ALICE HLT Project * * All rights reserved. * * * * Primary Authors: * * Indranil Das * * * * Permission to use, copy, modify and distribute this software and its * * documentation strictly for non-commercial purposes is hereby granted * * without fee, provided that the above copyright notice appears in all * * copies and that both the copyright notice and this permission notice * * appear in the supporting documentation. The authors make no claims * * about the suitability of this software for any purpose. It is * * provided "as is" without express or implied warranty. * **************************************************************************/ /* $Id$ */ /// /// /// The HitRec Component is designed to deal the rawdata inputfiles to findout the /// the reconstructed hits. The output is send to the output block for further /// processing. /// /// Author : Indranil Das ( indra.das@saha.ac.in || indra.ehep@gmail.com ) /// #include "AliHLTMUONRecHitsBlockStruct.h" #include "AliHLTMUONHitReconstructorComponent.h" #include "AliHLTMUONHitReconstructor.h" #include "AliHLTMUONConstants.h" #include "AliHLTMUONUtils.h" #include "AliHLTMUONDataBlockWriter.h" #include "AliHLTLogging.h" #include "AliHLTSystem.h" #include "AliHLTDefinitions.h" #include #include #include ClassImp(AliHLTMUONHitReconstructorComponent) AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent() : AliHLTProcessor(), fHitRec(NULL), fDDLDir(""), fDDL(0), fReaderType(false), fWarnForUnexpecedBlock(false) { /// /// Default constructor. /// } AliHLTMUONHitReconstructorComponent::~AliHLTMUONHitReconstructorComponent() { /// /// Default destructor. /// } const char* AliHLTMUONHitReconstructorComponent::GetComponentID() { /// /// Inherited from AliHLTComponent. Returns the component ID. /// return AliHLTMUONConstants::HitReconstructorId(); } void AliHLTMUONHitReconstructorComponent::GetInputDataTypes( std::vector& list) { /// /// Inherited from AliHLTProcessor. Returns the list of expected input data types. /// list.clear(); list.push_back( AliHLTMUONConstants::DDLRawDataType() ); } AliHLTComponentDataType AliHLTMUONHitReconstructorComponent::GetOutputDataType() { /// /// Inherited from AliHLTComponent. Returns the output data type. /// return AliHLTMUONConstants::RecHitsBlockDataType(); } void AliHLTMUONHitReconstructorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { /// /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size. /// constBase = sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType); inputMultiplier = 1; } AliHLTComponent* AliHLTMUONHitReconstructorComponent::Spawn() { /// /// Inherited from AliHLTComponent. Creates a new object instance. /// return new AliHLTMUONHitReconstructorComponent; } int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv) { /// /// Inherited from AliHLTComponent. /// Parses the command line parameters and initialises the component. /// // perform initialization. We check whether our relative output size is specified in the arguments. HLTInfo("Initialising DHLT HitReconstruction Component"); fHitRec = new AliHLTMUONHitReconstructor(); fWarnForUnexpecedBlock = false; // this is to get rid of the warning "unused parameter" if (argc==0 && argv==NULL) { HLTError("Arguments missing", " no arguments" ); } char lutFileName[500],buspatchFileName[500]; int i = 0; char* cpErr; while ( i < argc ) { HLTDebug("argv[%d] == %s", i, argv[i] ); if ( !strcmp( argv[i], "-lut" ) ) { if ( argc <= i+1 ) { HLTError("LookupTable filename not specified" ); return EINVAL; /* Invalid argument */ } sprintf(lutFileName,"%s",argv[i+1]); i += 2; continue; }// lut argument if ( !strcmp( argv[i], "-ddl" ) ) { if ( argc <= i+1 ) { HLTError("DDL number not specified" ); return EINVAL; /* Invalid argument */ } unsigned long num = strtoul( argv[i+1], &cpErr, 0 ); if (cpErr == NULL or *cpErr != '\0') { HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] ); return EINVAL; } if (num < 13 or 20 < num) { HLTError("The DDL number must be in the range [13..20]."); return EINVAL; } fDDL = num - 1; i += 2; continue; }// ddl argument if ( !strcmp( argv[i], "-rawdir" ) ) { if ( argc <= i+1 ) { HLTError("DDL directory not specified" ); return EINVAL; /* Invalid argument */ } fDDLDir = argv[i+1] ; i += 2; continue; }// ddl directory argument if ( !strcmp( argv[i], "-buspatchmap" ) ) { if ( argc <= i+1 ) { HLTError("Buspatch filename not specified" ); return EINVAL; /* Invalid argument */ } sprintf(buspatchFileName,"%s",argv[i+1]); i += 2; continue; }// buspatch argument if ( !strcmp( argv[i], "-rawreader" ) ) { fReaderType = true; // true when using rawreader for standalone it is set to false. i += 1; continue; } if ( !strcmp( argv[i], "-warn_on_unexpected_block" ) ) { fWarnForUnexpecedBlock = true; i++; continue; } HLTError("Unknown option '%s'", argv[i] ); return EINVAL; }//while loop int lutline = fHitRec->GetLutLine(fDDL); AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline]; if(!ReadLookUpTable(lookupTable,lutFileName)){ HLTError("Failed to read lut, lut cannot be read, DoInit"); return ENOENT ; /* No such file or directory */ }else{ BusToDetElem busToDetElem; BusToDDL busToDDL; if(!ReadBusPatchToDetElemFile(busToDetElem,busToDDL,buspatchFileName)){ HLTError("Failed to read buspatchmap, buspatchmap cannot be read, DoInit"); return ENOENT ; /* No such file or directory */ } fHitRec->SetBusToDetMap(busToDetElem); fHitRec->SetBusToDDLMap(busToDDL); fHitRec->LoadLookUpTable(lookupTable,fDDL); }// reading lut delete []lookupTable; HLTInfo("Initialisation of DHLT HitReconstruction Component is done"); return 0; } int AliHLTMUONHitReconstructorComponent::DoDeinit() { /// /// Inherited from AliHLTComponent. Performs a cleanup of the component. /// if(fHitRec) delete fHitRec; HLTInfo(" Deinitialising DHLT HitReconstruction Component"); return 0; } int AliHLTMUONHitReconstructorComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, std::vector& outputBlocks ) { /// /// Inherited from AliHLTProcessor. Processes the new event data. /// // Process an event unsigned long totalSize = 0; // Amount of memory currently consumed in bytes. HLTDebug("Processing event %llu with %u input data blocks.", evtData.fEventID, evtData.fBlockCnt ); // Loop over all input blocks in the event for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ ) { #ifdef __DEBUG char id[kAliHLTComponentDataTypefIDsize+1]; for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) id[i] = blocks[n].fDataType.fID[i]; id[kAliHLTComponentDataTypefIDsize] = '\0'; char origin[kAliHLTComponentDataTypefOriginSize+1]; for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) origin[i] = blocks[n].fDataType.fOrigin[i]; origin[kAliHLTComponentDataTypefOriginSize] = '\0'; #endif // __DEBUG HLTDebug("Handling block: %u, with fDataType.fID = '%s'," " fDataType.fID = '%s', fPtr = %p and fSize = %u bytes.", n, static_cast(id), static_cast(origin), blocks[n].fPtr, blocks[n].fSize ); if (blocks[n].fDataType != AliHLTMUONConstants::DDLRawDataType() or not AliHLTMUONUtils::IsTrackerDDL(blocks[n].fSpecification) ) { // Log a message indicating that we got a data block that we // do not know how to handle. char id[kAliHLTComponentDataTypefIDsize+1]; for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) id[i] = blocks[n].fDataType.fID[i]; id[kAliHLTComponentDataTypefIDsize] = '\0'; char origin[kAliHLTComponentDataTypefOriginSize+1]; for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) origin[i] = blocks[n].fDataType.fOrigin[i]; origin[kAliHLTComponentDataTypefOriginSize] = '\0'; if (fWarnForUnexpecedBlock) HLTWarning("Received a data block of a type we cannot handle: '%s' origin: '%s' spec: 0x%X", static_cast(id), static_cast(origin), blocks[n].fSpecification ); else HLTDebug("Received a data block of a type we cannot handle: '%s' origin: '%s' spec: 0x%X", static_cast(id), static_cast(origin), blocks[n].fSpecification ); continue; } // Create a new output data block and initialise the header. AliHLTMUONRecHitsBlockWriter block(outputPtr+totalSize, size-totalSize); if (not block.InitCommonHeader()) { HLTError("There is not enough space in the output buffer for the new data block.", " We require at least %u bytes, but have %u bytes left.", sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType), block.BufferSize() ); break; } AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t); AliHLTUInt32_t ddlRawDataSize = totalDDLSize - fHitRec->GetkDDLHeaderSize(); AliHLTUInt32_t* buffer = reinterpret_cast(blocks[n].fPtr) + fHitRec->GetkDDLHeaderSize(); AliHLTUInt32_t nofHit = block.MaxNumberOfEntries(); HLTDebug("=========== Dumping DDL payload buffer =========="); for (AliHLTUInt32_t j = 0; j < totalDDLSize; j++) HLTDebug("buffer[%d] : %x",j,buffer[j]); HLTDebug("================== End of dump ================="); if (not fHitRec->Run(buffer, ddlRawDataSize, block.GetArray(), nofHit)) { HLTError("Error while processing of hit reconstruction algorithm."); size = totalSize; // Must tell the framework how much buffer space was used. return EIO; } // nofHit should now contain the number of reconstructed hits actually found // and filled into the output data block, so we can set this number. assert( nofHit <= block.MaxNumberOfEntries() ); block.SetNumberOfEntries(nofHit); HLTDebug("Number of reconstructed hits found is %d", nofHit); // Fill a block data structure for our output block. AliHLTComponentBlockData bd; FillBlockData(bd); bd.fPtr = outputPtr; // This block's start (offset) is after all other blocks written so far. bd.fOffset = totalSize; bd.fSize = block.BytesUsed(); bd.fDataType = AliHLTMUONConstants::RecHitsBlockDataType(); bd.fSpecification = blocks[n].fSpecification; outputBlocks.push_back(bd); // Increase the total amount of data written so far to our output memory totalSize += block.BytesUsed(); } // Finally we set the total size of output memory we consumed. size = totalSize; return 0; } bool AliHLTMUONHitReconstructorComponent::ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath) { /// /// Read in the lookup table from a text file. /// if (fDDL < AliHLTMUONHitReconstructor::GetkDDLOffSet() || fDDL >= AliHLTMUONHitReconstructor::GetkDDLOffSet() + AliHLTMUONHitReconstructor::GetkNofDDL()){ HLTError("DDL number is out of range"); return false; } int lutLine = fHitRec->GetLutLine(fDDL); FILE* fin = fopen(lutpath, "r"); if (fin == NULL){ HLTError("Failed to open file: %s",lutpath); return false; } for(int i=0;i= 700 && detElem <= 1025){ for(int i = minBusPatch; i <= maxBusPatch; i++){ busToDetElem[i] = detElem; busToDDL[i] = ddl; }//for loop } // detElem condn } // while loop for file fclose(fin); return true; }