1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
18 // This class which defines the trigger bunch-crossing mask
21 ///////////////////////////////////////////////////////////////////////////////
22 #include <Riostream.h>
23 #include <TObjArray.h>
24 #include <TObjString.h>
26 #include "AliTriggerBCMask.h"
31 ClassImp(AliTriggerBCMask)
33 //_____________________________________________________________________________
34 AliTriggerBCMask::AliTriggerBCMask():
37 // Default constructor
38 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 0;
41 //_____________________________________________________________________________
42 AliTriggerBCMask::AliTriggerBCMask( TString & name ):
46 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 255;
49 //_____________________________________________________________________________
50 AliTriggerBCMask::AliTriggerBCMask( TString & name, TString & mask ):
57 //_____________________________________________________________________________
58 AliTriggerBCMask::AliTriggerBCMask( const char* name, const char* mask ):
65 //_____________________________________________________________________________
66 AliTriggerBCMask::~AliTriggerBCMask()
70 //_____________________________________________________________________________
71 AliTriggerBCMask::AliTriggerBCMask( const AliTriggerBCMask& mask ):
75 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = mask.fBCMask[i];
78 //______________________________________________________________________________
79 AliTriggerBCMask& AliTriggerBCMask::operator=(const AliTriggerBCMask& mask)
81 // AliTriggerBCMask assignment operator.
84 TNamed::operator=(mask);
85 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = mask.fBCMask[i];
90 //_____________________________________________________________________________
91 Bool_t AliTriggerBCMask::GetMask( UShort_t index) const
93 // Return true or false whenever the mask is active
94 // for the bunch-crossing # = index
95 UShort_t position = index/8;
96 if (position >= kNBytesPerBCMask) return kFALSE;
97 UChar_t offset = index%8;
98 return (fBCMask[position] & (0x1 << offset));
101 //_____________________________________________________________________________
102 void AliTriggerBCMask::Print( const Option_t* opt) const
105 cout << "Trigger bunch-crossing mask:" << endl;
106 cout << " Name: " << GetName() << endl;
107 cout << " Mask: " << GetTitle() << endl;
109 if (strcmp(opt,"bits") == 0) {
110 cout << " Bits: " << endl;
111 for (UShort_t i = 0; i < kNBits; i++) {
123 Bool_t AliTriggerBCMask::SetMask (const char *mask)
125 // Wrapper used in pileup generators
126 // Call directly CreateMask method.
128 return CreateMask(fTitle);
131 //_____________________________________________________________________________
132 Bool_t AliTriggerBCMask::CreateMask(TString &mask)
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.
143 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 255;
145 mask.ReplaceAll("("," ( ");
146 mask.ReplaceAll(")"," ) ");
147 mask.ReplaceAll("H"," H ");
148 mask.ReplaceAll("h"," H ");
149 mask.ReplaceAll("L"," L ");
150 mask.ReplaceAll("l"," L ");
151 TObjArray *tokens = mask.Tokenize(" \t");
152 if (tokens->GetEntriesFast() == 0) {
158 Int_t index = 0, ibit = 0, level = 0;
159 if ((!Bcm2Bits(tokens,index,bits,ibit,level)) ||
160 (index != tokens->GetEntriesFast())) {
161 AliError("Invalid bunch-crossing mask syntax. Empty mask produced.");
168 if (ibit != kNBits) {
169 AliError(Form("Incomplete bunch-crossing mask. Only the first %d bits are filled.",ibit));
178 Bool_t AliTriggerBCMask::Bcm2Bits(TObjArray *tokens, Int_t &index, TBits &bits, Int_t &ibit, Int_t &level) const
185 if (index == tokens->GetEntriesFast()) {
187 AliError("Missing )");
192 TString st = ((TObjString*)tokens->At(index))->String();
193 if (st.CompareTo("H") == 0) {
194 for (Int_t i = 0; i < repetion; i++) bits.SetBitNumber(ibit++,kTRUE);
198 else if (st.CompareTo("L") == 0) {
199 for (Int_t i = 0; i < repetion; i++) bits.SetBitNumber(ibit++,kFALSE);
203 else if (st.IsDigit()) {
204 repetion = st.Atoi();
207 else if (st.CompareTo("(") == 0) {
210 if (!Bcm2Bits(tokens,index,bits,ibit,level)) {
214 for (Int_t i = 0; i < (repetion-1); i++) {
215 for (Int_t j = ibit1; j < ibit2; j++) {
216 bits.SetBitNumber(ibit++,bits.TestBitNumber(j));
221 else if (st.CompareTo(")") == 0) {
224 AliError("Incorrectly placed )");
230 AliError(Form("Incorrect BC mask field: %s",st.Data()));
238 //_____________________________________________________________________________
239 UShort_t AliTriggerBCMask::GetNUnmaskedBCs() const
242 for (Int_t i=0; i<kNBits; i++){
243 if (!GetMask(i)) nBCs++;