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