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. */
24 #include "AliHLTMUONTriggerReconstructorComponent.h"
25 #include "AliHLTMUONTriggerReconstructor.h"
26 #include "AliHLTMUONHitReconstructor.h"
27 #include "AliHLTMUONConstants.h"
28 #include "AliHLTMUONDataBlockWriter.h"
35 // This is a global object used for automatic component registration,
36 // do not use this for calculation.
37 AliHLTMUONTriggerReconstructorComponent gAliHLTMUONTriggerReconstructorComponent;
42 ClassImp(AliHLTMUONTriggerReconstructorComponent)
45 AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent() :
49 fWarnForUnexpecedBlock(false),
50 fSuppressPartialTrigs(false)
55 AliHLTMUONTriggerReconstructorComponent::~AliHLTMUONTriggerReconstructorComponent()
60 const char* AliHLTMUONTriggerReconstructorComponent::GetComponentID()
62 return AliHLTMUONConstants::TriggerReconstructorId();
66 void AliHLTMUONTriggerReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list)
69 list.push_back( AliHLTMUONConstants::TriggerDDLRawDataType() );
73 AliHLTComponentDataType AliHLTMUONTriggerReconstructorComponent::GetOutputDataType()
75 return AliHLTMUONConstants::TriggerRecordsBlockDataType();
79 void AliHLTMUONTriggerReconstructorComponent::GetOutputDataSize(
80 unsigned long& constBase, double& inputMultiplier
83 constBase = sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType);
88 AliHLTComponent* AliHLTMUONTriggerReconstructorComponent::Spawn()
90 return new AliHLTMUONTriggerReconstructorComponent;
94 int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
96 // perform initialization. We check whether our relative output size is
97 // specified in the arguments.
99 HLTInfo("Initialising DHLT Trigger Record Component");
101 fWarnForUnexpecedBlock = false;
102 fSuppressPartialTrigs = false;
103 fTrigRec = new AliHLTMUONTriggerReconstructor();
105 // this is just to get rid of the warning "unused parameter"
106 if (argc==0 && argv==NULL) {
107 HLTError("Arguments missing, no arguments" );
110 char lutFileName[500],reglocFileName[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]);
130 if ( !strcmp( argv[i], "ddl" ) ) {
132 HLTError("DDL number not specified" );
133 return EINVAL; /* Invalid argument */
136 fDDL = strtoul( argv[i+1], &cpErr, 0 );
139 HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] );
142 //fDDL = atoi(argv[i+1]);
148 if ( !strcmp( argv[i], "rawdir" ) ) {
150 HLTError("DDL directory not specified" );
151 return EINVAL; /* Invalid argument */
154 fDDLDir = argv[i+1] ;
157 }// ddl directory argument
159 if ( !strcmp( argv[i], "reglocmap" ) ) {
161 HLTError("Regional to Local Card mapping filename not specified" );
162 return EINVAL; /* Invalid argument */
165 sprintf(reglocFileName,"%s",argv[i+1]);
169 }// regtolocalmap argument
171 if ( !strcmp( argv[i], "-warn_on_unexpected_block" ) ) {
172 fWarnForUnexpecedBlock = true;
177 if ( !strcmp( argv[i], "-suppress_partial_triggers" ) ) {
178 fSuppressPartialTrigs = true;
183 HLTError("Unknown option '%s'", argv[i] );
188 int lutline = fTrigRec->GetLutLine();
189 AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline];
190 if(!ReadLookUpTable(lookupTable,lutFileName)){
191 HLTError("Failed to read lut, lut cannot be read");
192 return ENOENT ; /* No such file or directory */
195 fTrigRec->LoadLookUpTable(lookupTable,fDDL+AliHLTMUONTriggerReconstructor::GetkDDLOffSet());
197 AliHLTMUONTriggerReconstructor::RegToLoc regToLocMap[128]; // 16(locCard)*8(regCard)
198 if(!ReadRegToLocMap(regToLocMap,reglocFileName)){
199 HLTError("Failed to read RegToLocMap file");
200 return ENOENT ; /* No such file or directory */
203 if(!(fTrigRec->SetRegToLocCardMap(regToLocMap))){
204 HLTError("Failed to assign RegToLocMap to TrigRec Class due to memory problem");
205 return ENOMEM ; /*cannot allocate memory*/
210 delete []lookupTable;
212 HLTInfo("Initialisation of DHLT Trigger Record Component is done");
218 int AliHLTMUONTriggerReconstructorComponent::DoDeinit()
220 HLTInfo("Deinitialising DHLT Trigger Record Component");
231 int AliHLTMUONTriggerReconstructorComponent::DoEvent(
232 const AliHLTComponentEventData& evtData,
233 const AliHLTComponentBlockData* blocks,
234 AliHLTComponentTriggerData& trigData,
235 AliHLTUInt8_t* outputPtr,
236 AliHLTUInt32_t& size,
237 std::vector<AliHLTComponentBlockData>& outputBlocks
241 unsigned long totalSize = 0; // Amount of memory currently consumed in bytes.
243 HLTDebug("Processing event %llu with %u input data blocks.",
244 evtData.fEventID, evtData.fBlockCnt
247 // Loop over all input blocks in the event and run the trigger DDL
248 // reconstruction algorithm on the raw data.
249 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
252 char id[kAliHLTComponentDataTypefIDsize+1];
253 for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
254 id[i] = blocks[n].fDataType.fID[i];
255 id[kAliHLTComponentDataTypefIDsize] = '\0';
256 char origin[kAliHLTComponentDataTypefOriginSize+1];
257 for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
258 origin[i] = blocks[n].fDataType.fOrigin[i];
259 origin[kAliHLTComponentDataTypefOriginSize] = '\0';
261 HLTDebug("Handling block: %u, with fDataType.fID = '%s',"
262 " fDataType.fID = '%s', fPtr = %p and fSize = %u bytes.",
263 n, static_cast<char*>(id), static_cast<char*>(origin),
264 blocks[n].fPtr, blocks[n].fSize
267 if (blocks[n].fDataType != AliHLTMUONConstants::TriggerDDLRawDataType())
269 // Log a message indicating that we got a data block that we
270 // do not know how to handle.
271 char id[kAliHLTComponentDataTypefIDsize+1];
272 for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
273 id[i] = blocks[n].fDataType.fID[i];
274 id[kAliHLTComponentDataTypefIDsize] = '\0';
275 char origin[kAliHLTComponentDataTypefOriginSize+1];
276 for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
277 origin[i] = blocks[n].fDataType.fOrigin[i];
278 origin[kAliHLTComponentDataTypefOriginSize] = '\0';
280 if (fWarnForUnexpecedBlock)
281 HLTWarning("Received a data block of a type we can not handle: %s origin %s",
282 static_cast<char*>(id), static_cast<char*>(origin)
285 HLTDebug("Received a data block of a type we can not handle: %s origin %s",
286 static_cast<char*>(id), static_cast<char*>(origin)
292 // Create a new output data block and initialise the header.
293 AliHLTMUONTriggerRecordsBlockWriter block(outputPtr+totalSize, size-totalSize);
294 if (not block.InitCommonHeader())
296 HLTError("There is not enough space in the output buffer for the new data block.",
297 " We require at least %u bytes, but have %u bytes left.",
298 sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType),
304 AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t);
305 AliHLTUInt32_t ddlRawDataSize = totalDDLSize - fTrigRec->GetkDDLHeaderSize();
306 AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr)
307 + fTrigRec->GetkDDLHeaderSize();
308 AliHLTUInt32_t nofTrigRec = block.MaxNumberOfEntries();
310 bool runOk = fTrigRec->Run(
311 buffer, ddlRawDataSize,
312 block.GetArray(), nofTrigRec,
313 fSuppressPartialTrigs
317 HLTError("Error while processing of trigger DDL reconstruction algorithm.");
318 size = totalSize; // Must tell the framework how much buffer space was used.
322 // nofTrigRec should now contain the number of triggers actually found
323 // and filled into the output data block, so we can set this number.
324 assert( nofTrigRec <= block.MaxNumberOfEntries() );
325 block.SetNumberOfEntries(nofTrigRec);
327 HLTDebug("Number of trigger records found is %d", nofTrigRec);
329 // Fill a block data structure for our output block.
330 AliHLTComponentBlockData bd;
333 // This block's start (offset) is after all other blocks written so far.
334 bd.fOffset = totalSize;
335 bd.fSize = block.BytesUsed();
336 bd.fDataType = AliHLTMUONConstants::TriggerRecordsBlockDataType();
337 bd.fSpecification = blocks[n].fSpecification;
338 outputBlocks.push_back(bd);
340 HLTDebug("Created a new output data block at fPtr = %p,"
341 " with fOffset = %u (0x%.X) and fSize = %u bytes.",
342 bd.fPtr, bd.fOffset, bd.fOffset, bd.fSize
345 // Increase the total amount of data written so far to our output memory.
346 totalSize += block.BytesUsed();
349 // Finally we set the total size of output memory we consumed.
355 bool AliHLTMUONTriggerReconstructorComponent::ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath)
357 if (fDDL < 0 || fDDL >= 2){
358 HLTError("DDL number is out of range");
362 int lutLine = fTrigRec->GetLutLine();
364 FILE* fin = fopen(lutpath, "r");
366 HLTError("Failed to open file: %s",lutpath);
370 for(int i=0;i<lutLine;i++){
373 "%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",
374 &lookupTable[i].fIdManuChannel,
377 &lookupTable[i].fRealX,
378 &lookupTable[i].fRealY,
379 &lookupTable[i].fRealZ,
380 &lookupTable[i].fPcbZone,
381 &lookupTable[i].fPlane
390 bool AliHLTMUONTriggerReconstructorComponent::ReadRegToLocMap(AliHLTMUONTriggerReconstructor::RegToLoc* regToLocMap,const char* reglocFileName)
392 int iTrigDDL,iReg,iLoc,locId,switchWord,detElemId[4];
395 memset(regToLocMap,-1,128*sizeof(AliHLTMUONTriggerReconstructor::RegToLoc));
398 ifstream fin(reglocFileName);
401 HLTError("Failed to open file %s",reglocFileName);
405 while(fin.getline(s,100)){
406 sscanf(s,"%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d",
407 &iTrigDDL,&iReg,&iLoc,&locId,&switchWord,&detElemId[0],&detElemId[1],&detElemId[2],&detElemId[3]);
409 index = iReg*16 + iLoc;
410 regToLocMap[index].fTrigDDL = iTrigDDL ;
411 regToLocMap[index].fRegId = iReg ;
412 regToLocMap[index].fLoc = iLoc ;
413 regToLocMap[index].fLocId = locId ;
414 regToLocMap[index].fSwitch = switchWord ;
415 for(int idet = 0; idet<4; idet++)
416 regToLocMap[index].fDetElemId[idet] = detElemId[idet] ;
417 }// if matches with fDDL