Added new classes for the new trigger framework:
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 8 Jan 2010 07:49:11 +0000 (07:49 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 8 Jan 2010 07:49:11 +0000 (07:49 +0000)
 AliTrigScheduledEntry - ABC for scheduled responses of a device that is
                         able to fire-up single response functions or the
                         full device scheduled sequence. The start time is
                         in arbitrary units and in case it is 0 will not be
                         considered when ordering by time by schedulers.
 AliTrigScheduledResponse - Scheduled device response function. Fires-up a
                         single response function at a time.
 AliTrigScheduledDevice - Scheduled entry for a full device sequence. Invokes
                         the device scheduler when firing-up.
 AliTrigScheduledGroup - A group of scheduled entries that will simply be
                         fired-up sequentially. The group delay in global time
                         units is the latest start time of the contained
                         entries. A group has a priority assigned by the
                         owner scheduler object. Groups are fired-up according
                         a programable sequence.
 AliTrigScheduledSequence - A programable group sequence. Scheduled groups
                         are owned and controlled by a trigger scheduler. They
                         are fired-up in such a sequence. A sequence supports some
                         default modes but can also be programed manually.
 AliTrigScheduler -      Device response function scheduler. Every device has a
                         scheduler, but the same scheduler can replay responses of
                         several devices. A scheduler holds groups of scheduled
                         entries. The groups can be replayed in programable
                         sequences. A default group and sequence are always created.

14 files changed:
TRIGGER/AliTrigConnector.cxx
TRIGGER/AliTrigConnector.h
TRIGGER/AliTrigDevice.cxx
TRIGGER/AliTrigDevice.h
TRIGGER/AliTrigDigitalCircuit.cxx
TRIGGER/AliTrigDigitalCircuit.h
TRIGGER/AliTrigEvent.cxx
TRIGGER/AliTrigEvent.h
TRIGGER/AliTrigScheduledEntry.cxx [new file with mode: 0644]
TRIGGER/AliTrigScheduledEntry.h [new file with mode: 0644]
TRIGGER/AliTrigScheduler.cxx [new file with mode: 0644]
TRIGGER/AliTrigScheduler.h [new file with mode: 0644]
TRIGGER/TRIGGERbaseLinkDef.h
TRIGGER/libTRIGGERbase.pkg

index 0a82cc7..e91df70 100644 (file)
@@ -45,8 +45,8 @@ AliTrigConnector::AliTrigConnector(const AliTrigConnector &other)
 {
 // Copy ctor.
   if (fArraySize && other.fInputs) {
-    fInputs = new UInt_t[fArraySize];
-    memcpy(fInputs, other.fInputs, fNclients*sizeof(UInt_t));
+    fInputs = new Int_t[fArraySize];
+    memcpy(fInputs, other.fInputs, fNclients*sizeof(Int_t));
     fDevices = new TObjArray(fArraySize);
     for (Int_t i=0; i<fNclients; i++) fDevices->Add(other.fDevices->At(i));
   }   
@@ -73,8 +73,8 @@ AliTrigConnector& AliTrigConnector::operator=(const AliTrigConnector &other)
   fInputs = 0;
   fDevices = 0;
   if (fArraySize && other.fInputs) {
-    fInputs = new UInt_t[fArraySize];
-    memcpy(fInputs, other.fInputs, fNclients*sizeof(UInt_t));
+    fInputs = new Int_t[fArraySize];
+    memcpy(fInputs, other.fInputs, fNclients*sizeof(Int_t));
     fDevices = new TObjArray(fArraySize);
     for (Int_t i=0; i<fNclients; i++) fDevices->Add(other.fDevices->At(i));
   }     
@@ -82,7 +82,7 @@ AliTrigConnector& AliTrigConnector::operator=(const AliTrigConnector &other)
 }
 
 //______________________________________________________________________________
-void AliTrigConnector::Connect(AliTrigDevice *client, UInt_t input)
+void AliTrigConnector::Connect(AliTrigDevice *client, Int_t input)
 {
 // Adds the device and its input to the list of clients.
   // Loop array of inputs to check if this input is already connected.
@@ -93,19 +93,19 @@ void AliTrigConnector::Connect(AliTrigDevice *client, UInt_t input)
       return;
     } 
   }
-  if (!client->SetInputType(fFeeder->GetOutputType(fOutput))) {
-    Fatal("Cannot connect output slot #%d (type %s) of device %s to input slot #%d of device %s. Aborting",
-            fOutput, fFeeder->GetInputType(fOutput), fFeeder->GetName(), input, client->GetName());
-  }          
+//  if (strcmp(client->GetInputType(fFeeder->GetOutputType(fOutput))) {
+//    Fatal("Cannot connect output slot #%d (type %s) of device %s to input slot #%d of device %s. Aborting",
+//            fOutput, fFeeder->GetInputType(fOutput), fFeeder->GetName(), input, client->GetName());
+//  }          
   if (!fArraySize) {
     fArraySize = 8;
-    fInputs = new UInt_t[fArraySize];
+    fInputs = new Int_t[fArraySize];
     fDevices = new TObjArray(fArraySize);
   }
   if (fNclients >= fArraySize) {
     fArraySize *= 2;
-    UInt_t *array = new UInt_t[fArraySize];
-    memcpy(array, fInputs, fNclients*sizeof(UInt_t));
+    Int_t *array = new Int_t[fArraySize];
+    memcpy(array, fInputs, fNclients*sizeof(Int_t));
     delete [] fInputs;
     fInputs = array;
   }
index 8ea668a..6041fc6 100644 (file)
@@ -23,14 +23,14 @@ class AliTrigConnector : public TNamed {
 
 public:
   AliTrigConnector() : TNamed(), fFeeder(0), fOutput(0), fNclients(0), fArraySize(0), fInputs(0), fDevices(0) {}
-  AliTrigConnector(const char *name, AliTrigDevice *feeder, UInt_t output) : TNamed(name, ""), fFeeder(feeder), fOutput(output), fNclients(0), fArraySize(0), fInputs(0), fDevices(0) {}
+  AliTrigConnector(const char *name, AliTrigDevice *feeder, Int_t output) : TNamed(name, ""), fFeeder(feeder), fOutput(output), fNclients(0), fArraySize(0), fInputs(0), fDevices(0) {}
   AliTrigConnector(const AliTrigConnector &other);
   virtual ~AliTrigConnector();
 
   AliTrigConnector &operator=(const AliTrigConnector &other);
   
   // Connect a client input.
-  void                      Connect(AliTrigDevice *client, UInt_t input);
+  void                      Connect(AliTrigDevice *client, Int_t input);
 
   virtual void              Print(Option_t *option="") const;  
   
@@ -41,10 +41,10 @@ public:
   
 private:
   AliTrigDevice            *fFeeder;    // Feeder device
-  UInt_t                    fOutput;    // Output slot index for the feeder
+  Int_t                     fOutput;    // Output slot index for the feeder
   Int_t                     fNclients;  // Number of clients
   Int_t                     fArraySize; // Size of the clients array
-  UInt_t                   *fInputs;    //[fArraySize] Array of input slot indices
+  Int_t                    *fInputs;    //[fArraySize] Array of input slot indices
   TObjArray                *fDevices;   // Array of client devices
    
   ClassDef(AliTrigConnector,1)  // Class representing a connector between devices.
index 2479734..a1e85f2 100644 (file)
 /* $Id$ */
 // Author: Andrei Gheata, 28/07/2009
 
+
+#include "AliTrigDevice.h"
+
+#include <TObjArray.h>
+#include "AliTrigScheduler.h"
+#include "AliTrigScheduledEntry.h"
+
+ClassImp(AliTrigDevice)
 //==============================================================================
 //   AliTrigDevice - Generic device class. A device has a number of inputs and
 // outputs. The data handled by the device can be either Boolean (digital
 // devices) or arbitrary (wrapped by the class AliTrigSignal). A device must
 // provide a response function that may depend on the output id. To replay the 
 // device response function for a given output id, the device MUST register the
-// output via the RegisterOutput() method providing the delay in arbitrary time
-// units. After the execution of the response for some output, the Emit() method
-// will be invoked to propagate the computed result to all devices connected to 
-// this output. The method Connect() must be implemented by all devices and should
-// create a connector specific to the device types that are linked. 
+// output via the RegisterResponseFunction() method providing the delay in arbitrary time
+// units. After the execution of the response for some output, the result will
+// be propagated to all devices connected to this output. The method CreateDevice() 
+// must be implemented by all devices and should connect all component devices
+// and register all response functions. 
 // The ResetInputs() method is called during simulation after the execution of 
 // all response functions.
 //==============================================================================
 
-#include "AliTrigDevice.h"
-
-ClassImp(AliTrigDevice)
-
 //______________________________________________________________________________
 AliTrigDevice::AliTrigDevice()
+              :TNamed(),
+               fNinputs(0),
+               fNoutputs(0),
+               fScheduler(NULL),
+               fComponents(NULL),
+               fResponseFunctions(NULL) 
 {
-// Destructor.
-   if (fComponents) delete fComponents;
-}   
+// I/O constructor.
+}
 
 //______________________________________________________________________________
