//
// File   : VirtualReadout.hh
//
// Purpose: Declaration of the class VReadout
//
// $Id: VirtualReadout.hh 11934 2011-01-25 08:55:29Z mathes $
//



/** @file VirtualReadout.hh
  * Declaration of the class VReadout.
  * @author H.-J. Mathes, FzK
  */


#ifndef _VirtualReadout_hh_
#define _VirtualReadout_hh_

#include <string>

#include <ErrorLogging.hh>
#include <FdNumbering.hh>
#include <FadcData.hh>

// --- forward declaration(s)

class FEPageDesc;
class TMirrorEventHeader;
class TMirrorPixelData;
class TMirrorRunHeader;
class TMirrorRunTrailer;

/** Abstract base class for the concept of event data readout.
  *
  * Actually event data might be extracted from:
  * @li the frontend hardware (classes FEReadoutV3,  FEReadoutV4 or class 
  *     FECachedReadout)
  * @li a file (class FEFileReadout)
  */
class VirtualReadout {
public:
    /** Constructor for the class VirtualReadout. */
    VirtualReadout() : fColumnList(0), fName("VirtualReadout") { }

    /** Virtual destructor of the class VirtualReadout. */
    virtual ~VirtualReadout() { }

    /** Do the initialisation of the acquisition. */
    virtual int AcquisitionInit() = 0;

    /** Do the shutdown of the acquisition. */
    virtual int AcquisitionShutdown() = 0;

    /** Perform the start of the acquisition. */
    virtual int AcquisitionStart() = 0;

    /** Perform the stop of the acquisition. */
    virtual int AcquisitionStop() = 0;
   
    /** Delete all 'references' to the current events data.
      *
      * This implies also the deletion of cached data entries !
      */
    virtual void DeleteEvent(FEPageDesc*) = 0;

    /** Fill the run header with some information got from the hardware. */
    virtual void FillRunHeader(TMirrorRunHeader*) = 0;

    /** Fill the run trailer with some information got from the hardware. */
    virtual void FillRunTrailer(TMirrorRunTrailer*) = 0;
    
    /** Get bit vector which has set bit for each present FE module. */
    virtual unsigned long GetColumnList() { return fColumnList; }

    /** Do the readout of the TMirrorEventHeader object. 
      *
      * If the storage for this object is supplied, its data are read to this 
      * storage otherwise the object is created and cached internally.
      */
    virtual TMirrorEventHeader* 
            GetEventHeader(FEPageDesc*,TMirrorEventHeader* hdr=NULL) = 0;

    /** Read the FADCData of the specified pixel.
      *
      * If the data is already in the cache, get a reference to it, otherwise 
      * read it directly from the data source and create a cache entry.
      */
    virtual TFADCData* GetFADCData(FEPageDesc*,TFADCData*) = 0;
    
    /** Read the FADCData of the specified pixel.
      *
      * If storage are is supplied for this object, data is read into this 
      * area, otherwise a new object is created. This method does always a 
      * full readout of the FADC trace.
      */
    virtual TFADCData* GetFADCData(FEPageDesc*,
                                   FdUtil::Fd::PixelNumber,
				   TFADCData* data=NULL) = 0;
    
    /** Read the FADCData of the specified pixel.
      *
      * The specification of the desired pixel and its range of interest 
      * for readout is supplied by
      * @li the PixelNumber
      * @li and the start/end bin of the FADC data
      *
      * If the storage for this object is supplied. the data will be read into 
      * the supplied storage otherwise the object will be created.
      *
      * The object read will be cached for subsequent calls with the 
      * same pixel number.
      */
    virtual TFADCData* GetFADCData(FEPageDesc*, 
                                   FdUtil::Fd::PixelNumber,
			           TFADCData::FADCTraceInfo,
			           TFADCData *data=NULL) = 0;
    
    /** Get the pixels monitoring data for the specified pixel.
      *
      * If the storage area for the monitoring data is supplied, data will be
      * copied into that area otherwise new storage area will be supplied.
      */
    virtual TFADCData::PixelMonitorData GetMonitorData(FEPageDesc*,
                          FdUtil::Fd::PixelNumber,TFADCData::PixelMonitorData data=NULL) = 0;
    
    /** Get the name of this class instance. */
    const std::string& GetName()
     { return fName; }
     
    /** Get the pixels SLT data and the multiplicity data from FLT (TMirrorPixelData).
      *
      * If the storage area for the SLT data is supplied, data will be
      * copied into that area, otherwise new storage area will be supplied.
      */
    virtual TMirrorPixelData* GetPixelData(FEPageDesc*,
                                           TMirrorPixelData* data=NULL) = 0;
    
    /** Set the name for this class instance. */
    void SetName(const char* name)
     { fName = name; }

    /** Set the name of this class instance. */
    void SetName(const std::string& name)
     { fName = name; }

    /** Wait until a NxPage signal has occurred and return the corresponding 
      * descriptor for that page.
      */
    virtual FEPageDesc* WaitForNextPage()
     { FD_CERR << "VirtualReadout::WaitForNextPage() is not implemented !" 
                 << std::endl; return NULL; }
   
protected:

    /** Bit vector of FE columns present in the actual configuration. 
      *
      * This variable is used to cache this information for further use.
      */
    unsigned int      fColumnList;      ///< FE module present bits.
    
    /** Name of this class instance. */
    std::string       fName;
};

#endif  // _VirtualReadout_hh_