3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
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 **************************************************************************/
19 /** @file AliHLTTRDClusterizerComponent.cxx
20 @author Timm Steinbeck, Matthias Richter
22 @brief A TRDClusterizer processing component for the HLT. */
24 // see header file for class documentation //
26 // refer to README to build package //
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt //
38 #include "AliHLTTRDClusterizerComponent.h"
39 #include "AliHLTTRDDefinitions.h"
40 #include "AliHLTTRDCluster.h"
42 #include "AliGeomManager.h"
43 #include "AliTRDReconstructor.h"
44 #include "AliCDBManager.h"
45 #include "AliHLTTRDClusterizer.h"
46 #include "AliTRDrecoParam.h"
47 #include "AliTRDrawStreamBase.h"
48 #include "AliTRDcluster.h"
50 #include "AliRawReaderMemory.h"
52 #ifdef HAVE_VALGRIND_CALLGRIND_H
53 #include <valgrind/callgrind.h>
55 #define CALLGRIND_START_INSTRUMENTATION do { } while (0)
56 #define CALLGRIND_STOP_INSTRUMENTATION do { } while (0)
63 ClassImp(AliHLTTRDClusterizerComponent)
65 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent():
67 fOutputPercentage(100), // By default we copy to the output exactly what we got as input
68 fStrorageDBpath("local://$ALICE_ROOT/OCDB"),
76 // Default constructor
78 fGeometryFileName = getenv("ALICE_ROOT");
79 fGeometryFileName += "/HLT/TRD/geometry.root";
82 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
85 // Work is Done in DoDeInit()
89 const char* AliHLTTRDClusterizerComponent::GetComponentID()
91 // Return the component ID const char *
92 return "TRDClusterizer"; // The ID of this component
95 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
97 // Get the list of input data
98 list.clear(); // We do not have any requirements for our input data type(s).
99 list.push_back( AliHLTTRDDefinitions::fgkDDLRawDataType );
102 AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
104 // Get the output data type
105 return AliHLTTRDDefinitions::fgkClusterDataType;
108 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
110 // Get the output data size
112 inputMultiplier = ((double)fOutputPercentage)/100.0;
115 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
117 // Spawn function, return new instance of this class
118 return new AliHLTTRDClusterizerComponent;
121 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
123 // perform initialization. We check whether our relative output size is specified in the arguments.
124 fOutputPercentage = 100;
125 Int_t iRawDataVersion = 2;
129 Int_t iRecoParamType = -1; // default will be the low flux
131 // the data type will become obsolete as soon as the formats are established
132 Int_t iRecoDataType = -1; // default will be simulation
133 Int_t iyPosMethod = 1; // 0=COG 1=LUT 2=Gauss
137 HLTDebug("argv[%d] == %s", i, argv[i] );
138 if ( !strcmp( argv[i], "output_percentage" ) )
142 HLTError("Missing output_percentage parameter");
145 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
146 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
149 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
152 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
155 else if ( strcmp( argv[i], "-cdb" ) == 0)
159 HLTError("Missing -cdb argument");
162 fStrorageDBpath = argv[i+1];
163 HLTInfo("DB storage is %s", fStrorageDBpath.c_str() );
166 else if ( strcmp( argv[i], "-lowflux" ) == 0)
169 HLTDebug("Low flux reco selected.");
172 else if ( strcmp( argv[i], "-highflux" ) == 0)
175 HLTDebug("High flux reco selected.");
178 else if ( strcmp( argv[i], "-cosmics" ) == 0)
181 HLTDebug("Cosmic test reco selected.");
184 // raw data type - sim or experiment
185 else if ( strcmp( argv[i], "-simulation" ) == 0)
190 else if ( strcmp( argv[i], "-experiment" ) == 0)
195 else if ( strcmp( argv[i], "-rawver" ) == 0)
199 HLTError("Missing -rawver argument");
202 iRawDataVersion = atoi( argv[i+1] );
203 HLTInfo("Raw data version is %d", iRawDataVersion );
208 else if ( strcmp( argv[i], "-geometry" ) == 0)
212 HLTError("Missing -geometry argument");
215 fGeometryFileName = argv[i+1];
216 HLTInfo("GeomFile storage is %s", fGeometryFileName.c_str() );
220 else if ( strcmp( argv[i], "-yPosMethod" ) == 0)
224 HLTError("Missing -yPosMethod argument");
227 if( strcmp(argv[i], "COG") )
229 else if( strcmp(argv[i], "LUT") )
231 else if( strcmp(argv[i], "Gauss") )
234 HLTError("Unknown -yPosMethod argument");
241 HLTError("Unknown option '%s'", argv[i] );
247 // THE "REAL" INIT COMES HERE
249 if (iRecoParamType < 0 || iRecoParamType > 2)
251 HLTWarning("No reco param selected. Use -lowflux or -highflux flag. Defaulting to low flux.");
255 if (iRecoParamType == 0)
257 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
258 HLTDebug("Low flux params init.");
261 if (iRecoParamType == 1)
263 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
264 HLTDebug("High flux params init.");
267 if (iRecoParamType == 2)
269 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
270 HLTDebug("Cosmic Test params init.");
275 HLTError("No reco params initialized. Sniffing big trouble!");
279 fReconstructor = new AliTRDReconstructor();
280 fReconstructor->SetRecoParam(fRecoParam);
281 fReconstructor->SetStreamLevel(0, AliTRDReconstructor::kClusterizer); // default value
282 HLTInfo("Not writing clusters. I.e. output is a TClonesArray of clusters");
283 TString recoOptions="hlt,!cw,sl_cf_0";
284 switch(iRecoDataType){
285 case 0: recoOptions += ",tc"; break;
286 case 1: recoOptions += ",!tc"; break;
289 case 0: recoOptions += ",!gs,!lut"; break;
290 case 1: recoOptions += ",!gs,lut"; break;
291 case 2: recoOptions += ",gs,!lut"; break;
294 fReconstructor->SetOption(recoOptions.Data());
296 // init the raw data type to be used...
297 // the switch here will become obsolete as soon as the data structures is fixed
298 // both: in sim and reality
299 if (iRecoDataType < 0 || iRecoDataType > 1)
301 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
305 if (iRecoDataType == 0)
307 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
308 HLTDebug("Data type expected is SIMULATION!");
311 if (iRecoDataType == 1)
313 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
314 HLTDebug("Data type expected is EXPERIMENT!");
317 // the DATA BASE STUFF
318 fCDB = AliCDBManager::Instance();
321 HLTError("Could not get CDB instance", "fCDB 0x%x", fCDB);
325 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
326 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
327 HLTDebug("CDB instance; fCDB 0x%x", fCDB);
330 if((AliGeomManager::GetGeometry()) == NULL){
332 if ( TFile::Open(fGeometryFileName.c_str())) {
333 AliGeomManager::LoadGeometry(fGeometryFileName.c_str());
336 HLTError("Cannot load geometry from file %s",fGeometryFileName.c_str());
341 HLTInfo("Geometry Already Loaded");
343 fMemReader = new AliRawReaderMemory;
345 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
346 fClusterizer->SetReconstructor(fReconstructor);
347 fClusterizer->SetUseLabels(kFALSE);
348 fClusterizer->SetRawVersion(iRawDataVersion);
352 int AliHLTTRDClusterizerComponent::DoDeinit()
354 // Deinitialization of the component
360 fReconstructor->SetClusters(0x0);
361 delete fReconstructor;
362 fReconstructor = 0x0;
368 HLTDebug("destroy fCDB");
375 HLTDebug("Deleting fRecoParam");
381 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
382 const AliHLTComponentBlockData* blocks,
383 AliHLTComponent_TriggerData& /*trigData*/,
384 AliHLTUInt8_t* outputPtr,
385 AliHLTUInt32_t& size,
386 vector<AliHLTComponent_BlockData>& outputBlocks )
389 HLTDebug( "NofBlocks %lu", evtData.fBlockCnt );
391 AliHLTUInt32_t totalSize = 0, offset = 0;
393 //implement a usage of the following
394 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
395 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
396 // void *triggerData = trigData.fData;
397 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
399 // Loop over all input blocks in the event
400 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
401 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
403 if (evtData.fEventID == 1)
404 CALLGRIND_START_INSTRUMENTATION;
406 const AliHLTComponentBlockData &block = blocks[i];
407 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
408 // which is depreciated - we use HLT global defs instead
409 // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
410 AliHLTComponentDataType inputDataType = block.fDataType;
411 if ( inputDataType != expectedDataType)
413 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s; Skipping",
414 i, evtData.fBlockCnt,
415 evtData.fEventID, evtData.fEventID,
416 DataType2Text(inputDataType).c_str(),
417 DataType2Text(expectedDataType).c_str());
422 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s",
423 i, evtData.fBlockCnt,
424 evtData.fEventID, evtData.fEventID,
425 DataType2Text(inputDataType).c_str());
428 // fMemReader->Reset();
429 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
431 AliHLTUInt32_t spec = block.fSpecification;
435 for ( Int_t ii = 0; ii < 18 ; ii++ ) {
436 if ( spec & 0x00000001 ) {
443 fMemReader->SetEquipmentID( id );
445 fClusterizer->SetMemBlock((AliHLTUInt8_t*)(outputPtr+offset));
446 Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
447 if (iclustered == kTRUE)
449 HLTDebug( "Clustered successfully");
453 HLTError("Clustering ERROR");
457 // put the tree into output
460 AliHLTUInt32_t addedSize = fClusterizer->GetAddedSize();
462 // Using low-level interface
463 // with interface classes
464 totalSize += addedSize;
465 if ( totalSize > size )
467 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
473 AliHLTComponentBlockData bd;
476 bd.fSize = addedSize;
477 //bd.fSpecification = spec;
478 bd.fSpecification = gkAliEventTypeData;
479 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
480 outputBlocks.push_back( bd );
481 HLTDebug( "BD fPtr 0x%x, fOffset %i, size %i, dataType %s, spec 0x%x ", bd.fPtr, bd.fOffset, bd.fSize, DataType2Text(bd.fDataType).c_str(), spec);
486 HLTWarning("Array of clusters is empty!");
488 fReconstructor->SetClusters(0x0);
491 HLTDebug("Event is done. size written to the output is %i", size);
495 void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
497 AliTRDcluster* cluster=0x0;
499 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
500 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
501 HLTDebug("cluster[%i]",i);
502 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
503 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
504 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());