LCOV - code coverage report
Current view: top level - HLT/EMCAL - AliHLTEMCALTriggerDataMakerComponent.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 17 155 11.0 %
Date: 2016-06-14 17:26:59 Functions: 7 23 30.4 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * This file is property of and copyright by the ALICE HLT Project        *
       3             :  * All rights reserved.                                                   *
       4             :  *                                                                        *
       5             :  * Primary Authors: Markus Fasel                                          *
       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             : #include "AliHLTCaloTriggerDataStruct.h"
      16             : #include "AliHLTCaloTriggerHeaderStruct.h"
      17             : #include "AliHLTCaloTriggerRawDigitDataStruct.h"
      18             : #include "AliEMCALTriggerSTURawStream.h"
      19             : #include "AliHLTEMCALDefinitions.h"
      20             : #include "AliHLTEMCALGeometry.h"
      21             : #include "AliHLTEMCALTriggerDataMakerComponent.h"
      22             : 
      23           6 : ClassImp(AliHLTEMCALTriggerDataMakerComponent)
      24             : 
      25             : AliHLTEMCALTriggerDataMakerComponent::AliHLTEMCALTriggerDataMakerComponent():
      26           3 : AliHLTCaloProcessor(),
      27           9 : AliHLTCaloConstantsHandler("EMCAL"),
      28           3 : fGeometry(NULL),
      29           3 : fSTUHeader(),
      30           3 : fNRawDigitsTRU(0),
      31           3 : fNRawDigitsSTU(0),
      32           3 : fMaxChannel(0)
      33          18 : {
      34       35778 :   for(Short_t iter = 0; iter < kMaxChannels; iter++){
      35       17886 :     fRawIndexesTRU[iter] = -1;
      36       17886 :     fRawIndexesSTU[iter] = -1;
      37             :   }
      38           6 : }
      39             : 
      40          18 : AliHLTEMCALTriggerDataMakerComponent::~AliHLTEMCALTriggerDataMakerComponent() {
      41           3 :   if(fGeometry) delete fGeometry;
      42           9 : }
      43             : 
      44             : int AliHLTEMCALTriggerDataMakerComponent::DoInit(int argc, const char **argv){
      45           0 :   fGeometry = new AliHLTEMCALGeometry(GetRunNo());
      46           0 :   return 0;
      47           0 : }
      48             : 
      49             : int AliHLTEMCALTriggerDataMakerComponent::DoDeinit(){
      50           0 :   if(fGeometry) delete fGeometry;
      51           0 :   fGeometry = NULL;
      52           0 :   return 0;
      53             : }
      54             : 
      55             : const char* AliHLTEMCALTriggerDataMakerComponent::GetComponentID(){
      56         288 :   return "EmcalTriggerDataMaker";
      57             : }
      58             : 
      59             : void AliHLTEMCALTriggerDataMakerComponent::GetInputDataTypes( std::vector <AliHLTComponentDataType>& list){
      60           0 :   list.clear();
      61           0 :   list.push_back( AliHLTEMCALDefinitions::fgkTriggerRawDigitDataType   | kAliHLTDataOriginEMCAL );
      62           0 :   list.push_back( AliHLTEMCALDefinitions::fgkTriggerSTUDataType | kAliHLTDataOriginEMCAL );
      63           0 : }
      64             : 
      65             : AliHLTComponentDataType AliHLTEMCALTriggerDataMakerComponent::GetOutputDataType(){
      66           0 :   return kAliHLTDataTypeCaloTrigger | kAliHLTDataOriginEMCAL;
      67             : }
      68             : 
      69             : void AliHLTEMCALTriggerDataMakerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier){
      70           0 :   constBase = sizeof(AliHLTCaloTriggerHeaderStruct);
      71           0 :   inputMultiplier = 1.5;
      72           0 : }
      73             : 
      74             : AliHLTComponent* AliHLTEMCALTriggerDataMakerComponent::Spawn(){
      75           0 :   return new AliHLTEMCALTriggerDataMakerComponent;
      76           0 : }
      77             : 
      78             : bool AliHLTEMCALTriggerDataMakerComponent::CheckInputDataType(const AliHLTComponentDataType &datatype) {
      79             :   //comment
      80           0 :   vector <AliHLTComponentDataType> validTypes;
      81           0 :   GetInputDataTypes(validTypes);
      82             : 
      83           0 :   for(UInt_t i=0; i < validTypes.size(); i++) {
      84           0 :     if ( datatype  ==  validTypes.at(i) ) {
      85           0 :       return true;
      86             :     }
      87             :   }
      88             : 
      89             :   HLTDebug("Invalid Datatype");
      90           0 :   return false;
      91           0 : }
      92             : 
      93             : int AliHLTEMCALTriggerDataMakerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
      94             :          AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
      95             :          AliHLTUInt32_t& size, std::vector<AliHLTComponentBlockData>& outputBlocks ){
      96             : 
      97           0 :   if(!IsDataEvent()) {
      98           0 :     size = 0;
      99           0 :     return 0;
     100             :   }
     101             : 
     102             :   UInt_t totSize            = 0;
     103             :   const AliHLTComponentBlockData* iter = NULL;
     104             : 
     105             :   // Get pointers to output buffer
     106           0 :   AliHLTCaloTriggerHeaderStruct *headerPtr = reinterpret_cast<AliHLTCaloTriggerHeaderStruct *>(outputPtr);
     107           0 :   AliHLTCaloTriggerDataStruct *dataIter = reinterpret_cast<AliHLTCaloTriggerDataStruct *>(outputPtr + sizeof(AliHLTCaloTriggerHeaderStruct));
     108             :   totSize += sizeof(AliHLTCaloTriggerHeaderStruct);
     109             : 
     110           0 :   Reset();
     111             :   AliHLTCaloTriggerRawDigitDataStruct *dataptr = NULL;
     112           0 :   for(ULong_t ndx = 0; ndx < evtData.fBlockCnt; ndx++){
     113           0 :     iter = blocks + ndx;
     114             : 
     115           0 :     if(!this->CheckInputDataType(iter->fDataType)){
     116             :       continue;
     117             :     }
     118             : 
     119           0 :     if(iter->fDataType == AliHLTEMCALDefinitions::fgkTriggerRawDigitDataType){
     120             :       // Handle TRU data
     121           0 :       Int_t ndigits = iter->fSize / sizeof(AliHLTCaloTriggerRawDigitDataStruct);
     122             :       HLTDebug("Data containing %d TRU digits", ndigits);
     123           0 :       dataptr = reinterpret_cast<AliHLTCaloTriggerRawDigitDataStruct *>(iter->fPtr);
     124           0 :       ReadTRUData(ndigits, dataptr);
     125           0 :     } else if(iter->fDataType == AliHLTEMCALDefinitions::fgkTriggerSTUDataType){
     126             :       // Handle STU data
     127           0 :       AliHLTEMCALSTUHeaderStruct *stuheader = reinterpret_cast<AliHLTEMCALSTUHeaderStruct *>(iter->fPtr);
     128           0 :       AliHLTInt32_t sizeExpected = sizeof(AliHLTEMCALSTUHeaderStruct) + sizeof(AliHLTCaloTriggerRawDigitDataStruct) * stuheader->fNRawDigits;
     129           0 :       if(iter->fSize != sizeExpected){
     130           0 :         HLTWarning("STU-reader: Size of the input buffer not matching for amount of digits, expected %d, obtained %d", sizeExpected, iter->fSize);
     131           0 :         continue;
     132             :       }
     133           0 :       dataptr = reinterpret_cast<AliHLTCaloTriggerRawDigitDataStruct *>(reinterpret_cast<AliHLTUInt8_t*>(iter->fPtr) + sizeof(AliHLTEMCALSTUHeaderStruct));
     134             :       HLTDebug("Data containing %d STU digits", stuheader->fNRawDigits);
     135           0 :       ReadSTUData(stuheader, dataptr);
     136           0 :     }
     137             :   }
     138             : 
     139             :   // Write header
     140           0 :   memcpy(headerPtr->fL1Threshold, fSTUHeader.fL1Threshold, sizeof(Int_t) *4);
     141           0 :   memcpy(headerPtr->fL1V0, fSTUHeader.fL1V0, sizeof(Int_t) * 2);
     142           0 :   headerPtr->fL1FrameMask = fSTUHeader.fL1FrameMask;
     143             : 
     144           0 :   AliHLTUInt32_t availableSize = size - sizeof(AliHLTCaloTriggerHeaderStruct);
     145             : 
     146             :   // Write data
     147           0 :   Int_t dataSize = MakeTriggerData(dataIter, availableSize);
     148           0 :   totSize += dataSize;
     149           0 :   headerPtr->fNfastor = dataSize / sizeof(AliHLTCaloTriggerDataStruct);
     150             : 
     151           0 :   AliHLTComponentBlockData bdChannelData;
     152           0 :   FillBlockData( bdChannelData );
     153           0 :   bdChannelData.fOffset = 0; //FIXME
     154           0 :   bdChannelData.fSize = totSize;
     155           0 :   bdChannelData.fDataType = GetOutputDataType();
     156           0 :   outputBlocks.push_back(bdChannelData);
     157           0 :   outputPtr += totSize; //Updating position of the output buffer
     158           0 :   size = totSize;
     159             :   return 0;
     160           0 : }
     161             : 
     162             : 
     163             : void AliHLTEMCALTriggerDataMakerComponent::ReadSTUData(AliHLTEMCALSTUHeaderStruct *headerptr, AliHLTCaloTriggerRawDigitDataStruct *dataptr){
     164           0 :   fSTUHeader = *headerptr;
     165           0 :   for(UShort_t idig = 0; idig < headerptr->fNRawDigits; idig++){
     166           0 :         if(dataptr->fID > kMaxChannels || dataptr->fID < 0){
     167           0 :                 HLTWarning("Invalid TRU index: %d", dataptr->fID);
     168           0 :                 dataptr++;
     169           0 :                 continue;
     170             :         }
     171           0 :     fRawIndexesSTU[dataptr->fID] = fNRawDigitsSTU;
     172           0 :     if(dataptr->fID > fMaxChannel) fMaxChannel = dataptr->fID;
     173           0 :     fSTURawDigitBuffer[fNRawDigitsSTU] = *dataptr;
     174           0 :     dataptr++;
     175           0 :     fNRawDigitsSTU++;
     176           0 :   }
     177             :   HLTDebug("Successfully read in %d STU digits", fNRawDigitsSTU);
     178           0 : }
     179             : 
     180             : void AliHLTEMCALTriggerDataMakerComponent::ReadTRUData(UShort_t ndigits, AliHLTCaloTriggerRawDigitDataStruct *triggerdata){
     181           0 :   for(UShort_t idig = 0; idig < ndigits; idig++){
     182           0 :     fRawIndexesTRU[triggerdata->fID] = fNRawDigitsTRU;
     183           0 :     if(triggerdata->fID > fMaxChannel) fMaxChannel = triggerdata->fID;
     184           0 :     fTRURawDigitBuffer[fNRawDigitsTRU] = *triggerdata;
     185           0 :     triggerdata++;
     186           0 :     fNRawDigitsTRU++;
     187             :   }
     188             :   HLTDebug("Successfully read in %d TRU digits", fNRawDigitsTRU);
     189           0 : }
     190             : 
     191             : Int_t AliHLTEMCALTriggerDataMakerComponent::MakeTriggerData(AliHLTCaloTriggerDataStruct *outputdata, AliHLTUInt32_t &availableSize) {
     192           0 :   if(availableSize < sizeof(AliHLTCaloTriggerDataStruct)){
     193           0 :           HLTWarning("Not enough space in buffer to write triggers");
     194           0 :           return 0;
     195             :   }
     196           0 :   Int_t outputsize = 0, col = 0, row = 0, ntriggers = 0 ;
     197           0 :   AliHLTCaloTriggerRawDigitDataStruct tmpdigit;
     198           0 :   for(UShort_t indcounter = 0; indcounter <= fMaxChannel; indcounter++){
     199           0 :     if(availableSize < sizeof(AliHLTCaloTriggerDataStruct)){
     200           0 :       HLTWarning("Buffer exceeded after %d triggers", ntriggers);
     201           0 :       break;
     202             :     }
     203           0 :     fGeometry->GetGeometryPtr()->GetPositionInEMCALFromAbsFastORIndex(indcounter, col, row);
     204           0 :     if(fRawIndexesTRU[indcounter] >= 0 && fRawIndexesSTU[indcounter] >=0){
     205           0 :       CombineTRUSTUDigit(tmpdigit, fTRURawDigitBuffer[fRawIndexesTRU[indcounter]], fSTURawDigitBuffer[fRawIndexesSTU[indcounter]]);
     206           0 :       ConvertRawDigit(outputdata, &tmpdigit, col, row);
     207           0 :       outputsize += sizeof(AliHLTCaloTriggerDataStruct);
     208           0 :       availableSize -= sizeof(AliHLTCaloTriggerDataStruct);
     209           0 :       outputdata++;
     210           0 :       ntriggers++;
     211           0 :     } else if(fRawIndexesTRU[indcounter] >= 0){
     212           0 :       ConvertRawDigit(outputdata, &(fTRURawDigitBuffer[fRawIndexesTRU[indcounter]]), col, row);
     213           0 :       outputsize += sizeof(AliHLTCaloTriggerDataStruct);
     214           0 :       availableSize -= sizeof(AliHLTCaloTriggerDataStruct);
     215           0 :       outputdata++;
     216           0 :       ntriggers++;
     217           0 :     } else if(fRawIndexesSTU[indcounter] >= 0){
     218           0 :       ConvertRawDigit(outputdata, &(fSTURawDigitBuffer[fRawIndexesSTU[indcounter]]), col, row);
     219           0 :       outputsize += sizeof(AliHLTCaloTriggerDataStruct);
     220           0 :       availableSize -= sizeof(AliHLTCaloTriggerDataStruct);
     221           0 :       outputdata++;
     222           0 :       ntriggers++;
     223           0 :     }
     224             :   }
     225             :   return outputsize;
     226           0 : }
     227             : 
     228             : void AliHLTEMCALTriggerDataMakerComponent::CombineTRUSTUDigit(
     229             :     AliHLTCaloTriggerRawDigitDataStruct &target,
     230             :     const AliHLTCaloTriggerRawDigitDataStruct &trudigit,
     231             :     const AliHLTCaloTriggerRawDigitDataStruct &studigit){
     232             :   AliHLTCaloTriggerRawDigitDataStruct merged;
     233           0 :   target.fID = trudigit.fID;
     234           0 :   target.fNTimeSamples = trudigit.fNTimeSamples;
     235           0 :   memcpy(target.fTimeSamples, trudigit.fTimeSamples, sizeof(target.fTimeSamples));
     236           0 :   target.fNL0Times = trudigit.fNL0Times;
     237           0 :   memcpy(target.fL0Times, trudigit.fL0Times, sizeof(target.fL0Times));
     238           0 :   target.fL1TimeSum = studigit.fL1TimeSum;
     239           0 :   target.fTriggerBits = trudigit.fTriggerBits | studigit.fTriggerBits;
     240           0 : }
     241             : 
     242             : void AliHLTEMCALTriggerDataMakerComponent::Reset(){
     243           0 :   for(Short_t iter = 0; iter < kMaxChannels; iter++){
     244           0 :     fRawIndexesTRU[iter] = -1;
     245           0 :     fRawIndexesSTU[iter] = -1;
     246             :   }
     247           0 :   fNRawDigitsTRU = 0;
     248           0 :   fNRawDigitsSTU = 0;
     249           0 :   fMaxChannel = 0;
     250           0 : }
     251             : 
     252             : void AliHLTEMCALTriggerDataMakerComponent::ConvertRawDigit(AliHLTCaloTriggerDataStruct *target, const AliHLTCaloTriggerRawDigitDataStruct *source, Int_t col, Int_t row) {
     253           0 :   target->fCol = col;
     254           0 :   target->fRow = row;
     255           0 :   Int_t amplitude(0), time(0);
     256           0 :   GetRawDigitMaximumAmplitude(*source, amplitude, time);
     257           0 :   target->fAmplitude = static_cast<Float_t>(amplitude);
     258           0 :   target->fTime = static_cast<Float_t>(time);
     259           0 :   target->fL1TimeSum = source->fL1TimeSum;
     260           0 :   target->fNL0Times = source->fNL0Times;
     261           0 :   memcpy(target->fL0Times, source->fL0Times, sizeof(UChar_t) * 10);
     262           0 :   target->fTriggerBits = source->fTriggerBits;
     263           0 : }

Generated by: LCOV version 1.11