// $Id: UgliDbiScintPln.h,v 1.9 2005/04/29 04:49:06 minoscvs Exp $

#ifndef UGLIDBISCINTPLN_H
#define UGLIDBISCINTPLN_H

////////////////////////////////////////////////////////////////////////
// UgliDbiScintPln
//
// Package: UgliGeometry
//
// Concept:
//
//
// R. Hatcher 2001-08-08
////////////////////////////////////////////////////////////////////////

#include "DatabaseInterface/DbiTableRow.h"
#include "LeakChecker/Lea.h"

#include "UgliGeometry/Ugli.h"
#include "Plex/PlexPlaneId.h"

class DbiValidityRec;

#include <iosfwd>

class UgliDbiScintPln;
std::ostream& operator<<(std::ostream& os, const UgliDbiScintPln& udsp);

class UgliDbiScintPln : public DbiTableRow
{

public:

// Constructors and destructors.

   UgliDbiScintPln()
      : fPlaneId(), fThickness(-1), fGap(-1),
        fX0RelSteel(0), fY0RelSteel(0), fZRotRelSteelRad(0) { LEA_CTOR; };

   UgliDbiScintPln(PlexPlaneId plnid, Float_t thick, Float_t gap,
                   Float_t x0rel, Float_t y0rel, Float_t zrot)
      : fPlaneId(plnid), fThickness(thick), fGap(gap),
        fX0RelSteel(x0rel), fY0RelSteel(y0rel), fZRotRelSteelRad(zrot)
      { LEA_CTOR; };

   virtual ~UgliDbiScintPln(){ LEA_DTOR; };

// State testing member functions

   virtual Int_t    GetAggregateNo() const { return fPlaneId.GetPlane(); }
   virtual UInt_t   GetIndex(UInt_t /* defIndex */) const { return fPlaneId.GetPlane(); }

   PlexPlaneId  GetPlaneId() const { return fPlaneId; }
   Int_t        GetPlane() const { return fPlaneId.GetPlane(); }
   Float_t      GetThickness() const { return fThickness; }
   Float_t      GetGap() const { return fGap; }
   Float_t      GetX0RelSteel() const { return fX0RelSteel; }
   Float_t      GetY0RelSteel() const { return fY0RelSteel; }
   Float_t      GetZRotRelSteelRad() const { return fZRotRelSteelRad; }
   Float_t      GetZRotRelSteelDeg() const { return fZRotRelSteelRad * Ugli::rad2deg; }

   virtual DbiTableRow* CreateTableRow() const { return new UgliDbiScintPln; }

// I/O  member functions

   virtual void          Fill(DbiResultSet& rs,
                              const DbiValidityRec* vrec);
   virtual void          Store(DbiOutRowStream& ors,
                               const DbiValidityRec* vrec) const;

   virtual std::ostream& FormatToOStream(std::ostream& os,
                                         Option_t *option="",
                                         const DbiValidityRec* vrec=0) const;
   virtual void          Print(Option_t *option="") const;

   static const char*    GetTableDescr();
   static void           SetDefensiveUnpkg(Bool_t defensive) 
      { fgDefensiveUnpkg = defensive; }
   static Bool_t         GetDefensiveUnpkg() { return fgDefensiveUnpkg; }

private:  

// Constructors and destructors.

   UgliDbiScintPln(const UgliDbiScintPln& from)
     : DbiTableRow(from) { LEA_CTOR; *this = from; }

// Data members

   PlexPlaneId  fPlaneId;         // scint plane id
   //Int_t        fPlane;           // plane # (View and Coverage from UgliDbiSteelPln)
   Float_t      fThickness;       // thickness of the steel
   Float_t      fGap;             // gap between face of steel and scint
   Float_t      fX0RelSteel;      // center of scint relative to center of steel
   Float_t      fY0RelSteel;      // center of scint relative to center of steel
   Float_t      fZRotRelSteelRad; // rotation around z-axis relative to steel
                                  // aligned planes would have U=-pi/4, V=+pi/4

// class-wide static

   static Bool_t fgDefensiveUnpkg;

ClassDef(UgliDbiScintPln,0)

};

#endif  // UGLIDBISCINTPLN_H
