]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RALICE/AliEvent.cxx
Coding Convention Violation correction
[u/mrichter/AliRoot.git] / RALICE / AliEvent.cxx
index 54b455b6c551813816c6b5b6c85f3497ac75a75a..54ca223f729144fd365195138d70f9faf36825ff 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-// $Id: AliEvent.cxx,v 1.6 2002/04/26 11:23:37 nick Exp $
+// $Id: AliEvent.cxx,v 1.18 2004/01/12 08:23:22 nick Exp $
 
 ///////////////////////////////////////////////////////////////////////////
 // Class AliEvent
 // Creation and investigation of an Alice physics event.
 // An AliEvent can be constructed by adding AliTracks, Alivertices, AliJets
-// and/or AliCalorimeters.
+// and/or devices like AliCalorimeters.
+// All objects which are derived from TObject can be regarded as a device.
 //
 // The basic functionality of AliEvent is identical to the one of AliVertex.
 // So, an AliEvent may be used as the primary vertex with some additional
 //
 // To provide maximal flexibility to the user, the two modes of track/jet/vertex
 // storage as described in AliJet and AliVertex can be used.
-// In addition an identical structure is provided for the storage of AliCalorimeter
-// objects, which can be selected by means of the memberfunction SetCalCopy().
-//
-// a) SetCalCopy(0) (which is the default).
-//    Only the pointers of the 'added' calorimeters are stored.
-//    This mode is typically used by making cal. studies based on a fixed set
-//    of calorimeters which stays under user control or is kept on an external
+// In addition an identical structure is provided for the storage of devices like
+// AliCalorimeter objects, which can be selected by means of the memberfunction
+// SetDevCopy().
+//
+// a) SetDevCopy(0) (which is the default).
+//    Only the pointers of the 'added' devices are stored.
+//    This mode is typically used by making studies based on a fixed set
+//    of devices which stays under user control or is kept on an external
 //    file/tree. 
 //    In this way the AliEvent just represents a 'logical structure' for the
 //    physics analysis.
 //
 //    Note :
-//    Modifications made to the original calorimeters also affect the AliCalorimeter
+//    Modifications made to the original devices also affect the device
 //    objects which are stored in the AliEvent. 
 //
-// b) SetCalCopy(1).
-//    Of every 'added' calorimeter a private copy will be made of which the pointer
+// b) SetDevCopy(1).
+//    Of every 'added' device a private copy will be made of which the pointer
 //    will be stored.
 //    In this way the AliEvent represents an entity on its own and modifications
 //    made to the original calorimeters do not affect the AliCalorimeter objects
 //    which are stored in the AliEvent. 
-//    This mode will allow 'adding' many different AliCalorimeters into an AliEvent by
-//    creating only one AliCalorimeter instance in the main programme and using the
-//    AliCalorimeter::Reset() and AliCalorimeter parameter setting memberfunctions.
+//    This mode will allow 'adding' many different devices into an AliEvent by
+//    creating only one device instance in the main programme and using the
+//    Reset() and parameter setting memberfunctions of the object representing the device.
+//
+//    Note :
+//    The copy is made using the Clone() memberfunction.
+//    All devices (i.e. classes derived from TObject) have the default TObject::Clone() 
+//    memberfunction.
+//    However, devices generally contain an internal (signal) data structure
+//    which may include pointers to other objects. Therefore it is recommended to provide
+//    for all devices a specific copy constructor and override the default Clone()
+//    memberfunction using this copy constructor.
+//    An example for this may be seen from AliCalorimeter.   
 //
 // See also the documentation provided for the memberfunction SetOwner(). 
 //
@@ -66,7 +78,7 @@
 // Specify the event object as the repository of all objects
 // for the event building and physics analysis.
 // 
-//        evt.SetCalCopy(1);
+//        evt.SetDevCopy(1);
 //        evt.SetTrackCopy(1);
 //
 // Fill the event structure with the basic objects
@@ -76,7 +88,7 @@
 //         ... // code to fill the calorimeter data
 //         ...
 //
