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),
84 // Default constructor
88 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
91 // Work is Done in DoDeInit()
95 const char* AliHLTTRDClusterizerComponent::GetComponentID()
97 // Return the component ID const char *
98 return "TRDClusterizer"; // The ID of this component
101 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
103 // Get the list of input data
104 list.clear(); // We do not have any requirements for our input data type(s).
105 list.push_back( (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) );
108 AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
110 // Get the output data type
111 return kAliHLTMultipleDataType;
114 int AliHLTTRDClusterizerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
116 // Get the output data type
118 tgtList.push_back(AliHLTTRDDefinitions::fgkClusterDataType);
119 tgtList.push_back(AliHLTTRDDefinitions::fgkMCMtrackletDataType);
120 return tgtList.size();
124 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
126 // Get the output data size
127 constBase = fOutputConst;
128 inputMultiplier = ((double)fOutputPercentage)/100.0;
131 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
133 // Spawn function, return new instance of this class
134 return new AliHLTTRDClusterizerComponent;
137 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
139 // perform initialization. We check whether our relative output size is specified in the arguments.
142 fReconstructor = new AliTRDReconstructor();
143 HLTDebug("TRDReconstructor at 0x%x", fReconstructor);
145 TString configuration="";
147 for (int i=0; i<argc && iResult>=0; i++) {
149 if (!configuration.IsNull()) configuration+=" ";
150 configuration+=argument;
153 if (!configuration.IsNull()) {
154 iResult=Configure(configuration.Data());
156 iResult=Reconfigure(NULL, NULL);
160 HLTFatal("Clusterizer was not initialized!");
164 fMemReader = new AliRawReaderMemory;
165 fClusterizer->SetReconstructor(fReconstructor);
166 fClusterizer->SetUseLabels(kFALSE);
168 if(fReconstructor->IsProcessingTracklets())
169 fOutputConst = fClusterizer->GetTrMemBlockSize();
173 int AliHLTTRDClusterizerComponent::DoDeinit()
175 // Deinitialization of the component
181 fReconstructor->SetClusters(0x0);
182 delete fReconstructor;
183 fReconstructor = 0x0;
188 HLTDebug("Deleting fRecoParam");
194 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
195 const AliHLTComponentBlockData* blocks,
196 AliHLTComponent_TriggerData& /*trigData*/,
197 AliHLTUInt8_t* outputPtr,
198 AliHLTUInt32_t& size,
199 vector<AliHLTComponent_BlockData>& outputBlocks )
203 if (evtData.fEventID == 1)
204 CALLGRIND_START_INSTRUMENTATION;
206 HLTDebug( "NofBlocks %i", evtData.fBlockCnt );
208 AliHLTUInt32_t totalSize = 0, offset = 0;
210 //implement a usage of the following
211 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
212 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
213 // void *triggerData = trigData.fData;
214 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
216 // Loop over all input blocks in the event
217 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
218 for ( UInt_t iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
220 const AliHLTComponentBlockData &block = blocks[iBlock];
221 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
222 // which is depreciated - we use HLT global defs instead
223 // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
224 AliHLTComponentDataType inputDataType = block.fDataType;
225 if ( inputDataType != expectedDataType)
227 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - required datatype: %s; Skipping",
228 iBlock, evtData.fBlockCnt,
229 evtData.fEventID, evtData.fEventID,
230 DataType2Text(inputDataType).c_str(),
231 DataType2Text(expectedDataType).c_str());
236 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
237 iBlock, evtData.fBlockCnt,
238 evtData.fEventID, evtData.fEventID,
239 DataType2Text(inputDataType).c_str(),
243 // fMemReader->Reset();
244 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
246 AliHLTUInt32_t spec = block.fSpecification;
250 for ( Int_t ii = 0; ii < 18 ; ii++ ) {
258 fMemReader->SetEquipmentID( id );
260 fClusterizer->SetMemBlock(outputPtr+offset);
261 Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
262 if (iclustered == kTRUE)
264 HLTDebug( "Clustered successfully");
268 HLTError("Clustering ERROR");
272 // put the tree into output
275 AliHLTUInt32_t addedSize;
276 if(fReconstructor->IsProcessingTracklets()){
277 addedSize = fClusterizer->GetAddedTrSize();
278 totalSize += fClusterizer->GetTrMemBlockSize(); //if IsProcessingTracklets() is enabled we always reserve a data block of size GetTrMemBlockSize() for the tracklets
280 // Using low-level interface
281 // with interface classes
282 if ( totalSize > size )
284 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
290 AliHLTComponentBlockData bd;
293 bd.fSize = addedSize;
294 //bd.fSpecification = spec;
295 bd.fSpecification = gkAliEventTypeData;
296 bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
297 outputBlocks.push_back( bd );
298 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);
303 addedSize = fClusterizer->GetAddedClSize();
305 // Using low-level interface
306 // with interface classes
307 totalSize += addedSize;
308 if ( totalSize > size )
310 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
316 AliHLTComponentBlockData bd;
319 bd.fSize = addedSize;
320 //bd.fSpecification = spec;
321 bd.fSpecification = gkAliEventTypeData;
322 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
323 outputBlocks.push_back( bd );
324 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);
329 HLTWarning("Array of clusters is empty!");
331 fReconstructor->SetClusters(0x0);
334 HLTDebug("Event is done. size written to the output is %i", size);
338 void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
340 AliTRDcluster* cluster=0x0;
342 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
343 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
344 HLTDebug("cluster[%i]",i);
345 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
346 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
347 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
352 int AliHLTTRDClusterizerComponent::Configure(const char* arguments){
354 if (!arguments) return iResult;
356 TString allArgs=arguments;
360 TObjArray* pTokens=allArgs.Tokenize(" ");
362 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
363 argument=((TObjString*)pTokens->At(i))->GetString();
364 if (argument.IsNull()) continue;
366 if (argument.CompareTo("-OFFLINE")==0) {
367 fOfflineMode = kTRUE;
368 HLTFatal("You have selected OFFLINE mode!");
369 HLTFatal("This program shall NOT run on the HLT cluster like this!");
372 else if (argument.CompareTo("output_percentage")==0) {
373 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
374 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
375 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
378 else if (argument.CompareTo("-geometry")==0) {
379 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
380 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
381 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
384 if (argument.CompareTo("-lowflux")==0) {
386 HLTInfo("Low flux reconstruction selected");
389 if (argument.CompareTo("-highflux")==0) {
391 HLTInfo("High flux reconstruction selected");
394 if (argument.CompareTo("-cosmics")==0) {
396 HLTInfo("Cosmics reconstruction selected");
399 if (argument.CompareTo("-simulation")==0) {
401 HLTInfo("Awaiting simulated data");
404 if (argument.CompareTo("-experiment")==0) {
406 HLTInfo("Awaiting real data");
409 if (argument.CompareTo("-processTracklets")==0) {
410 fProcessTracklets = kTRUE;
411 HLTInfo("Processing L1 Tracklets");
414 if (argument.CompareTo("-noZS")==0) {
415 fOutputPercentage = 100;
416 HLTInfo("Awaiting non zero surpressed data");
419 if (argument.CompareTo("-faststreamer")==0) {
420 fHLTstreamer = kTRUE;
421 HLTInfo("Useing fast raw streamer");
424 else if (argument.CompareTo("-rawver")==0) {
425 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
426 HLTInfo("Raw data version is: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
427 fRawDataVersion=((TObjString*)pTokens->At(i))->GetString().Atoi();
430 else if (argument.CompareTo("-yPosMethod")==0) {
431 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
432 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
433 if (toCompareTo.CompareTo("COG")==0){
434 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
437 else if (toCompareTo.CompareTo("LUT")==0){
438 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
441 else if (toCompareTo.CompareTo("Gauss")==0){
442 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
446 HLTError("unknown argument for yPosMethod: %s", toCompareTo.Data());
454 HLTError("unknown argument: %s", argument.Data());
462 HLTError("missing parameter for argument %s", argument.Data());
466 if(fOfflineMode)SetOfflineParams();
472 int AliHLTTRDClusterizerComponent::SetParams()
475 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
476 HLTError("DefaultStorage is not Set in CDBManager");
479 if(AliCDBManager::Instance()->GetRun()<0){
480 HLTError("Run Number is not set in CDBManager");
483 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
485 if(!AliGeomManager::GetGeometry()){
486 if(!TFile::Open(fgeometryFileName.Data())){
487 HLTInfo("Loading standard geometry file");
488 AliGeomManager::LoadGeometry();
490 HLTWarning("Loading NON-standard geometry file");
491 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
493 if(!AliGeomManager::GetGeometry()){
494 HLTError("Cannot load geometry");
499 HLTInfo("Geometry Already Loaded!");
502 TString recoOptions="hlt,!cw,sl_cf_0";
504 switch(fRecoDataType){
505 case 0: recoOptions += ",tc"; break;
506 case 1: recoOptions += ",!tc"; break;
509 case 0: recoOptions += ",!gs,!lut"; break;
510 case 1: recoOptions += ",!gs,lut"; break;
511 case 2: recoOptions += ",gs,!lut"; break;
513 if(fProcessTracklets) recoOptions += ",tp";
514 else recoOptions += ",!tp";
517 if (fRecoParamType == 0)
519 HLTDebug("Low flux params init.");
520 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
523 if (fRecoParamType == 1)
525 HLTDebug("High flux params init.");
526 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
529 if (fRecoParamType == 2)
531 HLTDebug("Cosmic Test params init.");
532 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
537 HLTError("No reco params initialized. Sniffing big trouble!");
541 fReconstructor->SetRecoParam(fRecoParam);
542 fReconstructor->SetStreamLevel(0, AliTRDReconstructor::kClusterizer);
544 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
545 fReconstructor->SetOption(recoOptions.Data());
547 if (fRecoDataType < 0 || fRecoDataType > 1)
549 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
553 if (fRecoDataType == 0)
555 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
556 HLTDebug("Data type expected is SIMULATION!");
559 if (fRecoDataType == 1)
561 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
562 HLTDebug("Data type expected is EXPERIMENT!");
567 AliTRDrawStreamBase::SetRawStreamVersion("FAST");
568 HLTDebug("fast rawstreamer used");
572 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
573 HLTDebug("TRDClusterizer at 0x%x", fClusterizer);
576 fClusterizer->SetRawVersion(fRawDataVersion);
581 void AliHLTTRDClusterizerComponent::SetOfflineParams(){
582 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
583 HLTFatal("You are resetting the Default Storage of the CDBManager!");
584 HLTFatal("Let's hope that this program is NOT running on the HLT cluster!");
585 //AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
587 HLTError("DefaultStorage was already set!");
589 if(AliCDBManager::Instance()->GetRun()<0){
590 HLTFatal("You are resetting the CDB run number to 0!");
591 HLTFatal("Let's hope that this program is NOT running on the HLT cluster!");
592 //AliCDBManager::Instance()->SetRun(0);
594 HLTError("Run Number was already set!");
598 int AliHLTTRDClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
600 // see header file for class documentation
603 const char* path="HLT/ConfigTRD/ClusterizerComponent";
604 const char* defaultNotify="";
607 defaultNotify=" (default)";
610 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
611 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
613 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
615 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
616 iResult=Configure(pString->GetString().Data());
618 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
621 HLTError("cannot fetch object \"%s\" from CDB", path);