]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TRD/AliHLTTRDCalibrationComponent.cxx
initial HLT-TRD commit
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDCalibrationComponent.cxx
CommitLineData
0af7cb2e 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
9 * *
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 **************************************************************************/
18
19/** @file AliHLTTRDCalibrationComponent.cxx
20 @author Timm Steinbeck, Matthias Richter
21 @date
22 @brief A TRDCalibration processing component for the HLT. */
23
24#if __GNUC__ >= 3
25using namespace std;
26#endif
27
28#include "AliHLTTRDCalibra.h"
29#include "AliHLTTRDCalibrationComponent.h"
30#include "AliHLTTRDDefinitions.h"
31
32#include "AliCDBManager.h"
33#include "AliTRDtriggerHLT.h"
34#include "AliTRDtrigParam.h"
35#include "AliRawReaderMemory.h"
36
37#include "TTree.h"
38#include "TBranch.h"
39
40#include <cstdlib>
41#include <cerrno>
42#include <string>
43
44// this is a global object used for automatic component registration, do not use this
45AliHLTTRDCalibrationComponent gAliHLTTRDCalibrationComponent;
46
47ClassImp(AliHLTTRDCalibrationComponent)
48
49AliHLTTRDCalibrationComponent::AliHLTTRDCalibrationComponent()
50{
51 fMCMtrigger = 0;
52
53 fOutputPercentage = 100; // By default we copy to the output exactly what we got as input
54
55 fTriggerParDebugLevel = 0;
56 fLTUpTcut = 2.3; // GeV/c
57 fBField = 0.5; //TESLA
58
59
60 fStrorageDBpath = "local://$ALICE_ROOT";
61}
62
63AliHLTTRDCalibrationComponent::~AliHLTTRDCalibrationComponent()
64{
65}
66
67const char* AliHLTTRDCalibrationComponent::GetComponentID()
68{
69 return "TRDCalibration"; // The ID of this component
70}
71
72void AliHLTTRDCalibrationComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
73{
74 list.clear(); // We do not have any requirements for our input data type(s).
75 list.push_back( AliHLTTRDDefinitions::gkDDLRawDataType );
76}
77
78AliHLTComponent_DataType AliHLTTRDCalibrationComponent::GetOutputDataType()
79{
80 return AliHLTTRDDefinitions::gkClusterDataType;
81}
82
83void AliHLTTRDCalibrationComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
84{
85 constBase = 0;
86 inputMultiplier = ((double)fOutputPercentage)/100.0;
87}
88
89
90// Spawn function, return new instance of this class
91AliHLTComponent* AliHLTTRDCalibrationComponent::Spawn()
92{
93 return new AliHLTTRDCalibrationComponent;
94};
95
96int AliHLTTRDCalibrationComponent::DoInit( int argc, const char** argv )
97{
98 // perform initialization. We check whether our relative output size is specified in the arguments.
99 fOutputPercentage = 100;
100 int i = 0;
101 char* cpErr;
102 while ( i < argc )
103 {
104 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
105 if ( !strcmp( argv[i], "output_percentage" ) )
106 {
107 if ( i+1>=argc )
108 {
109 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing output_percentage parameter");
110 return ENOTSUP;
111 }
112 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
113 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
114 if ( *cpErr )
115 {
116 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
117 return EINVAL;
118 }
119 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
120 i += 2;
121 continue;
122 }
123
124 if ( strcmp( argv[i], "-cdb" ) == 0)
125 {
126 if ( i+1 >= argc )
127 {
128 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing -cdb argument");
129 return ENOTSUP;
130 }
131 fStrorageDBpath = argv[i+1];
132 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );
133 i += 2;
134 continue;
135 }
136
137 if ( strcmp( argv[i], "-dbg" ) == 0)
138 {
139 if ( i+1 >= argc )
140 {
141 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing -dbg argument");
142 return ENOTSUP;
143 }
144 fTriggerParDebugLevel = strtol( argv[i+1], &cpErr, 10 );
145 if ( *cpErr )
146 {
147 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Wrong Argument", "Cannot convert -dbg parameter '%s'", argv[i+1] );
148 return EINVAL;
149 }
150 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "Trigger Params", "Debug Level set to %d ", fTriggerParDebugLevel);
151 i += 2;
152 continue;
153 }
154
155 if ( strcmp( argv[i], "-ptcut" ) == 0)
156 {
157 if ( i+1 >= argc )
158 {
159 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing -ptcut argument");
160 return ENOTSUP;
161 }
162 fLTUpTcut = strtod( argv[i+1], &cpErr);
163 if ( *cpErr )
164 {
165 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Wrong Argument", "Cannot convert -ptcut parameter '%s'", argv[i+1] );
166 return EINVAL;
167 }
168 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "Trigger Params", "Pt Cut set to %d GeV/c", fLTUpTcut);
169 i += 2;
170 continue;
171 }
172
173 if ( strcmp( argv[i], "-field" ) == 0)
174 {
175 if ( i+1 >= argc )
176 {
177 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing -field argument");
178 return ENOTSUP;
179 }
180 fBField = strtod( argv[i+1], &cpErr);
181 if ( *cpErr )
182 {
183 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Wrong Argument", "Cannot convert -field parameter '%s'", argv[i+1] );
184 return EINVAL;
185 }
186 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "Trigger Params", "Field set to %d ", fBField);
187 i += 2;
188 continue;
189 }
190
191 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
192 return EINVAL;
193 }
194
195 cdb = AliCDBManager::Instance();
196 if (!cdb)
197 {
198 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get CDB instance", "cdb 0x%x", cdb);
199 }
200 else
201 {
202 cdb->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
203 cdb->SetDefaultStorage(fStrorageDBpath.c_str());
204 Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "CDB instance", "cdb 0x%x", cdb);
205 }
206
207 calibra = AliHLTTRDCalibra::Instance();
208 if (!calibra)
209 {
210 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get Calibra instance", "calibra 0x%x", calibra);
211 }
212 else
213 {
214 // init the histograms for output!
215 calibra->SetOn();
216 calibra->Init2Dhistos();
217 Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "Calibra instance", "calibra 0x%x", calibra);
218 }
219
220 rmem = new AliRawReaderMemory;
221
222 fMCMtriggerParams = new AliTRDtrigParam("TRDMCMtriggerParams", "TRDMCMtriggerParams");
223 fMCMtriggerParams->SetDebugLevel(fTriggerParDebugLevel);
224 fMCMtriggerParams->SetLtuPtCut(fLTUpTcut);
225 fMCMtriggerParams->SetField(fBField);
226
227 fMCMtrigger = new AliTRDtriggerHLT("TRDMCMtrigger", "TRDMCMtrigger");
228 fMCMtrigger->SetParameter(fMCMtriggerParams);
229 fMCMtrigger->Init();
230
231 return 0;
232}
233
234int AliHLTTRDCalibrationComponent::DoDeinit()
235{
236 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destruct", "start");
237
238 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "delete", "rmem");
239 delete rmem;
240 rmem = 0;
241
242 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "delete", "fMCMtriggerParams");
243 delete fMCMtriggerParams;
244 fMCMtriggerParams = 0;
245
246 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "delete", "fMCMtrigger");
247 delete fMCMtrigger;
248 fMCMtrigger = 0;
249
250 if (calibra)
251 {
252 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "calibra");
253 calibra->Destroy();
254 calibra = 0;
255 }
256
257 if (cdb)
258 {
259 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "cdb");
260 cdb->Destroy();
261 cdb = 0;
262 }
263
264 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destruct", "all done!");
265 return 0;
266}
267
268int AliHLTTRDCalibrationComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks,
269 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
270 AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
271{
272 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
273 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
274 // Process an event
275 unsigned long totalSize = 0;
276 AliHLTUInt32_t fDblock_Specification = 0;
277
278 // Loop over all input blocks in the event
279 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
280 {
281 char tmp1[14], tmp2[14];
282 DataType2Text( blocks[i].fDataType, tmp1 );
283 DataType2Text( AliHLTTRDDefinitions::gkDDLRawDataType, tmp2 );
284 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoEvent", "Event received",
285 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
286 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
287
288 if ( blocks[i].fDataType != AliHLTTRDDefinitions::gkDDLRawDataType )
289 {
290 Logging (kHLTLogError, "HLT::TRDCalibration::DoEvent", "COMPARE FAILED", "type=%d is type=%d",
291 blocks[i].fDataType, AliHLTTRDDefinitions::gkDDLRawDataType);
292 continue;
293 }
294 fDblock_Specification = blocks[i].fSpecification;
295 unsigned long blockSize = blocks[i].fSize;
296 totalSize += blockSize;
297 }
298
299 void *memBufIn = calloc(totalSize, 1);
300 AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)memBufIn;
301 if (memBufIn == NULL)
302 {
303 Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "MEMORY", "Unable to allocate %lu bytes", totalSize);
304 return -1;
305 }
306
307 // Make the memory continuous
308 unsigned long copied = 0;
309 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
310 {
311 if ( blocks[i].fDataType != AliHLTTRDDefinitions::gkDDLRawDataType )
312 continue;
313
314 void *pos = (void*)(pBuf + copied);
315 void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize);
316 if (copyret < 0)
317 {
318 Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "MEMORY", "Unable to copy %lu bytes", blocks[i].fSize);
319 return -1;
320 }
321 copied += blocks[i].fSize;
322 }
323
324 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "COPY STATS", "total=%lu copied=%lu", totalSize, copied);
325
326 rmem->Reset();
327 rmem->SetMemory((UChar_t*)memBufIn, totalSize);
328 //rmem->Reset();
329 Bool_t ihead = rmem->ReadHeader();
330 if (ihead == kTRUE)
331 {
332 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "HEADER", "Header read successfully");
333 }
334 else
335 {
336 Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "HEADER", "Header read ERROR");
337 //return -1; -- not FATAL
338 }
339
340 fMCMtrigger->ResetTree();
341 Bool_t ireadD = fMCMtrigger->ReadDigits(rmem);
342 if (ireadD == kTRUE)
343 {
344 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "DIGITS", "Digits read successfully");
345 }
346 else
347 {
348 Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "DIGITS", "Digits read ERROR");
349 return -1;
350 }
351
352 Bool_t iclustered = fMCMtrigger->MakeTracklets();
353 if (iclustered == kTRUE)
354 {
355 Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "TRACKLETS", "Tracklets created successfully");
356 }
357 else
358 {
359 Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "TRACKLETS", "Tracklets creation ERROR");
360 return -1;
361 }
362
363 free(memBufIn);
364
365 UInt_t memBufOutSize = 0;
366
367 // put the tree into output blocks of TObjArrays
368 TTree *fcTree = fMCMtrigger->GetTrackletTree();
369 TList *lt = (TList*)fcTree->GetListOfBranches();
370 TIter it(lt);
371 it.Reset();
372 TBranch *tb = 0;
373 while ((tb = (TBranch*)it.Next()) != 0)
374 {
375 TObjArray *detTracklets = 0;
376 tb->SetAddress(&detTracklets);
377 for (Int_t icb = 0; icb < tb->GetEntries(); icb++)
378 {
379 tb->GetEntry(icb);
380 PushBack(detTracklets, AliHLTTRDDefinitions::gkMCMtrackletDataType, fDblock_Specification);
381 }
382 }
383
384 // add the histograms...
385 //gkMCMCalibrationDataType
386
387 //AliHLTTRDCalibra *calibra = AliHLTTRDCalibra::Instance();
388 if (!calibra)
389 {
390 Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Calibra not valid");
391 }
392 else
393 {
394 Logging( kHLTLogDebug, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Here we should put the histos...");
395// // TH2I *GetCH2d();
396// TH2I *chtmp = calibra->GetCH2d();
397// if (chtmp)
398// PushBack(chtmp, AliHLTTRDDefinitions::gkMCMcalibrationDataType, fDblock_Specification);
399// else
400// Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Could not calibra->GetCH2d()");
401// // TProfile2D *GetPH2d();
402// TProfile2D *phtmp = calibra->GetPH2d();
403// if (phtmp)
404// PushBack(phtmp, AliHLTTRDDefinitions::gkMCMcalibrationDataType, fDblock_Specification);
405// else
406// Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Could not calibra->GetPH2d()");
407// // TProfile2D *GetPRF2d();
408// TProfile2D *prf = calibra->GetPRF2d();
409// if (prf)
410// PushBack(prf, AliHLTTRDDefinitions::gkMCMcalibrationDataType, fDblock_Specification);
411// else
412// Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Could not calibra->GetPRF2d()");
413 }
414
415 return 0;
416}