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 AliHLTTRDCalibrationComponent.cxx
20 @author Timm Steinbeck, Matthias Richter
22 @brief A TRDCalibration processing component for the HLT. */
28 #include "AliHLTTRDCalibra.h"
29 #include "AliHLTTRDCalibrationComponent.h"
30 #include "AliHLTTRDDefinitions.h"
32 #include "AliCDBManager.h"
33 #include "AliTRDtriggerHLT.h"
34 #include "AliTRDtrigParam.h"
35 #include "AliRawReaderMemory.h"
44 // this is a global object used for automatic component registration, do not use this
45 AliHLTTRDCalibrationComponent gAliHLTTRDCalibrationComponent;
47 ClassImp(AliHLTTRDCalibrationComponent)
49 AliHLTTRDCalibrationComponent::AliHLTTRDCalibrationComponent()
56 fOutputPercentage = 100; // By default we copy to the output exactly what we got as input
58 fTriggerParDebugLevel = 0;
59 fLTUpTcut = 2.3; // GeV/c
60 fBField = 0.5; //TESLA
63 fStrorageDBpath = "local://$ALICE_ROOT";
66 AliHLTTRDCalibrationComponent::~AliHLTTRDCalibrationComponent()
69 // default decontructor
73 const char* AliHLTTRDCalibrationComponent::GetComponentID()
76 // return component id
78 return "TRDCalibration"; // The ID of this component
81 void AliHLTTRDCalibrationComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
84 // insert input data type
86 list.clear(); // We do not have any requirements for our input data type(s).
87 list.push_back( AliHLTTRDDefinitions::fgkDDLRawDataType );
90 AliHLTComponent_DataType AliHLTTRDCalibrationComponent::GetOutputDataType()
93 // get the output data type
95 return AliHLTTRDDefinitions::fgkClusterDataType;
98 void AliHLTTRDCalibrationComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
101 // get the ouput data size
104 inputMultiplier = ((double)fOutputPercentage)/100.0;
108 // Spawn function, return new instance of this class
109 AliHLTComponent* AliHLTTRDCalibrationComponent::Spawn()
112 // spawn implementation
114 return new AliHLTTRDCalibrationComponent;
117 int AliHLTTRDCalibrationComponent::DoInit( int argc, const char** argv )
120 // perform initialization. We check whether our relative output size is specified in the arguments.
122 fOutputPercentage = 100;
127 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
128 if ( !strcmp( argv[i], "output_percentage" ) )
132 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing output_percentage parameter");
135 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
136 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
139 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
142 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
147 if ( strcmp( argv[i], "-cdb" ) == 0)
151 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing -cdb argument");
154 fStrorageDBpath = argv[i+1];
155 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );
160 if ( strcmp( argv[i], "-dbg" ) == 0)
164 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing -dbg argument");
167 fTriggerParDebugLevel = strtol( argv[i+1], &cpErr, 10 );
170 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Wrong Argument", "Cannot convert -dbg parameter '%s'", argv[i+1] );
173 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "Trigger Params", "Debug Level set to %d ", fTriggerParDebugLevel);
178 if ( strcmp( argv[i], "-ptcut" ) == 0)
182 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing -ptcut argument");
185 fLTUpTcut = strtod( argv[i+1], &cpErr);
188 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Wrong Argument", "Cannot convert -ptcut parameter '%s'", argv[i+1] );
191 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "Trigger Params", "Pt Cut set to %d GeV/c", fLTUpTcut);
196 if ( strcmp( argv[i], "-field" ) == 0)
200 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing -field argument");
203 fBField = strtod( argv[i+1], &cpErr);
206 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Wrong Argument", "Cannot convert -field parameter '%s'", argv[i+1] );
209 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "Trigger Params", "Field set to %d ", fBField);
214 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
218 fCDB = AliCDBManager::Instance();
221 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get CDB instance", "fCDB 0x%x", fCDB);
225 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
226 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
227 Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "CDB instance", "fCDB 0x%x", fCDB);
230 fCalibra = AliHLTTRDCalibra::Instance();
233 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get Calibra instance", "calibra 0x%x", fCalibra);
237 // init the histograms for output!
239 fCalibra->Init2Dhistos();
240 Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "Calibra instance", "calibra 0x%x", fCalibra);
243 fRmem = new AliRawReaderMemory;
245 fMCMtriggerParams = new AliTRDtrigParam("TRDMCMtriggerParams", "TRDMCMtriggerParams");
246 fMCMtriggerParams->SetDebugLevel(fTriggerParDebugLevel);
247 fMCMtriggerParams->SetLtuPtCut(fLTUpTcut);
248 fMCMtriggerParams->SetField(fBField);
250 fMCMtrigger = new AliTRDtriggerHLT("TRDMCMtrigger", "TRDMCMtrigger");
251 fMCMtrigger->SetParameter(fMCMtriggerParams);
257 int AliHLTTRDCalibrationComponent::DoDeinit()
262 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destruct", "start");
264 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "delete", "fRmem");
268 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "delete", "fMCMtriggerParams");
269 delete fMCMtriggerParams;
270 fMCMtriggerParams = 0;
272 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "delete", "fMCMtrigger");
278 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "fCalibra");
285 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "fCDB");
290 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destruct", "all done!");
294 int AliHLTTRDCalibrationComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks,
295 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
296 AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
301 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
302 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
304 unsigned long totalSize = 0;
305 AliHLTUInt32_t fDblockSpecification = 0;
307 // Loop over all input blocks in the event
308 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
310 char tmp1[14], tmp2[14];
311 DataType2Text( blocks[i].fDataType, tmp1 );
312 DataType2Text( AliHLTTRDDefinitions::fgkDDLRawDataType, tmp2 );
313 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoEvent", "Event received",
314 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
315 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
317 if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType )
319 Logging (kHLTLogError, "HLT::TRDCalibration::DoEvent", "COMPARE FAILED", "type=%d is type=%d",
320 blocks[i].fDataType, AliHLTTRDDefinitions::fgkDDLRawDataType);
323 fDblockSpecification = blocks[i].fSpecification;
324 unsigned long blockSize = blocks[i].fSize;
325 totalSize += blockSize;
328 void *memBufIn = calloc(totalSize, 1);
329 AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)memBufIn;
330 if (memBufIn == NULL)
332 Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "MEMORY", "Unable to allocate %lu bytes", totalSize);
336 // Make the memory continuous
337 unsigned long copied = 0;
338 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
340 if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType )
343 void *pos = (void*)(pBuf + copied);
344 void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize);
347 Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "MEMORY", "Unable to copy %lu bytes", blocks[i].fSize);
350 copied += blocks[i].fSize;
353 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "COPY STATS", "total=%lu copied=%lu", totalSize, copied);
356 fRmem->SetMemory((UChar_t*)memBufIn, totalSize);
358 Bool_t ihead = fRmem->ReadHeader();
361 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "HEADER", "Header read successfully");
365 Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "HEADER", "Header read ERROR");
366 //return -1; -- not FATAL
369 fMCMtrigger->ResetTree();
370 Bool_t ireadD = fMCMtrigger->ReadDigits(fRmem);
373 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "DIGITS", "Digits read successfully");
377 Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "DIGITS", "Digits read ERROR");
381 Bool_t iclustered = fMCMtrigger->MakeTracklets();
382 if (iclustered == kTRUE)
384 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "TRACKLETS", "Tracklets created successfully");
388 Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "TRACKLETS", "Tracklets creation ERROR");
394 UInt_t memBufOutSize = 0;
396 // put the tree into output blocks of TObjArrays
397 TTree *fcTree = fMCMtrigger->GetTrackletTree();
398 TList *lt = (TList*)fcTree->GetListOfBranches();
402 while ((tb = (TBranch*)it.Next()) != 0)
404 TObjArray *detTracklets = 0;
405 tb->SetAddress(&detTracklets);
406 for (Int_t icb = 0; icb < tb->GetEntries(); icb++)
409 PushBack(detTracklets, AliHLTTRDDefinitions::fgkMCMtrackletDataType, fDblockSpecification);
413 // add the histograms...
414 //gkMCMCalibrationDataType
416 //AliHLTTRDCalibra *calibra = AliHLTTRDCalibra::Instance();
419 Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Calibra not valid");
423 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Here we should put the histos...");
424 // // TH2I *GetCH2d();
425 // TH2I *chtmp = fCalibra->GetCH2d();
427 // PushBack(chtmp, AliHLTTRDDefinitions::fgkMCMcalibrationDataType, fDblockSpecification);
429 // Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Could not fCalibra->GetCH2d()");
430 // // TProfile2D *GetPH2d();
431 // TProfile2D *phtmp = fCalibra->GetPH2d();
433 // PushBack(phtmp, AliHLTTRDDefinitions::fgkMCMcalibrationDataType, fDblockSpecification);
435 // Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Could not fCalibra->GetPH2d()");
436 // // TProfile2D *GetPRF2d();
437 // TProfile2D *prf = fCalibra->GetPRF2d();
439 // PushBack(prf, AliHLTTRDDefinitions::fgkMCMcalibrationDataType, fDblockSpecification);
441 // Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Could not fCalibra->GetPRF2d()");