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