]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliTriggerBCMask.cxx
Compatibility with ROOT trunk
[u/mrichter/AliRoot.git] / STEER / ESD / AliTriggerBCMask.cxx
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 ClassImp(AliTriggerBCMask)
32
33 //_____________________________________________________________________________
34 AliTriggerBCMask::AliTriggerBCMask():
35   TNamed()
36 {
37   // Default constructor
38   for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 0;
39 }
40
41 //_____________________________________________________________________________
42 AliTriggerBCMask::AliTriggerBCMask( TString & name ):
43   TNamed( name, name )
44 {
45   // Constructor
46   for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 255;
47 }
48
49 //_____________________________________________________________________________
50 AliTriggerBCMask::AliTriggerBCMask( TString & name, TString & mask ):
51   TNamed( name, mask )
52 {
53   // Constructor
54   CreateMask(mask);
55 }
56
57 //_____________________________________________________________________________
58 AliTriggerBCMask::AliTriggerBCMask( const char* name, const char* mask ):
59   TNamed( name, mask )
60 {
61   // Constructor
62   SetMask(mask);
63 }
64
65 //_____________________________________________________________________________
66 AliTriggerBCMask::~AliTriggerBCMask() 
67
68   // Destructor
69 }
70 //_____________________________________________________________________________
71 AliTriggerBCMask::AliTriggerBCMask( const AliTriggerBCMask& mask ):
72   TNamed( mask )
73 {
74    // Copy constructor
75   for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = mask.fBCMask[i];
76 }
77
78 //______________________________________________________________________________
79 AliTriggerBCMask& AliTriggerBCMask::operator=(const AliTriggerBCMask& mask)
80 {
81    // AliTriggerBCMask assignment operator.
82
83    if (this != &mask) {
84       TNamed::operator=(mask);
85       for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = mask.fBCMask[i];
86    }
87    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   UShort_t position = index/8;
96   if (position >= kNBytesPerBCMask) return kFALSE;
97   UChar_t offset = index%8;
98   return (fBCMask[position] & (0x1 << offset));
99 }
100
101 //_____________________________________________________________________________
102 void AliTriggerBCMask::Print( const Option_t* opt) const
103 {
104    // Print
105   cout << "Trigger bunch-crossing mask:" << endl;
106   cout << "  Name:                      " << GetName() << endl;
107   cout << "  Mask:                      " << GetTitle() << endl;
108
109   if (strcmp(opt,"bits") == 0) {
110     cout << "  Bits:                      " << endl;
111     for (UShort_t i = 0; i < kNBits; i++) {
112       if (GetMask(i)) {
113         cout << "1";
114       }
115       else {
116         cout << "0";
117       }
118     }
119     cout << endl;
120   }
121 }
122
123 Bool_t AliTriggerBCMask::SetMask (const char *mask)
124 {
125   // Wrapper used in pileup generators
126   // Call directly CreateMask method.
127   SetTitle(mask);
128   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   for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 255;
144
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) {
153     delete tokens;
154     return kTRUE;
155   }
156
157   TBits bits(kNBits);
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.");
162     delete tokens;
163     return kFALSE;
164   }
165
166   delete tokens;
167
168   if (ibit != kNBits) {
169     AliError(Form("Incomplete bunch-crossing mask. Only the first %d bits are filled.",ibit));
170     return kFALSE;
171   }
172
173   bits.Get(fBCMask);
174
175   return kTRUE;
176 }
177
178 Bool_t AliTriggerBCMask::Bcm2Bits(TObjArray *tokens, Int_t &index, TBits &bits, Int_t &ibit, Int_t &level) const
179 {
180
181   level++;
182   Int_t repetion = 1;
183
184   while(1) {
185     if (index == tokens->GetEntriesFast()) {
186       if (level > 1) {
187         AliError("Missing )");
188         return kFALSE;
189       }
190       break;
191     }
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);
195       repetion = 1;
196       index++;
197     }
198     else if (st.CompareTo("L") == 0) {
199       for (Int_t i = 0; i < repetion; i++) bits.SetBitNumber(ibit++,kFALSE);
200       repetion = 1;
201       index++;
202     }
203     else if (st.IsDigit()) {
204       repetion = st.Atoi();
205       index++;
206     }
207     else if (st.CompareTo("(") == 0) {
208       index++;
209       Int_t ibit1 = ibit;
210       if (!Bcm2Bits(tokens,index,bits,ibit,level)) {
211         return kFALSE;
212       }
213       Int_t ibit2 = ibit;
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));
217         }
218       }
219       repetion = 1;
220     }
221     else if (st.CompareTo(")") == 0) {
222       index++;
223       if (level <= 1) {
224         AliError("Incorrectly placed )");
225         return kFALSE;
226       }
227       break;
228     }
229     else {
230       AliError(Form("Incorrect BC mask field: %s",st.Data()));
231       return kFALSE;
232     }
233   }
234   level--;
235   return kTRUE;
236
237 }
238 //_____________________________________________________________________________
239 UShort_t AliTriggerBCMask::GetNUnmaskedBCs() const
240 {
241   UShort_t nBCs=0;
242   for (Int_t i=0; i<kNBits; i++){
243     if (!GetMask(i)) nBCs++;
244   }
245   return nBCs;
246 }