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"
41 #include "AliGeomManager.h"
42 #include "AliTRDReconstructor.h"
43 #include "AliCDBManager.h"
44 #include "AliTRDclusterizerHLT.h"
45 #include "AliTRDrecoParam.h"
46 #include "AliTRDrawStreamBase.h"
48 #include "AliRawReaderMemory.h"
54 // this is a global object used for automatic component registration, do not use this
55 AliHLTTRDClusterizerComponent gAliHLTTRDClusterizerComponent;
57 ClassImp(AliHLTTRDClusterizerComponent);
59 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent()
61 , fOutputPercentage(100) // By default we copy to the output exactly what we got as input
62 , fStrorageDBpath("local://$ALICE_ROOT")
67 , fGeometryFileName("")
69 , fReconstructor(NULL)
71 // Default constructor
73 fGeometryFileName = getenv("ALICE_ROOT");
74 fGeometryFileName += "/HLT/TRD/geometry.root";
77 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
80 // Work is Done in DoDeInit()
82 const char* AliHLTTRDClusterizerComponent::GetComponentID()
84 // Return the component ID const char *
85 return "TRDClusterizer"; // The ID of this component
88 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
90 // Get the list of input data
91 list.clear(); // We do not have any requirements for our input data type(s).
92 list.push_back( AliHLTTRDDefinitions::fgkDDLRawDataType );
95 AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
97 // Get the output data type
98 return AliHLTTRDDefinitions::fgkClusterDataType;
101 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
103 // Get the output data size
105 inputMultiplier = ((double)fOutputPercentage)/100.0;
108 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
110 // Spawn function, return new instance of this class
111 return new AliHLTTRDClusterizerComponent;
114 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
116 // perform initialization. We check whether our relative output size is specified in the arguments.
117 fOutputPercentage = 100;
118 Int_t iRawDataVersion = 2;
121 Bool_t bWriteClusters = kTRUE;
124 Int_t iRecoParamType = -1; // default will be the low flux
126 // the data type will become obsolete as soon as the formats are established
127 Int_t iRecoDataType = -1; // default will be simulation
131 HLTDebug("argv[%d] == %s", i, argv[i] );
132 if ( !strcmp( argv[i], "output_percentage" ) )
136 HLTError("Missing output_percentage parameter");
139 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
140 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
143 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
146 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
149 else if ( strcmp( argv[i], "-cdb" ) == 0)
153 HLTError("Missing -cdb argument");
156 fStrorageDBpath = argv[i+1];
157 HLTInfo("DB storage is %s", fStrorageDBpath.c_str() );
162 else if ( strcmp( argv[i], "-lowflux" ) == 0)
165 HLTDebug("Low flux reco selected.");
170 else if ( strcmp( argv[i], "-highflux" ) == 0)
173 HLTDebug("High flux reco selected.");
178 else if ( strcmp( argv[i], "-cosmics" ) == 0)
181 HLTDebug("Cosmic test reco selected.");
186 // raw data type - sim or experiment
187 else if ( strcmp( argv[i], "-simulation" ) == 0)
194 else if ( strcmp( argv[i], "-experiment" ) == 0)
201 else if ( strcmp( argv[i], "-rawver" ) == 0)
205 HLTError("Missing -rawver argument");
208 iRawDataVersion = atoi( argv[i+1] );
209 HLTInfo("Raw data version is %d", iRawDataVersion );
214 else if ( strcmp( argv[i], "-geometry" ) == 0)
218 HLTError("Missing -geometry argument");
221 fGeometryFileName = argv[i+1];
222 HLTInfo("GeomFile storage is %s", fGeometryFileName.c_str() );
227 HLTError("Unknown option '%s'", argv[i] );
233 // THE "REAL" INIT COMES HERE
235 if (iRecoParamType < 0 || iRecoParamType > 2)
237 HLTWarning("No reco param selected. Use -lowflux or -highflux flag. Defaulting to low flux.");
241 if (iRecoParamType == 0)
243 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
244 HLTDebug("Low flux params init.");
247 if (iRecoParamType == 1)
249 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
250 HLTDebug("High flux params init.");
253 if (iRecoParamType == 2)
255 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
256 HLTDebug("Cosmic Test params init.");
261 HLTError("No reco params initialized. Sniffing big trouble!");
265 fReconstructor = new AliTRDReconstructor();
266 fReconstructor->SetRecoParam(fRecoParam);
267 //fReconstructor->SetStreamLevel(0, AliTRDReconstructor::kClusterizer); // default value
268 fReconstructor->SetOption("!cw,sl_cf_0");
270 // init the raw data type to be used...
271 // the switch here will become obsolete as soon as the data structures is fixed
272 // both: in sim and reality
273 if (iRecoDataType < 0 || iRecoDataType > 1)
275 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
279 if (iRecoDataType == 0)
281 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
282 HLTDebug("Data type expected is SIMULATION!");
285 if (iRecoDataType == 1)
287 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
288 HLTDebug("Data type expected is EXPERIMENT!");
291 // the DATA BASE STUFF
292 fCDB = AliCDBManager::Instance();
295 HLTError("Could not get CDB instance", "fCDB 0x%x", fCDB);
299 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
300 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
301 HLTDebug("CDB instance; fCDB 0x%x", fCDB);
304 fGeometryFile = TFile::Open(fGeometryFileName.c_str());
307 AliGeomManager::LoadGeometry(fGeometryFileName.c_str());
311 HLTError("Unable to open file. FATAL!");
315 fMemReader = new AliRawReaderMemory;
317 fClusterizer = new AliTRDclusterizerHLT("TRDCclusterizer", "TRDCclusterizer");
318 fClusterizer->SetReconstructor(fReconstructor);
320 fClusterizer->SetRawVersion(iRawDataVersion);
321 fClusterizer->InitClusterTree();
325 int AliHLTTRDClusterizerComponent::DoDeinit()
327 // Deinitialization of the component
333 fReconstructor->SetClusters(0x0);
334 delete fReconstructor;
335 fReconstructor = 0x0;
340 fGeometryFile->Close();
341 delete fGeometryFile;
347 HLTDebug("destroy fCDB");
354 HLTDebug("Deleting fRecoParam");
360 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
361 const AliHLTComponentBlockData* blocks,
362 AliHLTComponent_TriggerData& /*trigData*/,
363 AliHLTUInt8_t* /*outputPtr*/,
364 AliHLTUInt32_t& size,
365 vector<AliHLTComponent_BlockData>& /*outputBlocks*/ )
368 HLTDebug( "NofBlocks %lu", evtData.fBlockCnt );
371 //implement a usage of the following
372 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
373 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
374 // void *triggerData = trigData.fData;
375 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
377 // Loop over all input blocks in the event
378 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
379 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
381 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
382 // which is depreciated - we use HLT global defs instead
383 // if ( blocks[i].fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
384 AliHLTComponentDataType inputDataType = blocks[i].fDataType;
385 if ( inputDataType != expectedDataType)
387 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s; Skipping",
388 i, evtData.fBlockCnt,
389 evtData.fEventID, evtData.fEventID,
390 DataType2Text(inputDataType).c_str(),
391 DataType2Text(expectedDataType).c_str());
396 HLTDebug("We get the right data type!");
399 // fMemReader->Reset();
400 fMemReader->SetMemory((UChar_t*) blocks[i].fPtr, blocks[i].fSize);
402 AliHLTUInt32_t spec = blocks[i].fSpecification;
406 for ( Int_t ii = 0; ii < 18 ; ii++ ) {
407 if ( spec & 0x00000001 ) {
414 fMemReader->SetEquipmentID( id );
416 fClusterizer->ResetTree();
417 Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
418 if (iclustered == kTRUE)
420 HLTDebug( "Clustered successfully");
424 HLTError("Clustering ERROR");
428 // put the tree into output blocks
430 TClonesArray *clusterArray = fClusterizer->RecPoints();
431 fClusterizer->SetClustersOwner(kFALSE);
434 HLTDebug("clusterArray: Entries - %i; Size - %i",clusterArray->GetEntriesFast(),sizeof(clusterArray));
435 PushBack(clusterArray, AliHLTTRDDefinitions::fgkClusterDataType, blocks[i].fSpecification);
438 HLTWarning("Array of clusters is empty!");
441 clusterArray->Delete();
446 }// for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
451 size=0; // this function did not write data to the buffer directly