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 **************************************************************************/
19 /** @file AliHLTMUONTriggerReconstructorComponent.cxx
22 @brief Implementation of the trigger DDL reconstructor component. */
28 #include "AliHLTSystem.h"
29 #include "AliHLTMUONTriggerReconstructorComponent.h"
30 #include "AliHLTMUONTriggerReconstructor.h"
31 #include "AliHLTMUONHitReconstructor.h"
32 #include "AliHLTMUONConstants.h"
39 // This is a global object used for automatic component registration,
40 // do not use this for calculation.
41 AliHLTMUONTriggerReconstructorComponent gAliHLTMUONTriggerReconstructorComponent;
45 ClassImp(AliHLTMUONTriggerReconstructorComponent)
48 AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent()
57 AliHLTMUONTriggerReconstructorComponent::~AliHLTMUONTriggerReconstructorComponent()
62 const char* AliHLTMUONTriggerReconstructorComponent::GetComponentID()
64 return "MUONTrigRec"; // The ID of this component
68 void AliHLTMUONTriggerReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list)
71 list.push_back( AliHLTMUONConstants::TriggerDDLRawDataType() );
75 AliHLTComponentDataType AliHLTMUONTriggerReconstructorComponent::GetOutputDataType()
77 return AliHLTMUONConstants::TriggerRecordsBlockDataType();
81 void AliHLTMUONTriggerReconstructorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
88 // Spawn function, return new instance of this class
89 AliHLTComponent* AliHLTMUONTriggerReconstructorComponent::Spawn()
91 return new AliHLTMUONTriggerReconstructorComponent;
95 int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
97 // perform initialization. We check whether our relative output size is specified in the arguments.
99 HLTInfo("Initialising DHLT Trigger Record Component");
101 fTrigRec = new AliHLTMUONTriggerReconstructor();
103 // this is just to get rid of the warning "unused parameter"
104 if (argc==0 && argv==NULL) {
105 HLTError("Arguments missing, no arguments" );
109 char lutFileName[500],reglocFileName[500];
115 HLTDebug("argv[%d] == %s", i, argv[i] );
117 if ( !strcmp( argv[i], "lut" ) ) {
119 HLTError("LookupTable filename not specified" );
120 return EINVAL; /* Invalid argument */
123 sprintf(lutFileName,"%s",argv[i+1]);
129 if ( !strcmp( argv[i], "ddl" ) ) {
131 HLTError("DDL number not specified" );
132 return EINVAL; /* Invalid argument */
135 fDDL = strtoul( argv[i+1], &cpErr, 0 );
138 HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] );
141 //fDDL = atoi(argv[i+1]);
147 if ( !strcmp( argv[i], "rawdir" ) ) {
149 HLTError("DDL directory not specified" );
150 return EINVAL; /* Invalid argument */
153 fDDLDir = argv[i+1] ;
156 }// ddl directory argument
158 if ( !strcmp( argv[i], "reglocmap" ) ) {
160 HLTError("Regional to Local Card mapping filename not specified" );
161 return EINVAL; /* Invalid argument */
164 sprintf(reglocFileName,"%s",argv[i+1]);
168 }// regtolocalmap argument
170 HLTError("Unknown option '%s'", argv[i] );
175 int lutline = fTrigRec->GetLutLine();
176 AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline];
177 if(!ReadLookUpTable(lookupTable,lutFileName)){
178 HLTError("Failed to read lut, lut cannot be read");
179 return ENOENT ; /* No such file or directory */
182 fTrigRec->LoadLookUpTable(lookupTable,fDDL+AliHLTMUONTriggerReconstructor::GetkDDLOffSet());
184 AliHLTMUONTriggerReconstructor::RegToLoc regToLocMap[128]; // 16(locCard)*8(regCard)
185 if(!ReadRegToLocMap(regToLocMap,reglocFileName)){
186 HLTError("Failed to read RegToLocMap file");
187 return ENOENT ; /* No such file or directory */
190 if(!(fTrigRec->SetRegToLocCardMap(regToLocMap))){
191 HLTError("Failed to assign RegToLocMap to TrigRec Class due to memory problem");
192 return ENOMEM ; /*cannot allocate memory*/
197 delete []lookupTable;
199 HLTInfo("Initialisation of DHLT Trigger Record Component is done");
205 int AliHLTMUONTriggerReconstructorComponent::DoDeinit()
210 HLTInfo(" Deinitialising DHLT Trigger Record Component");
215 int AliHLTMUONTriggerReconstructorComponent::DoEvent(
216 const AliHLTComponentEventData& evtData,
217 const AliHLTComponentBlockData* blocks,
218 AliHLTComponentTriggerData& trigData,
219 AliHLTUInt8_t* outputPtr,
220 AliHLTUInt32_t& size,
221 std::vector<AliHLTComponentBlockData>& outputBlocks
225 unsigned long totalSize = 0;
226 HLTDebug("Output percentage set to %lu and totalSize %lu",fOutputPercentage,totalSize );
228 HLTDebug("Event : %d has : %lu blocks",(int)evtData.fEventID,evtData.fBlockCnt);
229 // Loop over all input blocks in the event
230 for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
233 HLTDebug("block : %d, block rawData : %p, block.fSize (bytes) : %d, blocks.fDataType.fID : %s, blocks.fDataType.fOrigin : %s, required type : %s\n",
234 n,blocks[n].fPtr,blocks[n].fSize,(char *)(blocks[n].fDataType.fID),
235 (char *)(blocks[n].fDataType.fOrigin,(char *)(AliHLTMUONConstants::TriggerDDLRawDataType().fID)));
238 if(strncmp((char *)(blocks[n].fDataType.fID),(char *)(AliHLTMUONConstants::TriggerDDLRawDataType().fID),kAliHLTComponentDataTypefIDsize)) continue;
240 if ( totalSize > size )
243 int totalDDLSize = blocks[n].fSize/sizeof(int);
244 int ddlRawDataSize = totalDDLSize - fTrigRec->GetkDDLHeaderSize();
246 int *buffer = (int *)((int *)blocks[n].fPtr + fTrigRec->GetkDDLHeaderSize()) ;
248 AliHLTMUONTriggerRecordStruct trigRecord[300];
249 int nofTrigRec = 300;
251 if(! (fTrigRec->Run(buffer,&ddlRawDataSize,&trigRecord[0],&nofTrigRec))){
252 HLTError("ERROR In Processing of TrigRec Algo ");
256 // if(! (fTrigRec->Run((int)evtData.fEventID,fDDL,trigRecord,&nofTrigRec))){
257 // HLTError("ERROR In Processing of TrigRec Algo ");
261 unsigned long mySize = sizeof(AliHLTMUONTriggerRecordStruct)*nofTrigRec;
263 HLTDebug("Number record found is %d",nofTrigRec);
264 // for(int ihit=0;ihit<nofTrigRec;ihit++)
265 // cout<<"\tdetelem : "<<trigRecord[ihit].fId
266 // <<"\t"<<trigRecord[ihit].fHit[0].fX
267 // <<"\t"<<trigRecord[ihit].fHit[0].fY
268 // <<"\t"<<trigRecord[ihit].fHit[0].fZ
271 // Check how much space we have left and adapt this output block's size accordingly.
272 if ( totalSize + mySize > size )
273 mySize = size-totalSize;
275 Logging( kHLTLogDebug, "AliHLTMUONTriggerReconstructor::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu",
276 mySize, totalSize, size );
279 continue; // No room left to write a further block.
281 // Now copy the input block
282 unsigned long copied = 0;
283 // First copy all full multiples of the input block
285 // And the copy the remaining fragment of the block
286 Logging( kHLTLogDebug, "AliHLTMUONTriggerReconstructor::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B",
287 mySize-copied, copied, totalSize );
288 //memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, mySize-copied );
289 memcpy( outputPtr+totalSize+copied, &trigRecord[0], mySize);
290 Logging( kHLTLogDebug, "AliHLTMUONTriggerReconstructor::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B",
293 // Fill a block data structure for our output block.
294 AliHLTComponentBlockData bd;
297 // This block's start (offset) is after all other blocks written so far.
298 bd.fOffset = totalSize;
300 bd.fDataType = AliHLTMUONConstants::TriggerRecordsBlockDataType();
301 bd.fSpecification = blocks[n].fSpecification;
302 outputBlocks.push_back(bd);
304 // Increase the total amount of data written so far to our output memory
307 // Finally we set the total size of output memory we consumed.
314 bool AliHLTMUONTriggerReconstructorComponent::ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath)
316 if (fDDL < 0 || fDDL >= 2){
317 HLTError("DDL number is out of range");
321 int lutLine = fTrigRec->GetLutLine();
323 FILE* fin = fopen(lutpath, "r");
325 HLTError("Failed to open file: %s",lutpath);
329 for(int i=0;i<lutLine;i++){
332 "%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",
333 &lookupTable[i].fIdManuChannel,
336 &lookupTable[i].fRealX,
337 &lookupTable[i].fRealY,
338 &lookupTable[i].fRealZ,
339 &lookupTable[i].fPcbZone,
340 &lookupTable[i].fPlane
349 bool AliHLTMUONTriggerReconstructorComponent::ReadRegToLocMap(AliHLTMUONTriggerReconstructor::RegToLoc* regToLocMap,const char* reglocFileName)
351 int iTrigDDL,iReg,iLoc,locId,switchWord,detElemId[4];
354 memset(regToLocMap,-1,128*sizeof(AliHLTMUONTriggerReconstructor::RegToLoc));
357 ifstream fin(reglocFileName);
360 HLTError("Failed to open file %s",reglocFileName);
364 while(fin.getline(s,100)){
365 sscanf(s,"%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d",
366 &iTrigDDL,&iReg,&iLoc,&locId,&switchWord,&detElemId[0],&detElemId[1],&detElemId[2],&detElemId[3]);
368 index = iReg*16 + iLoc;
369 regToLocMap[index].fTrigDDL = iTrigDDL ;
370 regToLocMap[index].fRegId = iReg ;
371 regToLocMap[index].fLoc = iLoc ;
372 regToLocMap[index].fLocId = locId ;
373 regToLocMap[index].fSwitch = switchWord ;
374 for(int idet = 0; idet<4; idet++)
375 regToLocMap[index].fDetElemId[idet] = detElemId[idet] ;
376 }// if matches with fDDL