Line data Source code
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 172 : ClassImp(AliTriggerDescriptor)
35 :
36 : //_____________________________________________________________________________
37 : AliTriggerDescriptor::AliTriggerDescriptor():
38 90 : TNamed()
39 450 : {
40 : // Default constructor
41 180 : }
42 :
43 : //_____________________________________________________________________________
44 : AliTriggerDescriptor::AliTriggerDescriptor( TString & name, TString &cond ):
45 18 : TNamed( name, cond )
46 90 : {
47 : // Constructor
48 36 : }
49 : //_____________________________________________________________________________
50 : AliTriggerDescriptor::~AliTriggerDescriptor()
51 288 : {
52 : // Destructor
53 288 : }
54 : //_____________________________________________________________________________
55 : AliTriggerDescriptor::AliTriggerDescriptor( const AliTriggerDescriptor& desc ):
56 0 : TNamed( desc )
57 0 : {
58 : // Copy constructor
59 0 : }
60 :
61 : //______________________________________________________________________________
62 : AliTriggerDescriptor& AliTriggerDescriptor::operator=(const AliTriggerDescriptor& desc)
63 : {
64 : // AliTriggerDescriptor assignment operator.
65 :
66 0 : if (this != &desc) {
67 0 : TNamed::operator=(desc);
68 0 : }
69 0 : 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 72 : TString condition( GetTitle() );
81 108 : TObjArray* tokens = condition.Tokenize(" !&|()\t");
82 :
83 : Bool_t IsInput = kFALSE;
84 :
85 36 : Int_t ntokens = tokens->GetEntriesFast();
86 200 : for( Int_t i=0; i<ntokens; i++ ) {
87 92 : TObjString* iname = (TObjString*)tokens->At( i );
88 138 : if (functions.FindObject(iname->String())) {
89 : // Logical function of the first 4 inputs
90 10 : if (IsInput) {
91 0 : AliError("Logical functions can not follow inputs, they are always declared first !");
92 0 : delete tokens;
93 0 : return kFALSE;
94 : }
95 : IsInput = kFALSE;
96 10 : continue;
97 : }
98 108 : if (inputs.FindObject(iname->String())) {
99 : // already a trigger input
100 : IsInput = kTRUE;
101 36 : continue;
102 : }
103 0 : AliError(Form("Invalid trigger input or function (%s)",iname->String().Data()));
104 0 : delete tokens;
105 0 : return kFALSE;
106 : }
107 :
108 72 : delete tokens;
109 36 : return kTRUE;
110 36 : }
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 0 : TString condition( GetTitle() );
120 0 : TObjArray* tokens = condition.Tokenize(" !&|()\t");
121 :
122 0 : Int_t ntokens = tokens->GetEntriesFast();
123 0 : for( Int_t i=0; i<ntokens; i++ ) {
124 0 : TObjString* iname = (TObjString*)tokens->At( i );
125 0 : AliTriggerInteraction *interact = (AliTriggerInteraction *)functions.FindObject(iname->String());
126 0 : if (interact) {
127 0 : if (!interact->IsActive(inputs)) {
128 0 : AliWarning(Form("The descriptor (%s) will be disabled, because the function (%s) is disabled",
129 : GetName(),iname->String().Data()));
130 0 : delete tokens;
131 0 : return kFALSE;
132 : }
133 0 : continue;
134 : }
135 0 : AliTriggerInput *inp = (AliTriggerInput *)inputs.FindObject(iname->String());
136 0 : if (inp) {
137 0 : if (!inp->IsActive()) {
138 0 : AliWarning(Form("The descriptor (%s) will be disabled, because the input (%s) is disabled",
139 : GetName(),iname->String().Data()));
140 0 : delete tokens;
141 0 : return kFALSE;
142 : }
143 0 : continue;
144 : }
145 0 : AliError(Form("Desciptor (%s) contains invalid trigger input or function (%s)",
146 : GetName(),iname->String().Data()));
147 0 : delete tokens;
148 0 : return kFALSE;
149 : }
150 :
151 0 : delete tokens;
152 0 : return kTRUE;
153 :
154 0 : }
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 144 : TString condition( GetTitle() );
163 216 : TObjArray* tokens = condition.Tokenize(" !&|()\t");
164 :
165 72 : Int_t ntokens = tokens->GetEntriesFast();
166 246 : for( Int_t i=0; i<ntokens; i++ ) {
167 144 : TObjString* iname = (TObjString*)tokens->At( i );
168 216 : AliTriggerInteraction *interact = (AliTriggerInteraction *)functions.FindObject(iname->String());
169 72 : if (interact) {
170 40 : if (!interact->Trigger(inputs)) {
171 40 : delete tokens;
172 20 : return kFALSE;
173 : }
174 0 : continue;
175 : }
176 156 : AliTriggerInput *inp = (AliTriggerInput *)inputs.FindObject(iname->String());
177 52 : if (inp) {
178 52 : if (!inp->Status()) {
179 36 : delete tokens;
180 18 : return kFALSE;
181 : }
182 34 : continue;
183 : }
184 0 : AliError(Form("Desciptor (%s) contains invalid trigger input or function (%s)",
185 : GetName(),iname->String().Data()));
186 0 : delete tokens;
187 0 : return kFALSE;
188 : }
189 :
190 68 : delete tokens;
191 34 : return kTRUE;
192 :
193 72 : }
194 :
195 : //_____________________________________________________________________________
196 : void AliTriggerDescriptor::Print( const Option_t* ) const
197 : {
198 : // Print
199 0 : cout << "Trigger Descriptor:" << endl;
200 0 : cout << " Name: " << GetName() << endl;
201 0 : cout << " Logic: " << GetTitle() << endl;
202 0 : }
|