]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTrackerDataMaker.cxx
Write only detector coefficients from HLT (Raphaelle)
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerDataMaker.cxx
CommitLineData
b6f591ae 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
7* Permission to use, copy, modify and distribute this software and its *
8* documentation strictly for non-commercial purposes is hereby granted *
9* without fee, provided that the above copyright notice appears in all *
10* copies and that both the copyright notice and this permission notice *
11* appear in the supporting documentation. The authors make no claims *
12* about the suitability of this software for any purpose. It is *
13* provided "as is" without express or implied warranty. *
14**************************************************************************/
15
16// $Id$
17
18/// \class AliMUONTrackerDataMaker
19///
20/// Implementation of VTrackerDataMaker to read raw data and
21/// calibrate it (if required)
22///
23/// \author Laurent Aphecetche, Subatech
24
25#include "AliMUONTrackerDataMaker.h"
26
27#include "AliCDBManager.h"
28#include "AliCDBStorage.h"
29#include "AliCodeTimer.h"
30#include "AliDAQ.h"
31#include "AliLog.h"
32#include "AliMUON2DMap.h"
33#include "AliMUONCalibParamND.h"
34#include "AliMUONCalibrationData.h"
35#include "AliMUONDigitCalibrator.h"
64c2397e 36#include "AliMUONLogger.h"
b6f591ae 37#include "AliMUONRawStreamTrackerHP.h"
38#include "AliMUONTrackerData.h"
39#include "AliMpDDLStore.h"
40#include "AliRawEventHeaderBase.h"
41#include "AliRawReader.h"
42#include "Riostream.h"
43
44/// \cond CLASSIMP
45ClassImp(AliMUONTrackerDataMaker)
46/// \endcond
47
48Int_t AliMUONTrackerDataMaker::fgkCounter(0);
49
50//_____________________________________________________________________________
51AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(TRootIOCtor*)
52:
53AliMUONVTrackerDataMaker(),
54fRawReader(0x0),
55fAccumulatedData(0x0),
b3d57767 56fIsOwnerOfAccumulatedData(kTRUE),
b6f591ae 57fOneEventData(0x0),
58fDigitCalibrator(0x0),
59fCalibrationData(0x0),
60fSource(""),
61fOCDBPath(""),
62fNumberOfEvents(0),
63fRunNumber(0),
64fIsRunning(kFALSE),
65fIsOwnerOfRawReader(kFALSE),
64c2397e 66fIsEventByEvent(kFALSE),
b3d57767 67fLogger(0x0),
68fLastEventWasEmpty(kFALSE),
69fNumberOfPhysicsEvents(0),
9074a9a9 70fNumberOfGoodPhysicsEvents(0),
71fTryRecover(kFALSE),
72fFirstEvent(-1),
73fLastEvent(-1)
b6f591ae 74{
cddcc1f3 75/// Root IO ctor
b6f591ae 76}
77
78//_____________________________________________________________________________
79AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
80 Int_t runNumber,
81 AliRawReader* rawReader,
82 const char* cdbPath,
83 const char* calibMode,
84 Bool_t histogram,
85 Double_t xmin,
86 Double_t xmax)
87:
88AliMUONVTrackerDataMaker(),
89fRawReader(rawReader),
90fAccumulatedData(0x0),
b3d57767 91fIsOwnerOfAccumulatedData(kTRUE),
b6f591ae 92fOneEventData(new AliMUON2DMap(true)),
93fDigitCalibrator(0x0),
94fCalibrationData(0x0),
95fSource(""),
96fOCDBPath(cdbPath),
97fNumberOfEvents(0),
98fRunNumber(runNumber),
99fIsRunning(kFALSE),
100fIsOwnerOfRawReader(kFALSE),
64c2397e 101fIsEventByEvent(kFALSE),
b3d57767 102fLogger(0x0),
103fLastEventWasEmpty(kFALSE),
104fNumberOfPhysicsEvents(0),
9074a9a9 105fNumberOfGoodPhysicsEvents(0),
106fTryRecover(kFALSE),
107fFirstEvent(-1),
108fLastEvent(-1)
b6f591ae 109{
110 /// Ctor in which this object will NOT be the owner of the reader
111 /// and can NOT apply rewind to it, nor use Next on it.
112 Ctor(recoParam,runNumber,calibMode,histogram,xmin,xmax);
113}
114
115
116//_____________________________________________________________________________
117AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
118 AliRawReader* rawReader,
119 const char* cdbPath,
120 const char* calibMode,
121 Bool_t histogram,
122 Double_t xmin,
123 Double_t xmax)
124:
125AliMUONVTrackerDataMaker(),
126fRawReader(rawReader),
127fAccumulatedData(0x0),
b3d57767 128fIsOwnerOfAccumulatedData(kTRUE),
b6f591ae 129fOneEventData(new AliMUON2DMap(true)),
130fDigitCalibrator(0x0),
131fCalibrationData(0x0),
132fSource(""),
133fOCDBPath(cdbPath),
134fNumberOfEvents(0),
135fRunNumber(0),
136fIsRunning(kFALSE),
137fIsOwnerOfRawReader(kTRUE),
64c2397e 138fIsEventByEvent(kFALSE),
b3d57767 139fLogger(0x0),
140fLastEventWasEmpty(kFALSE),
141fNumberOfPhysicsEvents(0),
9074a9a9 142fNumberOfGoodPhysicsEvents(0),
143fTryRecover(kFALSE),
144fFirstEvent(-1),
145fLastEvent(-1)
b6f591ae 146{
147 /// Ctor in which we take the ownership of the rawReader, so we can rewind
148 /// and advance it as we wish
149
150 if (fRawReader)
151 {
152 fRawReader->NextEvent(); // to be sure to get run number available
153 fRunNumber = fRawReader->GetRunNumber();
154 fRawReader->RewindEvents();
155 }
156
157 Ctor(recoParam,fRunNumber,calibMode,histogram,xmin,xmax);
158}
159
160//_____________________________________________________________________________
161AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(AliRawReader* rawReader, Bool_t histogram)
162:
163AliMUONVTrackerDataMaker(),
164fRawReader(rawReader),
165fAccumulatedData(0x0),
b3d57767 166fIsOwnerOfAccumulatedData(kTRUE),
b6f591ae 167fOneEventData(new AliMUON2DMap(true)),
168fDigitCalibrator(0x0),
169fCalibrationData(0x0),
170fSource(""),
171fOCDBPath(""),
172fNumberOfEvents(0),
173fRunNumber(0),
174fIsRunning(kFALSE),
175fIsOwnerOfRawReader(kTRUE),
64c2397e 176fIsEventByEvent(kFALSE),
b3d57767 177fLogger(0x0),
178fLastEventWasEmpty(kFALSE),
179fNumberOfPhysicsEvents(0),
9074a9a9 180fNumberOfGoodPhysicsEvents(0),
181fTryRecover(kFALSE),
182fFirstEvent(-1),
183fLastEvent(-1)
b6f591ae 184{
ca04ed6c 185 /// Ctor from raw data reader
b6f591ae 186 if (fRawReader)
187 {
188 fRawReader->NextEvent(); // to be sure to get run number available
189 fRunNumber = fRawReader->GetRunNumber();
190 fRawReader->RewindEvents();
191 }
192
193 Ctor(0x0,fRunNumber,"",histogram);
194
195}
196
197//_____________________________________________________________________________
198void
199AliMUONTrackerDataMaker::Ctor(const AliMUONRecoParam* recoParam,
200 Int_t runNumber,
201 const char* calibMode,
202 Bool_t histogram,
203 Double_t xmin, Double_t xmax)
204{
205 /// "designated constructor"
f2bc8ba0 206
207 Bool_t calibrate = ( strlen(calibMode) > 0 );
b6f591ae 208
209 TString name;
210 TString type("RAW");
211
212 if ( calibrate )
213 {
214 TString scalib(calibMode);
215 scalib.ToUpper();
216 if ( scalib == "GAIN" ) type = "CALC";
217 if ( scalib == "NOGAIN" ) type = "CALZ";
218 if ( scalib == "GAINCONSTANTCAPA") type = "CALG";
66cdf5b3 219 if ( scalib == "INJECTIONGAIN" ) type = "CALE";
b6f591ae 220 }
221
222 if ( !fRunNumber )
223 {
224 ++fgkCounter;
225 name = Form("%s%s_%d",(histogram?"H":""),type.Data(),fgkCounter);
226 }
227 else
228 {
229 name = Form("%s%s%d",(histogram?"H":""),type.Data(),fRunNumber);
230 }
231
232 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
233 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
234 if (histogram)
235 {
236 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
237 }
238
239 if ( calibrate )
240 {
241 fCalibrationData = new AliMUONCalibrationData(runNumber);
242
243 // force the reading of calibration NOW
244 // FIXME: not really elegant and error prone (as we have the list of calib data twice,
245 // once here and once in the digitcalibrator class, hence the change of them getting
246 // out of sync)
247 // But with the current CDBManager implementation, I don't know how to solve
248 // this better (e.g. to avoid clearing cache messages and so on).
ed66881d 249
250 AliCDBStorage* storage(0x0);
b6f591ae 251
ed66881d 252 if ( fOCDBPath.Length() > 0 )
b6f591ae 253 {
ed66881d 254 storage = AliCDBManager::Instance()->GetDefaultStorage();
255
256 if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
257 {
258 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
259 }
b6f591ae 260 }
261
262 fCalibrationData->Pedestals();
263 fCalibrationData->Gains();
264 fCalibrationData->Neighbours();
265 fCalibrationData->HV();
266 fCalibrationData->Capacitances();
267
ed66881d 268 if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
b6f591ae 269 {
270 AliCDBManager::Instance()->SetDefaultStorage(storage);
271 }
272
273 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode);
274 //FIXME: get the reco param from GUI and/or from OCDB if not used from the QA code ?
275 }
276}
277
278//_____________________________________________________________________________
279AliMUONTrackerDataMaker::~AliMUONTrackerDataMaker()
280{
cddcc1f3 281/// dtor
282
b6f591ae 283 delete fOneEventData;
b3d57767 284 if ( fIsOwnerOfAccumulatedData ) delete fAccumulatedData;
b6f591ae 285 if ( fIsOwnerOfRawReader ) delete fRawReader;
286 delete fCalibrationData;
287 delete fDigitCalibrator;
288}
289
290//_____________________________________________________________________________
291Bool_t
292AliMUONTrackerDataMaker::Add(const AliMUONTrackerDataMaker& other)
293{
294 /// Adds other to this
295
296 if (!fAccumulatedData) return kFALSE;
297
298 if ( fIsEventByEvent )
299 {
300 AliError("Cannot add event by event objects !");
301 return kFALSE;
302 }
303
304 if ( fRunNumber != other.fRunNumber ) fRunNumber = -1;
305
306 fSource += "\n";
307 fSource += other.fSource;
308
309 fNumberOfEvents += other.fNumberOfEvents;
b3d57767 310 fNumberOfPhysicsEvents += other.fNumberOfPhysicsEvents;
311 fNumberOfGoodPhysicsEvents += other.fNumberOfGoodPhysicsEvents;
312
b6f591ae 313 TList list;
314 list.Add(other.fAccumulatedData);
315
316 fAccumulatedData->Merge(&list);
317
318 return kTRUE;
319}
320
321//_____________________________________________________________________________
322Bool_t
323AliMUONTrackerDataMaker::NextEvent()
324{
325 /// Read and process next event
326
327 if ( !fIsOwnerOfRawReader )
328 {
329 AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
330 return kFALSE;
331 }
332
99c136e1 333 AliCodeTimerAuto("",0);
b6f591ae 334
b6f591ae 335 if ( !IsRunning() ) return kTRUE;
336
9074a9a9 337 Bool_t ok(kTRUE);
338
339 if ( fLastEvent >= fFirstEvent && fLastEvent > 0 ) // do we have an event range to consider ?
340 {
341 // skip up to first event
342
343 while ( (fNumberOfEvents-1) < fFirstEvent && ( ok = fRawReader->NextEvent() ) )
344 {
345 ++fNumberOfEvents;
346 }
347
348 if ( ok && (fNumberOfEvents-1) <= fLastEvent )
349 {
350 ok = fRawReader->NextEvent();
351 }
352 else
353 {
354 fNumberOfEvents=fLastEvent+1;
355 return kFALSE;
356 }
357 }
358 else
359 {
360 // no event range, just proceed...
361 ok = fRawReader->NextEvent();
362 }
b6f591ae 363
364 if (!ok)
365 {
366 return kFALSE;
367 }
368
b3d57767 369 ProcessEvent();
b6f591ae 370
371 return kTRUE;
372}
373
374//_____________________________________________________________________________
375Bool_t AliMUONTrackerDataMaker::ProcessEvent()
376{
377 /// Process current event
378 ///
379 /// Note that in case of calibration, we do not simply reuse the
380 /// AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore&) method,
381 /// as this would require filling first a digitStore, and then calibrate it,
382 /// and then convert it into a VStore, all this taking too much time.
383 /// But we *do* reuse the AliMUONDigitCalibrator::CalibrateDigit in order not to
384 /// duplicate this critical piece of calibration code !
385 ///
386
b3d57767 387 ++fNumberOfEvents;
388
389 Int_t eventType = fRawReader->GetType();
390
391 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
392 {
393 return kTRUE; // for the moment
394 }
395
396 ++fNumberOfPhysicsEvents;
397
398 fLastEventWasEmpty = kFALSE;
399
99c136e1 400 AliCodeTimerAuto("",0);
b6f591ae 401
402 AliMUONRawStreamTrackerHP stream(fRawReader);
64c2397e 403
b6f591ae 404 stream.DisableWarnings();
64c2397e 405 stream.DisableRawReaderErrorLogger();
406 stream.DisableMUONErrorLogger();
9074a9a9 407
408 if ( fTryRecover )
409 {
410 stream.TryRecover(kTRUE);
411 }
412 else
413 {
414 stream.TryRecover(kFALSE);
415 }
64c2397e 416
417 if (fLogger)
418 {
419 stream.EnableMUONErrorLogger();
420 stream.SetMUONErrorLogger(fLogger);
421 stream.SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kMediumErrorDetail);
422 }
b6f591ae 423
424 const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK");
425 TArrayI nevents(nddls);
426
427 for ( Int_t i = 0; i < nddls; ++i )
428 {
429 nevents[i] = 0;
430 }
431
432 fOneEventData->Clear();
433
434 Int_t buspatchId;
435 UShort_t manuId;
436 UChar_t manuChannel;
437 UShort_t adc;
438
439 stream.First();
440
441 while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) )
442 {
443 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
444
445 Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus(buspatchId);
446
447 nevents[ddl] = 1;
448
449 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
450 if (!param)
451 {
452 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
453 AliMUONVCalibParam::InvalidFloatValue());
454 fOneEventData->Add(param);
455 }
456
457 Double_t charge(adc);
458
459 if ( fDigitCalibrator )
460 {
461 if ( fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel) )
462 {
8f29b706 463 charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc);
b6f591ae 464 }
2b8a1212 465 else
466 {
467 charge = 0.0;
468 }
b6f591ae 469 }
470
471 if (charge > 0.0 )
472 {
473 param->SetValueAsDouble(manuChannel,0,charge);
474 }
475 }
476
477 Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError();
478
479 if (!badEvent)
480 {
b3d57767 481 fAccumulatedData->Add(*fOneEventData,&nevents);
482 if ( fOneEventData->GetSize() == 0 ) fLastEventWasEmpty = kTRUE;
483 ++fNumberOfGoodPhysicsEvents;
b6f591ae 484 }
64c2397e 485
b3d57767 486 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,fNumberOfPhysicsEvents,fNumberOfGoodPhysicsEvents));
487
b6f591ae 488 return !badEvent;
489}
490
491
492//_____________________________________________________________________________
493void
494AliMUONTrackerDataMaker::Print(Option_t*) const
495{
496 /// Printout
497
498 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
499 << endl;
500}
501
502//_____________________________________________________________________________
503void AliMUONTrackerDataMaker::Rewind()
504{
505 /// Rewind events
506 if ( fIsOwnerOfRawReader )
507 {
508 fRawReader->RewindEvents();
509 fNumberOfEvents=0;
b3d57767 510 fNumberOfPhysicsEvents=0;
511 fNumberOfGoodPhysicsEvents=0;
b6f591ae 512 }
513 else
514 {
515 AliError("Wrong usage of this class : cannot rewind as I am not owner of the raw reader !");
516 }
517}
518
519//_____________________________________________________________________________
520Long64_t AliMUONTrackerDataMaker::Merge(TCollection* list)
521{
522 /// Merge objects in collection
523
524 if (!list) return 0;
525
526 if ( list->IsEmpty() ) return NumberOfEvents();
527
528 TIter next(list);
529 const TObject* o(0x0);
530
531 while ( ( o = next() ) )
532 {
533 const AliMUONTrackerDataMaker* data = dynamic_cast<const AliMUONTrackerDataMaker*>(o);
534 if (!o)
535 {
536 AliError(Form("Object named %s is not an AliMUONTrackerDataMaker ! Skipping it",
537 o->GetName()));
538 }
539 else
540 {
541 Bool_t ok = Add(*data);
542 if (!ok)
543 {
544 AliError("Got incompatible objects");
545 }
546 }
547 }
548
549 return NumberOfEvents();
550}
551
552//_____________________________________________________________________________
553void
554AliMUONTrackerDataMaker::SetRawReader(AliRawReader* rawReader)
555{
556 /// Change the rawreader (only works if isowner=true)
557
558 if ( fIsOwnerOfRawReader )
559 {
560 AliFatal("Improper use of this class ! Cannot change raw reader in this case");
561 }
562
563 fRawReader = rawReader;
564
565}