-//        evt.AddCalorimeter(emcal);
+//        evt.AddDevice(emcal);
 //
 //        AliTrack* tx=new AliTrack();
 //        for (Int_t i=0; i<10; i++)
 // Note : All quantities are in GeV, GeV/c or GeV/c**2
 //
 //--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht
-//- Modified: NvE $Date: 2003/02/03 13:19:44 $ UU-SAP Utrecht
+//- Modified: NvE $Date: 2004/01/12 08:23:22 $ UU-SAP Utrecht
 ///////////////////////////////////////////////////////////////////////////
 
 #include "AliEvent.h"
+#include "Riostream.h"
  
 ClassImp(AliEvent) // Class implementation to enable ROOT I/O
  
-AliEvent::AliEvent()
+AliEvent::AliEvent() : AliVertex()
 {
 // Default constructor.
 // All variables initialised to default values.
@@ -211,16 +224,18 @@ AliEvent::AliEvent()
  fZtarg=0;
  fPnucTarg=0;
  fIdTarg=0;
- fNcals=0;
- fCalorimeters=0;
- fCalCopy=0;
+ fDevices=0;
+ fDevCopy=0;
 }
 ///////////////////////////////////////////////////////////////////////////
-AliEvent::AliEvent(Int_t n): AliVertex(n)
+AliEvent::AliEvent(Int_t n) : AliVertex(n)
 {
 // Create an event to hold initially a maximum of n tracks
 // All variables initialised to default values
- cout << "AliEvent init with n = " << n << endl;
+ if (n<=0)
+ {
+  cout << " *** This AliVertex initialisation was invoked via the AliEvent ctor." << endl;
+ }
  fDaytime.Set();
  fRun=0;
  fEvent=0;
@@ -232,18 +247,57 @@ AliEvent::AliEvent(Int_t n): AliVertex(n)
  fZtarg=0;
  fPnucTarg=0;
  fIdTarg=0;
- fNcals=0;
- fCalorimeters=0;
- fCalCopy=0;
+ fDevices=0;
+ fDevCopy=0;
 }
 ///////////////////////////////////////////////////////////////////////////
 AliEvent::~AliEvent()
 {
 // Default destructor
- if (fCalorimeters)
+ if (fDevices)
+ {
+  delete fDevices;
+  fDevices=0;
+ }
+}
+///////////////////////////////////////////////////////////////////////////
+AliEvent::AliEvent(AliEvent& evt) : AliVertex(evt)
+{
+// Copy constructor.
+ fDaytime=evt.fDaytime;
+ fRun=evt.fRun;
+ fEvent=evt.fEvent;
+ fAproj=evt.fAproj;
+ fZproj=evt.fZproj;
+ fPnucProj=evt.fPnucProj;
+ fIdProj=evt.fIdProj;
+ fAtarg=evt.fAtarg;
+ fZtarg=evt.fZtarg;
+ fPnucTarg=evt.fPnucTarg;
+ fIdTarg=evt.fIdTarg;
+ fDevCopy=evt.fDevCopy;
+
+ fDevices=0;
+ Int_t ndevs=evt.GetNdevices();
+ if (ndevs)
  {
-  delete fCalorimeters;
-  fCalorimeters=0;
+  fDevices=new TObjArray(ndevs);
+  if (fDevCopy) fDevices->SetOwner();
+  for (Int_t i=1; i<=ndevs; i++)
+  {
+   TObject* dev=evt.GetDevice(i);
+   if (dev)
+   {
+    if (fDevCopy)
+    {
+     fDevices->Add(dev->Clone());
+    }
+    else
+    {
+     fDevices->Add(dev);
+    }
+   }
+  }
  }
 }
 ///////////////////////////////////////////////////////////////////////////
@@ -253,6 +307,9 @@ void AliEvent::Reset()
 // The max. number of tracks is set to the initial value again
 // The max. number of vertices is set to the default value again
 // Note : The CalCopy mode is maintained as it was set by the user before.
+
+ AliVertex::Reset();
+
  fDaytime.Set();
  fRun=0;
  fEvent=0;
@@ -265,14 +322,11 @@ void AliEvent::Reset()
  fPnucTarg=0;
  fIdTarg=0;
 