-AliTrigDevice::AliTrigDevice(const AliTrigDevice &other)
-                    :TNamed(other), 
-                     fNinputs(other.fNinputs), 
-                     fNoutputs(other.fNoutputs),
-                     fComponents(0)
+AliTrigDevice::AliTrigDevice(const char *name, Int_t ninputs, Int_t noutputs)
+              :TNamed(name, ""),
+               fNinputs(ninputs),
+               fNoutputs(noutputs),
+               fScheduler(new AliTrigScheduler(name)),
+               fComponents(NULL),
+               fResponseFunctions(NULL) 
 {
-// Copy ctor.
-  if (other.fComponents) {
-     fComponents = new TObjArray();
-     TIter next(other.fComponents);
-     AliTrigDevice *dev;
-     while ((dev=(AliTrigDevice*)next())) fComponents->Add(dev);
-  }   
-}                        
+// Constructor.
+}
 
 //______________________________________________________________________________
-AliTrigDevice& AliTrigDevice::operator=(const AliTrigDevice &other)
+AliTrigDevice::~AliTrigDevice()
 {
-// Assignment
-  if (&other == this) return *this;
-  TNamed::operator=(other);
-  fNinputs  = other.fNinputs;
-  fNoutputs = other.fNoutputs;
-  fComponents = 0;
-  if (other.fComponents) {
-     fComponents = new TObjArray();
-     TIter next(other.fComponents);
-     AliTrigDevice *dev;
-     while ((dev=(AliTrigDevice*)next())) fComponents->Add(dev);
-  }   
-  return *this;
-}
+// Destructor.
+  delete fScheduler;
+  if (fComponents) {fComponents->Delete(); delete fComponents;}
+  if (fResponseFunctions) {fResponseFunctions->Delete(); delete fResponseFunctions;}
+}   
 
 //______________________________________________________________________________
 void AliTrigDevice::AddDevice(AliTrigDevice *other)
@@ -85,7 +81,7 @@ void AliTrigDevice::AddDevice(AliTrigDevice *other)
 }
 
 //______________________________________________________________________________
