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