]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliTriggerDescriptor.cxx
Fixed leak in reading ESD friends with AliESDInputHandler
[u/mrichter/AliRoot.git] / STEER / ESD / AliTriggerDescriptor.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 descriptor objects
19 //
20 //
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #include <Riostream.h>
24 #include <TObjArray.h>
25 #include <TObjString.h>
26
27 #include "AliLog.h"
28 #include "AliTriggerDescriptor.h"
29 #include "AliTriggerInput.h"
30 #include "AliTriggerInteraction.h"
31
32 using std::endl;
33 using std::cout;
34 ClassImp(AliTriggerDescriptor)
35
36 //_____________________________________________________________________________
37 AliTriggerDescriptor::AliTriggerDescriptor():
38   TNamed()
39 {
40   // Default constructor
41 }
42
43 //_____________________________________________________________________________
44 AliTriggerDescriptor::AliTriggerDescriptor( TString & name, TString &cond ):
45   TNamed( name, cond )
46 {
47   // Constructor
48 }
49 //_____________________________________________________________________________
50 AliTriggerDescriptor::~AliTriggerDescriptor() 
51
52   // Destructor
53 }
54 //_____________________________________________________________________________
55 AliTriggerDescriptor::AliTriggerDescriptor( const AliTriggerDescriptor& desc ):
56   TNamed( desc )
57 {
58    // Copy constructor
59 }
60
61 //______________________________________________________________________________
62 AliTriggerDescriptor& AliTriggerDescriptor::operator=(const AliTriggerDescriptor& desc)
63 {
64    // AliTriggerDescriptor assignment operator.
65
66    if (this != &desc) {
67       TNamed::operator=(desc);
68    }
69    return *this;
70 }
71
72 //_____________________________________________________________________________
73 Bool_t AliTriggerDescriptor::CheckInputsAndFunctions(const TObjArray &inputs, const TObjArray &functions) const
74 {
75   // Check the existance of trigger inputs and functions
76   // and the logic used.
77   // Return false in case of wrong interaction
78   // definition.
79
80    TString condition( GetTitle() );
81    TObjArray* tokens = condition.Tokenize(" !&|()\t");
82
83    Bool_t IsInput = kFALSE;
84
85    Int_t ntokens = tokens->GetEntriesFast();
86    for( Int_t i=0; i<ntokens; i++ ) {
87       TObjString* iname = (TObjString*)tokens->At( i );
88       if (functions.FindObject(iname->String())) {
89         // Logical function of the first 4 inputs
90         if (IsInput) {
91           AliError("Logical functions can not follow inputs, they are always declared first !");
92           delete tokens;
93           return kFALSE;
94         }
95         IsInput = kFALSE;
96         continue;
97       }
98       if (inputs.FindObject(iname->String())) {
99         // already a trigger input
100         IsInput = kTRUE;
101         continue;
102       }
103       AliError(Form("Invalid trigger input or function (%s)",iname->String().Data()));
104       delete tokens;
105       return kFALSE;
106    }
107
108    delete tokens;
109    return kTRUE;
110 }
111
112 //_____________________________________________________________________________
113 Bool_t AliTriggerDescriptor::IsActive(const TObjArray &inputs, const TObjArray &functions) const
114 {
115   // Check if the trigger inputs and functions
116   // are active
117   // Return false in case one or more inputs
118   // are disabled
119    TString condition( GetTitle() );
120    TObjArray* tokens = condition.Tokenize(" !&|()\t");
121
122    Int_t ntokens = tokens->GetEntriesFast();
123    for( Int_t i=0; i<ntokens; i++ ) {
124       TObjString* iname = (TObjString*)tokens->At( i );
125       AliTriggerInteraction *interact = (AliTriggerInteraction *)functions.FindObject(iname->String());
126       if (interact) {
127         if (!interact->IsActive(inputs)) {
128           AliWarning(Form("The descriptor (%s) will be disabled, because the function (%s) is disabled",
129                           GetName(),iname->String().Data()));
130           delete tokens;
131           return kFALSE;
132         }
133         continue;
134       }
135       AliTriggerInput *inp = (AliTriggerInput *)inputs.FindObject(iname->String());
136       if (inp) {
137         if (!inp->IsActive()) {
138           AliWarning(Form("The descriptor (%s) will be disabled, because the input (%s) is disabled",
139                           GetName(),iname->String().Data()));
140           delete tokens;
141           return kFALSE;
142         }
143         continue;
144       }
145       AliError(Form("Desciptor (%s) contains invalid trigger input or function (%s)",
146                     GetName(),iname->String().Data()));
147       delete tokens;
148       return kFALSE;
149    }
150
151    delete tokens;
152    return kTRUE;
153
154 }
155
156 //_____________________________________________________________________________
157 Bool_t AliTriggerDescriptor::Trigger( const TObjArray &inputs, const TObjArray &functions) const
158 {
159   // Check if the inputs and functions 
160   // satify the descriptor conditions 
161
162   TString condition( GetTitle() );
163   TObjArray* tokens = condition.Tokenize(" !&|()\t");
164
165   Int_t ntokens = tokens->GetEntriesFast();
166   for( Int_t i=0; i<ntokens; i++ ) {
167     TObjString* iname = (TObjString*)tokens->At( i );
168     AliTriggerInteraction *interact = (AliTriggerInteraction *)functions.FindObject(iname->String());
169     if (interact) {
170       if (!interact->Trigger(inputs)) {
171         delete tokens;
172         return kFALSE;
173       }
174       continue;
175     }
176     AliTriggerInput *inp = (AliTriggerInput *)inputs.FindObject(iname->String());
177     if (inp) {
178       if (!inp->Status()) {
179         delete tokens;
180         return kFALSE;
181       }
182       continue;
183     }
184     AliError(Form("Desciptor (%s) contains invalid trigger input or function (%s)",
185                   GetName(),iname->String().Data()));
186     delete tokens;
187     return kFALSE;
188   }
189
190   delete tokens;
191   return kTRUE;
192
193 }
194
195 //_____________________________________________________________________________
196 void AliTriggerDescriptor::Print( const Option_t* ) const
197 {
198    // Print
199   cout << "Trigger Descriptor:" << endl;
200   cout << "  Name:             " << GetName() << endl;
201   cout << "  Logic:            " << GetTitle() << endl;
202 }