LCOV - code coverage report
Current view: top level - STEER/ESD - AliTriggerBCMask.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 61 117 52.1 %
Date: 2016-06-14 17:26:59 Functions: 10 21 47.6 %

          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             : ///////////////////////////////////////////////////////////////////////////////
      17             : //
      18             : // This class which defines the trigger bunch-crossing mask
      19             : //
      20             : //
      21             : ///////////////////////////////////////////////////////////////////////////////
      22             : #include <Riostream.h>
      23             : #include <TObjArray.h>
      24             : #include <TObjString.h>
      25             : 
      26             : #include "AliTriggerBCMask.h"
      27             : #include "AliLog.h"
      28             : 
      29             : using std::endl;
      30             : using std::cout;
      31         172 : ClassImp(AliTriggerBCMask)
      32             : 
      33             : //_____________________________________________________________________________
      34             : AliTriggerBCMask::AliTriggerBCMask():
      35          17 :   TNamed()
      36          85 : {
      37             :   // Default constructor
      38       15198 :   for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 0;
      39          34 : }
      40             : 
      41             : //_____________________________________________________________________________
      42             : AliTriggerBCMask::AliTriggerBCMask( TString & name ):
      43           0 :   TNamed( name, name )
      44           0 : {
      45             :   // Constructor
      46           0 :   for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 255;
      47           0 : }
      48             : 
      49             : //_____________________________________________________________________________
      50             : AliTriggerBCMask::AliTriggerBCMask( TString & name, TString & mask ):
      51           3 :   TNamed( name, mask )
      52          15 : {
      53             :   // Constructor
      54           3 :   CreateMask(mask);
      55           6 : }
      56             : 
      57             : //_____________________________________________________________________________
      58             : AliTriggerBCMask::AliTriggerBCMask( const char* name, const char* mask ):
      59           0 :   TNamed( name, mask )
      60           0 : {
      61             :   // Constructor
      62           0 :   SetMask(mask);
      63           0 : }
      64             : 
      65             : //_____________________________________________________________________________
      66             : AliTriggerBCMask::~AliTriggerBCMask() 
      67          48 : { 
      68             :   // Destructor
      69          48 : }
      70             : //_____________________________________________________________________________
      71             : AliTriggerBCMask::AliTriggerBCMask( const AliTriggerBCMask& mask ):
      72           0 :   TNamed( mask )
      73           0 : {
      74             :    // Copy constructor
      75           0 :   for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = mask.fBCMask[i];
      76           0 : }
      77             : 
      78             : //______________________________________________________________________________
      79             : AliTriggerBCMask& AliTriggerBCMask::operator=(const AliTriggerBCMask& mask)
      80             : {
      81             :    // AliTriggerBCMask assignment operator.
      82             : 
      83           0 :    if (this != &mask) {
      84           0 :       TNamed::operator=(mask);
      85           0 :       for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = mask.fBCMask[i];
      86           0 :    }
      87           0 :    return *this;
      88             : }
      89             : 
      90             : //_____________________________________________________________________________
      91             : Bool_t AliTriggerBCMask::GetMask( UShort_t index) const
      92             : {
      93             :   // Return true or false whenever the mask is active
      94             :   // for the bunch-crossing # = index
      95           0 :   UShort_t position = index/8;
      96           0 :   if (position >= kNBytesPerBCMask) return kFALSE;
      97           0 :   UChar_t offset = index%8;
      98           0 :   return (fBCMask[position] & (0x1 << offset));
      99           0 : }
     100             : 
     101             : //_____________________________________________________________________________
     102             : void AliTriggerBCMask::Print( const Option_t* opt) const
     103             : {
     104             :    // Print
     105           0 :   cout << "Trigger bunch-crossing mask:" << endl;
     106           0 :   cout << "  Name:                      " << GetName() << endl;
     107           0 :   cout << "  Mask:                      " << GetTitle() << endl;
     108             : 
     109           0 :   if (strcmp(opt,"bits") == 0) {
     110           0 :     cout << "  Bits:                      " << endl;
     111           0 :     for (UShort_t i = 0; i < kNBits; i++) {
     112           0 :       if (GetMask(i)) {
     113           0 :         cout << "1";
     114           0 :       }
     115             :       else {
     116           0 :         cout << "0";
     117             :       }
     118             :     }
     119           0 :     cout << endl;
     120           0 :   }
     121           0 : }
     122             : 
     123             : Bool_t AliTriggerBCMask::SetMask (const char *mask)
     124             : {
     125             :   // Wrapper used in pileup generators
     126             :   // Call directly CreateMask method.
     127           0 :   SetTitle(mask);
     128           0 :   return CreateMask(fTitle);
     129             : }
     130             : 
     131             : //_____________________________________________________________________________
     132             : Bool_t AliTriggerBCMask::CreateMask(TString &mask)
     133             : {
     134             :   // (re)creates the bc mask bit pattern
     135             :   // according to the bc string.
     136             :   // The string has the following syntax:
     137             :   //   "25L 25(2H2LH 3(23HL))"
     138             :   //        - H/h -> 1  L/l -> 0
     139             :   //        - spaces, new lines are white characters
     140             :   // The method returns kTRUE in case of successful
     141             :   // parsing and kFALSE otherwise.
     142             : 
     143        2685 :   for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 255;
     144             : 
     145           3 :   mask.ReplaceAll("("," ( ");
     146           3 :   mask.ReplaceAll(")"," ) ");
     147           3 :   mask.ReplaceAll("H"," H ");
     148           3 :   mask.ReplaceAll("h"," H ");
     149           3 :   mask.ReplaceAll("L"," L ");
     150           3 :   mask.ReplaceAll("l"," L ");
     151           6 :   TObjArray *tokens = mask.Tokenize(" \t");
     152           3 :   if (tokens->GetEntriesFast() == 0) {
     153           0 :     delete tokens;
     154           0 :     return kTRUE;
     155             :   }
     156             : 
     157           3 :   TBits bits(kNBits);
     158           3 :   Int_t index = 0, ibit = 0, level = 0;
     159           9 :   if ((!Bcm2Bits(tokens,index,bits,ibit,level)) ||
     160           6 :       (index != tokens->GetEntriesFast())) {
     161           0 :     AliError("Invalid bunch-crossing mask syntax. Empty mask produced.");
     162           0 :     delete tokens;
     163           0 :     return kFALSE;
     164             :   }
     165             : 
     166           6 :   delete tokens;
     167             : 
     168           3 :   if (ibit != kNBits) {
     169           0 :     AliError(Form("Incomplete bunch-crossing mask. Only the first %d bits are filled.",ibit));
     170           0 :     return kFALSE;
     171             :   }
     172             : 
     173           3 :   bits.Get(fBCMask);
     174             : 
     175           3 :   return kTRUE;
     176           6 : }
     177             : 
     178             : Bool_t AliTriggerBCMask::Bcm2Bits(TObjArray *tokens, Int_t &index, TBits &bits, Int_t &ibit, Int_t &level) const
     179             : {
     180             : 
     181          20 :   level++;
     182             :   Int_t repetion = 1;
     183             : 
     184          10 :   while(1) {
     185          43 :     if (index == tokens->GetEntriesFast()) {
     186           3 :       if (level > 1) {
     187           0 :         AliError("Missing )");
     188           0 :         return kFALSE;
     189             :       }
     190             :       break;
     191             :     }
     192          40 :     TString st = ((TObjString*)tokens->At(index))->String();
     193          80 :     if (st.CompareTo("H") == 0) {
     194          45 :       for (Int_t i = 0; i < repetion; i++) bits.SetBitNumber(ibit++,kTRUE);
     195             :       repetion = 1;
     196           9 :       index++;
     197           9 :     }
     198          62 :     else if (st.CompareTo("L") == 0) {
     199          50 :       for (Int_t i = 0; i < repetion; i++) bits.SetBitNumber(ibit++,kFALSE);
     200             :       repetion = 1;
     201          10 :       index++;
     202          10 :     }
     203          42 :     else if (st.IsDigit()) {
     204           7 :       repetion = st.Atoi();
     205           7 :       index++;
     206           7 :     }
     207          28 :     else if (st.CompareTo("(") == 0) {
     208           0 :       index++;
     209           0 :       Int_t ibit1 = ibit;
     210           7 :       if (!Bcm2Bits(tokens,index,bits,ibit,level)) {
     211           0 :         return kFALSE;
     212             :       }
     213           7 :       Int_t ibit2 = ibit;
     214        7224 :       for (Int_t i = 0; i < (repetion-1); i++) {
     215       28556 :         for (Int_t j = ibit1; j < ibit2; j++) {
     216       10673 :           bits.SetBitNumber(ibit++,bits.TestBitNumber(j));
     217             :         }
     218             :       }
     219             :       repetion = 1;
     220           7 :     }
     221          14 :     else if (st.CompareTo(")") == 0) {
     222           7 :       index++;
     223           7 :       if (level <= 1) {
     224           0 :         AliError("Incorrectly placed )");
     225           0 :         return kFALSE;
     226             :       }
     227           7 :       break;
     228             :     }
     229             :     else {
     230           0 :       AliError(Form("Incorrect BC mask field: %s",st.Data()));
     231           0 :       return kFALSE;
     232             :     }
     233          88 :   }
     234          10 :   level--;
     235          10 :   return kTRUE;
     236             : 
     237          10 : }
     238             : //_____________________________________________________________________________
     239             : UShort_t AliTriggerBCMask::GetNUnmaskedBCs() const
     240             : {
     241             :   UShort_t nBCs=0;
     242           0 :   for (Int_t i=0; i<kNBits; i++){
     243           0 :     if (!GetMask(i)) nBCs++;
     244             :   }
     245           0 :   return nBCs;
     246             : }

Generated by: LCOV version 1.11