]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructorComponent.cxx
Detectors can have more than one AMANDA server. SHUTTLE queries the servers sequentially,
[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
6efe69e7 24#include "AliHLTMUONTriggerReconstructorComponent.h"
960d54ad 25#include "AliHLTMUONTriggerReconstructor.h"
26#include "AliHLTMUONHitReconstructor.h"
27#include "AliHLTMUONConstants.h"
227e7192 28#include "AliHLTMUONDataBlockWriter.h"
29#include <cstdlib>
30#include <cerrno>
5d1682b9 31#include <cassert>
6efe69e7 32
960d54ad 33namespace
34{
35 // This is a global object used for automatic component registration,
36 // do not use this for calculation.
37 AliHLTMUONTriggerReconstructorComponent gAliHLTMUONTriggerReconstructorComponent;
227e7192 38
960d54ad 39} // end of namespace
40
6efe69e7 41
42ClassImp(AliHLTMUONTriggerReconstructorComponent)
43
960d54ad 44
227e7192 45AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent() :
46 fTrigRec(NULL),
47 fDDLDir(""),
5d1682b9 48 fDDL(0),
49 fWarnForUnexpecedBlock(false)
960d54ad 50{
51}
52
6efe69e7 53
54AliHLTMUONTriggerReconstructorComponent::~AliHLTMUONTriggerReconstructorComponent()
960d54ad 55{
56}
57
6efe69e7 58
59const char* AliHLTMUONTriggerReconstructorComponent::GetComponentID()
960d54ad 60{
227e7192 61 return AliHLTMUONConstants::TriggerReconstructorId();
960d54ad 62}
63
64
65void AliHLTMUONTriggerReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list)
66{
227e7192 67 list.clear();
68 list.push_back( AliHLTMUONConstants::TriggerDDLRawDataType() );
960d54ad 69}
6efe69e7 70
6efe69e7 71
72AliHLTComponentDataType AliHLTMUONTriggerReconstructorComponent::GetOutputDataType()
960d54ad 73{
227e7192 74 return AliHLTMUONConstants::TriggerRecordsBlockDataType();
960d54ad 75}
6efe69e7 76
6efe69e7 77
227e7192 78void AliHLTMUONTriggerReconstructorComponent::GetOutputDataSize(
79 unsigned long& constBase, double& inputMultiplier
80 )
960d54ad 81{
227e7192 82 constBase = sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType);
a91431f8 83 inputMultiplier = 100;
960d54ad 84}
6efe69e7 85
86
6efe69e7 87AliHLTComponent* AliHLTMUONTriggerReconstructorComponent::Spawn()
960d54ad 88{
227e7192 89 return new AliHLTMUONTriggerReconstructorComponent;
960d54ad 90}
91
6efe69e7 92
960d54ad 93int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
6efe69e7 94{
227e7192 95 // perform initialization. We check whether our relative output size is
96 // specified in the arguments.
960d54ad 97
98 HLTInfo("Initialising DHLT Trigger Record Component");
99
5d1682b9 100 fWarnForUnexpecedBlock = false;
960d54ad 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
960d54ad 108 char lutFileName[500],reglocFileName[500];
6efe69e7 109
960d54ad 110 int i = 0;
111 char* cpErr;
112 while ( i < argc )
113 {
114 HLTDebug("argv[%d] == %s", i, argv[i] );
115
116 if ( !strcmp( argv[i], "lut" ) ) {
117 if ( argc <= i+1 ) {
118 HLTError("LookupTable filename not specified" );
119 return EINVAL; /* Invalid argument */
120 }
6efe69e7 121
960d54ad 122 sprintf(lutFileName,"%s",argv[i+1]);
123
124 i += 2;
125 continue;
126 }// lut argument
127
128 if ( !strcmp( argv[i], "ddl" ) ) {
129 if ( argc <= i+1 ) {
130 HLTError("DDL number not specified" );
131 return EINVAL; /* Invalid argument */
132 }
6efe69e7 133
960d54ad 134 fDDL = strtoul( argv[i+1], &cpErr, 0 );
135 if ( *cpErr )
136 {
137 HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] );
138 return EINVAL;
139 }
140 //fDDL = atoi(argv[i+1]);
141
142 i += 2;
143 continue;
144 }// ddl argument
6efe69e7 145
960d54ad 146 if ( !strcmp( argv[i], "rawdir" ) ) {
147 if ( argc <= i+1 ) {
148 HLTError("DDL directory not specified" );
149 return EINVAL; /* Invalid argument */
150 }
151
152 fDDLDir = argv[i+1] ;
153 i += 2;
154 continue;
155 }// ddl directory argument
156
157 if ( !strcmp( argv[i], "reglocmap" ) ) {
158 if ( argc <= i+1 ) {
159 HLTError("Regional to Local Card mapping filename not specified" );
160 return EINVAL; /* Invalid argument */
161 }
6efe69e7 162
960d54ad 163 sprintf(reglocFileName,"%s",argv[i+1]);
164
165 i += 2;
166 continue;
167 }// regtolocalmap argument
5d1682b9 168
169 if ( !strcmp( argv[i], "-warn_on_unexpected_block" ) ) {
170 fWarnForUnexpecedBlock = true;
171 i++;
172 continue;
173 }
960d54ad 174
175 HLTError("Unknown option '%s'", argv[i] );
176 return EINVAL;
6efe69e7 177
960d54ad 178 }//while loop
6efe69e7 179
180 int lutline = fTrigRec->GetLutLine();
181 AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline];
182 if(!ReadLookUpTable(lookupTable,lutFileName)){
960d54ad 183 HLTError("Failed to read lut, lut cannot be read");
6efe69e7 184 return ENOENT ; /* No such file or directory */
185 }else{
186
960d54ad 187 fTrigRec->LoadLookUpTable(lookupTable,fDDL+AliHLTMUONTriggerReconstructor::GetkDDLOffSet());
188
189 AliHLTMUONTriggerReconstructor::RegToLoc regToLocMap[128]; // 16(locCard)*8(regCard)
190 if(!ReadRegToLocMap(regToLocMap,reglocFileName)){
191 HLTError("Failed to read RegToLocMap file");
192 return ENOENT ; /* No such file or directory */
193 }
194
195 if(!(fTrigRec->SetRegToLocCardMap(regToLocMap))){
196 HLTError("Failed to assign RegToLocMap to TrigRec Class due to memory problem");
197 return ENOMEM ; /*cannot allocate memory*/
198 }
6efe69e7 199
200 }// reading lut
201
202 delete []lookupTable;
203
960d54ad 204 HLTInfo("Initialisation of DHLT Trigger Record Component is done");
205
6efe69e7 206 return 0;
207}
208
960d54ad 209
6efe69e7 210int AliHLTMUONTriggerReconstructorComponent::DoDeinit()
960d54ad 211{
227e7192 212 HLTInfo("Deinitialising DHLT Trigger Record Component");
213
214 if(fTrigRec)
215 {
216 delete fTrigRec;
217 fTrigRec = NULL;
218 }
219 return 0;
960d54ad 220}
6efe69e7 221
227e7192 222
960d54ad 223int AliHLTMUONTriggerReconstructorComponent::DoEvent(
224 const AliHLTComponentEventData& evtData,
225 const AliHLTComponentBlockData* blocks,
226 AliHLTComponentTriggerData& trigData,
227 AliHLTUInt8_t* outputPtr,
228 AliHLTUInt32_t& size,
229 std::vector<AliHLTComponentBlockData>& outputBlocks
230 )
231{
227e7192 232 // Process an event
233 unsigned long totalSize = 0; // Amount of memory currently consumed in bytes.
6efe69e7 234
227e7192 235 HLTDebug("Processing event %llu with %u input data blocks.",
236 evtData.fEventID, evtData.fBlockCnt
237 );
6efe69e7 238
227e7192 239 // Loop over all input blocks in the event and run the trigger DDL
240 // reconstruction algorithm on the raw data.
241 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
242 {
5d1682b9 243#ifdef __DEBUG
227e7192 244 char id[kAliHLTComponentDataTypefIDsize+1];
245 for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
246 id[i] = blocks[n].fDataType.fID[i];
247 id[kAliHLTComponentDataTypefIDsize] = '\0';
248 char origin[kAliHLTComponentDataTypefOriginSize+1];
249 for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
250 origin[i] = blocks[n].fDataType.fOrigin[i];
251 origin[kAliHLTComponentDataTypefOriginSize] = '\0';
5d1682b9 252#endif // __DEBUG
227e7192 253 HLTDebug("Handling block: %u, with fDataType.fID = '%s',"
254 " fDataType.fID = '%s', fPtr = %p and fSize = %u bytes.",
a31f86fa 255 n, static_cast<char*>(id), static_cast<char*>(origin),
227e7192 256 blocks[n].fPtr, blocks[n].fSize
257 );
258
259 if (blocks[n].fDataType != AliHLTMUONConstants::TriggerDDLRawDataType())
260 {
261 // Log a message indicating that we got a data block that we
262 // do not know how to handle.
263 char id[kAliHLTComponentDataTypefIDsize+1];
264 for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
265 id[i] = blocks[n].fDataType.fID[i];
266 id[kAliHLTComponentDataTypefIDsize] = '\0';
267 char origin[kAliHLTComponentDataTypefOriginSize+1];
268 for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
269 origin[i] = blocks[n].fDataType.fOrigin[i];
270 origin[kAliHLTComponentDataTypefOriginSize] = '\0';
271
5d1682b9 272 if (fWarnForUnexpecedBlock)
273 HLTWarning("Received a data block of a type we can not handle: %s origin %s",
274 static_cast<char*>(id), static_cast<char*>(origin)
275 );
276 else
277 HLTDebug("Received a data block of a type we can not handle: %s origin %s",
278 static_cast<char*>(id), static_cast<char*>(origin)
279 );
280
227e7192 281 continue;
282 }
283
284 // Create a new output data block and initialise the header.
285 AliHLTMUONTriggerRecordsBlockWriter block(outputPtr+totalSize, size-totalSize);
286 if (not block.InitCommonHeader())
287 {
288 HLTError("There is not enough space in the output buffer for the new data block.",
289 " We require at least %u bytes, but have %u bytes left.",
290 sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType),
291 block.BufferSize()
292 );
293 break;
294 }
295
296 AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t);
297 AliHLTUInt32_t ddlRawDataSize = totalDDLSize - fTrigRec->GetkDDLHeaderSize();
298 AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr)
299 + fTrigRec->GetkDDLHeaderSize();
300 AliHLTUInt32_t nofTrigRec = block.MaxNumberOfEntries();
301
302 if (not fTrigRec->Run(buffer, ddlRawDataSize, block.GetArray(), nofTrigRec))
303 {
304 HLTError("Error while processing of trigger DDL reconstruction algorithm.");
305 size = totalSize; // Must tell the framework how much buffer space was used.
306 return EIO;
307 }
308
309 // nofTrigRec should now contain the number of triggers actually found
310 // and filled into the output data block, so we can set this number.
311 assert( nofTrigRec <= block.MaxNumberOfEntries() );
312 block.SetNumberOfEntries(nofTrigRec);
313
314 HLTDebug("Number of trigger records found is %d", nofTrigRec);
315
316 // Fill a block data structure for our output block.
317 AliHLTComponentBlockData bd;
318 FillBlockData(bd);
319 bd.fPtr = outputPtr;
320 // This block's start (offset) is after all other blocks written so far.
321 bd.fOffset = totalSize;
322 bd.fSize = block.BytesUsed();
323 bd.fDataType = AliHLTMUONConstants::TriggerRecordsBlockDataType();
324 bd.fSpecification = blocks[n].fSpecification;
325 outputBlocks.push_back(bd);
326
327 HLTDebug("Created a new output data block at fPtr = %p,"
328 " with fOffset = %u (0x%.X) and fSize = %u bytes.",
329 bd.fPtr, bd.fOffset, bd.fOffset, bd.fSize
330 );
331
332 // Increase the total amount of data written so far to our output memory.
333 totalSize += block.BytesUsed();
334 }
960d54ad 335
227e7192 336 // Finally we set the total size of output memory we consumed.
337 size = totalSize;
338 return 0;
960d54ad 339}
340
6efe69e7 341
342bool AliHLTMUONTriggerReconstructorComponent::ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath)
343{
960d54ad 344 if (fDDL < 0 || fDDL >= 2){
6efe69e7 345 HLTError("DDL number is out of range");
346 return false;
347 }
348
349 int lutLine = fTrigRec->GetLutLine();
350
351 FILE* fin = fopen(lutpath, "r");
352 if (fin == NULL){
353 HLTError("Failed to open file: %s",lutpath);
354 return false;
355 }
356
357 for(int i=0;i<lutLine;i++){
358 fscanf(
359 fin,
360 "%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",
361 &lookupTable[i].fIdManuChannel,
362 &lookupTable[i].fIX,
363 &lookupTable[i].fIY,
364 &lookupTable[i].fRealX,
365 &lookupTable[i].fRealY,
366 &lookupTable[i].fRealZ,
960d54ad 367 &lookupTable[i].fPcbZone,
368 &lookupTable[i].fPlane
6efe69e7 369 );
370 }
371
372 fclose(fin);
373 return true;
374}
375
6efe69e7 376
960d54ad 377bool AliHLTMUONTriggerReconstructorComponent::ReadRegToLocMap(AliHLTMUONTriggerReconstructor::RegToLoc* regToLocMap,const char* reglocFileName)
378{
379 int iTrigDDL,iReg,iLoc,locId,switchWord,detElemId[4];
380 int index;
381
382 memset(regToLocMap,-1,128*sizeof(AliHLTMUONTriggerReconstructor::RegToLoc));
383
384 char s[100];
385 ifstream fin(reglocFileName);
386
387 if(!fin){
388 HLTError("Failed to open file %s",reglocFileName);
389 return false;
390 }
391
392 while(fin.getline(s,100)){
393 sscanf(s,"%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d",
394 &iTrigDDL,&iReg,&iLoc,&locId,&switchWord,&detElemId[0],&detElemId[1],&detElemId[2],&detElemId[3]);
395 if(iTrigDDL==fDDL){
396 index = iReg*16 + iLoc;
397 regToLocMap[index].fTrigDDL = iTrigDDL ;
398 regToLocMap[index].fRegId = iReg ;
399 regToLocMap[index].fLoc = iLoc ;
400 regToLocMap[index].fLocId = locId ;
401 regToLocMap[index].fSwitch = switchWord ;
402 for(int idet = 0; idet<4; idet++)
403 regToLocMap[index].fDetElemId[idet] = detElemId[idet] ;
404 }// if matches with fDDL
405 }//file loop
406
407 fin.close();
408 return true;
409}