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 "AliCDBStorage.h"
46 #include "AliCDBEntry.h"
47 #include "AliHLTTRDClusterizer.h"
48 #include "AliTRDrecoParam.h"
49 #include "AliTRDrawStreamBase.h"
50 #include "AliTRDcluster.h"
52 #include "AliRawReaderMemory.h"
54 #ifdef HAVE_VALGRIND_CALLGRIND_H
55 #include <valgrind/callgrind.h>
57 #define CALLGRIND_START_INSTRUMENTATION do { } while (0)
58 #define CALLGRIND_STOP_INSTRUMENTATION do { } while (0)
65 ClassImp(AliHLTTRDClusterizerComponent)
67 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent():
69 fOutputPercentage(500),
79 fgeometryFileName(""),
80 fProcessTracklets(kFALSE),
83 // Default constructor
87 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
90 // Work is Done in DoDeInit()
94 const char* AliHLTTRDClusterizerComponent::GetComponentID()
96 // Return the component ID const char *
97 return "TRDClusterizer"; // The ID of this component
100 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
102 // Get the list of input data
103 list.clear(); // We do not have any requirements for our input data type(s).
104 list.push_back( (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) );
107 AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
109 // Get the output data type
110 return kAliHLTMultipleDataType;
113 int AliHLTTRDClusterizerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
115 // Get the output data type
117 tgtList.push_back(AliHLTTRDDefinitions::fgkClusterDataType);
118 tgtList.push_back(AliHLTTRDDefinitions::fgkMCMtrackletDataType);
119 return tgtList.size();
123 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
125 // Get the output data size
126 constBase = fOutputConst;
127 inputMultiplier = ((double)fOutputPercentage)/100.0;
130 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
132 // Spawn function, return new instance of this class
133 return new AliHLTTRDClusterizerComponent;
136 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
138 // perform initialization. We check whether our relative output size is specified in the arguments.
141 fReconstructor = new AliTRDReconstructor();
142 HLTDebug("TRDReconstructor at 0x%x", fReconstructor);
144 TString configuration="";
146 for (int i=0; i<argc && iResult>=0; i++) {
148 if (!configuration.IsNull()) configuration+=" ";
149 configuration+=argument;
152 if (!configuration.IsNull()) {
153 iResult=Configure(configuration.Data());
155 iResult=Reconfigure(NULL, NULL);
159 HLTFatal("Clusterizer was not initialized!");
163 fMemReader = new AliRawReaderMemory;
164 fClusterizer->SetReconstructor(fReconstructor);
165 fClusterizer->SetUseLabels(kFALSE);
167 if(fReconstructor->IsProcessingTracklets())
168 fOutputConst = fClusterizer->GetTrMemBlockSize();
172 int AliHLTTRDClusterizerComponent::DoDeinit()
174 // Deinitialization of the component
180 fReconstructor->SetClusters(0x0);
181 delete fReconstructor;
182 fReconstructor = 0x0;
187 HLTDebug("Deleting fRecoParam");
193 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
194 const AliHLTComponentBlockData* blocks,
195 AliHLTComponent_TriggerData& /*trigData*/,
196 AliHLTUInt8_t* outputPtr,
197 AliHLTUInt32_t& size,
198 vector<AliHLTComponent_BlockData>& outputBlocks )
202 if (evtData.fEventID == 1)
203 CALLGRIND_START_INSTRUMENTATION;
205 HLTDebug( "NofBlocks %i", evtData.fBlockCnt );
207 AliHLTUInt32_t totalSize = 0, offset = 0;
209 //implement a usage of the following
210 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
211 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
212 // void *triggerData = trigData.fData;
213 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
215 // Loop over all input blocks in the event
216 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
217 for ( UInt_t iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
219 const AliHLTComponentBlockData &block = blocks[iBlock];
220 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
221 // which is depreciated - we use HLT global defs instead
222 // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
223 AliHLTComponentDataType inputDataType = block.fDataType;
224 if ( inputDataType != expectedDataType)
226 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - required datatype: %s; Skipping",
227 iBlock, evtData.fBlockCnt,
228 evtData.fEventID, evtData.fEventID,
229 DataType2Text(inputDataType).c_str(),
230 DataType2Text(expectedDataType).c_str());
235 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
236 iBlock, evtData.fBlockCnt,
237 evtData.fEventID, evtData.fEventID,
238 DataType2Text(inputDataType).c_str(),
242 // fMemReader->Reset();
243 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
245 AliHLTUInt32_t spec = block.fSpecification;
249 for ( Int_t ii = 1; ii < 19 ; ii++ ) {
257 fMemReader->SetEquipmentID( id );
259 fClusterizer->SetMemBlock(outputPtr+offset);
260 Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
261 if (iclustered == kTRUE)
263 HLTDebug( "Clustered successfully");
267 HLTError("Clustering ERROR");
271 // put the tree into output
274 AliHLTUInt32_t addedSize;
275 if(fReconstructor->IsProcessingTracklets()){
276 addedSize = fClusterizer->GetAddedTrSize();
277 totalSize += fClusterizer->GetTrMemBlockSize(); //if IsProcessingTracklets() is enabled we always reserve a data block of size GetTrMemBlockSize() for the tracklets
279 // Using low-level interface
280 // with interface classes
281 if ( totalSize > size )
283 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
289 AliHLTComponentBlockData bd;
292 bd.fSize = addedSize;
293 //bd.fSpecification = spec;
294 bd.fSpecification = gkAliEventTypeData;
295 bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
296 outputBlocks.push_back( bd );
297 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);
302 addedSize = fClusterizer->GetAddedClSize();
304 // Using low-level interface
305 // with interface classes
306 totalSize += addedSize;
307 if ( totalSize > size )
309 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
315 AliHLTComponentBlockData bd;
318 bd.fSize = addedSize;
319 //bd.fSpecification = spec;
320 bd.fSpecification = gkAliEventTypeData;
321 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
322 outputBlocks.push_back( bd );
323 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);
328 HLTWarning("Array of clusters is empty!");
330 fReconstructor->SetClusters(0x0);
333 HLTDebug("Event is done. size written to the output is %i", size);
337 void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
339 AliTRDcluster* cluster=0x0;
341 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
342 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
343 HLTDebug("cluster[%i]",i);
344 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
345 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
346 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
351 int AliHLTTRDClusterizerComponent::Configure(const char* arguments){
353 if (!arguments) return iResult;
355 TString allArgs=arguments;
359 TObjArray* pTokens=allArgs.Tokenize(" ");
361 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
362 argument=((TObjString*)pTokens->At(i))->GetString();
363 if (argument.IsNull()) continue;
365 if (argument.CompareTo("-OFFLINE")==0) {
366 fOfflineMode = kTRUE;
367 HLTFatal("You have selected OFFLINE mode!");
368 HLTFatal("This program shall NOT run on the HLT cluster like this!");
371 else if (argument.CompareTo("output_percentage")==0) {
372 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
373 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
374 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
377 else if (argument.CompareTo("-geometry")==0) {
378 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
379 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
380 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
383 if (argument.CompareTo("-lowflux")==0) {
385 HLTInfo("Low flux reconstruction selected");
388 if (argument.CompareTo("-highflux")==0) {
390 HLTInfo("High flux reconstruction selected");
393 if (argument.CompareTo("-cosmics")==0) {
395 HLTInfo("Cosmics reconstruction selected");
398 if (argument.CompareTo("-simulation")==0) {
400 HLTInfo("Awaiting simulated data");
403 if (argument.CompareTo("-experiment")==0) {
405 HLTInfo("Awaiting real data");
408 if (argument.CompareTo("-processTracklets")==0) {
409 fProcessTracklets = kTRUE;
410 HLTInfo("Processing L1 Tracklets");
413 if (argument.CompareTo("-noZS")==0) {
414 fOutputPercentage = 100;
415 HLTInfo("Awaiting non zero surpressed data");
418 if (argument.CompareTo("-faststreamer")==0) {
419 fHLTstreamer = kTRUE;
420 HLTInfo("Useing fast raw streamer");
423 else if (argument.CompareTo("-rawver")==0) {
424 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
425 HLTInfo("Raw data version is: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
426 fRawDataVersion=((TObjString*)pTokens->At(i))->GetString().Atoi();
429 else if (argument.CompareTo("-yPosMethod")==0) {
430 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
431 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
432 if (toCompareTo.CompareTo("COG")==0){
433 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
436 else if (toCompareTo.CompareTo("LUT")==0){
437 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
440 else if (toCompareTo.CompareTo("Gauss")==0){
441 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
445 HLTError("unknown argument for yPosMethod: %s", toCompareTo.Data());
453 HLTError("unknown argument: %s", argument.Data());
461 HLTError("missing parameter for argument %s", argument.Data());
465 if(fOfflineMode)SetOfflineParams();
471 int AliHLTTRDClusterizerComponent::SetParams()
474 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
475 HLTError("DefaultStorage is not Set in CDBManager");
478 if(AliCDBManager::Instance()->GetRun()<0){
479 HLTError("Run Number is not set in CDBManager");
482 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
484 if(!AliGeomManager::GetGeometry()){
485 if(!TFile::Open(fgeometryFileName.Data())){
486 HLTInfo("Loading standard geometry file");
487 AliGeomManager::LoadGeometry();
489 HLTWarning("Loading NON-standard geometry file");
490 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
492 if(!AliGeomManager::GetGeometry()){
493 HLTError("Cannot load geometry");
498 HLTInfo("Geometry Already Loaded!");
501 TString recoOptions="hlt,!cw,sl_cf_0";
503 switch(fRecoDataType){
504 case 0: recoOptions += ",tc"; break;
505 case 1: recoOptions += ",!tc"; break;
508 case 0: recoOptions += ",!gs,!lut"; break;
509 case 1: recoOptions += ",!gs,lut"; break;
510 case 2: recoOptions += ",gs,!lut"; break;
512 if(fProcessTracklets) recoOptions += ",tp";
513 else recoOptions += ",!tp";
516 if (fRecoParamType == 0)
518 HLTDebug("Low flux params init.");
519 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
522 if (fRecoParamType == 1)
524 HLTDebug("High flux params init.");
525 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
528 if (fRecoParamType == 2)
530 HLTDebug("Cosmic Test params init.");
531 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
536 HLTError("No reco params initialized. Sniffing big trouble!");
540 fReconstructor->SetRecoParam(fRecoParam);
541 fReconstructor->SetStreamLevel(0, AliTRDReconstructor::kClusterizer);
543 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
544 fReconstructor->SetOption(recoOptions.Data());
546 if (fRecoDataType < 0 || fRecoDataType > 1)
548 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
552 if (fRecoDataType == 0)
554 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
555 HLTDebug("Data type expected is SIMULATION!");
558 if (fRecoDataType == 1)
560 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
561 HLTDebug("Data type expected is EXPERIMENT!");
566 AliTRDrawStreamBase::SetRawStreamVersion("FAST");
567 HLTDebug("fast rawstreamer used");
571 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
572 HLTDebug("TRDClusterizer at 0x%x", fClusterizer);
575 fClusterizer->SetRawVersion(fRawDataVersion);
580 void AliHLTTRDClusterizerComponent::SetOfflineParams(){
581 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
582 HLTFatal("You are resetting the Default Storage of the CDBManager!");
583 HLTFatal("Let's hope that this program is NOT running on the HLT cluster!");
584 //AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
586 HLTError("DefaultStorage was already set!");
588 if(AliCDBManager::Instance()->GetRun()<0){
589 HLTFatal("You are resetting the CDB run number to 0!");
590 HLTFatal("Let's hope that this program is NOT running on the HLT cluster!");
591 //AliCDBManager::Instance()->SetRun(0);
593 HLTError("Run Number was already set!");
597 int AliHLTTRDClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
599 // see header file for class documentation
602 const char* path="HLT/ConfigTRD/ClusterizerComponent";
603 const char* defaultNotify="";
606 defaultNotify=" (default)";
609 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
610 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
612 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
614 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
615 iResult=Configure(pString->GetString().Data());
617 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
620 HLTError("cannot fetch object \"%s\" from CDB", path);