]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTriggerBCMask.cxx
Method RemoveForMaterial has been removed. A duplicate exists in AliITStrackV2 (A...
[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
112//_____________________________________________________________________________
113Bool_t AliTriggerBCMask::CreateMask(TString &mask)
114{
115 // (re)creates the bc mask bit pattern
116 // according to the bc string.
117 // The string has the following syntax:
118 // "25L 25(2H2LH 3(23HL))"
119 // - H/h -> 1 L/l -> 0
120 // - spaces, new lines are white characters
121 // The method returns kTRUE in case of successful
122 // parsing and kFALSE otherwise.
123
124 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 255;
125
126 mask.ReplaceAll("("," ( ");
127 mask.ReplaceAll(")"," ) ");
128 mask.ReplaceAll("H"," H ");
129 mask.ReplaceAll("h"," H ");
130 mask.ReplaceAll("L"," L ");
131 mask.ReplaceAll("l"," L ");
132 TObjArray *tokens = mask.Tokenize(" \t");
133 if (tokens->GetEntriesFast() == 0) {
134 delete tokens;
135 return kTRUE;
136 }
137
138 TBits bits(kNBits);
139 Int_t index = 0, ibit = 0, level = 0;
140 if ((!Bcm2Bits(tokens,index,bits,ibit,level)) ||
141 (index != tokens->GetEntriesFast())) {
142 AliError("Invalid bunch-crossing mask syntax. Empty mask produced.");
143 delete tokens;
144 return kFALSE;
145 }
146
147 delete tokens;
148
149 if (ibit != kNBits) {
150 AliWarning(Form("Incomplete bunch-crossing mask. Only the first %d bits are filled.",ibit));
151 }
152
153 bits.Get(fBCMask);
154
155 return kTRUE;
156}
157
158Bool_t AliTriggerBCMask::Bcm2Bits(TObjArray *tokens, Int_t &index, TBits &bits, Int_t &ibit, Int_t &level) const
159{
160
161 level++;
162 Int_t repetion = 1;
163
164 while(1) {
165 if (index == tokens->GetEntriesFast()) {
166 if (level > 1) {
167 AliError("Missing )");
168 return kFALSE;
169 }
170 break;
171 }
172 TString st = ((TObjString*)tokens->At(index))->String();
173 if (st.CompareTo("H") == 0) {
174 for (Int_t i = 0; i < repetion; i++) bits.SetBitNumber(ibit++,kTRUE);
175 repetion = 1;
176 index++;
177 }
178 else if (st.CompareTo("L") == 0) {
179 for (Int_t i = 0; i < repetion; i++) bits.SetBitNumber(ibit++,kFALSE);
180 repetion = 1;
181 index++;
182 }
183 else if (st.IsDigit()) {
184 repetion = st.Atoi();
185 index++;
186 }
187 else if (st.CompareTo("(") == 0) {
188 index++;
189 Int_t ibit1 = ibit;
190 if (!Bcm2Bits(tokens,index,bits,ibit,level)) {
191 return kFALSE;
192 }
193 Int_t ibit2 = ibit;
194 for (Int_t i = 0; i < (repetion-1); i++) {
195 for (Int_t j = ibit1; j < ibit2; j++) {
196 bits.SetBitNumber(ibit++,bits.TestBitNumber(j));
197 }
198 }
199 repetion = 1;
200 }
201 else if (st.CompareTo(")") == 0) {
202 index++;
203 if (level <= 1) {
204 AliError("Incorrectly placed )");
205 return kFALSE;
206 }
207 break;
208 }
209 else {
210 AliError(Form("Incorrect BC mask field: %s",st.Data()));
211 return kFALSE;
212 }
213 }
214 level--;
215 return kTRUE;
216
51f6d619 217}
710035a8 218