// // File : MiPixelList.hh // // Purpose: Declaration of Mirror pixel list class // // $Id: MiPixelList.hh 12082 2011-02-21 17:11:29Z mathes $ // /** @file MiPixelList.hh * Declaration of class TMirrorPixelList * @author H.-J. Mathes, FzK */ #ifndef _MiPixelList_hh_ #define _MiPixelList_hh_ // --> prevent users from including that file directly #ifndef __CINT__ # if (!defined _MiEvent_hh_) && (!defined _VMiEvent_hh_) # error You are not supposed to include that header file ! # error Please use MiEvent.hh instead ! # endif // !_MiEvent_hh_ && !_VMiEvent_hh_ #endif // __CINT__ #include #include #include #include // ----- forward declarations class TMirrorBitArray; class TMirrorPixelData; /** @anchor MiPixelList * List of triggered/readout pixels. * * This class holds a list of pixels. This list could be used to: * @li steer the processing of pixel related data * @li steer the loading/saving of the FADCData in order to save time and * disk/memory space * @li be inserted into the EyePixelList made up of the pixel lists of * individual mirrors */ class TMirrorPixelList : public TObject { friend class TMirrorEvent; friend class TShmEvent; friend class ShmEventDescriptor; friend bool TestMirrorStructSizes(); // test code protected: /** Space to hold bit-vector for all pixels. */ static const int kPixelVectorSize = 15; // 480/sizeof(int) /** Mirror pixel list structure. * * This structure makes up a variable length list of the pixels * which are present in the current event. This struct is created in such * a way that it can hold up to the maximum number of pixels. */ typedef struct _MiPixelList { /** Internally used structure version information. */ Version_t fVersion; /** Number of PixelNumberRec in this list. */ UInt_t fNPixels; /** Location for the first pixels PixelNumberRec struct. */ FdUtil::Fd::PixelNumberRec fPixelNumber[1]; #if 0 // new/changed for version 2 /** We have a bit set for each pixel present in the list. */ UInt_t fPixelVector[kPixelVectorSize]; #endif } MiPixelListRec, *MiPixelList; public: /** Default constructor for class TMirrorPixelList. * * This constructor allocates space for the data using the C-function * MiPixelListCreate(). */ TMirrorPixelList(); /** Constructor from void pointer (useful for SHM). */ TMirrorPixelList(void*); /** Constructor for a TMirrorPixelList from a TMirrorBitArray. * * All pixels whose corresponding bit in the TMirrorBitArray is set are added * to the pixel list. In addition the virtual channels of all columns where at * least one bit is set are added, too. * * @todo * @li optimize for even/odd rows virtual channels * @li adjust mirror and eye number of the created pixel list entries */ TMirrorPixelList(const TMirrorBitArray*); /** Construct a TMirrorPixelList object and add all pixels to the list * are set in the passed TMirrorPixelData object. * * @param start_slice The time slice from which we start to take the data. * @param end_slice The time slice where we stop to take the data. * The default is Fd::kMI_NSLT_BINS which means that all * time slices should be or'ed together. */ TMirrorPixelList(const TMirrorPixelData*, UInt_t start_slice = 0, UInt_t end_slice = FdUtil::Fd::kMI_NSLT_BINS); /** Copy constructor for class TMirrorPixelList. * * This copy constructor performs a deep copy without using any reference * counting scheme. */ TMirrorPixelList(const TMirrorPixelList&); /** Destructor for class TMirrorPixelList. * * The destructor destroys the object in a way which is compatible to the * specific method of its construction. */ virtual ~TMirrorPixelList(); /** operator=() for class TMirrorPixelList. * * This operator has to be defined in order to perform a deep copy of * a TMirrorPixelList object. */ TMirrorPixelList& operator=(const TMirrorPixelList&); /** operator==() for class TMirrorPixelList. */ bool operator==(const TMirrorPixelList&) const; // FdUtil::Fd::PixelNumber &operator[](UInt_t); // const FdUtil::Fd::PixelNumber &operator[](UInt_t) const; /** Add a pixel specified by its Fd::PixelNumber to the pixel list. * Return 1, if an illegal pixel number was specified or if the size of the * list will exceed the maximum number of pixels. * * @todo * @li Check if the pixel was already added before. */ virtual int AddPixel(FdUtil::Fd::PixelNumber pixel); /** Add a pixel specified by its column and row indices to the pixel list. * * Returns 1, if the index is outside the valid range. * * Could throw exception range_error() ??? */ virtual int AddPixel(UInt_t col, UInt_t row); /** Add a virtual pixel (outside the regular pixel matrix) to the pixel list. * * @param col column index in the range Fd::kMI_FIRST_COL .. Fd::kMI_LAST_COL * @param virt index for the virtual channel, 1 .. 2 * (Fd::kMI_FIRST_VCHANNEL .. Fd::kMI_LAST_VCHANNEL) * * @Return 0, if the PixelNumber is inside the valid range, 1 otherwise. */ virtual int AddVirtualPixel(UInt_t col, UInt_t virt); /** Clear the contents of a TMirrorPixelList object. */ virtual void Clear(Option_t * ="") { Init(); } /** Copy the PixelList data from another pixel list (deep copy). */ void CopyFrom(TMirrorPixelList*); /** Print the contents of a pixel list to the specified stream. */ virtual void Show(std::ostream& ostr=std::cout) const; // --- getters /** Get the maximum size which a mirror pixel list could have (in Bytes). */ static UInt_t GetMaxSize() { return ( sizeof(MiPixelListRec) + sizeof(FdUtil::Fd::PixelNumberRec) * (FdUtil::Fd::kMI_NEXTROWS*FdUtil::Fd::kMI_NCOLS - 1)); } /** Get the number of pixels stored in the mirror pixel list. * * This number is needed as the limit for the loop in subsequent accesses * to the pixel list via the method GetPixel(). */ UInt_t GetNumPixels() const { return fPixelList->fNPixels; } /** TMirrorPixelList contains NumPixels() pixels which could be retrieved * by this function just applying an index 0...NumPixels()-1 . */ FdUtil::Fd::PixelNumber GetPixel(UInt_t seq) const; /** Return the actual size of the pixel list. * * In case of copying the PixelList or allocating space for it, the actual * size of the PixelList might be needed, though the present implementation * holds always the maximum needed space. */ UInt_t GetSize() const { return sizeof( MiPixelListRec ) + fPixelList->fNPixels * sizeof( FdUtil::Fd::PixelNumberRec ); } /** Return the version of the data structure. */ Version_t GetVersion() const { return fPixelList->fVersion; } /** Merge the contents of two TMirrorPixelList objects. */ void Merge(TMirrorPixelList*); /** Merge the content of the TMirrorPixelList object with the * content of TMirrorBitArray object. */ void Merge(TMirrorBitArray*); // --- setters /** Reset the pixel list, i.e. set the number of pixels which are in the * list to 0. */ void Reset() { SetNumPixels( 0 ); } /** Set the entries of the pixel list for each bit set in the passed * TMirrorBitArray object. */ void Set(TMirrorBitArray*); /** Set the number of pixels in the pixel list. * * Usually this is done by adding pixels but sometimes it is necessary to * set the initial value to 0 ! * When a TMirrorPixelList is constructed, the initial size is set to 0. */ void SetNumPixels(UInt_t n_pixel) { fPixelList->fNPixels = n_pixel; } protected: /** Sort the pixel list according to the pixel numbers. */ virtual void Sort(); private: /** Create a raw MiPixelList struct in memory. */ void Construct(); /** Remove a raw MiPixelList struct from memory. */ void Destruct() { std::free( fPixelList ); fPixelList = NULL; } /** Init a TMirrorPixelList object partially (0 pixels). */ void Init(); MiEvent::Constructor_t fConstructorType; //! how object was created MiPixelList fPixelList; //! pointer to C-struct bool fIsSorted; //! flag to indicate sort FdUtil::Fd::PixelNumberRec fPixelNumber; //! pixel number to return ClassDef(TMirrorPixelList,MiEVENTVERSIONv1) }; #endif // _MiPixelList_hh_