]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliTriggerClass.cxx
doxy: do not show whitespace diffs on bulk edit
[u/mrichter/AliRoot.git] / STEER / ESD / AliTriggerClass.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 classes objects
19 //
20 //
21 ///////////////////////////////////////////////////////////////////////////////
22 #include <Riostream.h>
23 #include <TMath.h>
24
25 #include "AliLog.h"
26 #include "AliTriggerClass.h"
27 #include "AliTriggerConfiguration.h"
28 #include "AliTriggerDescriptor.h"
29 #include "AliTriggerCluster.h"
30 #include "AliTriggerPFProtection.h"
31 #include "AliTriggerBCMask.h"
32
33 using std::endl;
34 using std::cout;
35 using std::hex;
36 using std::dec;
37 ClassImp(AliTriggerClass)
38
39 //_____________________________________________________________________________
40 AliTriggerClass::AliTriggerClass():
41   TNamed(),
42   fClassMask(0),
43   fClassMaskNext50(0),
44   fIndex(0),
45   fDescriptor(NULL),
46   fCluster(NULL),
47   fPFProtection(NULL),
48   fPrescaler(0),
49   fAllRare(kFALSE),
50   fStatus(kFALSE),
51   fTimeGroup(0),
52   fTimeWindow(0)
53 {
54   // Default constructor
55   for(Int_t i = 0; i < kNMaxMasks; i++)fMask[i]=0; 
56 }
57
58 //_____________________________________________________________________________
59 AliTriggerClass::AliTriggerClass( TString & name, UChar_t index,
60                                   AliTriggerDescriptor *desc, AliTriggerCluster *clus,
61                                   AliTriggerPFProtection *pfp, AliTriggerBCMask *mask,
62                                   UInt_t prescaler, Bool_t allrare) :
63   TNamed( name, name ),
64   fClassMask((index<51) ? (1ull << ULong64_t(index-1)): 0),
65   fClassMaskNext50((index<51) ? 0 :(1ull << ULong64_t(index-51))),
66   fIndex(index),
67   fDescriptor( desc ),
68   fCluster( clus ),
69   fPFProtection( pfp ),
70   fPrescaler( prescaler ),
71   fAllRare( allrare ),
72   fStatus(kFALSE),
73   fTimeGroup(0),
74   fTimeWindow(0)
75 {
76   // Constructor
77   // This should be used with old version of config
78   for(Int_t i = 0; i < kNMaxMasks; i++)fMask[i]=0; 
79   fMask[0]=mask;
80 }
81
82 //_____________________________________________________________________________
83 AliTriggerClass::AliTriggerClass( AliTriggerConfiguration *config,
84                                   TString & name, UChar_t index,
85                                   TString &desc, TString &clus,
86                                   TString &pfp, TString &mask,
87                                   UInt_t prescaler, Bool_t allrare) :
88   TNamed( name, name ),
89   fClassMask((index<51) ? (1ull << ULong64_t(index-1)): 0),
90   fClassMaskNext50((index<51) ? 0 :(1ull << ULong64_t(index-51))),
91   fIndex(index),
92   fDescriptor( NULL ),
93   fCluster( NULL ),
94   fPFProtection( NULL ),
95   fPrescaler( prescaler ),
96   fAllRare( allrare ),
97   fStatus(kFALSE),
98   fTimeGroup(0),
99   fTimeWindow(0)
100 {
101   // This should be used with old version of config
102   fDescriptor = (AliTriggerDescriptor*)config->GetDescriptors().FindObject(desc);
103   fCluster = (AliTriggerCluster*)config->GetClusters().FindObject(clus);
104   pfp.ReplaceAll("{","");
105   pfp.ReplaceAll("}","");
106   fPFProtection = (AliTriggerPFProtection*)config->GetPFProtections().FindObject(pfp);
107   // BC masks
108   for(Int_t i = 0; i < kNMaxMasks; i++)fMask[i]=0;
109   mask.ReplaceAll("{","");
110   mask.ReplaceAll("}","");
111   fMask[0] = (AliTriggerBCMask*)config->GetMasks().FindObject(mask);
112 }
113 //_____________________________________________________________________________
114 AliTriggerClass::AliTriggerClass( AliTriggerConfiguration *config,
115                                   TString & name, UChar_t index,
116                                   TString &desc, TString &clus,
117                                   TString &pfp,
118                                   UInt_t prescaler, Bool_t allrare,
119                                   UInt_t timegroup,UInt_t timewindow) :
120   TNamed( name, name ),
121   fClassMask((index<51) ? (1ull << ULong64_t(index-1)): 0),
122   fClassMaskNext50((index<51) ? 0 :(1ull << ULong64_t(index-51))),
123   fIndex(index),
124   fDescriptor( NULL ),
125   fCluster( NULL ),
126   fPFProtection( NULL ),
127   fPrescaler( prescaler ),
128   fAllRare( allrare ),
129   fStatus(kFALSE),
130   fTimeGroup(timegroup),
131   fTimeWindow(timewindow)
132 {
133   fDescriptor = (AliTriggerDescriptor*)config->GetDescriptors().FindObject(desc);
134   fCluster = (AliTriggerCluster*)config->GetClusters().FindObject(clus);
135   pfp.ReplaceAll("{","");
136   pfp.ReplaceAll("}","");
137   fPFProtection = (AliTriggerPFProtection*)config->GetPFProtections().FindObject(pfp);
138   // masks are added by seter
139   for(Int_t i = 0; i < kNMaxMasks; i++)fMask[i]=0;
140 }
141 //_____________________________________________________________________________
142 AliTriggerClass::~AliTriggerClass() 
143
144   // Destructor
145 }
146 //_____________________________________________________________________________
147 AliTriggerClass::AliTriggerClass( const AliTriggerClass& trclass ):
148   TNamed( trclass ),
149   fClassMask(trclass.fClassMask),
150   fClassMaskNext50(trclass.fClassMaskNext50),
151   fIndex(trclass.fIndex),
152   fDescriptor(trclass.fDescriptor),
153   fCluster(trclass.fCluster),
154   fPFProtection(trclass.fPFProtection),
155   fPrescaler(trclass.fPrescaler),
156   fAllRare(trclass.fAllRare),
157   fStatus(trclass.fStatus),
158   fTimeGroup(trclass.fTimeGroup),
159   fTimeWindow(trclass.fTimeWindow)
160 {
161    // Copy constructor
162    for(Int_t i = 0; i < kNMaxMasks; i++)fMask[i]=trclass.fMask[i];
163 }
164 //______________________________________________________________________________
165 AliTriggerClass& AliTriggerClass::operator=(const AliTriggerClass& trclass)
166 {
167    // AliTriggerClass assignment operator.
168
169    if (this != &trclass) {
170       TNamed::operator=(trclass);
171       fClassMask = trclass.fClassMask;
172       fClassMaskNext50 = trclass.fClassMaskNext50;
173       fIndex=trclass.fIndex;
174       fDescriptor = trclass.fDescriptor;
175       fCluster = trclass.fCluster;
176       fPFProtection = trclass.fPFProtection;
177       for(Int_t i=0; i< kNMaxMasks; i++)fMask[i]=trclass.fMask[i];
178       fPrescaler = trclass.fPrescaler;
179       fAllRare = trclass.fAllRare;
180       fStatus = trclass.fStatus;
181       fTimeGroup = trclass.fTimeGroup;
182       fTimeWindow = trclass.fTimeWindow;
183    }
184    return *this;
185 }
186 //_____________________________________________________________________________
187 Bool_t AliTriggerClass::SetMasks(AliTriggerConfiguration* config,TString& masks)
188 {
189  masks.ReplaceAll("{","");
190  masks.ReplaceAll("}","");
191  masks.ReplaceAll(" ","");
192  masks.ReplaceAll("\t","");
193  TObjArray *tokens = masks.Tokenize(",");
194  Int_t ntokens = tokens->GetEntriesFast();
195  if(ntokens==0){
196    delete tokens;
197    AliError(Form("The class (%s) has invalid mask pattern: (%s)",GetName(),masks.Data()));
198    return kFALSE;
199  }
200  Int_t nmask=0;
201  while(fMask[nmask])nmask++;
202  if(nmask+ntokens>=kNMaxMasks){
203    delete tokens;
204    AliError(Form("The class (%s) exceeds %i masks",GetName(),kNMaxMasks));
205    return kFALSE;
206  }
207  for(Int_t i=nmask; i<nmask+ntokens; i++){
208     fMask[i] = (AliTriggerBCMask*)config->GetMasks().FindObject(((TObjString*)tokens->At(i-nmask))->String());
209     if(!fMask[i]){
210       AliError(Form("The class (%s) unknown mask %s",GetName(),(((TObjString*)tokens->At(i-nmask))->String().Data())));
211       return kFALSE;
212     }
213  }
214  delete tokens;
215  return kTRUE;
216 }
217 //_____________________________________________________________________________
218 Bool_t AliTriggerClass::CheckClass(AliTriggerConfiguration* config) const
219 {
220   // Check the existance of trigger inputs and functions
221   // and the logic used.
222   // Return false in case of wrong class
223   // definition.
224
225   if (!fClassMask && !fClassMaskNext50) {
226     AliError(Form("The class (%s) has invalid mask pattern !",GetName()));
227     return kFALSE;
228   }
229
230   // check consistency of index and mask
231
232   if (!config->GetDescriptors().FindObject(fDescriptor)) {
233     AliError(Form("The class (%s) contains invalid descriptor !",GetName()));
234     return kFALSE;
235   }
236   else {
237     if (!(fDescriptor->CheckInputsAndFunctions(config->GetInputs(),config->GetFunctions()))) {
238       AliError(Form("The class (%s) contains bad descriptor !",GetName()));
239       return kFALSE;
240     }
241   }
242
243   if (!config->GetClusters().FindObject(fCluster)) {
244     AliError(Form("The class (%s) contains invalid cluster !",GetName()));
245     return kFALSE;
246   }
247
248   if (!config->GetPFProtections().FindObject(fPFProtection)) {
249     AliError(Form("The class (%s) contains invalid past-future protection !",GetName()));
250     return kFALSE;
251   }
252   
253   for(Int_t i=0; i< kNMaxMasks; i++){
254      if(fMask[i]){
255         if (!config->GetMasks().FindObject(fMask[i])) {
256            AliError(Form("The class (%s) contains invalid BC mask !",GetName()));
257            return kFALSE;
258        }
259      }
260   }
261   return kTRUE;
262 }
263
264 //_____________________________________________________________________________
265 void AliTriggerClass::Trigger( const TObjArray& inputs , const TObjArray& functions)
266 {
267    // Check if the inputs satify the trigger class conditions
268   fStatus = fDescriptor->Trigger(inputs,functions);
269 }
270
271 //_____________________________________________________________________________
272 Bool_t AliTriggerClass::IsActive( const TObjArray& inputs, const TObjArray& functions) const
273 {
274    // Check if the inputs satify the trigger class conditions
275   if (fDescriptor)
276     return fDescriptor->IsActive(inputs,functions);
277
278   return kFALSE;
279 }
280
281 //_____________________________________________________________________________
282 void AliTriggerClass::Print( const Option_t* ) const
283 {
284    // Print
285   cout << "Trigger Class:" << endl;
286   cout << "  Name:         " << GetName() << endl;
287   cout << "  ClassBit:    1..50 0x" << hex << fClassMask << " 51..10 0x" << fClassMaskNext50 << dec << endl;
288   cout << "  Index:        " <<  (UInt_t)fIndex <<  endl;
289   cout << "  Descriptor:   " << fDescriptor->GetName() << endl;
290   cout << "  Cluster:      " << fCluster->GetName() << endl;
291   cout << "  PF Protection:" << fPFProtection->GetName() << endl;
292   cout << "  BC Mask:      " ;
293   for(Int_t i=0; i< kNMaxMasks; i++)if(fMask[i])cout << fMask[i]->GetName() << " ";
294   cout << endl;
295   cout << "  Prescaler:    " << fPrescaler << endl;
296   cout << "  AllRare:      " << fAllRare << endl;
297   cout << "  Time Group:      " << fTimeGroup << endl;
298   cout << "  Time Window:      " << fTimeWindow << endl;
299   if (fStatus)
300      cout << "   Class is fired      " << endl;
301    else
302      cout << "   Class is not fired  " << endl;
303 }
304 //______________________________________________________________________
305  Int_t AliTriggerClass::GetDownscaleFactor(Double_t& ds) const 
306 {
307  // There are 2 types of downscaling:
308  // - Random time veto downscale (option=0 <=> bit 31=0)
309  // - Class busy veto (option=1 <=> bit 31=1)
310  // 
311  Int_t option=0;
312  if(fPrescaler&(1<<31)) option=1;
313  if(option){
314    ds = (fPrescaler&0x1ffffff)/100.; // class busy in milisec
315  }else{
316    ds = 1.- fPrescaler/2097151.;     // reduction factor in %
317  }
318  return option;
319 }
320