]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructorComponent.cxx
Applying fixes and updates (Indra)
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONTriggerReconstructorComponent.cxx
CommitLineData
6efe69e7 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
4 * *
5 * Primary Authors: *
6 * Indranil Das <indra.das@saha.ac.in> *
7 * *
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 **************************************************************************/
16
17/* $Id$ */
18
19/** @file AliHLTMUONTriggerReconstructorComponent.cxx
20 @author Indranil Das
21 @date
960d54ad 22 @brief Implementation of the trigger DDL reconstructor component. */
6efe69e7 23
24#if __GNUC__ >= 3
25using namespace std;
26#endif
27
28#include "AliHLTSystem.h"
29#include "AliHLTMUONTriggerReconstructorComponent.h"
960d54ad 30#include "AliHLTMUONTriggerReconstructor.h"
31#include "AliHLTMUONHitReconstructor.h"
32#include "AliHLTMUONConstants.h"
33
6efe69e7 34#include <stdlib.h>
35#include <errno.h>
36
960d54ad 37namespace
38{
39 // This is a global object used for automatic component registration,
40 // do not use this for calculation.
41 AliHLTMUONTriggerReconstructorComponent gAliHLTMUONTriggerReconstructorComponent;
42} // end of namespace
43
6efe69e7 44
45ClassImp(AliHLTMUONTriggerReconstructorComponent)
46
960d54ad 47
6efe69e7 48AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent()
49 :
960d54ad 50 fTrigRec(NULL),
6efe69e7 51 fDDLDir(""),
960d54ad 52 fDDL(0)
53{
54}
55
6efe69e7 56
57AliHLTMUONTriggerReconstructorComponent::~AliHLTMUONTriggerReconstructorComponent()
960d54ad 58{
59}
60
6efe69e7 61
62const char* AliHLTMUONTriggerReconstructorComponent::GetComponentID()
960d54ad 63{
64 return "MUONTrigRec"; // The ID of this component
65}
66
67
68void AliHLTMUONTriggerReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list)
69{
70 list.clear();
71 list.push_back( AliHLTMUONConstants::TriggerDDLRawDataType() );
72}
6efe69e7 73
6efe69e7 74
75AliHLTComponentDataType AliHLTMUONTriggerReconstructorComponent::GetOutputDataType()
960d54ad 76{
77 return AliHLTMUONConstants::TriggerRecordsBlockDataType();
78}
6efe69e7 79
6efe69e7 80
960d54ad 81void AliHLTMUONTriggerReconstructorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
82{
83 constBase = 0;
84 inputMultiplier = 1;
85}
6efe69e7 86
87
88// Spawn function, return new instance of this class
89AliHLTComponent* AliHLTMUONTriggerReconstructorComponent::Spawn()
960d54ad 90{
91 return new AliHLTMUONTriggerReconstructorComponent;
92}
93
6efe69e7 94
960d54ad 95int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
6efe69e7 96{
960d54ad 97 // perform initialization. We check whether our relative output size is specified in the arguments.
98
99 HLTInfo("Initialising DHLT Trigger Record Component");
100
101 fTrigRec = new AliHLTMUONTriggerReconstructor();
6efe69e7 102
960d54ad 103 // this is just to get rid of the warning "unused parameter"
104 if (argc==0 && argv==NULL) {
105 HLTError("Arguments missing, no arguments" );
106 }
107
108
109 char lutFileName[500],reglocFileName[500];
6efe69e7 110
960d54ad 111 int i = 0;
112 char* cpErr;
113 while ( i < argc )
114 {
115 HLTDebug("argv[%d] == %s", i, argv[i] );
116
117 if ( !strcmp( argv[i], "lut" ) ) {
118 if ( argc <= i+1 ) {
119 HLTError("LookupTable filename not specified" );
120 return EINVAL; /* Invalid argument */
121 }
6efe69e7 122
960d54ad 123 sprintf(lutFileName,"%s",argv[i+1]);
124
125 i += 2;
126 continue;
127 }// lut argument
128
129 if ( !strcmp( argv[i], "ddl" ) ) {
130 if ( argc <= i+1 ) {
131 HLTError("DDL number not specified" );
132 return EINVAL; /* Invalid argument */
133 }
6efe69e7 134
960d54ad 135 fDDL = strtoul( argv[i+1], &cpErr, 0 );
136 if ( *cpErr )
137 {
138 HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] );
139 return EINVAL;
140 }
141 //fDDL = atoi(argv[i+1]);
142
143 i += 2;
144 continue;
145 }// ddl argument
6efe69e7 146
960d54ad 147 if ( !strcmp( argv[i], "rawdir" ) ) {
148 if ( argc <= i+1 ) {
149 HLTError("DDL directory not specified" );
150 return EINVAL; /* Invalid argument */
151 }
152
153 fDDLDir = argv[i+1] ;
154 i += 2;
155 continue;
156 }// ddl directory argument
157
158 if ( !strcmp( argv[i], "reglocmap" ) ) {
159 if ( argc <= i+1 ) {
160 HLTError("Regional to Local Card mapping filename not specified" );
161 return EINVAL; /* Invalid argument */
162 }
6efe69e7 163
960d54ad 164 sprintf(reglocFileName,"%s",argv[i+1]);
165
166 i += 2;
167 continue;
168 }// regtolocalmap argument
169
170 HLTError("Unknown option '%s'", argv[i] );
171 return EINVAL;
6efe69e7 172
960d54ad 173 }//while loop
6efe69e7 174
175 int lutline = fTrigRec->GetLutLine();
176 AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline];
177 if(!ReadLookUpTable(lookupTable,lutFileName)){
960d54ad 178 HLTError("Failed to read lut, lut cannot be read");
6efe69e7 179 return ENOENT ; /* No such file or directory */
180 }else{
181
960d54ad 182 fTrigRec->LoadLookUpTable(lookupTable,fDDL+AliHLTMUONTriggerReconstructor::GetkDDLOffSet());
183
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 */
188 }
189
190 if(!(fTrigRec->SetRegToLocCardMap(regToLocMap))){
191 HLTError("Failed to assign RegToLocMap to TrigRec Class due to memory problem");
192 return ENOMEM ; /*cannot allocate memory*/
193 }
6efe69e7 194
195 }// reading lut
196
197 delete []lookupTable;
198
960d54ad 199 HLTInfo("Initialisation of DHLT Trigger Record Component is done");
200
6efe69e7 201 return 0;
202}
203
960d54ad 204
6efe69e7 205int AliHLTMUONTriggerReconstructorComponent::DoDeinit()
960d54ad 206{
207 if(fTrigRec)
208 delete fTrigRec;
6efe69e7 209
960d54ad 210 HLTInfo(" Deinitialising DHLT Trigger Record Component");
211
212 return 0;
213}
6efe69e7 214
960d54ad 215int 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
222 )
223{
224 // Process an event
225 unsigned long totalSize = 0;
226 HLTDebug("Output percentage set to %lu and totalSize %lu",fOutputPercentage,totalSize );
227
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++ )
6efe69e7 231 {
6efe69e7 232
960d54ad 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)));
236
6efe69e7 237
960d54ad 238 if(strncmp((char *)(blocks[n].fDataType.fID),(char *)(AliHLTMUONConstants::TriggerDDLRawDataType().fID),kAliHLTComponentDataTypefIDsize)) continue;
6efe69e7 239
960d54ad 240 if ( totalSize > size )
241 break;
242
243 int totalDDLSize = blocks[n].fSize/sizeof(int);
244 int ddlRawDataSize = totalDDLSize - fTrigRec->GetkDDLHeaderSize();
6efe69e7 245
960d54ad 246 int *buffer = (int *)((int *)blocks[n].fPtr + fTrigRec->GetkDDLHeaderSize()) ;
247
248 AliHLTMUONTriggerRecordStruct trigRecord[300];
249 int nofTrigRec = 300;
6efe69e7 250
960d54ad 251 if(! (fTrigRec->Run(buffer,&ddlRawDataSize,&trigRecord[0],&nofTrigRec))){
252 HLTError("ERROR In Processing of TrigRec Algo ");
253 return EIO;
254 }
255
256 // if(! (fTrigRec->Run((int)evtData.fEventID,fDDL,trigRecord,&nofTrigRec))){
257 // HLTError("ERROR In Processing of TrigRec Algo ");
258 // return EIO;
259 // }
260
261 unsigned long mySize = sizeof(AliHLTMUONTriggerRecordStruct)*nofTrigRec;
6efe69e7 262
960d54ad 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
269// <<endl;
6efe69e7 270
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;
274
960d54ad 275 Logging( kHLTLogDebug, "AliHLTMUONTriggerReconstructor::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu",
6efe69e7 276 mySize, totalSize, size );
277
278 if ( mySize<=0 )
279 continue; // No room left to write a further block.
280
281 // Now copy the input block
282 unsigned long copied = 0;
283 // First copy all full multiples of the input block
284
285 // And the copy the remaining fragment of the block
960d54ad 286 Logging( kHLTLogDebug, "AliHLTMUONTriggerReconstructor::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B",
6efe69e7 287 mySize-copied, copied, totalSize );
288 //memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, mySize-copied );
289 memcpy( outputPtr+totalSize+copied, &trigRecord[0], mySize);
960d54ad 290 Logging( kHLTLogDebug, "AliHLTMUONTriggerReconstructor::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B",
6efe69e7 291 copied, totalSize );
960d54ad 292
6efe69e7 293 // Fill a block data structure for our output block.
960d54ad 294 AliHLTComponentBlockData bd;
295 FillBlockData(bd);
296 bd.fPtr = outputPtr;
297 // This block's start (offset) is after all other blocks written so far.
298 bd.fOffset = totalSize;
299 bd.fSize = mySize;
300 bd.fDataType = AliHLTMUONConstants::TriggerRecordsBlockDataType();
301 bd.fSpecification = blocks[n].fSpecification;
302 outputBlocks.push_back(bd);
303
6efe69e7 304 // Increase the total amount of data written so far to our output memory
305 totalSize += mySize;
960d54ad 306 }
6efe69e7 307 // Finally we set the total size of output memory we consumed.
308 size = totalSize;
309
310 return 0;
960d54ad 311}
312
6efe69e7 313
314bool AliHLTMUONTriggerReconstructorComponent::ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath)
315{
960d54ad 316 if (fDDL < 0 || fDDL >= 2){
6efe69e7 317 HLTError("DDL number is out of range");
318 return false;
319 }
320
321 int lutLine = fTrigRec->GetLutLine();
322
323 FILE* fin = fopen(lutpath, "r");
324 if (fin == NULL){
325 HLTError("Failed to open file: %s",lutpath);
326 return false;
327 }
328
329 for(int i=0;i<lutLine;i++){
330 fscanf(
331 fin,
332 "%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",
333 &lookupTable[i].fIdManuChannel,
334 &lookupTable[i].fIX,
335 &lookupTable[i].fIY,
336 &lookupTable[i].fRealX,
337 &lookupTable[i].fRealY,
338 &lookupTable[i].fRealZ,
960d54ad 339 &lookupTable[i].fPcbZone,
340 &lookupTable[i].fPlane
6efe69e7 341 );
342 }
343
344 fclose(fin);
345 return true;
346}
347
6efe69e7 348
960d54ad 349bool AliHLTMUONTriggerReconstructorComponent::ReadRegToLocMap(AliHLTMUONTriggerReconstructor::RegToLoc* regToLocMap,const char* reglocFileName)
350{
351 int iTrigDDL,iReg,iLoc,locId,switchWord,detElemId[4];
352 int index;
353
354 memset(regToLocMap,-1,128*sizeof(AliHLTMUONTriggerReconstructor::RegToLoc));
355
356 char s[100];
357 ifstream fin(reglocFileName);
358
359 if(!fin){
360 HLTError("Failed to open file %s",reglocFileName);
361 return false;
362 }
363
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]);
367 if(iTrigDDL==fDDL){
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
377 }//file loop
378
379 fin.close();
380 return true;
381}