- fNcals=0;
- if (fCalorimeters)
+ if (fDevices)
  {
-  delete fCalorimeters;
-  fCalorimeters=0;
+  delete fDevices;
+  fDevices=0;
  }
-
- AliVertex::Reset();
 }
 ///////////////////////////////////////////////////////////////////////////
 void AliEvent::SetOwner(Bool_t own)
@@ -298,18 +352,32 @@ void AliEvent::SetOwner(Bool_t own)
 
  Int_t mode=1;
  if (!own) mode=0;
- if (fCalorimeters) fCalorimeters->SetOwner(own);
- fCalCopy=mode;
+ if (fDevices) fDevices->SetOwner(own);
+ fDevCopy=mode;
 
  AliVertex::SetOwner(own);
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliEvent::SetDayTime(TDatime& stamp)
+void AliEvent::SetDayTime(TTimeStamp& stamp)
 {
-// Set the date and time stamp for this event
+// Set the date and time stamp for this event.
+// An exact copy of the entered date/time stamp will be saved with an
+// accuracy of 1 nanosecond.
  fDaytime=stamp;
 }
 ///////////////////////////////////////////////////////////////////////////
+void AliEvent::SetDayTime(TDatime& stamp)
+{
+// Set the date and time stamp for this event.
+// The entered date/time will be interpreted as being the local date/time
+// and the accuracy is 1 second.
+// This function with the TDatime argument is mainly kept for backward
+// compatibility reasons. It is recommended to use the corresponding
+// function with the TTimeStamp argument.
+
+ fDaytime.Set(stamp.GetDate(),stamp.GetTime(),0,kFALSE,0);
+}
+///////////////////////////////////////////////////////////////////////////
 void AliEvent::SetRunNumber(Int_t run)
 {
 // Set the run number for this event
@@ -322,7 +390,7 @@ void AliEvent::SetEventNumber(Int_t evt)
  fEvent=evt;
 }
 ///////////////////////////////////////////////////////////////////////////
-TDatime AliEvent::GetDayTime()
+TTimeStamp AliEvent::GetDayTime()
 {
 // Provide the date and time stamp for this event
  return fDaytime;
@@ -411,10 +479,18 @@ Int_t AliEvent::GetTargetId()
 void AliEvent::HeaderData()
 {
 // Provide event header information
- cout << " *AliEvent::Data* Run : " << fRun << " Event : " << fEvent
-      << " Date : " << fDaytime.AsString() << endl;
+ const char* name=GetName();
+ const char* title=GetTitle();
+ Int_t ndevs=GetNdevices();
+ cout << " *" << ClassName() << "::Data*";
+ if (strlen(name))  cout << " Name : " << GetName();
+ if (strlen(title)) cout << " Title : " << GetTitle();
+ cout << endl;
+ cout << "  " << fDaytime.AsString() << endl;
+ cout << "  Run : " << fRun << " Event : " << fEvent
+      << " Number of devices : " << ndevs << endl;
 
ShowCalorimeters();
if (ndevs) ShowDevices();
 }
 ///////////////////////////////////////////////////////////////////////////
 void AliEvent::Data(TString f)
@@ -424,111 +500,147 @@ void AliEvent::Data(TString f)
  AliVertex::Data(f);
 } 
 ///////////////////////////////////////////////////////////////////////////
-Int_t AliEvent::GetNcalorimeters()
+Int_t AliEvent::GetNdevices()
 {
-// Provide the number of stored calorimeter systems
- return fNcals;
+// Provide the number of stored devices
+ Int_t ndevs=0;
+ if (fDevices) ndevs=fDevices->GetEntries();
+ return ndevs;
 } 
 ///////////////////////////////////////////////////////////////////////////
