Increased verbosity for data format errors (A. Mastroserio)
[u/mrichter/AliRoot.git] / TRIGGER / AliTrigEvent.cxx
CommitLineData
88f843f1 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
88f843f1 19#include "AliTrigEvent.h"
20
21#include <TClass.h>
22#include <TBits.h>
23#include <TROOT.h>
24
88f843f1 25ClassImp(AliTrigEvent)
26
79e35bac 27//==============================================================================
28// AliTrigEvent - Base class for generic information exchanged by a trigger
29// device. Trigger inputs and outputs are represented and
30// handled via AliTrigEvent objects. Trigger events are typically
31// wrappers for the information exchanged on a single I/O slot
32// or a group of correlated inputs.
33//==============================================================================
34
88f843f1 35//______________________________________________________________________________
79e35bac 36void AliTrigEvent::Activate(Bool_t flag)
88f843f1 37{
38// Activate/deactivate this signal.
39 TObject::SetBit(kActive, flag);
40}
41
42ClassImp(AliTrigEventWithMask)
43
44//______________________________________________________________________________
45Bool_t AliTrigEventWithMask::ImportData(AliTrigEvent *source)
46{
47// Import data from likewise signal.
48 AliTrigEventWithMask *src = (AliTrigEventWithMask *)source;
79e35bac 49 SetValue(src->GetValue());
88f843f1 50 return kTRUE;
51}
52
79e35bac 53//______________________________________________________________________________
54void AliTrigEventWithMask::SetValue(TBits *value)
55{
56// Set the mask value.
57 *fValue = *value;
58}
59
60//______________________________________________________________________________
61AliTrigEventWithMask::AliTrigEventWithMask(const AliTrigEventWithMask &other)
62 :AliTrigEvent(other),
63 fValue(NULL)
64{
65// Copy constructor.
66 *fValue = *other.fValue;
67}
68
69//______________________________________________________________________________
70AliTrigEventWithMask &AliTrigEventWithMask::operator=(const AliTrigEventWithMask &other)
71{
72// Assignment operator.
73 if (&other == this) return *this;
74 AliTrigEvent::operator=(other);
75 *fValue = *other.fValue;
76 return *this;
77}
78
88f843f1 79ClassImp(AliTrigEventWithObject)
80
81//______________________________________________________________________________
82AliTrigEventWithObject::AliTrigEventWithObject(const char *classname)
83 :AliTrigEvent(),
84 fValue(0),
79e35bac 85 fType("")
88f843f1 86{
87// Normal constructor where a class name is provided for the embedded object.
88// If the event is created in this way one will only be able to connect to
79e35bac 89// events embedding the same object type (via connectors). If empty string the type
88f843f1 90// will be set upon the first call of SetValue.
79e35bac 91 SetType(classname);
88f843f1 92}
93
94//______________________________________________________________________________
95AliTrigEventWithObject::AliTrigEventWithObject(const AliTrigEventWithObject &other)
96 :AliTrigEvent(other),
79e35bac 97 fValue(NULL),
88f843f1 98 fType(other.fType)
99{
100// Copy constructor.
79e35bac 101 TClass* pClass=TClass::GetClass(fType);
102 if (!pClass) return;
103 fValue = (TObject*)pClass->New();
104 fValue->Copy(*other.fValue);
88f843f1 105}
106
107//______________________________________________________________________________
79e35bac 108AliTrigEventWithObject &AliTrigEventWithObject::operator=(const AliTrigEventWithObject &other)
88f843f1 109{
110// Assignment operator.
79e35bac 111 if (&other == this) return *this;
112 AliTrigEvent::operator=(other);
113 fType = other.fType;
114 TClass* pClass=TClass::GetClass(fType);
115 if (!pClass) return *this;
116 fValue = (TObject*)pClass->New();
117 fValue->Copy(*other.fValue);
118 return *this;
88f843f1 119}
120
121//______________________________________________________________________________
122Bool_t AliTrigEventWithObject::ImportData(AliTrigEvent *source)
123{
124// Import data from likewise signal.
125 AliTrigEventWithObject *src = (AliTrigEventWithObject *)source;
126 Bool_t done = SetValue(src->GetValue());
127 if (!done) Error("ImportData", "Cannot import object <%s> of class <%s> since event type was set to: <%s>",
79e35bac 128 src->GetValue()->GetName(), src->GetValue()->ClassName(), fType.Data());
88f843f1 129 return done;
130}
131
132//______________________________________________________________________________
133Bool_t AliTrigEventWithObject::SetType(const char *classname)
134{
135// Set the type of this event. Can be done only once.
79e35bac 136 if (!strlen(classname)) return kFALSE;
137 if (!fType.IsNull()) {
138 Error("SetType", "Type for this trigger event already set to: %s", fType.Data());
139 return kFALSE;
140 }
88f843f1 141 TClass *type = gROOT->GetClass(classname);
142 if (!type) {
143 Error("SetType", "Unknown class %s", classname);
144 return kFALSE;
145 }
79e35bac 146 fType = classname;
88f843f1 147 return kTRUE;
148}
149
150//______________________________________________________________________________
151Bool_t AliTrigEventWithObject::SetValue(TObject *value)
152{
153// Set the current event content. Checks consistency with event type.
154 if (!value) {
155 // Reset current value.
156 fValue = NULL;
157 return kTRUE;
158 }
88f843f1 159 // Set the type if used for the first time.
79e35bac 160 if (!fType) fType = value->ClassName();
88f843f1 161 fValue = value;
162 return kTRUE;
163}