-Int_t AliTrigDevice::GetNcomponents()
+Int_t AliTrigDevice::GetNcomponents() const
 {
 // Returns number of components.
   if (!fComponents) return 0;
@@ -96,19 +92,32 @@ Int_t AliTrigDevice::GetNcomponents()
 AliTrigDevice *AliTrigDevice::GetComponent(Int_t n)
 {
 // Get component at index n.
-   if (!fComponents) return NULL;
-   return fComponents->At(n);
+  if (!fComponents) return NULL;
+  return (AliTrigDevice*)fComponents->At(n);
 }
-   
+
+//______________________________________________________________________________
+AliTrigScheduledResponse *AliTrigDevice::GetResponseFunction(const char *name)
+{
+// Get a response function by name.
+  if (!fResponseFunctions) return NULL;
+  return (AliTrigScheduledResponse*)fResponseFunctions->FindObject(name);
+}  
+
 //______________________________________________________________________________
-Bool_t AliTrigDevice::RegisterResponseFunction(AliTrigScheduler *calendar, UInt_t output, Int_t delay) const
+AliTrigScheduledResponse *AliTrigDevice::RegisterResponseFunction(const char *name, Int_t output, Int_t delay)
 {
-// Register the response functions to be replayed by the provided scheduler.
-// The delay argument is in arbitrary time units with respect to the startup
-// reference of the simulation.
-// CALLING SEQUENCE:
-//   The delay behaves like a BUSY gate for the device and MUST be called when
-//   configuring the whole setup of devices. The method may fail in case the
-//   determinism is not satisfied with other connected devices providing inputs.
-   return calendar->RegisterResponseFunction(this, output, delay);
+// Creates a response function of the device. The delay argument is in arbitrary 
+// time units with respect to the startup reference. Note that the created 
+// scheduled entry must be registered to the device scheduler via: 
+//    fDevice->AddScheduledEntry() method, otherwise it will not be replayed.
+  if (!fResponseFunctions) fResponseFunctions = new TObjArray();
+  if (fResponseFunctions->FindObject(name)) {
+    Error("RegisterResponseFunction", "A response function named %s was already registered for device %s",
+          name, GetName());
+    return NULL;
+  }        
+  AliTrigScheduledResponse *response = new AliTrigScheduledResponse(name, (AliTrigDevice*)this, output, delay);
+  fResponseFunctions->Add(response);
+  return response;
 }
index eb5c3c6..492f991 100644 (file)
 #include "TNamed.h"
 #endif
 
+class AliTrigEvent;
 class AliTrigScheduler;
+class AliTrigScheduledResponse;
 
 class AliTrigDevice : public TNamed {
 
-public:
-  AliTrigDevice() : TNamed(), fNinputs(0), fNoutputs(0) {}
-  AliTrigDevice(const char *name, UInt_t ninputs, UInt_t noutputs) 
-              : TNamed(name,""), fNinputs(ninputs), fNoutputs(noutputs) {}
+private:
   AliTrigDevice(const AliTrigDevice &other);
-  virtual ~AliTrigDevice();
   AliTrigDevice &operator=(const AliTrigDevice &other);
 
+public:
+  AliTrigDevice();
+  AliTrigDevice(const char *name, Int_t ninputs, Int_t noutputs);
+  virtual ~AliTrigDevice();
+
   virtual void              AddDevice(AliTrigDevice *other);
   Int_t                     GetNcomponents() const;
   AliTrigDevice            *GetComponent(Int_t n);
+  AliTrigScheduledResponse *GetResponseFunction(const char *name);
+  AliTrigScheduler         *GetScheduler() const {return fScheduler;}
+  
+  //____________________________________________________________________________
+  // Device creation method to be implemented by derived classes. The response
+  // functions are registered here. Connections between component devices should
+  // also be handled in this method.
+  virtual Bool_t            CreateDevice() {return kTRUE;}
   //____________________________________________________________________________
   // Connectivity to other devices. The method will create a connector between
   // an output of this device to one input of the other.
-  virtual Bool_t            Connect(UInt_t output, AliTrigDevice *other, UInt_t at_input) = 0;
+  virtual Bool_t            Connect(Int_t /*output*/, AliTrigDevice */*other*/, Int_t /*at_input*/) {return kTRUE;}
 
   //____________________________________________________________________________
-  // Response functions to be overloaded by specific devices. Has to propagate
+  // Response functions to be implemented by specific devices. Has to propagate
   // the response to all connected devices. Representing the output #n of the device.
-  virtual Bool_t            Response(UInt_t output = 0) = 0;
+  virtual Bool_t            Response(Int_t output = 0) = 0;
 
   //____________________________________________________________________________
-  // Register the response functions to be replayed by the global scheduler.
+  // Create the response functions of the device.
   // The delay argument is in arbitrary time units with respect to the startup
-  // reference.
-  Bool_t                    RegisterResponseFunction(AliTrigScheduler *calendar, UInt_t output, Int_t delay, Int_t group) const;
+  // reference. Note that the created scheduled entry must be registered to the
+  // device scheduler via: fDevice->AddScheduledEntry() method
+  AliTrigScheduledResponse *RegisterResponseFunction(const char *name, Int_t output, Int_t delay);
 
   //____________________________________________________________________________
   // Setting the value for a given input for digital devices of general ones
   // that are handling generic signals.
-  virtual const char       *GetOutputType(UInt_t output) {return 0;}
-  virtual Bool_t            SetInputType(UInt_t input, const char *classname) = 0;
-  virtual Bool_t            SetInputValue(UInt_t input, Bool_t value) = 0;
-  virtual Bool_t            SetInputValue(UInt_t input, AliTrigSignal *signal) = 0;
+  virtual const char       *GetOutputType(Int_t /*output*/) {return 0;}
+  virtual Bool_t            SetInputType(Int_t input, const char *classname) = 0;
+  virtual Bool_t            SetInputValue(Int_t input, Bool_t value) = 0;
+  virtual Bool_t            SetInputValue(Int_t input, AliTrigEvent *event) = 0;
 
   //____________________________________________________________________________
   // Device-dependent inputs reset method
   virtual void              ResetInputs() = 0;
 
-  UInt_t                    GetNinputs() const {return fNinputs;}
-  UInt_t                    GetNoutputs() const {return fNoutputs;}
+  Int_t                    GetNinputs() const {return fNinputs;}
+  Int_t                    GetNoutputs() const {return fNoutputs;}
    
 protected:
-  UInt_t                    fNinputs;  // Number of inputs.
-  UInt_t                    fNoutputs; // Number of outputs.
-  TObjArray                *fComponents; // Component devices if any
+  Int_t                    fNinputs;            // Number of inputs
+  Int_t                    fNoutputs;           // Number of outputs
+  AliTrigScheduler         *fScheduler;         // Device scheduler
+  TObjArray                *fComponents;        // Component devices
+  TObjArray                *fResponseFunctions; // List of response functions
    
   ClassDef(AliTrigDevice,1)  // Base class for trigger devices
 };
index 2f4c910..388dc4a 100644 (file)
 //==============================================================================
 
 #include "AliTrigDigitalCircuit.h"
+#include "AliTrigConnector.h"
 
 ClassImp(AliTrigDigitalCircuit)
 
 //______________________________________________________________________________
-AliTrigDigitalCircuit::AliTrigDigitalCircuit(const AliTrigDigitalCircuit &other)
-                    :AliTrigDevice(other),
-                     fLastOutput(other.fLastOutput),
-                     fConnector(0),
-                     fInputs(other.fInputs)
-{
-// Copy ctor.
-  if (other.fConnector) fConnector = new AliTrigConnector(*other.fConnector);
-}                        
-
-//______________________________________________________________________________
 AliTrigDigitalCircuit::~AliTrigDigitalCircuit()
 {
 // Destructor
@@ -45,31 +35,18 @@ AliTrigDigitalCircuit::~AliTrigDigitalCircuit()
 }  
 
 //______________________________________________________________________________
-AliTrigDigitalCircuit& AliTrigDigitalCircuit::operator=(const AliTrigDigitalCircuit &other)
-{
-// Assignment
-  if (&other == this) return *this;
-  AliTrigDevice::operator=(other);
-  fLastOutput = other.fLastOutput;
-  if (other.fConnector) fConnector = new AliTrigConnector(*other.fConnector);
-  else fConnector = 0;
-  fInputs = other.fInputs;
-  return *this;
-}
-
-//______________________________________________________________________________
-Bool_t AliTrigDigitalCircuit::Connect(UInt_t output, AliTrigDevice *other, UInt_t at_input)
+Bool_t AliTrigDigitalCircuit::Connect(Int_t output, AliTrigDevice *other, Int_t at_input)
 {
 // Connect to an input of another device.
-  if (!fConnector) fConnector = new AliTrigConnector(this, 0);
+  if (!fConnector) fConnector = new AliTrigConnector(Form("wire_%s_%d", GetName(), output), (AliTrigDevice*)this, 0);
   fConnector->Connect(other, at_input);
 }
 
 //______________________________________________________________________________
-Bool_t AliTrigDigitalCircuit::Response(UInt_t /*output*/)
+Bool_t AliTrigDigitalCircuit::Response(Int_t /*output*/)
 {
 // Response function of the digital circuit. Calling user-defined one.
-  fLastOutput = CircuitResponse();
+  fLastOutput = Trigger();
   if (fConnector) fConnector->Transmit(fLastOutput);
   return fLastOutput;
 }   
index 2e27a13..317382c 100644 (file)
@@ -29,19 +29,20 @@ class AliTrigDigitalCircuit : public AliTrigDevice {
 public:
   AliTrigDigitalCircuit() : AliTrigDevice(), fLastOutput(kFALSE), fConnector(0), fInputs() {}
   AliTrigDigitalCircuit(const char *name, UInt_t ninputs) : AliTrigDevice(name, ninputs, 1), fLastOutput(kFALSE), fConnector(0), fInputs(ninputs) {}
-  AliTrigDigitalCircuit(const AliTrigDigitalCircuit &other);
-  virtual ~AliTrigDigitalCircuit() {}
-  AliTrigDigitalCircuit &operator=(const AliTrigDigitalCircuit &other);
+  virtual ~AliTrigDigitalCircuit();
 
-  virtual Bool_t            Connect(UInt_t output, AliTrigDevice *other, UInt_t at_input);
-  virtual Bool_t            Response(UInt_t output);
+  virtual Bool_t            Connect(Int_t output, AliTrigDevice *other, Int_t at_input);
+  virtual Bool_t            Response(Int_t output);
   // Get/Set inputs
-  Bool_t                    GetInputValue(UInt_t input) const {return fInputs.TestBitNumber(input);}
+  Bool_t                    GetInputValue(Int_t input) const {return fInputs.TestBitNumber(input);}
   virtual void              ResetInputs() {fInputs.ResetAllBits();}
-  virtual void              SetInputValue(UInt_t input, Bool_t value) {fInputs.SetBitNumber(input,value);}
-  virtual void              SetInputValue(UInt_t input, AliTrigEvent *signal) {};
+  virtual Bool_t            SetInputType(Int_t /*input*/, const char */*classname*/) {return kFALSE;}
+  virtual Bool_t            SetInputValue(Int_t input, Bool_t value) {fInputs.SetBitNumber(input,value); return kTRUE;}
+  virtual Bool_t            SetInputValue(Int_t /*input*/, AliTrigEvent */*signal*/) {return  kFALSE;}
 private:
    // Circuit response function. 
+  AliTrigDigitalCircuit(const AliTrigDigitalCircuit &other);
+  AliTrigDigitalCircuit &operator=(const AliTrigDigitalCircuit &other);
   virtual Bool_t            Trigger() = 0;
    
 protected:
index 93b8fe6..9b7d53d 100644 (file)
 /* $Id$ */
 // Author: Andrei Gheata, 28/07/2009
 
-//==============================================================================
-//   AliTrigEvent - Base class for generic information exchanged by a trigger
-//                  device. Trigger inputs and outputs are represented and
-//                  handled via AliTrigEvent objects. Trigger events are typically
-//                  wrappers for the information exchanged on a single I/O slot
-//                  or a group of correlated inputs.
-//==============================================================================
-
 #include "AliTrigEvent.h"
 
 #include <TClass.h>
 #include <TBits.h>
 #include <TROOT.h>
 
-
 ClassImp(AliTrigEvent)
 
+//==============================================================================
+//   AliTrigEvent - Base class for generic information exchanged by a trigger
+//                  device. Trigger inputs and outputs are represented and
+//                  handled via AliTrigEvent objects. Trigger events are typically
+//                  wrappers for the information exchanged on a single I/O slot
+//                  or a group of correlated inputs.
+//==============================================================================
+
 //______________________________________________________________________________
-AliTrigEvent::Activate()
+void AliTrigEvent::Activate(Bool_t flag)
 {
 // Activate/deactivate this signal.
   TObject::SetBit(kActive, flag);
@@ -47,43 +46,76 @@ Bool_t AliTrigEventWithMask::ImportData(AliTrigEvent *source)
 {
 // Import data from likewise signal.
   AliTrigEventWithMask *src = (AliTrigEventWithMask *)source;
-  fValue = src->GetValue();
+  SetValue(src->GetValue());
   return kTRUE;
 }
 
+//______________________________________________________________________________
+void AliTrigEventWithMask::SetValue(TBits *value)
+{
+// Set the mask value.
+  *fValue = *value;
+}
+
+//______________________________________________________________________________
+AliTrigEventWithMask::AliTrigEventWithMask(const AliTrigEventWithMask &other)
+                       :AliTrigEvent(other),
+                        fValue(NULL)
+{
+// Copy constructor.   
+  *fValue = *other.fValue;
+}
+
+//______________________________________________________________________________
+AliTrigEventWithMask &AliTrigEventWithMask::operator=(const AliTrigEventWithMask &other)
+{
+// Assignment operator.
+   if (&other == this) return *this;
+   AliTrigEvent::operator=(other);
+   *fValue = *other.fValue;
+   return *this;
+}
+
 ClassImp(AliTrigEventWithObject)
 
 //______________________________________________________________________________
 AliTrigEventWithObject::AliTrigEventWithObject(const char *classname)
                        :AliTrigEvent(),
                         fValue(0),
-                        fType(0)
+                        fType("")
 {
 // Normal constructor where a class name is provided for the embedded object.
 // If the event is created in this way one will only be able to connect to 
-// events embedding the same object type (via connectors). Otherwise the type
+// events embedding the same object type (via connectors). If empty string the type
 // will be set upon the first call of SetValue.
-   fType = gROOT->GetClass(classname);
-   if (!fType) Error("ctor", "No class named <%s> available.", classname);
+  SetType(classname);
 }   
 
 //______________________________________________________________________________
 AliTrigEventWithObject::AliTrigEventWithObject(const AliTrigEventWithObject &other)
                        :AliTrigEvent(other),
-                        fValue(other.fValue),
+                        fValue(NULL),
                         fType(other.fType)
 {
 // Copy constructor.   
+  TClass* pClass=TClass::GetClass(fType);
+  if (!pClass) return;
+  fValue = (TObject*)pClass->New();
+  fValue->Copy(*other.fValue);
 }
 
 //______________________________________________________________________________
-AliTrigEventWithObject::operator=(const AliTrigEventWithObject &other)
+AliTrigEventWithObject &AliTrigEventWithObject::operator=(const AliTrigEventWithObject &other)
 {
 // Assignment operator.
-   if (&other == this) return *this;
-   AliTrigEvent::operator=(other);
-   fValue = other.fValue;
-   fType = other.fType;
+  if (&other == this) return *this;
+  AliTrigEvent::operator=(other);
+  fType = other.fType;
+  TClass* pClass=TClass::GetClass(fType);
+  if (!pClass) return *this;
+  fValue = (TObject*)pClass->New();
+  fValue->Copy(*other.fValue);
+  return *this;
 }
 
 //______________________________________________________________________________
@@ -93,7 +125,7 @@ Bool_t AliTrigEventWithObject::ImportData(AliTrigEvent *source)
   AliTrigEventWithObject *src = (AliTrigEventWithObject *)source;
   Bool_t done = SetValue(src->GetValue());
   if (!done) Error("ImportData", "Cannot import object <%s> of class <%s> since event type was set to: <%s>",
-                   src->GetValue()->GetName(), src->GetValue()->ClassName(), fType->GetName());
+                   src->GetValue()->GetName(), src->GetValue()->ClassName(), fType.Data());
   return done;
 }
 
@@ -101,17 +133,17 @@ Bool_t AliTrigEventWithObject::ImportData(AliTrigEvent *source)
 Bool_t AliTrigEventWithObject::SetType(const char *classname)
 {
 // Set the type of this event. Can be done only once.
+  if (!strlen(classname)) return kFALSE;
+  if (!fType.IsNull()) {
+    Error("SetType", "Type for this trigger event already set to: %s", fType.Data());
+    return kFALSE;
+  }  
   TClass *type = gROOT->GetClass(classname);
   if (!type) {
     Error("SetType", "Unknown class %s", classname);
     return kFALSE;
   }
-  if (!fType) fType = type;
-  if (fType != type) {
-    Error("SetType", "Type %s not matching the one defined for this event <%s>",
-          classname, fType->GetName());
-    return kFALSE;
-  }
+  fType = classname;
   return kTRUE;
 }
 
@@ -124,11 +156,8 @@ Bool_t AliTrigEventWithObject::SetValue(TObject *value)
     fValue = NULL;
     return kTRUE;
   }
