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 //_____________________________________________________________________________
113 Bool_t AliTriggerBCMask::CreateMask(TString &mask)
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.
124 for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 255;
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) {
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.");
149 if (ibit != kNBits) {
150 AliError(Form("Incomplete bunch-crossing mask. Only the first %d bits are filled.",ibit));
159 Bool_t AliTriggerBCMask::Bcm2Bits(TObjArray *tokens, Int_t &index, TBits &bits, Int_t &ibit, Int_t &level) const
166 if (index == tokens->GetEntriesFast()) {
168 AliError("Missing )");
173 TString st = ((TObjString*)tokens->At(index))->String();
174 if (st.CompareTo("H") == 0) {
175 for (Int_t i = 0; i < repetion; i++) bits.SetBitNumber(ibit++,kTRUE);
179 else if (st.CompareTo("L") == 0) {
180 for (Int_t i = 0; i < repetion; i++) bits.SetBitNumber(ibit++,kFALSE);
184 else if (st.IsDigit()) {
185 repetion = st.Atoi();
188 else if (st.CompareTo("(") == 0) {
191 if (!Bcm2Bits(tokens,index,bits,ibit,level)) {
195 for (Int_t i = 0; i < (repetion-1); i++) {
196 for (Int_t j = ibit1; j < ibit2; j++) {
197 bits.SetBitNumber(ibit++,bits.TestBitNumber(j));
202 else if (st.CompareTo(")") == 0) {
205 AliError("Incorrectly placed )");
211 AliError(Form("Incorrect BC mask field: %s",st.Data()));