LCOV - code coverage report
Current view: top level - MUON/MUONrec - AliMUONTrackerDataMaker.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 257 0.4 %
Date: 2016-06-14 17:26:59 Functions: 1 20 5.0 %

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

Generated by: LCOV version 1.11