]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TRD/AliHLTTRDClusterizerComponent.cxx
Track length update removed from the tracker code,since it is done in the track code...
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDClusterizerComponent.cxx
CommitLineData
0af7cb2e 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/** @file AliHLTTRDClusterizerComponent.cxx
20 @author Timm Steinbeck, Matthias Richter
21 @date
22 @brief A TRDClusterizer processing component for the HLT. */
23
c7500dae 24// see header file for class documentation //
25// or //
26// refer to README to build package //
27// or //
28// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt //
29
0af7cb2e 30#if __GNUC__ >= 3
31using namespace std;
32#endif
33
051a0e2d 34#include "TTree.h"
35#include "TFile.h"
36#include "TBranch.h"
37
0af7cb2e 38#include "AliHLTTRDClusterizerComponent.h"
39#include "AliHLTTRDDefinitions.h"
d679dd6c 40#include "AliHLTTRDCluster.h"
0af7cb2e 41
886e8d3d 42#include "AliGeomManager.h"
43#include "AliTRDReconstructor.h"
0af7cb2e 44#include "AliCDBManager.h"
dc2e6604 45#include "AliHLTTRDClusterizer.h"
519f385f 46#include "AliTRDrecoParam.h"
47#include "AliTRDrawStreamBase.h"
d679dd6c 48#include "AliTRDcluster.h"
519f385f 49
0af7cb2e 50#include "AliRawReaderMemory.h"
51
d679dd6c 52#ifdef HAVE_VALGRIND_CALLGRIND_H
53#include <valgrind/callgrind.h>
54#else
55#define CALLGRIND_START_INSTRUMENTATION() do { } while (0)
56#define CALLGRIND_STOP_INSTRUMENTATION() do { } while (0)
57#endif
58
0af7cb2e 59#include <cstdlib>
60#include <cerrno>
61#include <string>
62
3b021c25 63ClassImp(AliHLTTRDClusterizerComponent);
64
d679dd6c 65AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent():
66 AliHLTProcessor(),
67 fOutputPercentage(100), // By default we copy to the output exactly what we got as input
162637e4 68 fStrorageDBpath("local://$ALICE_ROOT/OCDB"),
d679dd6c 69 fClusterizer(NULL),
70 fRecoParam(NULL),
71 fCDB(NULL),
72 fMemReader(NULL),
73 fReconstructor(NULL),
dc2e6604 74 fGeometryFileName("")
0af7cb2e 75{
3b021c25 76 // Default constructor
051a0e2d 77
78 fGeometryFileName = getenv("ALICE_ROOT");
79 fGeometryFileName += "/HLT/TRD/geometry.root";
0af7cb2e 80}
81
82AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
83{
3b021c25 84 // Destructor
886e8d3d 85 // Work is Done in DoDeInit()
0af7cb2e 86}
d679dd6c 87
d679dd6c 88
0af7cb2e 89const char* AliHLTTRDClusterizerComponent::GetComponentID()
90{
3b021c25 91 // Return the component ID const char *
0af7cb2e 92 return "TRDClusterizer"; // The ID of this component
93}
94
95void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
96{
3b021c25 97 // Get the list of input data
0af7cb2e 98 list.clear(); // We do not have any requirements for our input data type(s).
efbd3157 99 list.push_back( AliHLTTRDDefinitions::fgkDDLRawDataType );
0af7cb2e 100}
101
102AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
103{
3b021c25 104 // Get the output data type
efbd3157 105 return AliHLTTRDDefinitions::fgkClusterDataType;
0af7cb2e 106}
107
108void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
109{
3b021c25 110 // Get the output data size
0af7cb2e 111 constBase = 0;
112 inputMultiplier = ((double)fOutputPercentage)/100.0;
113}
114
0af7cb2e 115AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
116{
3b021c25 117 // Spawn function, return new instance of this class
0af7cb2e 118 return new AliHLTTRDClusterizerComponent;
119};
120
121int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
122{
123 // perform initialization. We check whether our relative output size is specified in the arguments.
124 fOutputPercentage = 100;
d137c50b 125 Int_t iRawDataVersion = 2;
0af7cb2e 126 int i = 0;
127 char* cpErr;
519f385f 128
129 Int_t iRecoParamType = -1; // default will be the low flux
130
131 // the data type will become obsolete as soon as the formats are established
132 Int_t iRecoDataType = -1; // default will be simulation
133
0af7cb2e 134 while ( i < argc )
135 {
886e8d3d 136 HLTDebug("argv[%d] == %s", i, argv[i] );
0af7cb2e 137 if ( !strcmp( argv[i], "output_percentage" ) )
138 {
139 if ( i+1>=argc )
140 {
886e8d3d 141 HLTError("Missing output_percentage parameter");
0af7cb2e 142 return ENOTSUP;
143 }
886e8d3d 144 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
0af7cb2e 145 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
146 if ( *cpErr )
147 {
886e8d3d 148 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
0af7cb2e 149 return EINVAL;
150 }
886e8d3d 151 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
0af7cb2e 152 i += 2;
0af7cb2e 153 }
9aea5deb 154 else if ( strcmp( argv[i], "-cdb" ) == 0)
0af7cb2e 155 {
156 if ( i+1 >= argc )
157 {
886e8d3d 158 HLTError("Missing -cdb argument");
0af7cb2e 159 return ENOTSUP;
160 }
161 fStrorageDBpath = argv[i+1];
886e8d3d 162 HLTInfo("DB storage is %s", fStrorageDBpath.c_str() );
0af7cb2e 163 i += 2;
9aea5deb 164
0af7cb2e 165 }
166
9aea5deb 167 else if ( strcmp( argv[i], "-lowflux" ) == 0)
519f385f 168 {
169 iRecoParamType = 0;
170 HLTDebug("Low flux reco selected.");
171 i++;
9aea5deb 172
519f385f 173 }
174
9aea5deb 175 else if ( strcmp( argv[i], "-highflux" ) == 0)
519f385f 176 {
177 iRecoParamType = 1;
886e8d3d 178 HLTDebug("High flux reco selected.");
179 i++;
9aea5deb 180
886e8d3d 181 }
182
9aea5deb 183 else if ( strcmp( argv[i], "-cosmics" ) == 0)
886e8d3d 184 {
185 iRecoParamType = 2;
186 HLTDebug("Cosmic test reco selected.");
519f385f 187 i++;
9aea5deb 188
519f385f 189 }
190
191 // raw data type - sim or experiment
9aea5deb 192 else if ( strcmp( argv[i], "-simulation" ) == 0)
519f385f 193 {
194 iRecoDataType = 0;
195 i++;
9aea5deb 196
519f385f 197 }
198
9aea5deb 199 else if ( strcmp( argv[i], "-experiment" ) == 0)
519f385f 200 {
201 iRecoDataType = 1;
202 i++;
9aea5deb 203
519f385f 204 }
205
9aea5deb 206 else if ( strcmp( argv[i], "-rawver" ) == 0)
0af7cb2e 207 {
208 if ( i+1 >= argc )
209 {
886e8d3d 210 HLTError("Missing -rawver argument");
0af7cb2e 211 return ENOTSUP;
212 }
d137c50b 213 iRawDataVersion = atoi( argv[i+1] );
886e8d3d 214 HLTInfo("Raw data version is %d", iRawDataVersion );
0af7cb2e 215 i += 2;
9aea5deb 216
0af7cb2e 217 }
218
9aea5deb 219 else if ( strcmp( argv[i], "-geometry" ) == 0)
051a0e2d 220 {
221 if ( i+1 >= argc )
222 {
886e8d3d 223 HLTError("Missing -geometry argument");
051a0e2d 224 return ENOTSUP;
225 }
226 fGeometryFileName = argv[i+1];
886e8d3d 227 HLTInfo("GeomFile storage is %s", fGeometryFileName.c_str() );
051a0e2d 228 i += 2;
051a0e2d 229 }
9aea5deb 230 else{
231 HLTError("Unknown option '%s'", argv[i] );
232 return EINVAL;
233 }
234
0af7cb2e 235 }
236
519f385f 237 // THE "REAL" INIT COMES HERE
238
886e8d3d 239 if (iRecoParamType < 0 || iRecoParamType > 2)
519f385f 240 {
241 HLTWarning("No reco param selected. Use -lowflux or -highflux flag. Defaulting to low flux.");
242 iRecoParamType = 0;
243 }
244
245 if (iRecoParamType == 0)
246 {
247 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
248 HLTDebug("Low flux params init.");
249 }
250
251 if (iRecoParamType == 1)
252 {
253 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
254 HLTDebug("High flux params init.");
255 }
256
886e8d3d 257 if (iRecoParamType == 2)
258 {
259 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
260 HLTDebug("Cosmic Test params init.");
261 }
262
519f385f 263 if (fRecoParam == 0)
264 {
265 HLTError("No reco params initialized. Sniffing big trouble!");
266 return -1;
267 }
268
0d66dbf5 269 fReconstructor = new AliTRDReconstructor();
270 fReconstructor->SetRecoParam(fRecoParam);
0134491a 271 fReconstructor->SetStreamLevel(0, AliTRDReconstructor::kClusterizer); // default value
dc2e6604 272 HLTInfo("Not writing clusters. I.e. output is a TClonesArray of clusters");
273 fReconstructor->SetOption("hlt,!cw,sl_cf_0");
0134491a 274
275
519f385f 276 // init the raw data type to be used...
277 // the switch here will become obsolete as soon as the data structures is fixed
278 // both: in sim and reality
279 if (iRecoDataType < 0 || iRecoDataType > 1)
280 {
281 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
282 iRecoDataType = 0;
283 }
284
285 if (iRecoDataType == 0)
286 {
287 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
288 HLTDebug("Data type expected is SIMULATION!");
289 }
290
291 if (iRecoDataType == 1)
292 {
293 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
294 HLTDebug("Data type expected is EXPERIMENT!");
295 }
296
297 // the DATA BASE STUFF
3b021c25 298 fCDB = AliCDBManager::Instance();
299 if (!fCDB)
0af7cb2e 300 {
9aea5deb 301 HLTError("Could not get CDB instance", "fCDB 0x%x", fCDB);
0af7cb2e 302 }
303 else
304 {
3b021c25 305 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
306 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
886e8d3d 307 HLTDebug("CDB instance; fCDB 0x%x", fCDB);
0af7cb2e 308 }
309
d679dd6c 310 if((AliGeomManager::GetGeometry()) == NULL){
311
312 if ( TFile::Open(fGeometryFileName.c_str())) {
886e8d3d 313 AliGeomManager::LoadGeometry(fGeometryFileName.c_str());
051a0e2d 314 }
d679dd6c 315 else {
316 HLTError("Cannot load geometry from file %s",fGeometryFileName.c_str());
317 return EINVAL;
051a0e2d 318 }
d679dd6c 319 }
320 else
321 HLTInfo("Geometry Already Loaded");
322
3b021c25 323 fMemReader = new AliRawReaderMemory;
051a0e2d 324
dc2e6604 325 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
9aea5deb 326 fClusterizer->SetReconstructor(fReconstructor);
56397b53 327 fClusterizer->SetUseLabels(kFALSE);
d137c50b 328 fClusterizer->SetRawVersion(iRawDataVersion);
0af7cb2e 329 return 0;
330}
331
332int AliHLTTRDClusterizerComponent::DoDeinit()
333{
3b021c25 334 // Deinitialization of the component
335 delete fMemReader;
336 fMemReader = 0;
337 delete fClusterizer;
338 fClusterizer = 0;
9aea5deb 339
340 fReconstructor->SetClusters(0x0);
0d66dbf5 341 delete fReconstructor;
342 fReconstructor = 0x0;
0af7cb2e 343 return 0;
344
051a0e2d 345
3b021c25 346 if (fCDB)
0af7cb2e 347 {
886e8d3d 348 HLTDebug("destroy fCDB");
3b021c25 349 fCDB->Destroy();
350 fCDB = 0;
0af7cb2e 351 }
519f385f 352
353 if (fRecoParam)
354 {
355 HLTDebug("Deleting fRecoParam");
356 delete fRecoParam;
357 fRecoParam = 0;
358 }
0af7cb2e 359}
360
886e8d3d 361int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
362 const AliHLTComponentBlockData* blocks,
363 AliHLTComponent_TriggerData& /*trigData*/,
d679dd6c 364 AliHLTUInt8_t* outputPtr,
a28bfa0d 365 AliHLTUInt32_t& size,
d679dd6c 366 vector<AliHLTComponent_BlockData>& outputBlocks )
0af7cb2e 367{
3b021c25 368 // Process an event
886e8d3d 369 HLTDebug( "NofBlocks %lu", evtData.fBlockCnt );
0af7cb2e 370 // Process an event
d679dd6c 371 AliHLTUInt32_t totalSize = 0, offset = 0;
0af7cb2e 372
051a0e2d 373 //implement a usage of the following
519f385f 374 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
375 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
376 // void *triggerData = trigData.fData;
886e8d3d 377 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
051a0e2d 378
0af7cb2e 379 // Loop over all input blocks in the event
886e8d3d 380 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
0af7cb2e 381 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
382 {
d679dd6c 383 if (evtData.fEventID == 1)
384 CALLGRIND_START_INSTRUMENTATION();
385
386 const AliHLTComponentBlockData &block = blocks[i];
387 offset = totalSize;
519f385f 388 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
389 // which is depreciated - we use HLT global defs instead
d679dd6c 390 // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
391 AliHLTComponentDataType inputDataType = block.fDataType;
886e8d3d 392 if ( inputDataType != expectedDataType)
0af7cb2e 393 {
9aea5deb 394 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s; Skipping",
395 i, evtData.fBlockCnt,
396 evtData.fEventID, evtData.fEventID,
397 DataType2Text(inputDataType).c_str(),
398 DataType2Text(expectedDataType).c_str());
0af7cb2e 399 continue;
400 }
9aea5deb 401 else
402 {
d679dd6c 403 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s",
404 i, evtData.fBlockCnt,
405 evtData.fEventID, evtData.fEventID,
406 DataType2Text(inputDataType).c_str());
9aea5deb 407 }
408
886e8d3d 409 // fMemReader->Reset();
d679dd6c 410 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
886e8d3d 411
d679dd6c 412 AliHLTUInt32_t spec = block.fSpecification;
886e8d3d 413
414 Int_t id = 1024;
415
416 for ( Int_t ii = 0; ii < 18 ; ii++ ) {
417 if ( spec & 0x00000001 ) {
418 id += ii;
419 break;
420 }
421 spec = spec >> 1 ;
422 }
886e8d3d 423
d679dd6c 424 fMemReader->SetEquipmentID( id );
425
dc2e6604 426 fClusterizer->SetMemBlock(outputPtr);
886e8d3d 427 Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
428 if (iclustered == kTRUE)
0af7cb2e 429 {
886e8d3d 430 HLTDebug( "Clustered successfully");
431 }
432 else
433 {
434 HLTError("Clustering ERROR");
0af7cb2e 435 return -1;
436 }
519f385f 437
d679dd6c 438 // put the tree into output
886e8d3d 439 //fcTree->Print();
dc2e6604 440
441 AliHLTUInt32_t addedSize = fClusterizer->GetAddedSize();
442 if (addedSize > 0){
443 // Using low-level interface
444 // with interface classes
445 totalSize += addedSize;
446 if ( totalSize > size )
0134491a 447 {
dc2e6604 448 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
449 totalSize, size );
450 return EMSGSIZE;
0134491a 451 }
d679dd6c 452
dc2e6604 453 // Fill block
454 AliHLTComponentBlockData bd;
455 FillBlockData( bd );
456 bd.fOffset = offset;
457 bd.fSize = addedSize;
458 //bd.fSpecification = spec;
459 bd.fSpecification = gkAliEventTypeData;
460 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
461 outputBlocks.push_back( bd );
462 HLTDebug( "Block ; size %i; dataType %s; spec 0x%x ",
463 bd.fSize, DataType2Text(bd.fDataType).c_str(), spec);
d679dd6c 464
0134491a 465 }
dc2e6604 466 else
467 HLTWarning("Array of clusters is empty!");
468 }
d679dd6c 469 fReconstructor->SetClusters(0x0);
b39f18ce 470
d679dd6c 471 size = totalSize;
472 HLTDebug("Event is done. size written to the output is %i", size);
473 return 0;
474}
475
476
477void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
478{
479 AliTRDcluster* cluster=0x0;
9aea5deb 480
d679dd6c 481 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
482 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
483 HLTDebug("cluster[%i]",i);
484 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
485 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
486 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
487 }
9aea5deb 488
0af7cb2e 489}
d679dd6c 490