Some of the trigger base classes. Steering part not yet in.
[u/mrichter/AliRoot.git] / TRIGGER / AliTrigDevice.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 //   AliTrigDevice - Generic device class. A device has a number of inputs and
21 // outputs. The data handled by the device can be either Boolean (digital
22 // devices) or arbitrary (wrapped by the class AliTrigSignal). A device must
23 // provide a response function that may depend on the output id. To replay the 
24 // device response function for a given output id, the device MUST register the
25 // output via the RegisterOutput() method providing the delay in arbitrary time
26 // units. After the execution of the response for some output, the Emit() method
27 // will be invoked to propagate the computed result to all devices connected to 
28 // this output. The method Connect() must be implemented by all devices and should
29 // create a connector specific to the device types that are linked. 
30 // The ResetInputs() method is called during simulation after the execution of 
31 // all response functions.
32 //==============================================================================
33
34 #include "AliTrigDevice.h"
35
36 ClassImp(AliTrigDevice)
37
38 //______________________________________________________________________________
39 AliTrigDevice::AliTrigDevice()
40 {
41 // Destructor.
42    if (fComponents) delete fComponents;
43 }   
44
45 //______________________________________________________________________________
46 AliTrigDevice::AliTrigDevice(const AliTrigDevice &other)
47                     :TNamed(other), 
48                      fNinputs(other.fNinputs), 
49                      fNoutputs(other.fNoutputs),
50                      fComponents(0)
51 {
52 // Copy ctor.
53   if (other.fComponents) {
54      fComponents = new TObjArray();
55      TIter next(other.fComponents);
56      AliTrigDevice *dev;
57      while ((dev=(AliTrigDevice*)next())) fComponents->Add(dev);
58   }   
59 }                        
60
61 //______________________________________________________________________________
62 AliTrigDevice& AliTrigDevice::operator=(const AliTrigDevice &other)
63 {
64 // Assignment
65   if (&other == this) return *this;
66   TNamed::operator=(other);
67   fNinputs  = other.fNinputs;
68   fNoutputs = other.fNoutputs;
69   fComponents = 0;
70   if (other.fComponents) {
71      fComponents = new TObjArray();
72      TIter next(other.fComponents);
73      AliTrigDevice *dev;
74      while ((dev=(AliTrigDevice*)next())) fComponents->Add(dev);
75   }   
76   return *this;
77 }
78
79 //______________________________________________________________________________
80 void AliTrigDevice::AddDevice(AliTrigDevice *other)
81 {
82 // Add another device as component of this device.
83   if (!fComponents) fComponents = new TObjArray();
84   fComponents->Add(other);
85 }
86
87 //______________________________________________________________________________
88 Int_t AliTrigDevice::GetNcomponents()
89 {
90 // Returns number of components.
91   if (!fComponents) return 0;
92   return fComponents->GetEntriesFast();
93 }
94
95 //______________________________________________________________________________
96 AliTrigDevice *AliTrigDevice::GetComponent(Int_t n)
97 {
98 // Get component at index n.
99    if (!fComponents) return NULL;
100    return fComponents->At(n);
101 }
102    
103 //______________________________________________________________________________
104 Bool_t AliTrigDevice::RegisterResponseFunction(AliTrigScheduler *calendar, UInt_t output, Int_t delay) const
105 {
106 // Register the response functions to be replayed by the provided scheduler.
107 // The delay argument is in arbitrary time units with respect to the startup
108 // reference of the simulation.
109 // CALLING SEQUENCE:
110 //   The delay behaves like a BUSY gate for the device and MUST be called when
111 //   configuring the whole setup of devices. The method may fail in case the
112 //   determinism is not satisfied with other connected devices providing inputs.
113    return calendar->RegisterResponseFunction(this, output, delay);
114 }