1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // Author: Andrei Gheata, 28/07/2009
20 #include "AliTrigDevice.h"
22 #include <TObjArray.h>
23 #include "AliTrigScheduler.h"
24 #include "AliTrigScheduledEntry.h"
26 ClassImp(AliTrigDevice)
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
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.
38 // The ResetInputs() method is called during simulation after the execution of
39 // all response functions.
40 //==============================================================================
42 //______________________________________________________________________________
43 AliTrigDevice::AliTrigDevice()
49 fResponseFunctions(NULL)
54 //______________________________________________________________________________
55 AliTrigDevice::AliTrigDevice(const char *name, Int_t ninputs, Int_t noutputs)
59 fScheduler(new AliTrigScheduler(name)),
61 fResponseFunctions(NULL)
66 //______________________________________________________________________________
67 AliTrigDevice::~AliTrigDevice()
71 if (fComponents) {fComponents->Delete(); delete fComponents;}
72 if (fResponseFunctions) {fResponseFunctions->Delete(); delete fResponseFunctions;}
75 //______________________________________________________________________________
76 void AliTrigDevice::AddDevice(AliTrigDevice *other)
78 // Add another device as component of this device.
79 if (!fComponents) fComponents = new TObjArray();
80 fComponents->Add(other);
83 //______________________________________________________________________________
84 Int_t AliTrigDevice::GetNcomponents() const
86 // Returns number of components.
87 if (!fComponents) return 0;
88 return fComponents->GetEntriesFast();
91 //______________________________________________________________________________
92 AliTrigDevice *AliTrigDevice::GetComponent(Int_t n)
94 // Get component at index n.
95 if (!fComponents) return NULL;
96 return (AliTrigDevice*)fComponents->At(n);
99 //______________________________________________________________________________
100 AliTrigScheduledResponse *AliTrigDevice::GetResponseFunction(const char *name)
102 // Get a response function by name.
103 if (!fResponseFunctions) return NULL;
104 return (AliTrigScheduledResponse*)fResponseFunctions->FindObject(name);
107 //______________________________________________________________________________
108 AliTrigScheduledResponse *AliTrigDevice::RegisterResponseFunction(const char *name, Int_t output, Int_t delay)
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",
120 AliTrigScheduledResponse *response = new AliTrigScheduledResponse(name, (AliTrigDevice*)this, output, delay);
121 fResponseFunctions->Add(response);