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