]>
Commit | Line | Data |
---|---|---|
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 | |
25 | using 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 | |
45 | AliHLTTRDCalibrationComponent gAliHLTTRDCalibrationComponent; | |
46 | ||
47 | ClassImp(AliHLTTRDCalibrationComponent) | |
48 | ||
49 | AliHLTTRDCalibrationComponent::AliHLTTRDCalibrationComponent() | |
50 | { | |
efbd3157 | 51 | // |
52 | // default contructor | |
53 | // | |
0af7cb2e | 54 | fMCMtrigger = 0; |
55 | ||
56 | fOutputPercentage = 100; // By default we copy to the output exactly what we got as input | |
57 | ||
58 | fTriggerParDebugLevel = 0; | |
59 | fLTUpTcut = 2.3; // GeV/c | |
60 | fBField = 0.5; //TESLA | |
61 | ||
62 | ||
63 | fStrorageDBpath = "local://$ALICE_ROOT"; | |
64 | } | |
65 | ||
66 | AliHLTTRDCalibrationComponent::~AliHLTTRDCalibrationComponent() | |
67 | { | |
efbd3157 | 68 | // |
69 | // default decontructor | |
70 | // | |
0af7cb2e | 71 | } |
72 | ||
73 | const char* AliHLTTRDCalibrationComponent::GetComponentID() | |
74 | { | |
efbd3157 | 75 | // |
76 | // return component id | |
77 | // | |
0af7cb2e | 78 | return "TRDCalibration"; // The ID of this component |
79 | } | |
80 | ||
81 | void AliHLTTRDCalibrationComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list) | |
82 | { | |
efbd3157 | 83 | // |
84 | // insert input data type | |
85 | // | |
0af7cb2e | 86 | list.clear(); // We do not have any requirements for our input data type(s). |
efbd3157 | 87 | list.push_back( AliHLTTRDDefinitions::fgkDDLRawDataType ); |
0af7cb2e | 88 | } |
89 | ||
90 | AliHLTComponent_DataType AliHLTTRDCalibrationComponent::GetOutputDataType() | |
91 | { | |
efbd3157 | 92 | // |
93 | // get the output data type | |
94 | // | |
95 | return AliHLTTRDDefinitions::fgkClusterDataType; | |
0af7cb2e | 96 | } |
97 | ||
98 | void AliHLTTRDCalibrationComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
99 | { | |
efbd3157 | 100 | // |
101 | // get the ouput data size | |
102 | // | |
0af7cb2e | 103 | constBase = 0; |
104 | inputMultiplier = ((double)fOutputPercentage)/100.0; | |
105 | } | |
106 | ||
107 | ||
108 | // Spawn function, return new instance of this class | |
109 | AliHLTComponent* AliHLTTRDCalibrationComponent::Spawn() | |
110 | { | |
efbd3157 | 111 | // |
112 | // spawn implementation | |
113 | // | |
0af7cb2e | 114 | return new AliHLTTRDCalibrationComponent; |
115 | }; | |
116 | ||
117 | int AliHLTTRDCalibrationComponent::DoInit( int argc, const char** argv ) | |
118 | { | |
efbd3157 | 119 | // |
0af7cb2e | 120 | // perform initialization. We check whether our relative output size is specified in the arguments. |
efbd3157 | 121 | // |
0af7cb2e | 122 | fOutputPercentage = 100; |
123 | int i = 0; | |
124 | char* cpErr; | |
125 | while ( i < argc ) | |
126 | { | |
127 | Logging( kHLTLogDebug, "HLT::TRDCalibration::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] ); | |
128 | if ( !strcmp( argv[i], "output_percentage" ) ) | |
129 | { | |
130 | if ( i+1>=argc ) | |
131 | { | |
132 | Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing output_percentage parameter"); | |
133 | return ENOTSUP; | |
134 | } | |
135 | Logging( kHLTLogDebug, "HLT::TRDCalibration::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] ); | |
136 | fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 ); | |
137 | if ( *cpErr ) | |
138 | { | |
139 | Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] ); | |
140 | return EINVAL; | |
141 | } | |
142 | Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage ); | |
143 | i += 2; | |
144 | continue; | |
145 | } | |
146 | ||
147 | if ( strcmp( argv[i], "-cdb" ) == 0) | |
148 | { | |
149 | if ( i+1 >= argc ) | |
150 | { | |
151 | Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing -cdb argument"); | |
152 | return ENOTSUP; | |
153 | } | |
154 | fStrorageDBpath = argv[i+1]; | |
155 | Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() ); | |
156 | i += 2; | |
157 | continue; | |
158 | } | |
159 | ||
160 | if ( strcmp( argv[i], "-dbg" ) == 0) | |
161 | { | |
162 | if ( i+1 >= argc ) | |
163 | { | |
164 | Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing -dbg argument"); | |
165 | return ENOTSUP; | |
166 | } | |
167 | fTriggerParDebugLevel = strtol( argv[i+1], &cpErr, 10 ); | |
168 | if ( *cpErr ) | |
169 | { | |
170 | Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Wrong Argument", "Cannot convert -dbg parameter '%s'", argv[i+1] ); | |
171 | return EINVAL; | |
172 | } | |
173 | Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "Trigger Params", "Debug Level set to %d ", fTriggerParDebugLevel); | |
174 | i += 2; | |
175 | continue; | |
176 | } | |
177 | ||
178 | if ( strcmp( argv[i], "-ptcut" ) == 0) | |
179 | { | |
180 | if ( i+1 >= argc ) | |
181 | { | |
182 | Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing -ptcut argument"); | |
183 | return ENOTSUP; | |
184 | } | |
185 | fLTUpTcut = strtod( argv[i+1], &cpErr); | |
186 | if ( *cpErr ) | |
187 | { | |
188 | Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Wrong Argument", "Cannot convert -ptcut parameter '%s'", argv[i+1] ); | |
189 | return EINVAL; | |
190 | } | |
191 | Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "Trigger Params", "Pt Cut set to %d GeV/c", fLTUpTcut); | |
192 | i += 2; | |
193 | continue; | |
194 | } | |
195 | ||
196 | if ( strcmp( argv[i], "-field" ) == 0) | |
197 | { | |
198 | if ( i+1 >= argc ) | |
199 | { | |
200 | Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Missing Argument", "Missing -field argument"); | |
201 | return ENOTSUP; | |
202 | } | |
203 | fBField = strtod( argv[i+1], &cpErr); | |
204 | if ( *cpErr ) | |
205 | { | |
206 | Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Wrong Argument", "Cannot convert -field parameter '%s'", argv[i+1] ); | |
207 | return EINVAL; | |
208 | } | |
209 | Logging( kHLTLogInfo, "HLT::TRDCalibration::DoInit", "Trigger Params", "Field set to %d ", fBField); | |
210 | i += 2; | |
211 | continue; | |
212 | } | |
213 | ||
214 | Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] ); | |
215 | return EINVAL; | |
216 | } | |
217 | ||
efbd3157 | 218 | fCDB = AliCDBManager::Instance(); |
219 | if (!fCDB) | |
0af7cb2e | 220 | { |
efbd3157 | 221 | Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get CDB instance", "fCDB 0x%x", fCDB); |
0af7cb2e | 222 | } |
223 | else | |
224 | { | |
efbd3157 | 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); | |
0af7cb2e | 228 | } |
229 | ||
efbd3157 | 230 | fCalibra = AliHLTTRDCalibra::Instance(); |
231 | if (!fCalibra) | |
0af7cb2e | 232 | { |
efbd3157 | 233 | Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get Calibra instance", "calibra 0x%x", fCalibra); |
0af7cb2e | 234 | } |
235 | else | |
236 | { | |
237 | // init the histograms for output! | |
efbd3157 | 238 | fCalibra->SetOn(); |
239 | fCalibra->Init2Dhistos(); | |
240 | Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "Calibra instance", "calibra 0x%x", fCalibra); | |
0af7cb2e | 241 | } |
242 | ||
efbd3157 | 243 | fRmem = new AliRawReaderMemory; |
0af7cb2e | 244 | |
245 | fMCMtriggerParams = new AliTRDtrigParam("TRDMCMtriggerParams", "TRDMCMtriggerParams"); | |
246 | fMCMtriggerParams->SetDebugLevel(fTriggerParDebugLevel); | |
247 | fMCMtriggerParams->SetLtuPtCut(fLTUpTcut); | |
248 | fMCMtriggerParams->SetField(fBField); | |
249 | ||
250 | fMCMtrigger = new AliTRDtriggerHLT("TRDMCMtrigger", "TRDMCMtrigger"); | |
251 | fMCMtrigger->SetParameter(fMCMtriggerParams); | |
252 | fMCMtrigger->Init(); | |
253 | ||
254 | return 0; | |
255 | } | |
256 | ||
257 | int AliHLTTRDCalibrationComponent::DoDeinit() | |
258 | { | |
efbd3157 | 259 | // |
260 | // deinit component | |
261 | // | |
0af7cb2e | 262 | Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destruct", "start"); |
263 | ||
efbd3157 | 264 | Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "delete", "fRmem"); |
265 | delete fRmem; | |
266 | fRmem = 0; | |
0af7cb2e | 267 | |
268 | Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "delete", "fMCMtriggerParams"); | |
269 | delete fMCMtriggerParams; | |
270 | fMCMtriggerParams = 0; | |
271 | ||
272 | Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "delete", "fMCMtrigger"); | |
273 | delete fMCMtrigger; | |
274 | fMCMtrigger = 0; | |
275 | ||
efbd3157 | 276 | if (fCalibra) |
0af7cb2e | 277 | { |
efbd3157 | 278 | Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "fCalibra"); |
279 | fCalibra->Destroy(); | |
280 | fCalibra = 0; | |
0af7cb2e | 281 | } |
282 | ||
efbd3157 | 283 | if (fCDB) |
0af7cb2e | 284 | { |
efbd3157 | 285 | Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "fCDB"); |
286 | fCDB->Destroy(); | |
287 | fCDB = 0; | |
0af7cb2e | 288 | } |
289 | ||
290 | Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destruct", "all done!"); | |
291 | return 0; | |
292 | } | |
293 | ||
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 ) | |
297 | { | |
efbd3157 | 298 | // |
299 | // analyze | |
300 | // | |
0af7cb2e | 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 ); | |
303 | // Process an event | |
304 | unsigned long totalSize = 0; | |
efbd3157 | 305 | AliHLTUInt32_t fDblockSpecification = 0; |
0af7cb2e | 306 | |
307 | // Loop over all input blocks in the event | |
308 | for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ ) | |
309 | { | |
310 | char tmp1[14], tmp2[14]; | |
311 | DataType2Text( blocks[i].fDataType, tmp1 ); | |
efbd3157 | 312 | DataType2Text( AliHLTTRDDefinitions::fgkDDLRawDataType, tmp2 ); |
0af7cb2e | 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 ); | |
316 | ||
efbd3157 | 317 | if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType ) |
0af7cb2e | 318 | { |
319 | Logging (kHLTLogError, "HLT::TRDCalibration::DoEvent", "COMPARE FAILED", "type=%d is type=%d", | |
efbd3157 | 320 | blocks[i].fDataType, AliHLTTRDDefinitions::fgkDDLRawDataType); |
0af7cb2e | 321 | continue; |
322 | } | |
efbd3157 | 323 | fDblockSpecification = blocks[i].fSpecification; |
0af7cb2e | 324 | unsigned long blockSize = blocks[i].fSize; |
325 | totalSize += blockSize; | |
326 | } | |
327 | ||
328 | void *memBufIn = calloc(totalSize, 1); | |
329 | AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)memBufIn; | |
330 | if (memBufIn == NULL) | |
331 | { | |
332 | Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "MEMORY", "Unable to allocate %lu bytes", totalSize); | |
333 | return -1; | |
334 | } | |
335 | ||
336 | // Make the memory continuous | |
337 | unsigned long copied = 0; | |
338 | for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ ) | |
339 | { | |
efbd3157 | 340 | if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType ) |
0af7cb2e | 341 | continue; |
342 | ||
343 | void *pos = (void*)(pBuf + copied); | |
344 | void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize); | |
345 | if (copyret < 0) | |
346 | { | |
347 | Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "MEMORY", "Unable to copy %lu bytes", blocks[i].fSize); | |
348 | return -1; | |
349 | } | |
350 | copied += blocks[i].fSize; | |
351 | } | |
352 | ||
353 | Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "COPY STATS", "total=%lu copied=%lu", totalSize, copied); | |
354 | ||
efbd3157 | 355 | fRmem->Reset(); |
356 | fRmem->SetMemory((UChar_t*)memBufIn, totalSize); | |
357 | //fRmem->Reset(); | |
358 | Bool_t ihead = fRmem->ReadHeader(); | |
0af7cb2e | 359 | if (ihead == kTRUE) |
360 | { | |
361 | Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "HEADER", "Header read successfully"); | |
362 | } | |
363 | else | |
364 | { | |
365 | Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "HEADER", "Header read ERROR"); | |
366 | //return -1; -- not FATAL | |
367 | } | |
368 | ||
369 | fMCMtrigger->ResetTree(); | |
efbd3157 | 370 | Bool_t ireadD = fMCMtrigger->ReadDigits(fRmem); |
0af7cb2e | 371 | if (ireadD == kTRUE) |
372 | { | |
373 | Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "DIGITS", "Digits read successfully"); | |
374 | } | |
375 | else | |
376 | { | |
377 | Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "DIGITS", "Digits read ERROR"); | |
378 | return -1; | |
379 | } | |
380 | ||
381 | Bool_t iclustered = fMCMtrigger->MakeTracklets(); | |
382 | if (iclustered == kTRUE) | |
383 | { | |
384 | Logging( kHLTLogInfo, "HLT::TRDCalibration::DoEvent", "TRACKLETS", "Tracklets created successfully"); | |
385 | } | |
386 | else | |
387 | { | |
388 | Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "TRACKLETS", "Tracklets creation ERROR"); | |
389 | return -1; | |
390 | } | |
391 | ||
392 | free(memBufIn); | |
393 | ||
394 | UInt_t memBufOutSize = 0; | |
395 | ||
396 | // put the tree into output blocks of TObjArrays | |
397 | TTree *fcTree = fMCMtrigger->GetTrackletTree(); | |
398 | TList *lt = (TList*)fcTree->GetListOfBranches(); | |
399 | TIter it(lt); | |
400 | it.Reset(); | |
401 | TBranch *tb = 0; | |
402 | while ((tb = (TBranch*)it.Next()) != 0) | |
403 | { | |
404 | TObjArray *detTracklets = 0; | |
405 | tb->SetAddress(&detTracklets); | |
406 | for (Int_t icb = 0; icb < tb->GetEntries(); icb++) | |
407 | { | |
408 | tb->GetEntry(icb); | |
efbd3157 | 409 | PushBack(detTracklets, AliHLTTRDDefinitions::fgkMCMtrackletDataType, fDblockSpecification); |
0af7cb2e | 410 | } |
411 | } | |
412 | ||
413 | // add the histograms... | |
414 | //gkMCMCalibrationDataType | |
415 | ||
416 | //AliHLTTRDCalibra *calibra = AliHLTTRDCalibra::Instance(); | |
efbd3157 | 417 | if (!fCalibra) |
0af7cb2e | 418 | { |
419 | Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Calibra not valid"); | |
420 | } | |
421 | else | |
422 | { | |
423 | Logging( kHLTLogDebug, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Here we should put the histos..."); | |
424 | // // TH2I *GetCH2d(); | |
efbd3157 | 425 | // TH2I *chtmp = fCalibra->GetCH2d(); |
0af7cb2e | 426 | // if (chtmp) |
efbd3157 | 427 | // PushBack(chtmp, AliHLTTRDDefinitions::fgkMCMcalibrationDataType, fDblockSpecification); |
0af7cb2e | 428 | // else |
efbd3157 | 429 | // Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Could not fCalibra->GetCH2d()"); |
0af7cb2e | 430 | // // TProfile2D *GetPH2d(); |
efbd3157 | 431 | // TProfile2D *phtmp = fCalibra->GetPH2d(); |
0af7cb2e | 432 | // if (phtmp) |
efbd3157 | 433 | // PushBack(phtmp, AliHLTTRDDefinitions::fgkMCMcalibrationDataType, fDblockSpecification); |
0af7cb2e | 434 | // else |
efbd3157 | 435 | // Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Could not fCalibra->GetPH2d()"); |
0af7cb2e | 436 | // // TProfile2D *GetPRF2d(); |
efbd3157 | 437 | // TProfile2D *prf = fCalibra->GetPRF2d(); |
0af7cb2e | 438 | // if (prf) |
efbd3157 | 439 | // PushBack(prf, AliHLTTRDDefinitions::fgkMCMcalibrationDataType, fDblockSpecification); |
0af7cb2e | 440 | // else |
efbd3157 | 441 | // Logging( kHLTLogError, "HLT::TRDCalibration::DoEvent", "OUTPUT", "Could not fCalibra->GetPRF2d()"); |
0af7cb2e | 442 | } |
443 | ||
444 | return 0; | |
445 | } |