]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRIGGER/AliTrigEvent.cxx
Some of the trigger base classes. Steering part not yet in.
[u/mrichter/AliRoot.git] / TRIGGER / AliTrigEvent.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 /* $Id$ */
17 // Author: Andrei Gheata, 28/07/2009
18
19 //==============================================================================
20 //   AliTrigEvent - Base class for generic information exchanged by a trigger
21 //                  device. Trigger inputs and outputs are represented and
22 //                  handled via AliTrigEvent objects. Trigger events are typically
23 //                  wrappers for the information exchanged on a single I/O slot
24 //                  or a group of correlated inputs.
25 //==============================================================================
26
27 #include "AliTrigEvent.h"
28
29 #include <TClass.h>
30 #include <TBits.h>
31 #include <TROOT.h>
32
33
34 ClassImp(AliTrigEvent)
35
36 //______________________________________________________________________________
37 AliTrigEvent::Activate()
38 {
39 // Activate/deactivate this signal.
40   TObject::SetBit(kActive, flag);
41 }                        
42
43 ClassImp(AliTrigEventWithMask)
44
45 //______________________________________________________________________________
46 Bool_t AliTrigEventWithMask::ImportData(AliTrigEvent *source)
47 {
48 // Import data from likewise signal.
49   AliTrigEventWithMask *src = (AliTrigEventWithMask *)source;
50   fValue = src->GetValue();
51   return kTRUE;
52 }
53
54 ClassImp(AliTrigEventWithObject)
55
56 //______________________________________________________________________________
57 AliTrigEventWithObject::AliTrigEventWithObject(const char *classname)
58                        :AliTrigEvent(),
59                         fValue(0),
60                         fType(0)
61 {
62 // Normal constructor where a class name is provided for the embedded object.
63 // If the event is created in this way one will only be able to connect to 
64 // events embedding the same object type (via connectors). Otherwise the type
65 // will be set upon the first call of SetValue.
66    fType = gROOT->GetClass(classname);
67    if (!fType) Error("ctor", "No class named <%s> available.", classname);
68 }   
69
70 //______________________________________________________________________________
71 AliTrigEventWithObject::AliTrigEventWithObject(const AliTrigEventWithObject &other)
72                        :AliTrigEvent(other),
73                         fValue(other.fValue),
74                         fType(other.fType)
75 {
76 // Copy constructor.   
77 }
78
79 //______________________________________________________________________________
80 AliTrigEventWithObject::operator=(const AliTrigEventWithObject &other)
81 {
82 // Assignment operator.
83    if (&other == this) return *this;
84    AliTrigEvent::operator=(other);
85    fValue = other.fValue;
86    fType = other.fType;
87 }
88
89 //______________________________________________________________________________
90 Bool_t AliTrigEventWithObject::ImportData(AliTrigEvent *source)
91 {
92 // Import data from likewise signal.
93   AliTrigEventWithObject *src = (AliTrigEventWithObject *)source;
94   Bool_t done = SetValue(src->GetValue());
95   if (!done) Error("ImportData", "Cannot import object <%s> of class <%s> since event type was set to: <%s>",
96                    src->GetValue()->GetName(), src->GetValue()->ClassName(), fType->GetName());
97   return done;
98 }
99
100 //______________________________________________________________________________
101 Bool_t AliTrigEventWithObject::SetType(const char *classname)
102 {
103 // Set the type of this event. Can be done only once.
104   TClass *type = gROOT->GetClass(classname);
105   if (!type) {
106     Error("SetType", "Unknown class %s", classname);
107     return kFALSE;
108   }
109   if (!fType) fType = type;
110   if (fType != type) {
111     Error("SetType", "Type %s not matching the one defined for this event <%s>",
112           classname, fType->GetName());
113     return kFALSE;
114   }
115   return kTRUE;
116 }
117
118 //______________________________________________________________________________
119 Bool_t AliTrigEventWithObject::SetValue(TObject *value)
120 {
121 // Set the current event content. Checks consistency with event type.
122   if (!value) {
123     // Reset current value.
124     fValue = NULL;
125     return kTRUE;
126   }
127   TClass *type = value->IsA();
128   // Set the type if used for the first time.
129   if (!fType) fType = type;
130   // Check consistency of the value with event type.  
131   if (type != fType) return kFALSE;
132   fValue = value;
133   return kTRUE;
134 }