-  TClass *type = value->IsA();
   // Set the type if used for the first time.
-  if (!fType) fType = type;
-  // Check consistency of the value with event type.  
-  if (type != fType) return kFALSE;
+  if (!fType) fType = value->ClassName();
   fValue = value;
   return kTRUE;
 }  
index b129865..f973066 100644 (file)
 #include "TObject.h"
 #endif
 
+#ifndef ROOT_TString
+#include "TString.h"
+#endif
+
 class TClass;
 class AliTrigEvent : public TObject {
 
 public:
 enum ETrigSignalFlags {
   kActive = BIT(14)
-}
+};
   
-  AliTrigEvent() : TObject {}
+  AliTrigEvent() : TObject() {}
   virtual ~AliTrigEvent() {}
 
   void                      Activate(Bool_t flag);
@@ -34,8 +38,8 @@ enum ETrigSignalFlags {
   
   // Import data from a source signal. Has to be implemented by derived signals.
   virtual Bool_t            ImportData(AliTrigEvent *source) = 0;
-  virtual Bool_t            SetType(const char *classname) {return kTRUE;}
-  virtual TClass           *GetType() {return NULL;}
+  virtual Bool_t            SetType(const char */*classname*/) {return kTRUE;}
+  virtual const char       *GetType() const {return NULL;}
      
   ClassDef(AliTrigEvent,1)  // Generic event embedding data.
 };
