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"
29 ClassImp(AliTriggerBCMask)
31 //_____________________________________________________________________________
32 AliTriggerBCMask::AliTriggerBCMask():
35 // Default constructor
36 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 0;
39 //_____________________________________________________________________________
40 AliTriggerBCMask::AliTriggerBCMask( TString & name ):
44 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 255;
47 //_____________________________________________________________________________
48 AliTriggerBCMask::AliTriggerBCMask( TString & name, TString & mask ):
55 //_____________________________________________________________________________
56 AliTriggerBCMask::AliTriggerBCMask( const char* name, const char* mask ):
63 //_____________________________________________________________________________
64 AliTriggerBCMask::~AliTriggerBCMask()
68 //_____________________________________________________________________________
69 AliTriggerBCMask::AliTriggerBCMask( const AliTriggerBCMask& mask ):
73 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = mask.fBCMask[i];
76 //______________________________________________________________________________
77 AliTriggerBCMask& AliTriggerBCMask::operator=(const AliTriggerBCMask& mask)
79 // AliTriggerBCMask assignment operator.
82 TNamed::operator=(mask);
83 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = mask.fBCMask[i];
88 //_____________________________________________________________________________
89 Bool_t AliTriggerBCMask::GetMask( UShort_t index) const
91 // Return true or false whenever the mask is active
92 // for the bunch-crossing # = index
93 UShort_t position = index/8;
94 if (position >= kNBytesPerBCMask) return kFALSE;
95 UChar_t offset = index%8;
96 return (fBCMask[position] & (0x1 << offset));
99 //_____________________________________________________________________________
100 void AliTriggerBCMask::Print( const Option_t* opt) const
103 cout << "Trigger bunch-crossing mask:" << endl;
104 cout << " Name: " << GetName() << endl;
105 cout << " Mask: " << GetTitle() << endl;
107 if (strcmp(opt,"bits") == 0) {
108 cout << " Bits: " << endl;
109 for (UShort_t i = 0; i < kNBits; i++) {
121 Bool_t AliTriggerBCMask::SetMask (const char *mask)
123 // Wrapper used in pileup generators
124 // Call directly CreateMask method.
126 return CreateMask(fTitle);
129 //_____________________________________________________________________________
130 Bool_t AliTriggerBCMask::CreateMask(TString &mask)
132 // (re)creates the bc mask bit pattern
133 // according to the bc string.
134 // The string has the following syntax:
135 // "25L 25(2H2LH 3(23HL))"
136 // - H/h -> 1 L/l -> 0
137 // - spaces, new lines are white characters
138 // The method returns kTRUE in case of successful
139 // parsing and kFALSE otherwise.
141 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 255;
143 mask.ReplaceAll("("," ( ");
144 mask.ReplaceAll(")"," ) ");
145 mask.ReplaceAll("H"," H ");
146 mask.ReplaceAll("h"," H ");
147 mask.ReplaceAll("L"," L ");
148 mask.ReplaceAll("l"," L ");
149 TObjArray *tokens = mask.Tokenize(" \t");
150 if (tokens->GetEntriesFast() == 0) {
156 Int_t index = 0, ibit = 0, level = 0;
157 if ((!Bcm2Bits(tokens,index,bits,ibit,level)) ||
158 (index != tokens->GetEntriesFast())) {
159 AliError("Invalid bunch-crossing mask syntax. Empty mask produced.");
166 if (ibit != kNBits) {
167 AliError(Form("Incomplete bunch-crossing mask. Only the first %d bits are filled.",ibit));
176 Bool_t AliTriggerBCMask::Bcm2Bits(TObjArray *tokens, Int_t &index, TBits &bits, Int_t &ibit, Int_t &level) const
183 if (index == tokens->GetEntriesFast()) {
185 AliError("Missing )");
190 TString st = ((TObjString*)tokens->At(index))->String();
191 if (st.CompareTo("H") == 0) {
192 for (Int_t i = 0; i < repetion; i++) bits.SetBitNumber(ibit++,kTRUE);
196 else if (st.CompareTo("L") == 0) {
197 for (Int_t i = 0; i < repetion; i++) bits.SetBitNumber(ibit++,kFALSE);
201 else if (st.IsDigit()) {
202 repetion = st.Atoi();
205 else if (st.CompareTo("(") == 0) {
208 if (!Bcm2Bits(tokens,index,bits,ibit,level)) {
212 for (Int_t i = 0; i < (repetion-1); i++) {
213 for (Int_t j = ibit1; j < ibit2; j++) {
214 bits.SetBitNumber(ibit++,bits.TestBitNumber(j));
219 else if (st.CompareTo(")") == 0) {
222 AliError("Incorrectly placed )");
228 AliError(Form("Incorrect BC mask field: %s",st.Data()));