]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliTriggerCondition.cxx
First prototype of the trigger classes (E. Lopez Torres)
[u/mrichter/AliRoot.git] / STEER / AliTriggerCondition.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
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 /* $Id$ */
18
19 ///////////////////////////////////////////////////////////////////////////////
20 //
21 //  Class to define a Trigger Condition                                                                                                                 //
22 //
23 //  Ej                       Condition                        name   Description   class mask
24 //         inputs names  ___ _________ _________
25 //                          |         |         |
26 //   AliTriggerCondition("(T0_L0 & VZERO_MB_L0 & TRD_PRE_L0)", "MB", "Minimum Bias", 0x0100 );
27 //
28 //  A Trigger condition is defined from logical combination of trigger
29 //  inputs names (boolean expression), trigger inputs names must match
30 //  with the inputs defined in AliTriggerDetector classes
31 //
32 //      Allow operators:
33 //                &    =>  and
34 //                |    =>  or
35 //                !    =>  not
36 //
37 //    The name must be globally unique. Spaces are not allowed.
38 //
39 //    A maximun of 50 diffentes trigger signatures ("trigger classes" or conditions)
40 //    are allow to run simultaneously.
41 //    So, the "class mask" should set only 1 bit from the position 1 to 50.
42 //
43 //
44 ///////////////////////////////////////////////////////////////////////////////
45
46 #include <Riostream.h>
47 #include <TString.h>
48 #include <TObjString.h>
49 #include <TObjArray.h>
50
51 #include "AliLog.h"
52 #include "AliExpression.h"
53 #include "AliTriggerInput.h"
54 #include "AliTriggerCondition.h"
55
56 ClassImp( AliTriggerCondition )
57
58 //_____________________________________________________________________________
59 AliTriggerCondition::AliTriggerCondition() :
60    TNamed(),
61    fClassMask( 0 ),
62    fCondition( "" ),
63    fStatus( kFALSE )
64 {
65    // Default ctor
66 }
67
68 //______________________________________________________________________________
69 AliTriggerCondition::AliTriggerCondition(const AliTriggerCondition &cond) :
70    TNamed( cond ),
71    fClassMask( cond.fClassMask ),
72    fCondition( cond.fCondition ),
73    fStatus( cond.fStatus )
74 {
75    // AliTriggerCondition copy ctor.
76 }
77
78 //______________________________________________________________________________
79 AliTriggerCondition& AliTriggerCondition::operator=(const AliTriggerCondition& rhs)
80 {
81    // AliTriggerCondition assignment operator.
82
83    if (this != &rhs) {
84       TObject::operator=(rhs);
85       fClassMask  = rhs.fClassMask;
86       fCondition = rhs.fCondition;
87    }
88    return *this;
89 }
90
91 //_____________________________________________________________________________
92 AliTriggerCondition::AliTriggerCondition( TString & condition, TString & name,
93                                           TString & description, Long_t mask ) :
94    TNamed( name, description ),
95    fClassMask( mask ),
96    fCondition( condition ),
97    fStatus( kFALSE )
98 {
99    // Default Constructor
100
101    // check the expression 
102    AliExpression* exp = new AliExpression( fCondition );
103    delete exp;
104 }
105
106
107 //_____________________________________________________________________________
108 Bool_t AliTriggerCondition::CheckInputs( TObjArray& inputs )
109 {
110    // The "inputs" array should be the list of all possible inputs
111    // so each input in the condition is checked to be present in the array
112    // return false if one input is missing
113
114    TString condition( fCondition );
115    TObjArray* tokens = condition.Tokenize(".&+| ");
116
117    Int_t ntokens = tokens->GetEntriesFast();
118    for( Int_t i=0; i<ntokens; i++ ) {
119       TObjString* iname = (TObjString*)tokens->At( i );
120       Int_t nInputs = inputs.GetEntriesFast();
121       Int_t j;
122       for( j=0; j<nInputs; j++ ) {
123          AliTriggerInput* in = (AliTriggerInput*)inputs.At( j );
124          if( (iname->String()).CompareTo( in->GetName() ) == 0 ) break;
125       }
126
127       if( j >= nInputs ) {
128          AliWarning( Form( "The trigger input (%s) is not available for Condition (%s)",
129                       iname->String().Data(), GetName() ) );
130          delete tokens;
131          return kFALSE;
132       }
133    }
134
135    delete tokens;
136    return kTRUE;
137 }
138
139 //_____________________________________________________________________________
140 void AliTriggerCondition::Trigger( TObjArray& inputs )
141 {
142    // Check if the inputs satify the expression condition 
143    
144    AliExpression* exp = new AliExpression( fCondition );
145 //   cout << exp->Unparse() << endl;
146    fStatus = exp->Value( inputs );
147    delete exp;
148 }
149
150 //_____________________________________________________________________________
151 void AliTriggerCondition::Print( const Option_t* ) const
152 {
153    // Print
154    cout << "Trigger Condition:" << endl;
155    cout << "  Name:        " << GetName() << endl;
156    cout << "  Description: " << GetTitle() << endl;
157    cout << "  Condition:   " << fCondition << endl;
158    cout << "  Class Mask:  " << "0x" << hex << fClassMask << dec << endl;
159    cout << "  Value:       " << GetValue() << endl;
160 }