@@ -50,15 +54,17 @@ class AliTrigEventWithMask : public AliTrigEvent {
 
 public:
   AliTrigEventWithMask() : AliTrigEvent(), fValue() {}
+  AliTrigEventWithMask(const AliTrigEventWithMask &other);
   virtual ~AliTrigEventWithMask() {}
   
+  AliTrigEventWithMask   &operator=(const AliTrigEventWithMask &other);
   virtual Bool_t            ImportData(AliTrigEvent *source);
 
-  const TBits              &GetValue() const {return fValue;}
-  void                      SetValue(const TBits &value) {fValue = value;}
+  TBits                    *GetValue() const {return fValue;}
+  void                      SetValue(TBits *value);
 
 private:
-  TBits                     fValue;  // Mask value
+  TBits                    *fValue;  // Mask value
      
   ClassDef(AliTrigEventWithMask,1)  // Signal embedding a TBits object.
 };
@@ -68,7 +74,6 @@ private:
 // 
 //==============================================================================
 
-class TClass;
 class AliTrigEventWithObject : public AliTrigEvent {
 
 public:
@@ -79,14 +84,14 @@ public:
   
   AliTrigEventWithObject   &operator=(const AliTrigEventWithObject &other);
   virtual Bool_t            ImportData(AliTrigEvent *source);
-  virtual TClass           *GetType() const  {return fType;}
+  virtual const char       *GetType() const {return fType;}
   virtual Bool_t            SetType(const char *classname);
   TObject                  *GetValue() const {return fValue;}
   Bool_t                    SetValue(TObject *value);
 
 private:
   TObject                  *fValue;  // Embedded object
-  TClass                   *fType;   //! Object type
+  TString                   fType;   // Object type
      
   ClassDef(AliTrigEventWithObject,1)  // Signal embedding an object.
 };