-void AliEvent::AddCalorimeter(AliCalorimeter& c)
+void AliEvent::AddDevice(TObject& d)
 {
-// Add a calorimeter system to the event
- if (!fCalorimeters)
+// Add a device to the event.
+//
+// Note :
+// In case a private copy is made, this is performed via the Clone() memberfunction.
+// All devices (i.e. classes derived from TObject) have the default TObject::Clone() 
+// memberfunction.
+// However, devices generally contain an internal (signal) data structure
+// which may include pointers to other objects. Therefore it is recommended to provide
+// for all devices a specific copy constructor and override the default Clone()
+// memberfunction using this copy constructor.
+// An example for this may be seen from AliCalorimeter.   
+
+ if (!fDevices)
  {
-  fCalorimeters=new TObjArray();
-  if (fCalCopy) fCalorimeters->SetOwner();
+  fDevices=new TObjArray();
+  if (fDevCopy) fDevices->SetOwner();
  }
  
- // Add the calorimeter system to this event
- fNcals++;
- if (fCalCopy)
+ // Add the device to this event
+ if (fDevCopy)
  {
-  fCalorimeters->AddLast((AliCalorimeter*)c.Clone());
+  fDevices->Add(d.Clone());
  }
  else
  {
-  fCalorimeters->AddLast(&c);
+  fDevices->Add(&d);
  }
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliEvent::SetCalCopy(Int_t j)
+void AliEvent::SetDevCopy(Int_t j)
 {
-// (De)activate the creation of private copies of the added calorimeters.
-// j=0 ==> No private copies are made; pointers of original cals. are stored.
-// j=1 ==> Private copies of the cals. are made and these pointers are stored.
-//
-// Note : Once the storage contains pointer(s) to AliCalorimeter(s) one cannot
-//        change the CalCopy mode anymore.
-//        To change the CalCopy mode for an existing AliEvent containing
-//        calorimeters one first has to invoke Reset().
- if (!fCalorimeters)
+// (De)activate the creation of private copies of the added devices.
+// j=0 ==> No private copies are made; pointers of original devices are stored.
+// j=1 ==> Private copies of the devices are made and these pointers are stored.
+//
+//
+// Notes :
+//  In case a private copy is made, this is performed via the Clone() memberfunction.
+//  All devices (i.e. classes derived from TObject) have the default TObject::Clone() 
+//  memberfunction.
+//  However, devices generally contain an internal (signal) data structure
+//  which may include pointers to other objects. Therefore it is recommended to provide
+//  for all devices a specific copy constructor and override the default Clone()
+//  memberfunction using this copy constructor.
+//  An example for this may be seen from AliCalorimeter.   
+//
+//  Once the storage contains pointer(s) to device(s) one cannot
+//  change the DevCopy mode anymore.
+//  To change the DevCopy mode for an existing AliEvent containing
+//  devices one first has to invoke Reset().
+
+ if (!fDevices)
  {
   if (j==0 || j==1)
   {
-   fCalCopy=j;
+   fDevCopy=j;
   }
   else
   {
-   cout << "*AliEvent::SetCalCopy* Invalid argument : " << j << endl;
+   cout << " *" << ClassName() << "::SetDevCopy* Invalid argument : " << j << endl;
   }
  }
  else
  {
-  cout << "*AliEvent::SetCalCopy* Storage already contained calorimeters."
-       << "  ==> CalCopy mode not changed." << endl; 
+  cout << " *" << ClassName() << "::SetDevCopy* Storage already contained devices."
+       << "  ==> DevCopy mode not changed." << endl; 
  }
 }
 ///////////////////////////////////////////////////////////////////////////
-Int_t AliEvent::GetCalCopy()
+Int_t AliEvent::GetDevCopy()
 {
-// Provide value of the CalCopy mode.
-// 0 ==> No private copies are made; pointers of original cals. are stored.
-// 1 ==> Private copies of the cals. are made and these pointers are stored.
- return fCalCopy;
+// Provide value of the DevCopy mode.
+// 0 ==> No private copies are made; pointers of original devices are stored.
+// 1 ==> Private copies of the devices are made and these pointers are stored.
+//
+// Note :
+// In case a private copy is made, this is performed via the Clone() memberfunction.
+// All devices (i.e. classes derived from TObject) have the default TObject::Clone() 
+// memberfunction.
+// However, devices generally contain an internal (signal) data structure
+// which may include pointers to other objects. Therefore it is recommended to provide
+// for all devices a specific copy constructor and override the default Clone()
+// memberfunction using this copy constructor.
+// An example for this may be seen from AliCalorimeter.   
+
+ return fDevCopy;
 }
 ///////////////////////////////////////////////////////////////////////////
-AliCalorimeter* AliEvent::GetCalorimeter(Int_t i)
+TObject* AliEvent::GetDevice(Int_t i)
 {
-// Return the i-th calorimeter of this event
- if (!fCalorimeters)
+// Return the i-th device of this event.
+// The first device corresponds to i=1.
+
+ if (!fDevices)
  {
-  cout << " *AliEvent::GetCalorimeter* No calorimeters present." << endl;
   return 0;
  }
  else
  {
-  if (i<=0 || i>fNcals)
+  Int_t ndevs=GetNdevices();
+  if (i<=0 || i>ndevs)
   {
-   cout << " *AliEvent::GetCalorimeter* Invalid argument i : " << i
-        << " Ncals = " << fNcals << endl;
+   cout << " *" << ClassName() << "::GetDevice* Invalid argument i : " << i
+        << " ndevs = " << ndevs << endl;
    return 0;
   }
   else
   {
-   return (AliCalorimeter*)fCalorimeters->At(i-1);
+   return fDevices->At(i-1);
   }
  }
 }
 ///////////////////////////////////////////////////////////////////////////
-AliCalorimeter* AliEvent::GetCalorimeter(TString name)
+TObject* AliEvent::GetDevice(TString name)
 {
-// Return the calorimeter with name tag "name"
- if (!fCalorimeters)
+// Return the device with name tag "name"
+ if (!fDevices)
  {
-  cout << " *AliEvent::GetCalorimeter* No calorimeters present." << endl;
   return 0;
  }
  else
  {
-  AliCalorimeter* cx;
   TString s;
-  for (Int_t i=0; i<fNcals; i++)
+  Int_t ndevs=GetNdevices();
+  for (Int_t i=0; i<ndevs; i++)
   {
-   cx=(AliCalorimeter*)fCalorimeters->At(i);
-   if (cx)
+   TObject* dev=fDevices->At(i);
+   if (dev)
    {
-    s=cx->GetName();
-    if (s == name) return cx;
+    s=dev->GetName();
+    if (s == name) return dev;
    }
   }
 
@@ -536,22 +648,46 @@ AliCalorimeter* AliEvent::GetCalorimeter(TString name)
  }
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliEvent::ShowCalorimeters()
+void AliEvent::ShowDevices()
 {
-// Provide an overview of the available calorimeter systems.
- if (fNcals>0)
+// Provide an overview of the available devices.
+ Int_t ndevs=GetNdevices();
+ if (ndevs)
  {
-  cout << " The following " << fNcals << " calorimeter systems are available :" << endl; 
-  for (Int_t i=1; i<=fNcals; i++)
+  cout << " The following " << ndevs << " devices are available :" << endl; 
+  for (Int_t i=1; i<=ndevs; i++)
   {
-   AliCalorimeter* cal=GetCalorimeter(i);
-   if (cal) cout << " Calorimeter number : " << i << " Name : " << cal->GetName() << endl;
+   TObject* dev=GetDevice(i);
+   if (dev)
+   {
+    cout << " Device number : " << i
+         << " Class : " << dev->ClassName()
+         << " Name : " << dev->GetName() << endl;
+   }
   }
  }
  else
  {
-  cout << " No calorimeters present for this event." << endl;
+  cout << " No devices present for this event." << endl;
+ }
+}
+///////////////////////////////////////////////////////////////////////////
+TObject* AliEvent::Clone(const char* name)
+{
+// Make a deep copy of the current object and provide the pointer to the copy.
+// This memberfunction enables automatic creation of new objects of the
+// correct type depending on the object type, a feature which may be very useful
+// for containers when adding objects in case the container owns the objects.
+// This feature allows to store either AliEvent objects or objects derived from
+// AliEvent via some generic AddEvent memberfunction, provided these derived
+// classes also have a proper Clone memberfunction. 
+
+ AliEvent* evt=new AliEvent(*this);
+ if (name)
+ {
+  if (strlen(name)) evt->SetName(name);
  }
+ return evt;
 }
 ///////////////////////////////////////////////////////////////////////////