// $Id: UgliDbiStripStruct.h,v 1.15 2005/08/26 19:00:02 rhatcher Exp $

#ifndef UGLIDBISTRIPSTRUCT_H
#define UGLIDBISTRIPSTRUCT_H

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

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

class DbiValidityRec;

#include <iosfwd>

class UgliDbiStripStruct;
std::ostream& operator<<(std::ostream& os, const UgliDbiStripStruct& udss);

class UgliDbiStripStruct : public DbiTableRow
{

public:

// Constructors and destructors.

   UgliDbiStripStruct()
      : fDetViewCoverStrip(),
        fTotalLen(-1), fWlsLenEast(-1), fWlsLenWest(-1),
        fLenEastPart(-1), fLenWestPart(-1), fWlsLenBypass(-1)
      { LEA_CTOR; };


   UgliDbiStripStruct(PlexStripEndId strip, UShort_t inmodule,
                      Float_t totlen, Float_t wls_east, Float_t wls_west,
                      Float_t len_east, Float_t len_west, Float_t len_bypass)
      : fDetViewCoverStrip(strip), fInModule(inmodule), fTotalLen(totlen), 
        fWlsLenEast(wls_east), fWlsLenWest(wls_west),
        fLenEastPart(len_east), fLenWestPart(len_west),
        fWlsLenBypass(len_bypass)
      { LEA_CTOR; };

   UgliDbiStripStruct(Detector::Detector_t detector,
                      PlaneView::PlaneView_t view, 
                      PlaneCoverage::PlaneCoverage_t coverage,
                      UShort_t strip, UShort_t inmodule,
                      Float_t totlen, Float_t wls_east, Float_t wls_west,
                      Float_t len_east, Float_t len_west, Float_t len_bypass)
      : fDetViewCoverStrip(detector,view,coverage,strip),
        fInModule(inmodule), fTotalLen(totlen),
        fWlsLenEast(wls_east), fWlsLenWest(wls_west),
        fLenEastPart(len_east), fLenWestPart(len_west),
        fWlsLenBypass(len_bypass)
     { LEA_CTOR; }

   virtual ~UgliDbiStripStruct(){ LEA_DTOR; };

// State testing member functions

          UInt_t GetIndex(UInt_t defIndex) const;

   Detector::Detector_t            GetDetector() const;
   PlaneView::PlaneView_t          GetPlaneView() const;
   PlaneCoverage::PlaneCoverage_t  GetPlaneCoverage() const;

   UShort_t                        GetStrip() const;

   //   PlexStripEndId GetStripEndId() const;

   Short_t        GetInModule() const { return fInModule; }
   Float_t        GetTotalLen() const { return fTotalLen; }
   Float_t        GetWlsLenEast() const { return fWlsLenEast; }
   Float_t        GetWlsLenWest() const { return fWlsLenWest; }
   Float_t        GetLenEastPart() const { return fLenEastPart; }
   Float_t        GetLenWestPart() const { return fLenWestPart; }
   Float_t        GetWlsLenBypass() const { return fWlsLenBypass; }
   std::string    GetShapeName() const;

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

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

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

// Data members

   UgliDbiStructHash fDetViewCoverStrip; // det, plnview, cover, strip in pln
   UShort_t          fInModule;      // module # in the plane which it is in
   Float_t           fTotalLen;      // end-to-end length of logical strip
   Float_t           fWlsLenEast;    // pigtail length on - (east) side
   Float_t           fWlsLenWest;    // pigtail length on + (west) side
   Float_t           fLenEastPart;   // length of - (east) portion if split
   Float_t           fLenWestPart;   // length of + (west) portion if split
   Float_t           fWlsLenBypass;  // length of WLS fiber in bypas

// class-wide static

   static Bool_t fgDefensiveUnpkg;

ClassDef(UgliDbiStripStruct,0)

};

inline Detector::Detector_t UgliDbiStripStruct::GetDetector() const
{ return fDetViewCoverStrip.GetDetector(); }

inline PlaneView::PlaneView_t UgliDbiStripStruct::GetPlaneView() const
{ return fDetViewCoverStrip.GetPlaneView(); }

inline PlaneCoverage::PlaneCoverage_t  UgliDbiStripStruct::GetPlaneCoverage() const
{ return fDetViewCoverStrip.GetPlaneCoverage(); }

inline UShort_t UgliDbiStripStruct::GetStrip() const
{ return fDetViewCoverStrip.GetPart(); }

inline UInt_t UgliDbiStripStruct::GetIndex(UInt_t /* defIndex */) const 
{ return fDetViewCoverStrip.HashAsStrip(); }

//inline PlexStripEndId UgliDbiStripStruct::GetStripEndId() const 
//{ // no meaningful plane #!!
//  PlexStripEndId seid(GetDetector(),0,GetStrip());
//  seid.SetPlaneView(GetPlaneView());
//  seid.SetPlaneCoverage(GetPlaneCoverage());
//  return seid;
//}

#endif  // UGLIDBISTRIPSTRUCT_H
