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

#ifndef UGLIDBISTEELPLN_H
#define UGLIDBISTEELPLN_H

////////////////////////////////////////////////////////////////////////
// UgliDbiSteelPln
//
// 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 UgliDbiSteelPln;
std::ostream& operator<<(std::ostream& os, const UgliDbiSteelPln& udsp);

class UgliDbiSteelPln : public DbiTableRow
{

public:

// Constructors and destructors.

   UgliDbiSteelPln()
      : fPlaneId(), fMeltCode(-1), fThickness(-1), fTotalZ(-1),
        fX0(0), fY0(0), fZBack(0)
      { LEA_CTOR; 
        for (int i=0; i<3; i++) {
           fThetaXYZRad[i] = 0;
           fPhiXYZRad[i] = 0;
        }
      }

   UgliDbiSteelPln(PlexPlaneId plnid, Int_t melt, Float_t thick,
                   Float_t totalz, Float_t x0, Float_t y0, Float_t zback, 
                   Float_t theta_x, Float_t phi_x, Float_t theta_y, Float_t phi_y,
                   Float_t theta_z, Float_t phi_z)
      : fPlaneId(plnid), fMeltCode(melt), fThickness(thick), fTotalZ(totalz),
        fX0(x0), fY0(y0), fZBack(zback)
      { LEA_CTOR;
        fThetaXYZRad[0] = theta_x; fPhiXYZRad[0] = phi_x;
        fThetaXYZRad[1] = theta_y; fPhiXYZRad[1] = phi_y;
        fThetaXYZRad[2] = theta_z; fPhiXYZRad[2] = phi_z;
      }

   virtual ~UgliDbiSteelPln(){ 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(); }
   Int_t        GetMeltCode() const { return fMeltCode; }
   Float_t      GetThickness() const { return fThickness; }
   Float_t      GetTotalZ() const { return fTotalZ; }
   Float_t      GetX0() const { return fX0; }
   Float_t      GetY0() const { return fY0; }
   Float_t      GetZBack() const { return fZBack; }
   Float_t      GetThetaRad(Int_t indx) const { return fThetaXYZRad[indx]; }
   Float_t      GetPhiRad(Int_t indx) const { return fPhiXYZRad[indx]; }

   Float_t      GetThetaDeg(Int_t indx) const { return fThetaXYZRad[indx] * Ugli::rad2deg; }
   Float_t      GetPhiDeg(Int_t indx) const { return fPhiXYZRad[indx] * Ugli::rad2deg; }


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

// 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.

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

// Data members

   PlexPlaneId  fPlaneId;        // steel plane id
   Int_t        fMeltCode;       // identification of steel's composition properties
   Float_t      fThickness;      // thickness of the steel
   Float_t      fTotalZ;         // allocated dz (including gap + attached scint)
   Float_t      fX0,fY0;         // center of steel relative to world
   Float_t      fZBack;          // location of center back face (no scint) in the world
   Float_t      fThetaXYZRad[3]; // polar ang of steel's XYZ axis relative to world z
   Float_t      fPhiXYZRad[3];   // azimuthal ang of steel's XYZ axis to world x

// class-wide static

   static Bool_t fgDefensiveUnpkg;

ClassDef(UgliDbiSteelPln,0)

};

#endif  // UGLIDBISTEELPLN_H