diff --git a/TRIGGER/AliTrigScheduledEntry.cxx b/TRIGGER/AliTrigScheduledEntry.cxx
new file mode 100644 (file)
index 0000000..76e8baa
--- /dev/null
@@ -0,0 +1,88 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+// Author: Andrei Gheata, 04/01/2010
+
+#include "AliTrigScheduledEntry.h"
+
+#include "AliTrigScheduler.h"
+#include "AliTrigDevice.h"
+
+ClassImp(AliTrigScheduledEntry)
+//==============================================================================
+//
+//   AliTrigScheduledEntry - ABC for scheduled responses of a device that is
+//                           able to fire-up single response functions or the 
+//                           full device scheduled sequence. The start time is
+//                           in arbitrary units and in case it is 0 will not be
+//                           considered when ordering by time by schedulers.
+// 
+//==============================================================================
+
+//______________________________________________________________________________
+AliTrigScheduledEntry::AliTrigScheduledEntry(const char *name, AliTrigDevice *device, Int_t start)
+                      :TNamed(name,""), 
+                       fStartTime(start), 
+                       fDevice(device) 
+{
+// Default constructor. The only way to set the device.
+}
+
+
+ClassImp(AliTrigScheduledResponse)
+//==============================================================================
+//
+//   AliTrigScheduledResponse - Scheduled device response function. Fires-up a
+//                              single response function at a time.
+//
+//==============================================================================
+
+//______________________________________________________________________________
+AliTrigScheduledResponse::AliTrigScheduledResponse(const char *name, AliTrigDevice *device, Int_t output, Int_t start)
+                         :AliTrigScheduledEntry(name, device, start),
+                          fOutputID(output)
+{
+// Default constructor. The only way to set the device and response function.
+}
+
+//______________________________________________________________________________
+void AliTrigScheduledResponse::FireUp(Int_t /*time*/)
+{
+// Virtual fire-up method. Calls the device response function.
+   fDevice->Response(fOutputID);
+}
+
+ClassImp(AliTrigScheduledDevice)
+//==============================================================================
+//
+//   AliTrigScheduledDevice - Scheduled entry for a full device sequence. Invokes
+//                            the device scheduler when firing-up.
+//
+//==============================================================================
+
+//______________________________________________________________________________
+AliTrigScheduledDevice::AliTrigScheduledDevice(const char *name, AliTrigDevice *device, Int_t start)
+                         :AliTrigScheduledEntry(name, device, start)
+{
+// Default constructor. The only way to set the device. Device scheduler must be set up.
+}
+
+//______________________________________________________________________________
+void AliTrigScheduledDevice::FireUp(Int_t time)
+{
+// Virtual fire-up method. Calls the device response function.
+   fDevice->GetScheduler()->FireUp(time);
+}
diff --git a/TRIGGER/AliTrigScheduledEntry.h b/TRIGGER/AliTrigScheduledEntry.h
new file mode 100644 (file)
index 0000000..b2882a2
--- /dev/null
@@ -0,0 +1,97 @@
+#ifndef ALITRIGSCHEDULEDENTRY_H
+#define ALITRIGSCHEDULEDENTRY_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+// Author: Andrei Gheata, 04/01/2010
+
+//==============================================================================
+//
+//   AliTrigScheduledEntry - ABC for scheduled responses of a device that is
+//                           able to fire-up single response functions or the 
+//                           full device scheduled sequence. The start time is
+//                           in arbitrary units and in case it is 0 will not be
+//                           considered when ordering by time by schedulers.
+// 
+//==============================================================================
+
+#ifndef ROOT_TNamed
+#include "TNamed.h"
+#endif
+
+class AliTrigDevice;
+
+class AliTrigScheduledEntry : public TNamed {
+
+protected:
+  Int_t             fStartTime;           // Time to fire-up
+  AliTrigDevice    *fDevice;              // Device to fire-up
+  
+private:
+  AliTrigScheduledEntry(const AliTrigScheduledEntry &other);
+  AliTrigScheduledEntry &operator=(const AliTrigScheduledEntry &other);
+
+public:
+  AliTrigScheduledEntry() : TNamed(), fStartTime(0), fDevice(NULL) {}
+  AliTrigScheduledEntry(const char *name, AliTrigDevice *device, Int_t start=0);
+  virtual ~AliTrigScheduledEntry() {}
+
+  Int_t             GetStartTime() const     {return fStartTime;}
+  AliTrigDevice    *GetDevice()    const     {return fDevice;}
+  virtual void      FireUp(Int_t time)                                      = 0;
+  void              SetStartTime(Int_t time) {fStartTime = time;}
+
+  ClassDef(AliTrigScheduledEntry, 1) // ABC for scheduled responses
+};   
+
+//==============================================================================
+//
+//   AliTrigScheduledResponse - Scheduled device response function. Fires-up a
+//                              single response function at a time.
+//
+//==============================================================================
+
+class AliTrigScheduledResponse : public AliTrigScheduledEntry {
+
+private:
+  Int_t             fOutputID;            // Device output to be fired
+
+private:
+  AliTrigScheduledResponse(const AliTrigScheduledResponse &other);
+  AliTrigScheduledResponse &operator=(const AliTrigScheduledResponse &other);
+
+public:
+  AliTrigScheduledResponse() : AliTrigScheduledEntry(), fOutputID(-1) {}
+  AliTrigScheduledResponse(const char *name, AliTrigDevice *device, Int_t output, Int_t start=0);
+  virtual ~AliTrigScheduledResponse() {}
+  
+  Int_t             GetOutputID() const      {return fOutputID;}
+  virtual void      FireUp(Int_t time);
+  
+  ClassDef(AliTrigScheduledResponse, 1) // Scheduled response function for a device
+};
+
+//==============================================================================
+//
+//   AliTrigScheduledDevice - Scheduled entry for a full device sequence. Invokes
+//                            the device scheduler when firing-up.
+//
+//==============================================================================
+
+class AliTrigScheduledDevice : public AliTrigScheduledEntry {
+
+private:
+  AliTrigScheduledDevice(const AliTrigScheduledDevice &other);
+  AliTrigScheduledDevice &operator=(const AliTrigScheduledDevice &other);
+
+public:
+  AliTrigScheduledDevice() : AliTrigScheduledEntry() {}
+  AliTrigScheduledDevice(const char *name, AliTrigDevice *device, Int_t start=0);
+  virtual ~AliTrigScheduledDevice() {}
+  
+  virtual void      FireUp(Int_t time);
+  
+  ClassDef(AliTrigScheduledDevice, 1) // Scheduled device replay
+};
+#endif
diff --git a/TRIGGER/AliTrigScheduler.cxx b/TRIGGER/AliTrigScheduler.cxx
new file mode 100644 (file)
index 0000000..8a012b3
--- /dev/null
@@ -0,0 +1,370 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+// Author: Andrei Gheata, 05/01/2010
+
+#include "AliTrigScheduler.h"
+
+#include <TMath.h>
+#include <TList.h>
+#include <TObjArray.h>
+#include "AliTrigScheduledEntry.h"
+
+ClassImp(AliTrigScheduledGroup)
+
+//==============================================================================
+//
+//   AliTrigScheduledGroup - A group of scheduled entries that will simply be
+//                           fired-up sequentially. The group delay in global time
+//                           units is the latest start time of the contained
+//                           entries. A group has a priority assigned by the
+//                           owner scheduler object. Groups are fired-up according
+//                           a programable sequence.
+//
+//==============================================================================
+
+//______________________________________________________________________________
+AliTrigScheduledGroup::AliTrigScheduledGroup()
+                      :TNamed(),
+                       fPriority(0),
+                       fDelay(0),
+                       fEntries(NULL)
+{
+// I/O constructor. 
+}
+
+//______________________________________________________________________________
+AliTrigScheduledGroup::AliTrigScheduledGroup(const char *name, Int_t priority)
+                      :TNamed(name,""),
+                       fPriority(priority),
+                       fDelay(0),
+                       fEntries(new TObjArray())
+{
+// Constructor.
+}
+
+//______________________________________________________________________________
+AliTrigScheduledGroup::~AliTrigScheduledGroup()
+{
+// Destructor.
+  if (fEntries) delete fEntries;
+}  
+
+//______________________________________________________________________________
+void AliTrigScheduledGroup::AddEntry(AliTrigScheduledEntry *entry)
+{
+// Add a scheduled entry to the group. There is no check if an entry was added twice !
+  if (!fEntries) fEntries = new TObjArray();
+  fEntries->Add(entry);
+}
+
+//______________________________________________________________________________
+void AliTrigScheduledGroup::FireUp(Int_t time)
+{
+// Fire-up all entries in the group.
+  Int_t nentries = GetNentries();
+  AliTrigScheduledEntry *entry;
+  for (Int_t i=0; i<nentries; i++) {
+    entry = (AliTrigScheduledEntry*)fEntries->At(i);
+    entry->FireUp(time);
+  }
+}    
+
+//______________________________________________________________________________
+Int_t AliTrigScheduledGroup::GetNentries() const
+{
+// Get number of scheduled entries in the group.
+  return (fEntries)?fEntries->GetEntriesFast():0;
+}
+
+//______________________________________________________________________________
+void AliTrigScheduledGroup::Print(Option_t *option) const
+{
+// Print the group content.
+  Int_t nentries = GetNentries();
+  printf("Group: %s containing %d entries.\n", GetName(), nentries);
+  TString opt(option);
+  opt.ToUpper();
+  // Check if details are requested.
+  if (!opt.Contains("D")) return;
+  for (Int_t i=0; i<nentries; i++) {
+    printf("   %d: ", i);
+    fEntries->At(i)->Print(option);
+  }   
+}   
+
+//______________________________________________________________________________
+void AliTrigScheduledGroup::RemoveEntry(AliTrigScheduledEntry *entry)
+{
+// Remove an entry.
+   if (!fEntries) return;
+   fEntries->RecursiveRemove(entry);
+   fEntries->Compress();
+}
+   
+ClassImp(AliTrigScheduledSequence)
+
+//==============================================================================
+//
+//   AliTrigScheduledSequence - A programable group sequence. Scheduled groups
+//                      are owned and controlled by a trigger scheduler. They
+//                      are fired-up in such a sequence. A sequence supports some
+//                      default modes but can also be programed manually.
+//
+//==============================================================================
+
+//______________________________________________________________________________
+AliTrigScheduledSequence::AliTrigScheduledSequence()
+                :TNamed(),
+                 fScheduler(NULL),
+                 fNgroups(0),
+                 fType(AliTrigScheduledSequence::kDefault),
+                 fArray(NULL)
+{
+// I/O constructor
+}
+
+//______________________________________________________________________________
+AliTrigScheduledSequence::AliTrigScheduledSequence(const char *name, AliTrigScheduler *scheduler)
+                :TNamed(name,""),
+                 fScheduler(scheduler),
+                 fNgroups(scheduler->GetNgroups()),
+                 fType(AliTrigScheduledSequence::kDefault),
+                 fArray(NULL)
+{
+// Constructor
+  if (fNgroups) {
+    fArray = new Int_t[fNgroups];
+    for (Int_t i=0; i<fNgroups; i++) fArray[i] = i;
+  }
+}    
+   
+//______________________________________________________________________________
+AliTrigScheduledSequence::~AliTrigScheduledSequence()
+{
+// Destructor.
+  if (fArray) delete [] fArray;
+}  
+
+//______________________________________________________________________________
+void AliTrigScheduledSequence::Print(Option_t *) const
+{
+// Print the sequence.
+  printf("Sequence: %s scheduled by: %s\n", GetName(), fScheduler->GetName());
+  printf("   type: %d  sequence: ", (Int_t)fType);
+  for (Int_t i=0; i<fNgroups; i++) printf("%d ", fArray[i]);
+  printf("\n");
+}   
+
+//______________________________________________________________________________
+void AliTrigScheduledSequence::SortArray(Int_t *array, Bool_t increasing)
+{
+// Sort the internal sequence array.
+  Int_t *ind = new Int_t[fNgroups];
+  TMath::Sort(fNgroups, array, ind, !increasing);
+  memcpy(fArray, ind, fNgroups*sizeof(Int_t));
+  delete [] ind;
+}
+  
+//______________________________________________________________________________
+void AliTrigScheduledSequence::Sort(ESortingType type, Int_t *sequence)
+{
+  // Sort the group sequence according a predefined type. The sequence
+  // custom input array is considered only for kCustom type.
+  Int_t i;
+  Int_t *array = 0;
+  switch (type) {
+    case AliTrigScheduledSequence::kDefault:
+      // Just ID permutation
+      for (i=0; i<fNgroups; i++) fArray[i] = i;
+      break;
+    case AliTrigScheduledSequence::kTimeInc:
+      // Sort by increasing start time
+      array = new Int_t[fNgroups];
+      for (i=0; i<fNgroups; i++) {
+        array[i] = fScheduler->GetScheduledGroup(i)->GetDelay();
+      }  
+      SortArray(array, kTRUE);
+      break;
+    case AliTrigScheduledSequence::kTimeDec:
+      // Sort by decreasing start time
+      array = new Int_t[fNgroups];
+      for (i=0; i<fNgroups; i++) {
+        array[i] = fScheduler->GetScheduledGroup(i)->GetDelay();
+      }  
+      SortArray(array, kFALSE);
+      break;
+    case AliTrigScheduledSequence::kPriorityInc:
+      // Sort by increasing priority
+      array = new Int_t[fNgroups];
+      for (i=0; i<fNgroups; i++) {
+        array[i] = fScheduler->GetScheduledGroup(i)->GetPriority();
+      }  
+      SortArray(array, kTRUE);
+      break;
+    case AliTrigScheduledSequence::kPriorityDec:
+      // Sort by decreasing priority
+      array = new Int_t[fNgroups];
+      for (i=0; i<fNgroups; i++) {
+        array[i] = fScheduler->GetScheduledGroup(i)->GetPriority();
+      }  
+      SortArray(array, kFALSE);
+      break;
+    case AliTrigScheduledSequence::kCustom:
+      if (!sequence) {
+        Error("Sort", "Sequence array must be provided for custom type");
+        return;
+      }
+      memcpy(fArray, sequence, fNgroups*sizeof(Int_t));
+  }
+  if (array) delete [] array;  
+}            
+
+ClassImp(AliTrigScheduler)
+
+//==============================================================================
+//   AliTrigScheduler - Device response function scheduler. Every device has a
+//                      scheduler, but the same scheduler can replay responses of
+//                      several devices. A scheduler holds groups of scheduled 
+//                      entries. The groups can be replayed in programable
+//                      sequences. A default group and sequence are always created.
+//==============================================================================
+
+//______________________________________________________________________________
+AliTrigScheduler::AliTrigScheduler()
+                 :TNamed(),
+                  fNgroups(0),
+                  fGroups(NULL),
+                  fSequences(NULL),
+                  fCurrentSequence(NULL)
+{
+// I/O constructor.
+}
+
+//______________________________________________________________________________
+AliTrigScheduler::AliTrigScheduler(const char *name)
+                 :TNamed(name,""),
+                  fNgroups(0),
+                  fGroups(new TObjArray()),
+                  fSequences(new TObjArray()),
+                  fCurrentSequence(NULL)
+{
+// Constructor.
+  AddGroup("default");
+  AddSequence("default");
+}
+
+//______________________________________________________________________________
+AliTrigScheduler::~AliTrigScheduler()
+{
+// Destructor.
+  if (fGroups) {fGroups->Delete(); delete fGroups;}
+  if (fSequences) {fSequences->Delete(); delete fSequences;}
+}
+
+//______________________________________________________________________________
+void AliTrigScheduler::AddScheduledEntry(AliTrigScheduledEntry *entry, const char *togroup)
+{
+// Add a scheduled entry to a given group.
+  AliTrigScheduledGroup *group = GetScheduledGroup(togroup);
+  if (!group) {
+    Error("AddScheduledEntry", "Group %s does not exist in scheduler %s", togroup, GetName());
+    return;
+  }
+  group->AddEntry(entry);
+}
+
+//______________________________________________________________________________
+AliTrigScheduledGroup *AliTrigScheduler::AddGroup(const char *groupname)
+{
+// Add a group to the list of groups.
+  if (!fGroups) fGroups = new TObjArray();
+  if (fGroups->FindObject(groupname)) {
+    Error("AddGroup", "Scheduler %s contains already a group named: %s", GetName(), groupname);
+    return NULL;
+  }
+  AliTrigScheduledGroup *group = new AliTrigScheduledGroup(groupname);
+  fGroups->Add(group);
+  return group;
+}
+
+//______________________________________________________________________________
+AliTrigScheduledGroup *AliTrigScheduler::AddGroup(AliTrigScheduledGroup *group)
+{
+// Add a group to the list of groups.
+  if (!fGroups) fGroups = new TObjArray();
+  if (fGroups->FindObject(group->GetName())) {
+    Error("AddGroup", "Scheduler %s contains already a group named: %s", GetName(), group->GetName());
+    return NULL;
+  }
+  fGroups->Add(group);
+  return group;
+}
+
+//______________________________________________________________________________
+AliTrigScheduledSequence *AliTrigScheduler::AddSequence(const char *seqname, AliTrigScheduledSequence::ESortingType type, Int_t *sequence)
+{
+// Add a sequence to the scheduler. Becomes the current sequence.
+  if (!fSequences) fSequences = new TObjArray();
+  if (fSequences->FindObject(seqname)) {
+    Error("AddSequence", "Scheduler %s contains already a sequence named: %s", GetName(), seqname);
+    return NULL;
+  }
+  AliTrigScheduledSequence *seq = new AliTrigScheduledSequence(seqname, (AliTrigScheduler*)this); 
+  seq->Sort(type, sequence);
+  fCurrentSequence = seq;
+  return seq;
+}
+
+//______________________________________________________________________________
+void AliTrigScheduler::FireUp(Int_t time)
+{
+// Fire-up groups in the order given by the current sequence.
+  if (!fCurrentSequence) Fatal("FireUp", "No scheduled sequence booked for scheduler: %s", GetName());
+  Int_t *sequence = fCurrentSequence->GetArray();
+  AliTrigScheduledGroup *group;
+  for (Int_t i=0; i<fNgroups; i++) {
+    group = GetScheduledGroup(sequence[i]);
+    group->FireUp(time);
+  }
+}
+
+//______________________________________________________________________________
+AliTrigScheduledGroup *AliTrigScheduler::GetScheduledGroup(Int_t i) const
+{
+// Get i-th registered group (scheduling order does not matter, only group addition order).
+  return (AliTrigScheduledGroup*)fGroups->At(i);
+}
+
+//______________________________________________________________________________
+AliTrigScheduledGroup *AliTrigScheduler::GetScheduledGroup(const char *name) const
+{
+// Get a scheduled group by name.
+  return (AliTrigScheduledGroup*)fGroups->FindObject(name);
+}
+
+//______________________________________________________________________________
+void AliTrigScheduler::SetGroupPriority(const char *groupname, Int_t priority)
+{
+// Set the priority of a group.
+  AliTrigScheduledGroup *group = GetScheduledGroup(groupname);
+  if (!group) {
+    Error("SetGroupPriority", "Scheduler %s has no group named: %s", GetName(), groupname);
+    return;
+  }
+  group->SetPriority(priority);
+}
+  
diff --git a/TRIGGER/AliTrigScheduler.h b/TRIGGER/AliTrigScheduler.h
new file mode 100644 (file)
index 0000000..14bc68b
--- /dev/null
@@ -0,0 +1,153 @@
+#ifndef ALITRIGSCHEDULER_H
+#define ALITRIGSCHEDULER_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+// Author: Andrei Gheata, 27/07/2009
+
+#ifndef ROOT_TNamed
+#include "TNamed.h"
+#endif
+
+//==============================================================================
+//
+//   AliTrigScheduledGroup - A group of scheduled entries that will simply be
+//                           fired-up sequentially. The group delay in global time
+//                           units is the latest start time of the contained
+//                           entries. A group has a priority assigned by the
+//                           owner scheduler object. Groups are fired-up according
+//                           a programable sequence.
+//
+//==============================================================================
+
+class TObjArray;
+class AliTrigScheduledEntry;
+class AliTrigScheduler;
+
+//______________________________________________________________________________
+class AliTrigScheduledGroup : public TNamed {
+
+private:
+  Int_t                     fPriority;     // Group priority
+  Int_t                     fDelay;        // Group max. delay.
+  TObjArray                *fEntries;      // List of scheduled entries
+
+private:
+  AliTrigScheduledGroup(const AliTrigScheduledGroup &other);
+  AliTrigScheduledGroup &operator=(const AliTrigScheduledGroup &other);
+
+public:  
+  AliTrigScheduledGroup();
+  AliTrigScheduledGroup(const char *name, Int_t priority=0);
+  virtual ~AliTrigScheduledGroup();
+  
+  void                      AddEntry(AliTrigScheduledEntry *entry);
+  void                      FireUp(Int_t time);
+  TObjArray                *GetScheduledEntries() const {return fEntries;}
+  Int_t                     GetNentries() const;
+  Int_t                     GetPriority() const {return fPriority;}
+  Int_t                     GetDelay()    const {return fDelay;}
+  virtual void              Print(Option_t *option) const;
+  void                      RemoveEntry(AliTrigScheduledEntry *entry);  
+  void                      SetPriority(Int_t priority) {fPriority = priority;}
+    
+  ClassDef(AliTrigScheduledGroup, 1) // Groups of scheduled response functions
+};   
+
+//==============================================================================
+//
+//   AliTrigScheduledSequence - A programable group sequence. Scheduled groups
+//                      are owned and controlled by a trigger scheduler. They
+//                      are fired-up in such a sequence. A sequence supports some
+//                      default modes but can also be programed manually.
+//
+//==============================================================================
+
+//______________________________________________________________________________
+class AliTrigScheduledSequence : public TNamed {
+
+public:
+enum ESortingType {
+  kDefault       = 0,
+  kTimeInc       = 1,
+  kTimeDec       = 2,
+  kPriorityInc   = 3,
+  kPriorityDec   = 4,
+  kCustom        = 5
+};  
+
+private:
+  AliTrigScheduler         *fScheduler;    // Scheduler to which the sequence applies
+  Int_t                     fNgroups;      // Number of groups
+  ESortingType              fType;         // Sorting type
+  Int_t                    *fArray;        //[fNgroups] Array specifying the sequence
+
+private:
+  AliTrigScheduledSequence(const AliTrigScheduledSequence &other);
+  AliTrigScheduledSequence &operator=(const AliTrigScheduledSequence &other);
+  void                      SortArray(Int_t *array, Bool_t increasing);
+
+public:
+  AliTrigScheduledSequence();
+  AliTrigScheduledSequence(const char *name, AliTrigScheduler *scheduler);
+  virtual ~AliTrigScheduledSequence();
+  
+  Int_t                    *GetArray() const {return fArray;}
+  Int_t                     GetNgroups() const {return fNgroups;}
+  AliTrigScheduler         *GetScheduler() const {return fScheduler;}
+  ESortingType              GetSortingType() const {return fType;}
+  virtual void              Print(Option_t *option) const;
+  void                      Sort(ESortingType type, Int_t *sequence=0);
+  
+  ClassDef(AliTrigScheduledSequence, 1)  // Class for a scheduled group sequence
+};
+
+//==============================================================================
+//
+//   AliTrigScheduler - Device response function scheduler. Every device has a
+//                      scheduler, but the same scheduler can replay responses of
+//                      several devices. A scheduler holds groups of scheduled 
+//                      entries. The groups can be replayed in programable
+//                      sequences. A default group and sequence are always created.
+//
+//==============================================================================
+
+class AliTrigScheduledGroup;
+class AliTrigScheduledSequence;
+
+//______________________________________________________________________________
+class AliTrigScheduler : public TNamed {
+
+private:
+  Int_t                     fNgroups;      // Number of scheduled groups (at least one)
+  TObjArray                *fGroups;       // List of groups of response functions
+  TObjArray                *fSequences;    // List of group replay sequences
+  AliTrigScheduledSequence *fCurrentSequence; // Current group replay sequence
+
+private:
+  AliTrigScheduler(const AliTrigScheduler &other);
+  AliTrigScheduler &operator=(const AliTrigScheduler &other);
+
+public:
+  AliTrigScheduler();
+  AliTrigScheduler(const char *name);
+  virtual ~AliTrigScheduler();
+  
+  void                      AddScheduledEntry(AliTrigScheduledEntry *entry, const char *togroup="default");
+  AliTrigScheduledGroup    *AddGroup(const char *groupname);
+  AliTrigScheduledGroup    *AddGroup(AliTrigScheduledGroup *group);
+  AliTrigScheduledSequence *AddSequence(const char *seqname, AliTrigScheduledSequence::ESortingType type=AliTrigScheduledSequence::kDefault, 
+                                        Int_t *sequence = 0);
+  void                      FireUp(Int_t time);
+  AliTrigScheduledSequence *GetCurrentSequence() const {return fCurrentSequence;}
+  Int_t                     GetNgroups() const {return fNgroups;}
+  TObjArray                *GetScheduledGroups() const {return fGroups;}
+  AliTrigScheduledGroup    *GetScheduledGroup(Int_t i) const;
+  AliTrigScheduledGroup    *GetScheduledGroup(const char *name) const;
+  void                      SetCurrentSequence(AliTrigScheduledSequence *seq) {fCurrentSequence = seq;}
+  void                      SetGroupPriority(const char *groupname, Int_t priority);
+     
+  ClassDef(AliTrigScheduler,1)  // Trigger scheduler class
+};
+#endif
index 5f0e790..05b3766 100644 (file)
 #pragma link off all functions;
  
 #pragma link C++ class  AliTRIPreprocessor+;
