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 ):
54 //_____________________________________________________________________________
55 AliTriggerBCMask::~AliTriggerBCMask()
59 //_____________________________________________________________________________
60 AliTriggerBCMask::AliTriggerBCMask( const AliTriggerBCMask& mask ):
64 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = mask.fBCMask[i];
67 //______________________________________________________________________________
68 AliTriggerBCMask& AliTriggerBCMask::operator=(const AliTriggerBCMask& mask)
70 // AliTriggerBCMask assignment operator.
73 TNamed::operator=(mask);
74 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = mask.fBCMask[i];
79 //_____________________________________________________________________________
80 Bool_t AliTriggerBCMask::GetMask( UShort_t index) const
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));
90 //_____________________________________________________________________________
91 void AliTriggerBCMask::Print( const Option_t* opt) const
94 cout << "Trigger bunch-crossing mask:" << endl;
95 cout << " Name: " << GetName() << endl;
96 cout << " Mask: " << GetTitle() << endl;
98 if (strcmp(opt,"bits") == 0) {
99 cout << " Bits: " << endl;
100 for (UShort_t i = 0; i < kNBits; i++) {
112 Bool_t AliTriggerBCMask::SetMask (const char *mask)
114 // Wrapper used in pileup generators
115 // Call directly CreateMask method.
117 return CreateMask(fTitle);
120 //_____________________________________________________________________________
121 Bool_t AliTriggerBCMask::CreateMask(TString &mask)
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.
132 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 255;
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) {
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.");
157 if (ibit != kNBits) {
158 AliError(Form("Incomplete bunch-crossing mask. Only the first %d bits are filled.",ibit));
167 Bool_t AliTriggerBCMask::Bcm2Bits(TObjArray *tokens, Int_t &index, TBits &bits, Int_t &ibit, Int_t &level) const
174 if (index == tokens->GetEntriesFast()) {
176 AliError("Missing )");
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);
187 else if (st.CompareTo("L") == 0) {
188 for (Int_t i = 0; i < repetion; i++) bits.SetBitNumber(ibit++,kFALSE);
192 else if (st.IsDigit()) {
193 repetion = st.Atoi();
196 else if (st.CompareTo("(") == 0) {
199 if (!Bcm2Bits(tokens,index,bits,ibit,level)) {
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));
210 else if (st.CompareTo(")") == 0) {
213 AliError("Incorrectly placed )");
219 AliError(Form("Incorrect BC mask field: %s",st.Data()));