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 "AliHLTLogging.h"
34 #include "AliHLTSystem.h"
35 #include "AliHLTDefinitions.h"
41 // The global object used for automatic component registration,
42 // Note DO NOT use this component for calculation!
43 AliHLTMUONHitReconstructorComponent gAliHLTMUONHitReconstructorComponent;
46 ClassImp(AliHLTMUONHitReconstructorComponent)
49 AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent()
59 AliHLTMUONHitReconstructorComponent::~AliHLTMUONHitReconstructorComponent()
63 const char* AliHLTMUONHitReconstructorComponent::GetComponentID()
65 return "MUONHitRec"; // The ID of this component
69 void AliHLTMUONHitReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list)
72 list.push_back( AliHLTMUONConstants::TrackingDDLRawDataType() );
76 AliHLTComponentDataType AliHLTMUONHitReconstructorComponent::GetOutputDataType()
78 return AliHLTMUONConstants::RecHitsBlockDataType();
82 void AliHLTMUONHitReconstructorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
89 // Spawn function, return new instance of this class
90 AliHLTComponent* AliHLTMUONHitReconstructorComponent::Spawn()
92 return new AliHLTMUONHitReconstructorComponent;
96 int AliHLTMUONHitReconstructorComponent::DoInit( int argc, const char** argv )
98 // perform initialization. We check whether our relative output size is specified in the arguments.
100 HLTInfo("Initialising DHLT HitReconstruction Component");
102 fHitRec = new AliHLTMUONHitReconstructor();
105 // this is to get rid of the warning "unused parameter"
106 if (argc==0 && argv==NULL) {
107 HLTError("Arguments missing", " no arguments" );
110 char lutFileName[500],buspatchFileName[500];
116 HLTDebug("argv[%d] == %s", i, argv[i] );
118 if ( !strcmp( argv[i], "lut" ) ) {
120 HLTError("LookupTable filename not specified" );
121 return EINVAL; /* Invalid argument */
124 sprintf(lutFileName,"%s",argv[i+1]);
131 if ( !strcmp( argv[i], "ddl" ) ) {
133 HLTError("DDL number not specified" );
134 return EINVAL; /* Invalid argument */
137 fDDL = strtoul( argv[i+1], &cpErr, 0 );
140 HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] );
149 if ( !strcmp( argv[i], "rawdir" ) ) {
151 HLTError("DDL directory not specified" );
152 return EINVAL; /* Invalid argument */
155 fDDLDir = argv[i+1] ;
159 }// ddl directory argument
162 if ( !strcmp( argv[i], "buspatchmap" ) ) {
164 HLTError("Buspatch filename not specified" );
165 return EINVAL; /* Invalid argument */
168 sprintf(buspatchFileName,"%s",argv[i+1]);
172 }// buspatch argument
174 if ( !strcmp( argv[i], "rawreader" ) ) {
175 fReaderType = true; // true when using rawreader for standalone it is set to false.
180 HLTError("Unknown option '%s'", argv[i] );
185 int lutline = fHitRec->GetLutLine(fDDL);
186 AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline];
187 if(!ReadLookUpTable(lookupTable,lutFileName)){
188 HLTError("Failed to read lut, lut cannot be read, DoInit");
189 return ENOENT ; /* No such file or directory */
192 BusToDetElem busToDetElem;
194 if(!ReadBusPatchToDetElemFile(busToDetElem,busToDDL,buspatchFileName)){
195 HLTError("Failed to read buspatchmap, buspatchmap cannot be read, DoInit");
196 return ENOENT ; /* No such file or directory */
199 fHitRec->SetBusToDetMap(busToDetElem);
200 fHitRec->SetBusToDDLMap(busToDDL);
201 fHitRec->LoadLookUpTable(lookupTable,fDDL);
205 delete []lookupTable;
207 HLTInfo("Initialisation of DHLT HitReconstruction Component is done");
213 int AliHLTMUONHitReconstructorComponent::DoDeinit()
218 HLTInfo(" Deinitialising DHLT HitReconstruction Component");
224 int AliHLTMUONHitReconstructorComponent::DoEvent(
225 const AliHLTComponentEventData& evtData,
226 const AliHLTComponentBlockData* blocks,
227 AliHLTComponentTriggerData& trigData,
228 AliHLTUInt8_t* outputPtr,
229 AliHLTUInt32_t& size,
230 std::vector<AliHLTComponentBlockData>& outputBlocks
234 unsigned long totalSize = 0;
236 HLTDebug("Event : %d has : %lu blocks",(int)evtData.fEventID,evtData.fBlockCnt);
238 // Loop over all input blocks in the event
239 for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
242 HLTDebug("block : %d, block rawData : %p, block.fSize (bytes) : %d, blocks.fDataType.fID : %s, blocks.fDataType.fOrigin : %s, required type : %s\n",
243 n,blocks[n].fPtr,blocks[n].fSize,(char *)(blocks[n].fDataType.fID),
244 (char *)(blocks[n].fDataType.fOrigin,(char *)(AliHLTMUONConstants::TrackingDDLRawDataType().fID)));
247 if(strncmp((char *)(blocks[n].fDataType.fID),(char *)(AliHLTMUONConstants::TrackingDDLRawDataType().fID),kAliHLTComponentDataTypefIDsize)) continue;
250 if ( totalSize > size )
253 int totalDDLSize = blocks[n].fSize/sizeof(int);
255 if(!totalDDLSize) continue;
257 int ddlRawDataSize = totalDDLSize - fHitRec->GetkDDLHeaderSize();
258 int *buffer = (int *)blocks[n].fPtr;
261 for(int j=0;j<totalDDLSize;j++)
262 HLTDebug("buffer[%d] : %x\n",j,buffer[j]);
264 buffer = (int *)((int *)blocks[n].fPtr + fHitRec->GetkDDLHeaderSize()) ;
266 AliHLTMUONRecHitStruct recHit[300];
269 if(! (fHitRec->Run(buffer,&ddlRawDataSize,recHit,&nofHit))){
270 HLTError("ERROR In Processing of HitRec Algo ");
274 unsigned long mySize = sizeof(AliHLTMUONRecHitStruct) * nofHit;
276 HLTDebug("Event %d and block %d has nofHit %d\n",(int)evtData.fEventID,n,nofHit);
278 // Check how much space we have left and adapt this output block's size accordingly.
279 if ( totalSize + mySize > size )
280 mySize = size-totalSize;
282 Logging( kHLTLogDebug, "HLT::MUONHitRec::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu",
283 mySize, totalSize, size );
286 continue; // No room left to write a further block.
288 // Now copy the input block
289 unsigned long copied = 0;
290 // First copy all full multiples of the input block
292 // And the copy the remaining fragment of the block
293 Logging( kHLTLogDebug, "1 : HLT::MUONHitRec::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B",
294 mySize-copied, copied, totalSize );
295 memcpy( outputPtr+totalSize+copied, &recHit[0], mySize);
296 Logging( kHLTLogDebug, "HLT::MUONHitRec::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B",
299 // Fill a block data structure for our output block.
300 AliHLTComponentBlockData bd;
303 // This block's start (offset) is after all other blocks written so far.
304 bd.fOffset = totalSize;
306 bd.fDataType = AliHLTMUONConstants::RecHitsBlockDataType();
307 bd.fSpecification = blocks[n].fSpecification;
308 outputBlocks.push_back(bd);
310 // Increase the total amount of data written so far to our output memory
313 // Finally we set the total size of output memory we consumed.
320 bool AliHLTMUONHitReconstructorComponent::ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath)
322 if (fDDL < AliHLTMUONHitReconstructor::GetkDDLOffSet() ||
323 fDDL >= AliHLTMUONHitReconstructor::GetkDDLOffSet() + AliHLTMUONHitReconstructor::GetkNofDDL()){
324 HLTError("DDL number is out of range");
328 int lutLine = fHitRec->GetLutLine(fDDL);
330 FILE* fin = fopen(lutpath, "r");
332 HLTError("Failed to open file: %s",lutpath);
336 for(int i=0;i<lutLine;i++){
339 "%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",
340 &lookupTable[i].fIdManuChannel,
343 &lookupTable[i].fRealX,
344 &lookupTable[i].fRealY,
345 &lookupTable[i].fRealZ,
346 &lookupTable[i].fPcbZone,
347 &lookupTable[i].fPlane
356 bool AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile(BusToDetElem& busToDetElem, BusToDDL& busToDDL, const char* buspatchmappath)
360 int detElem, minBusPatch, maxBusPatch, ddl;
362 FILE* fin = fopen(buspatchmappath, "r");
364 HLTError("Failed to open file: %s",buspatchmappath);
368 while (feof(fin)==0){
369 fgets(getLine,80,fin);
370 sscanf(getLine, "%d\t%d %c %d\t%d", &detElem, &minBusPatch, &temp, &maxBusPatch,&ddl);
371 if (detElem >= 700 && detElem <= 1025){
373 for(int i = minBusPatch; i <= maxBusPatch; i++){
374 busToDetElem[i] = detElem;
378 } // while loop for file