LCOV - code coverage report
Current view: top level - HLT/CALO - AliHLTCaloRawAnalyzerComponentv3.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 21 230 9.1 %
Date: 2016-06-14 17:26:59 Functions: 3 26 11.5 %

          Line data    Source code
       1             : // $Id$
       2             : 
       3             : /**************************************************************************
       4             :  * This file is property of and copyright by the ALICE HLT Project        * 
       5             :  * All rights reserved.                                                   *
       6             :  *                                                                        *
       7             :  * Primary Authors: Per Thomas Hille, Oystein Djuvsland                   *
       8             :  *                                                                        *
       9             :  * Permission to use, copy, modify and distribute this software and its   *
      10             :  * documentation strictly for non-commercial purposes is hereby granted   *
      11             :  * without fee, provided that the above copyright notice appears in all   *
      12             :  * copies and that both the copyright notice and this permission notice   *
      13             :  * appear in the supporting documentation. The authors make no claims     *
      14             :  * about the suitability of this software for any purpose. It is          * 
      15             :  * provided "as is" without express or implied warranty.                  *
      16             :  **************************************************************************/
      17             : 
      18             : 
      19             : #include "AliCaloRawAnalyzer.h"
      20             : #include "AliCaloBunchInfo.h"
      21             : #include "AliCaloFitResults.h"
      22             : #include "AliHLTCaloRawAnalyzerComponentv3.h"
      23             : #include "AliHLTCaloChannelDataHeaderStruct.h"
      24             : #include "AliHLTCaloChannelDataStruct.h"
      25             : #include "AliHLTCaloMapper.h"
      26             : #include "AliHLTCaloSanityInspector.h"
      27             : #include "AliRawReaderMemory.h"
      28             : #include "AliCaloRawStreamV3.h"
      29             : #include "AliHLTCaloConstantsHandler.h"
      30             : #include "AliHLTCaloChannelRawDataStruct.h"
      31             : #include "AliLog.h"
      32             : #include "AliDAQ.h"
      33             : #include "TStopwatch.h"
      34             : 
      35             : #include "AliCaloRawAnalyzerFactory.h"
      36             : 
      37             : //#include "AliCaloConstants.h"
      38             : 
      39             : //#include "AliCaloRawAnalyzer.h"
      40             : 
      41             : //using namespace Algo;
      42             : 
      43             : #include <vector>
      44             : using namespace std;
      45             : 
      46           6 : ClassImp(AliHLTCaloRawAnalyzerComponentv3);
      47             : 
      48             : 
      49             : 
      50          18 : AliHLTCaloRawAnalyzerComponentv3::AliHLTCaloRawAnalyzerComponentv3(TString det, fitAlgorithm algo  ):AliHLTCaloProcessor(),
      51          54 :     AliHLTCaloConstantsHandler(det),
      52          18 :     fAnalyzerPtr(0),
      53          18 :     fMapperPtr(0),
      54          18 :     fCurrentSpec(-1),
      55          18 :     fDebug(false),
      56          18 :     fSanityInspectorPtr(0),
      57          18 :     fDetector(det),
      58          18 :     fAlgorithm(algo),
      59          18 :     fOffset(0),
      60          18 :     fBunchSizeCut(0),
      61          18 :     fMinPeakPosition(0),
      62          18 :     fMaxPeakPosition(100),
      63          18 :     fDoPushBadRawData(false),
      64          18 :     fDoPushRawData(false),
      65          18 :     fRawDataWriter(0)
      66             : 
      67          72 : {
      68             :   //Constructor
      69             : 
      70          18 : }
      71             : 
      72             : 
      73           0 : AliHLTCaloRawAnalyzerComponentv3::~AliHLTCaloRawAnalyzerComponentv3()
      74          36 : {
      75             :   //destructor
      76          18 : }
      77             : 
      78             : 
      79             : int
      80             : AliHLTCaloRawAnalyzerComponentv3::DoInit( int argc, const char** argv )
      81             : { 
      82             :   //See base class for documentation
      83             :   int iResult=0;
      84             : 
      85           0 :   for(int i = 0; i < argc; i++)
      86             :   {
      87           0 :     if(!strcmp("-offset", argv[i]))
      88             :     {
      89           0 :       fOffset = atoi(argv[i+1]);
      90           0 :     }
      91           0 :     if(!strcmp("-bunchsizecut", argv[i]))
      92             :     {
      93           0 :       fBunchSizeCut = atoi(argv[i+1]);
      94           0 :     }
      95           0 :     if(!strcmp("-minpeakposition", argv[i]))
      96             :     {
      97           0 :       fMinPeakPosition = atoi(argv[i+1]);
      98           0 :     }
      99           0 :     if(!strcmp("-maxpeakposition", argv[i]))
     100             :     {
     101           0 :       fMaxPeakPosition = atoi(argv[i+1]);
     102           0 :     }
     103           0 :     if(!strcmp("-pushrawdata", argv[i]))
     104             :     {
     105           0 :       fDoPushRawData = true;
     106           0 :     }
     107           0 :     if(!strcmp("-pushbaddata", argv[i]))
     108             :     {
     109           0 :       fDoPushBadRawData = true;
     110           0 :     }
     111           0 :     if(fDoPushBadRawData && fDoPushRawData)
     112             :     {
     113           0 :       HLTWarning("fDoPushBadRawData and fDoPushRawData in conflict, using fDoPushRawData");
     114           0 :       fDoPushBadRawData = false;
     115           0 :     }
     116           0 :     if(!strcmp("-suppressalilogwarnings", argv[i]))
     117             :     {
     118           0 :       AliLog::SetGlobalLogLevel(AliLog::kError);  //PHOS sometimes produces bad data -> Fill up the HLT logs...
     119           0 :     }
     120             :   }
     121             : 
     122           0 :   fAnalyzerPtr = AliCaloRawAnalyzerFactory::CreateAnalyzer(fAlgorithm);
     123           0 :   fAnalyzerPtr->SetIsZeroSuppressed(true);
     124           0 :   fSanityInspectorPtr = new AliHLTCaloSanityInspector();
     125             : 
     126           0 :   if( fDoPushRawData == true  )
     127             :   {
     128           0 :     fRawDataWriter  = new RawDataWriter(fCaloConstants);
     129           0 :   }
     130             : 
     131           0 :   return iResult;
     132           0 : }
     133             : 
     134             : 
     135             : int 
     136             : AliHLTCaloRawAnalyzerComponentv3::DoDeinit()
     137             : {
     138             :   //comment
     139           0 :   if (fRawDataWriter) delete fRawDataWriter;
     140           0 :   fRawDataWriter=NULL;
     141           0 :   if (fSanityInspectorPtr) delete fSanityInspectorPtr;
     142           0 :   fSanityInspectorPtr=NULL;
     143             : 
     144           0 :   return 0;
     145             : }
     146             : 
     147             : 
     148             : 
     149             : void 
     150             : AliHLTCaloRawAnalyzerComponentv3::PrintDebugInfo()
     151             : {
     152             :   //comment
     153           0 :   static TStopwatch  watch; //CRAP PTH
     154             :   static double wlast = -1;
     155             :   static double wcurrent = 0;
     156             : 
     157           0 :   if( true == fDebug )
     158             :   {
     159           0 :     if( fCaloEventCount %1000 == 0  )
     160             :     {
     161           0 :       cout << __FILE__ << __LINE__ << " : Processing event "  << fCaloEventCount << endl;
     162           0 :       wlast =  wcurrent;
     163           0 :       wcurrent =  watch.RealTime();
     164           0 :       cout << __FILE__ << __LINE__ << "The event rate is " <<
     165           0 :           1000/( wcurrent  -  wlast ) << "  Hz" << endl;    watch.Start(kFALSE);
     166           0 :     }
     167             :   }
     168           0 : }
     169             : 
     170             : 
     171             : void
     172             : AliHLTCaloRawAnalyzerComponentv3::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
     173             : {
     174             :   //comment
     175           0 :   constBase = sizeof(AliHLTCaloChannelDataHeaderStruct);
     176           0 :   inputMultiplier = 1.5;
     177           0 : }
     178             : 
     179             : 
     180             : bool 
     181             : AliHLTCaloRawAnalyzerComponentv3::CheckInputDataType(const AliHLTComponentDataType &datatype)
     182             : {
     183             :   //comment
     184           0 :   vector <AliHLTComponentDataType> validTypes;
     185           0 :   GetInputDataTypes(validTypes);
     186             : 
     187           0 :   for(UInt_t i=0; i < validTypes.size(); i++ )
     188             :   {
     189           0 :     if ( datatype  ==  validTypes.at(i) )
     190             :     {
     191           0 :       return true;
     192             :     }
     193             :   }
     194             : 
     195             :   HLTDebug("Invalid Datatype");
     196           0 :   return false;
     197           0 : }
     198             : 
     199             : 
     200             : int 
     201             : AliHLTCaloRawAnalyzerComponentv3::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
     202             :     AliHLTComponentTriggerData& /*trigData*/,
     203             :     AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
     204             : {
     205             :   //comment
     206           0 :   if(!IsDataEvent())
     207             :   {
     208           0 :     size = 0;
     209           0 :     return 0;
     210             :   }
     211           0 :   if( true == fDebug ) 
     212           0 :   { PrintDebugInfo();
     213           0 :   };
     214             : 
     215             :   Int_t blockSize          = -1;
     216           0 :   UInt_t totSize           = 0;
     217             :   UInt_t returnSize        = 0;
     218             :   const AliHLTComponentBlockData* iter = NULL; 
     219             :   unsigned long ndx;
     220             : 
     221           0 :   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
     222             :   {
     223           0 :     iter = blocks+ndx;
     224           0 :     if(  ! CheckInputDataType(iter->fDataType) )
     225             :     {
     226             :       continue;
     227             :     }
     228             : 
     229           0 :     if(!fDetector.CompareTo("EMCAL")) {
     230             :       // don't use STU DDLs
     231           0 :       if(iter->fSpecification >= AliDAQ::GetFirstSTUDDL()) continue;
     232             :     }
     233             :     //std::cout << "I-Raw Analyzer: Next Block: " << iter->fSpecification << std::endl;
     234           0 :     if(iter->fSpecification != fCurrentSpec)
     235             :     {
     236           0 :       fCurrentSpec = iter->fSpecification;
     237           0 :       InitMapping(iter->fSpecification);
     238           0 :     }
     239             : 
     240           0 :     blockSize = DoIt(iter, outputPtr, size, totSize); // Processing the block
     241           0 :     if (blockSize > 0)
     242             :     {
     243             :       //totSize += blockSize; //Keeping track of the used size
     244           0 :       AliHLTComponentBlockData bdChannelData;
     245           0 :       FillBlockData( bdChannelData );
     246           0 :       bdChannelData.fOffset = totSize - blockSize; //FIXME
     247           0 :       bdChannelData.fSize = blockSize;
     248           0 :       bdChannelData.fDataType = GetOutputDataType();
     249           0 :       bdChannelData.fSpecification = iter->fSpecification;
     250           0 :       outputBlocks.push_back(bdChannelData);
     251           0 :       outputPtr += blockSize; //Updating position of the output buffer
     252           0 :       returnSize = totSize;
     253           0 :     }
     254             :     else
     255             :     {
     256             :       break;
     257             :     }
     258           0 :   }
     259             : 
     260           0 :   fCaloEventCount++; 
     261           0 :   size = returnSize; //telling the framework how much buffer space we have used.
     262             : 
     263             :   return 0;
     264             : 
     265           0 : }//end DoEvent
     266             : 
     267             : 
     268             : 
     269             : Int_t
     270             : AliHLTCaloRawAnalyzerComponentv3::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
     271             : {
     272             :   //comment
     273             :   int tmpsize=  0;
     274             :   Int_t crazyness          = 0;
     275             :   Int_t nSamples           = 0;
     276             :   Short_t channelCount     = 0;
     277             : 
     278           0 :   AliHLTCaloChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(outputPtr); 
     279           0 :   AliHLTCaloChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*>(outputPtr+sizeof(AliHLTCaloChannelDataHeaderStruct)); 
     280           0 :   totSize += sizeof( AliHLTCaloChannelDataHeaderStruct );
     281           0 :   if(totSize > size)
     282             :   {
     283           0 :     HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
     284           0 :     return -1;
     285             :   }
     286           0 :   AliRawReaderMemory rawReaderMemoryPtr;
     287           0 :   rawReaderMemoryPtr.SetMemory(         reinterpret_cast<UChar_t*>( iter->fPtr ),  static_cast<ULong_t>( iter->fSize )  );
     288           0 :   rawReaderMemoryPtr.SetEquipmentID(    fMapperPtr->GetDDLFromSpec(  iter->fSpecification) + fCaloConstants->GetDDLOFFSET() );
     289             : 
     290           0 :   AliCaloRawStreamV3 altroRawStreamPtr(&rawReaderMemoryPtr, fDetector);
     291             : 
     292           0 :   rawReaderMemoryPtr.Reset();
     293           0 :   rawReaderMemoryPtr.NextEvent();
     294             : 
     295             : 
     296           0 :   if( fDoPushRawData == true)
     297             :   {
     298           0 :     fRawDataWriter->NewEvent( );
     299             :   }
     300             : 
     301           0 :   if(altroRawStreamPtr.NextDDL())
     302             :   {
     303             :     int cnt = 0;
     304           0 :     fOffset = 0;
     305           0 :     while( altroRawStreamPtr.NextChannel()  )
     306             :     {
     307           0 :       if(  altroRawStreamPtr.GetHWAddress() < 128 || ( altroRawStreamPtr.GetHWAddress() ^ 0x800) < 128 )
     308             :       {
     309             :         continue;
     310             :       }
     311             :       else
     312             :       {
     313           0 :         ++ cnt;
     314             :         //UShort_t* firstBunchPtr = 0;
     315           0 :         int chId = fMapperPtr->GetChannelID(iter->fSpecification, altroRawStreamPtr.GetHWAddress());
     316             :         //patch to skip LG in EMC
     317           0 :         if(fDetector.CompareTo("EMCAL") == 0 && (int)((chId >> 12)&0x1) == 0) continue;
     318           0 :         if( fDoPushRawData == true)
     319             :         {
     320           0 :           fRawDataWriter->SetChannelId( chId );
     321           0 :         }
     322             : 
     323           0 :         vector <AliCaloBunchInfo> bvctr;
     324           0 :         while( altroRawStreamPtr.NextBunch() == true )
     325             :         {
     326           0 :           bvctr.push_back( AliCaloBunchInfo( altroRawStreamPtr.GetStartTimeBin(),
     327           0 :               altroRawStreamPtr.GetBunchLength(),
     328           0 :               altroRawStreamPtr.GetSignals() ) );
     329             : 
     330           0 :           nSamples = altroRawStreamPtr.GetBunchLength();
     331           0 :           if( fDoPushRawData == true)
     332             :           {
     333           0 :             fRawDataWriter->WriteBunchData( altroRawStreamPtr.GetSignals(),
     334           0 :                 nSamples,  altroRawStreamPtr.GetEndTimeBin()  );
     335           0 :           }
     336             :           //firstBunchPtr = const_cast< UShort_t* >(  fAltroRawStreamPtr->GetSignals()  );
     337             :         }
     338             : 
     339           0 :         totSize += sizeof( AliHLTCaloChannelDataStruct );
     340           0 :         if(totSize > size)
     341             :         {
     342           0 :           HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
     343           0 :           return -1;
     344             :         }
     345             : 
     346             :         //fAnalyzerPtr->SetL1Phase(fAltroRawStreamPtr->GetL1Phase());
     347           0 :         AliCaloFitResults res = fAnalyzerPtr->Evaluate( bvctr,  altroRawStreamPtr.GetAltroCFG1(),
     348           0 :             altroRawStreamPtr.GetAltroCFG2() );
     349             : 
     350             :         HLTDebug("Channel energy: %f, max sig: %d, gain = %d, x = %d, z = %d", res.GetAmp(), res.GetMaxSig(),
     351             :             (chId >> 12)&0x1, chId&0x3f, (chId >> 6)&0x3f);
     352             :         {
     353           0 :           channelDataPtr->fChannelID =  chId;
     354           0 :           channelDataPtr->fEnergy = static_cast<Float_t>( res.GetAmp()  ) - fOffset;
     355           0 :           channelDataPtr->fTime = static_cast<Float_t>(  res.GetTof() );
     356             :           // Time from the raw rreader already converted - no need to multiply twice
     357             :           // if(fDetector.CompareTo("EMCAL") == 0) channelDataPtr->fTime = static_cast<Float_t>(  res.GetTof() )*100E-9 - fAltroRawStreamPtr->GetL1Phase();
     358           0 :           channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
     359           0 :           channelCount++;
     360           0 :           channelDataPtr++; // Updating position of the free output.
     361             :         }
     362           0 :       }
     363             :     }
     364           0 :     if( fDoPushRawData == true)
     365             :     {
     366           0 :       fRawDataWriter->NewChannel();
     367           0 :     }
     368           0 :   }
     369             : 
     370             : 
     371           0 :   channelDataHeaderPtr->fNChannels   =  channelCount;
     372           0 :   channelDataHeaderPtr->fAlgorithm   = fAlgorithm;
     373           0 :   channelDataHeaderPtr->fInfo        = 0;
     374             : 
     375           0 :   if( fDoPushRawData == true)
     376             :   {
     377           0 :     tmpsize += fRawDataWriter->CopyBufferToSharedMemory( (UShort_t *)channelDataPtr, size, totSize);
     378           0 :   }
     379             : 
     380           0 :   channelDataHeaderPtr->fHasRawData = fDoPushRawData;
     381             :   HLTDebug("Number of channels: %d", channelCount);
     382           0 :   tmpsize += sizeof(AliHLTCaloChannelDataStruct)*channelCount + sizeof(AliHLTCaloChannelDataHeaderStruct); 
     383           0 :   return  tmpsize;
     384             : 
     385           0 : }
     386             : 
     387             : 
     388             : 
     389             : AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::RawDataWriter(AliHLTCaloConstants* cConst) : 
     390           0 :       fRawDataBuffer(0),
     391           0 :       fCurrentChannelSize(0),
     392           0 :       fBufferIndex(0),
     393           0 :       fBufferSize( 64*56*cConst->GetNGAINS()*cConst->GetALTROMAXSAMPLES() +1000 ),
     394           0 :       fCurrentChannelIdPtr(0),
     395           0 :       fCurrentChannelSizePtr(0),
     396           0 :       fCurrentChannelDataPtr(0),
     397           0 :       fTotalSize(0)
     398           0 : {
     399             :   //comment
     400           0 :   fRawDataBuffer = new UShort_t[fBufferSize];
     401           0 :   Init();
     402           0 : }
     403             : 
     404             : 
     405             : AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::~RawDataWriter()
     406           0 : {
     407           0 :   delete [] fRawDataBuffer;
     408           0 : }
     409             : 
     410             : 
     411             : void  
     412             : AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::Init()
     413             : {
     414             :   //comment
     415           0 :   fCurrentChannelIdPtr = fRawDataBuffer;
     416           0 :   fCurrentChannelSizePtr = fRawDataBuffer +1;
     417           0 :   fCurrentChannelDataPtr = fRawDataBuffer +2;
     418           0 :   ResetBuffer();
     419           0 : }
     420             : 
     421             : 
     422             : void
     423             : AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewEvent()
     424             : {
     425             :   //comment
     426           0 :   Init();
     427           0 :   fTotalSize = 0;
     428           0 : }
     429             : 
     430             : 
     431             : void
     432             : AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewChannel( )
     433             : {
     434             :   //comment
     435           0 :   *fCurrentChannelSizePtr   = fCurrentChannelSize;
     436           0 :   fCurrentChannelIdPtr     += fCurrentChannelSize;
     437           0 :   fCurrentChannelSizePtr    += fCurrentChannelSize;
     438           0 :   fCurrentChannelDataPtr   += fCurrentChannelSize;
     439           0 :   fBufferIndex = 0;
     440           0 :   fCurrentChannelSize = 2;
     441           0 :   fTotalSize += 2;
     442           0 : }
     443             : 
     444             : 
     445             : void 
     446             : AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::WriteBunchData(const UShort_t *bunchdata,  const int length,   const UInt_t starttimebin )
     447             : {
     448           0 :   fCurrentChannelDataPtr[fBufferIndex] = starttimebin;
     449           0 :   fCurrentChannelSize ++;
     450           0 :   fBufferIndex++;
     451           0 :   fCurrentChannelDataPtr[fBufferIndex] = length;
     452           0 :   fCurrentChannelSize ++;
     453           0 :   fBufferIndex++;
     454             : 
     455           0 :   fTotalSize +=2;
     456             : 
     457           0 :   for(int i=0; i < length; i++)
     458             :   {
     459           0 :     fCurrentChannelDataPtr[ fBufferIndex + i ] =  bunchdata[i];
     460             :   }
     461             : 
     462           0 :   fCurrentChannelSize += length;
     463           0 :   fTotalSize += length;
     464           0 :   fBufferIndex += length;
     465           0 : }
     466             : 
     467             : 
     468             : void
     469             : AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::SetChannelId( const UShort_t channeldid  )
     470             : {
     471           0 :   *fCurrentChannelIdPtr =  channeldid;
     472           0 : }
     473             : 
     474             : 
     475             : void
     476             : AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::ResetBuffer()
     477             : {
     478           0 :   for(int i=0; i < fBufferSize ; i++ )
     479             :   {
     480           0 :     fRawDataBuffer[i] = 0;
     481             :   }
     482           0 : }
     483             : 
     484             : 
     485             : int
     486             : AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused )
     487             : {
     488           0 :   int sizerequested =  (sizeof(int)*fTotalSize + sizeused);
     489             : 
     490           0 :   if(  sizerequested   > sizetotal  )
     491             :   {
     492           0 :     return 0;
     493             :   }
     494             :   else
     495             :   {
     496           0 :     for(int i=0; i < fTotalSize; i++)
     497             :     {
     498           0 :       memPtr[i] = fRawDataBuffer[i];
     499             :     }
     500           0 :     return fTotalSize;
     501             :   }
     502           0 : }

Generated by: LCOV version 1.11