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 | |
79e35bac |
19 | |
20 | #include "AliTrigDevice.h" |
21 | |
22 | #include <TObjArray.h> |
23 | #include "AliTrigScheduler.h" |
24 | #include "AliTrigScheduledEntry.h" |
25 | |
26 | ClassImp(AliTrigDevice) |
88f843f1 |
27 | //============================================================================== |
28 | // AliTrigDevice - Generic device class. A device has a number of inputs and |
29 | // outputs. The data handled by the device can be either Boolean (digital |
30 | // devices) or arbitrary (wrapped by the class AliTrigSignal). A device must |
31 | // provide a response function that may depend on the output id. To replay the |
32 | // device response function for a given output id, the device MUST register the |
79e35bac |
33 | // output via the RegisterResponseFunction() method providing the delay in arbitrary time |
34 | // units. After the execution of the response for some output, the result will |
35 | // be propagated to all devices connected to this output. The method CreateDevice() |
36 | // must be implemented by all devices and should connect all component devices |
37 | // and register all response functions. |
88f843f1 |
38 | // The ResetInputs() method is called during simulation after the execution of |
39 | // all response functions. |
40 | //============================================================================== |
41 | |
88f843f1 |
42 | //______________________________________________________________________________ |
43 | AliTrigDevice::AliTrigDevice() |
79e35bac |
44 | :TNamed(), |
45 | fNinputs(0), |
46 | fNoutputs(0), |
47 | fScheduler(NULL), |
48 | fComponents(NULL), |
49 | fResponseFunctions(NULL) |
88f843f1 |
50 | { |
79e35bac |
51 | // I/O constructor. |
52 | } |
88f843f1 |
53 | |
54 | //______________________________________________________________________________ |
79e35bac |
55 | AliTrigDevice::AliTrigDevice(const char *name, Int_t ninputs, Int_t noutputs) |
56 | :TNamed(name, ""), |
57 | fNinputs(ninputs), |
58 | fNoutputs(noutputs), |
59 | fScheduler(new AliTrigScheduler(name)), |
60 | fComponents(NULL), |
61 | fResponseFunctions(NULL) |
88f843f1 |
62 | { |
79e35bac |
63 | // Constructor. |
64 | } |
88f843f1 |
65 | |
66 | //______________________________________________________________________________ |
79e35bac |
67 | AliTrigDevice::~AliTrigDevice() |
88f843f1 |
68 | { |
79e35bac |
69 | // Destructor. |
70 | delete fScheduler; |
71 | if (fComponents) {fComponents->Delete(); delete fComponents;} |
72 | if (fResponseFunctions) {fResponseFunctions->Delete(); delete fResponseFunctions;} |
73 | } |
88f843f1 |
74 | |
75 | //______________________________________________________________________________ |
76 | void AliTrigDevice::AddDevice(AliTrigDevice *other) |
77 | { |
78 | // Add another device as component of this device. |
79 | if (!fComponents) fComponents = new TObjArray(); |
80 | fComponents->Add(other); |
81 | } |
82 | |
83 | //______________________________________________________________________________ |
79e35bac |
84 | Int_t AliTrigDevice::GetNcomponents() const |
88f843f1 |
85 | { |
86 | // Returns number of components. |
87 | if (!fComponents) return 0; |
88 | return fComponents->GetEntriesFast(); |
89 | } |
90 | |
91 | //______________________________________________________________________________ |
92 | AliTrigDevice *AliTrigDevice::GetComponent(Int_t n) |
93 | { |
94 | // Get component at index n. |
79e35bac |
95 | if (!fComponents) return NULL; |
96 | return (AliTrigDevice*)fComponents->At(n); |
88f843f1 |
97 | } |
79e35bac |
98 | |
99 | //______________________________________________________________________________ |
100 | AliTrigScheduledResponse *AliTrigDevice::GetResponseFunction(const char *name) |
101 | { |
102 | // Get a response function by name. |
103 | if (!fResponseFunctions) return NULL; |
104 | return (AliTrigScheduledResponse*)fResponseFunctions->FindObject(name); |
105 | } |
106 | |
88f843f1 |
107 | //______________________________________________________________________________ |
79e35bac |
108 | AliTrigScheduledResponse *AliTrigDevice::RegisterResponseFunction(const char *name, Int_t output, Int_t delay) |
88f843f1 |
109 | { |
79e35bac |
110 | // Creates a response function of the device. The delay argument is in arbitrary |
111 | // time units with respect to the startup reference. Note that the created |
112 | // scheduled entry must be registered to the device scheduler via: |
113 | // fDevice->AddScheduledEntry() method, otherwise it will not be replayed. |
114 | if (!fResponseFunctions) fResponseFunctions = new TObjArray(); |
115 | if (fResponseFunctions->FindObject(name)) { |
116 | Error("RegisterResponseFunction", "A response function named %s was already registered for device %s", |
117 | name, GetName()); |
118 | return NULL; |
119 | } |
120 | AliTrigScheduledResponse *response = new AliTrigScheduledResponse(name, (AliTrigDevice*)this, output, delay); |
121 | fResponseFunctions->Add(response); |
122 | return response; |
88f843f1 |
123 | } |