+#pragma link C++ class  AliTrigConnector+;
+#pragma link C++ class  AliTrigDevice+;
+#pragma link C++ class  AliTrigDigitalCircuit+;
+#pragma link C++ class  AliTrigEvent+;
+#pragma link C++ class  AliTrigEventWithMask+;
+#pragma link C++ class  AliTrigEventWithObject+;
+#pragma link C++ class  AliTrigScheduledDevice+;
+#pragma link C++ class  AliTrigScheduledEntry+;
+#pragma link C++ class  AliTrigScheduledGroup+;
+#pragma link C++ class  AliTrigScheduledResponse+;
+#pragma link C++ class  AliTrigScheduledSequence+;
+#pragma link C++ class  AliTrigScheduler+;
 
 #endif
index bb595ac..9321e3b 100644 (file)
@@ -1,7 +1,9 @@
 #-*- Mode: Makefile -*-
 # $Id$
 
-SRCS:=  AliTRIPreprocessor.cxx  
+SRCS:=  AliTRIPreprocessor.cxx  AliTrigConnector.cxx AliTrigDevice.cxx \
+        AliTrigDigitalCircuit.cxx AliTrigEvent.cxx AliTrigScheduledEntry.cxx \
+        AliTrigScheduler.cxx
 CINTHDRS:= $(SRCS:.cxx=.h)
 
 HDRS:= $(SRCS:.cxx=.h)