Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

LatticeBase.h

Go to the documentation of this file.
00001 #if !defined(LATTICE_LATTICEBASE_H)
00002 #define LATTICE_LATTICEBASE_H
00003 // -*- C++ -*-
00004 //
00005 // Package:     Lattice
00006 // Module:      LatticeBase
00007 // 
00008 // Description: Lattice base class, for linking pairs of classes.
00009 //
00010 // Usage:
00011 //
00012 //-----------------------------------------------------------+
00013 // See the web documentation:                                |
00014 //    http://www.lns.cornell.edu/restricted/CLEO/CLEO3/soft/ |
00015 //            LibraryDocs/Lattice/Lattice.html               |
00016 //-----------------------------------------------------------+
00017 //
00018 // Author:      Jon Thaler
00019 // Created:     Fri July 30, 1999
00020 //
00021 //  Minos Revision History
00022 //  
00023 //  This file has been converted automatically from the corresponding CLEO
00024 //  Lattice code by Nick West on: 14/03/2000 08:38:07
00025 //  
00026 //  It is being used to explore the possibility that a modified Lattice
00027 //  can be used in MINOS.  The main changes are:-
00028 //  
00029 //      1)  The removal Lattice templates classes:-
00030 //  
00031 //           a)  LinkData is dummy
00032 //           b)  Left and Right ID types are void*
00033 //  
00034 //      2)  Conversion of CLEO types and includes to MINOS equivalents
00035 //          e.g.:-
00036 //  
00037 //           a)  DABoolean -> Bool_t
00038 //           b)  report    -> MSG
00039 #include "Lattice/LatticeDef.h"
00040 
00041 //
00042 
00043 //====================================================================
00044   class LatticeBase;
00045   class LatticeLink;
00046   class LatticeLeftNode;
00047   class LatticeRightNode;
00048 
00049 //--------------------+
00050 // user include files |
00051 //--------------------+
00052 #include "Rtypes.h"
00053 #include "Lattice/LatticeLink.h"
00054 #include "Lattice/LatticeNode.h"
00055 
00056 //-----+
00057 // STL | 
00058 //-----+
00059 #include <vector>
00060 #include <string>
00061 using namespace std;
00062 
00063 //==================================================================== 
00064 //          class LatticeDef::LinkData = DefaultLinkData>
00065 class LatticeBase
00066 {
00067  public:
00068   //-------------------------------------------+
00069   // typedefs                                  |
00070   //  LeftNodes     \                          |
00071   //  RightNodes     > Parts of the Lattice.   |
00072   //  Links         /                          |
00073   //  VectorLeftID  \ vectors of identifiers.  |
00074   //  VectorRightID /                          |
00075   //  LeftItr       \                          |
00076   //  RightItr       > vector const_iterators. |
00077   //  LinkItr       /                          |
00078   //-------------------------------------------+
00079   typedef LatticeDef::LinkData                   LinkData;
00080   typedef LatticeLink      Link;
00081   typedef LatticeLeftNode  LeftNode;
00082   typedef LatticeRightNode RightNode;
00083 
00084   typedef LatticeDef::Identifier LeftID;
00085   typedef LatticeDef::Identifier RightID;
00086 
00087   typedef vector<Link*>                   Links;
00088   typedef vector<LeftID>                  VectorLeftID;
00089   typedef vector<RightID>                 VectorRightID;
00090 
00091   typedef VectorLeftID ::const_iterator   LeftItr;
00092   typedef VectorRightID::const_iterator   RightItr;
00093   typedef Links        ::const_iterator   LinkItr;
00094 
00095   //-----------------------------------------------------------+
00096   // This enumerated type lists the connection topologies that |
00097   // each Lattice can support.  The presence of one or more of |
00098   // these in the constructor argument list enables multiple   |
00099   // connections at the corresponding nodes or links.  The     |
00100   // default is to disallow multiple connections.              |
00101   //-----------------------------------------------------------+
00102   enum LatticeTopology { Default = 0, LNodeMulti = 1, RNodeMulti = 2,
00103                                       LLinkMulti = 3, RLinkMulti = 4 };
00104       
00105   //------------------------------------------+
00106   // Constructor and destructor               |
00107   // Copy constructor and assignment operator |
00108   // are disabled (private).                  |
00109   //------------------------------------------+
00110   LatticeBase(LatticeTopology i = Default,
00111               LatticeTopology j = Default,
00112               LatticeTopology k = Default,
00113               LatticeTopology l = Default);
00114 
00115   virtual ~LatticeBase();
00116 
00117   //------------------------------------------------------------+
00118   // Link management:                                           |
00119   // connect();                                                 |
00120   //  Make or modify a Lattice Link.  Several versions:         |
00121   //  * (L,R,LinkData&) Make a new link between left & right.   |
00122   //                    LinkData is optional.                   |
00123   //  * (L,Link,R)      Connect L & R through an existing link. |
00124   //  * (L,Link*,R)     Calls (L,R) or (L,Link,R) depending on  |
00125   //                    whether Link* is zero or not.           |
00126   //  * (L,Link  ) or   Connect one node to an existing link.   |
00127   //    (  Link,R)                                              |
00128   // All versions of connect return a pointer to the link (new  |
00129   // or existing).  The pointer is 0 if the connection failed   |
00130   // (even if the link exists).                                 |
00131   //------------------------------------------------------------+
00132   virtual Link* connect(LeftID,        RightID, const LinkData&);
00133   virtual Link* connect(LeftID,        RightID);
00134   virtual Link* connect(LeftID, Link&, RightID);
00135   virtual Link* connect(LeftID, Link*, RightID);
00136   virtual Link* connect(LeftID, Link&);
00137   virtual Link* connect(        Link&, RightID);
00138 
00139   virtual void  removeLink(Link&);
00140 
00141   //------------------------------+
00142   // Query Lattice configuration. |
00143   //------------------------------+
00144   Bool_t isEmpty     () const;
00145   Bool_t isLNodeMulti() const;
00146   Bool_t isRNodeMulti() const;
00147   Bool_t isLLinkMulti() const;
00148   Bool_t isRLinkMulti() const;
00149   string    topologyText() const;
00150 
00151   //------------------------------+
00152   // Display Lattice information. |
00153   //------------------------------+
00154   void show     (          ostream&) const;
00155   void showLeft (LeftItr,  ostream&) const;
00156   void showLeft (LeftID,   ostream&) const;
00157   void showRight(RightItr, ostream&) const;
00158   void showRight(RightID,  ostream&) const;
00159   void showLink (Link*,    ostream&) const;
00160   void showLink (LinkItr,  ostream&) const;
00161 
00162   //------------------------------------------------+
00163   // Retrieve all the data or links in the Lattice. |
00164   //------------------------------------------------+
00165   const VectorLeftID&   vLeftID () const;
00166   const VectorRightID&  vRightID() const;
00167   const Links&          links   () const;
00168 
00169   //----------------------------------------------------+
00170   // Retrieve the vector of data that shares links with |
00171   // or is connected by links to a given datum.         |
00172   //----------------------------------------------------+
00173   virtual const VectorLeftID*  vLeftGivenLeft  (LeftID )  const;
00174   virtual const VectorLeftID*  vLeftGivenLeft  (LeftItr)  const;
00175       
00176   virtual const VectorRightID* vRightGivenRight(RightID ) const;
00177   virtual const VectorRightID* vRightGivenRight(RightItr) const;
00178       
00179   virtual const VectorRightID* vRightGivenLeft (LeftID )  const;
00180   virtual const VectorRightID* vRightGivenLeft (LeftItr)  const;
00181       
00182   virtual const VectorLeftID*  vLeftGivenRight (RightID ) const;
00183   virtual const VectorLeftID*  vLeftGivenRight (RightItr) const;
00184 
00185   //--------------------------------------------------------------------+
00186   // Retrieve the one datum on the left or right side of a given datum. |
00187   // Fails (returns 0) if there is not exactly one datum present.       |
00188   // These functions are inline to avoid Solaris compiler problems.     |
00189   //--------------------------------------------------------------------+
00190   virtual const LeftID* leftIDGivenLeft(LeftID leftID) const
00191   {
00192     const LeftNode* pLN = leftNode(leftID);
00193     return ( (0==pLN) || (1 != pLN->m_VLeftID.size()) ) ?
00194       0 : &(pLN->m_VLeftID.front());
00195   }
00196 
00197   virtual const LeftID* leftIDGivenLeft(LeftItr leftItr) const
00198   {
00199     return leftIDGivenLeft(*leftItr);
00200   }
00201   
00202   virtual const RightID* rightIDGivenLeft(LeftID leftID) const
00203   {
00204     const LeftNode* pLN = leftNode(leftID);
00205     return ( (0==pLN) || (1 != pLN->m_VRightID.size()) ) ?
00206       0 : &(pLN->m_VRightID.front());
00207   }
00208 
00209   virtual const RightID* rightIDGivenLeft(LeftItr leftItr) const
00210   {
00211     return rightIDGivenLeft(*leftItr);
00212   }
00213   
00214   virtual const LeftID* leftIDGivenRight(RightID rightID) const
00215   {
00216     const RightNode* pRN = rightNode(rightID);
00217     return ( (0==pRN) || (1 != pRN->m_VLeftID.size()) ) ?
00218       0 : &(pRN->m_VLeftID.front());
00219   }
00220   
00221   virtual const LeftID* leftIDGivenRight(RightItr rightItr) const
00222   {
00223     return leftIDGivenRight(*rightItr);
00224   }
00225   
00226   virtual const RightID* rightIDGivenRight(RightID rightID) const
00227   {
00228     const RightNode* pRN = rightNode(rightID);
00229     return ( (0==pRN) || (1 != pRN->m_VRightID.size()) ) ?
00230       0 : &(pRN->m_VRightID.front());
00231   }
00232 
00233   virtual const RightID* rightIDGivenRight(RightItr rightItr) const
00234   {
00235     return rightIDGivenRight(*rightItr);
00236   }
00237 
00238   //-----------------------------------------+
00239   // Retrieve one datum's (vector of) links. |
00240   //-----------------------------------------+
00241   virtual const Links* linksGivenLeft (LeftItr)  const;
00242   virtual const Links* linksGivenLeft (LeftID)   const;
00243 
00244   virtual const Links* linksGivenRight(RightItr) const;
00245   virtual const Links* linksGivenRight(RightID)  const;
00246 
00247   //----------------------------------------------------------------+
00248   // Retrieve one datum's only link.                                |
00249   // Fails (returns 0) if there is not exactly one link present.    |
00250   // Both const & non-const versions, so users can modify LinkData. |
00251   //----------------------------------------------------------------+
00252   virtual const Link* linkGivenLeft (LeftItr)  const;
00253   virtual       Link* linkGivenLeft (LeftItr);
00254 
00255   virtual const Link* linkGivenLeft (LeftID)   const;
00256   virtual       Link* linkGivenLeft (LeftID);
00257 
00258   virtual const Link* linkGivenRight(RightItr) const;
00259   virtual       Link* linkGivenRight(RightItr);
00260 
00261   virtual const Link* linkGivenRight(RightID)  const;
00262   virtual       Link* linkGivenRight(RightID);
00263 
00264   //-------------------------------------------------------+
00265   // Retrieve the links that connect one datum to another, |
00266   // or that they share.                                   |
00267   //-------------------------------------------------------+
00268   virtual void connectLinks   (LeftID,   RightID,  Links&) const;
00269   virtual void connectLinks   (LeftItr,  RightItr, Links&) const;
00270 
00271   virtual void shareLinksLeft (LeftID,   LeftID,   Links&) const;
00272   virtual void shareLinksLeft (LeftItr,  LeftItr,  Links&) const;
00273 
00274   virtual void shareLinksRight(RightID,  RightID,  Links&) const;
00275   virtual void shareLinksRight(RightItr, RightItr, Links&) const;
00276 
00277   //----------------------------------------------------------------+
00278   // Retrieve the one link connecting a datum to another,           |
00279   // or that they share.                                            |
00280   // Fails (returns 0) if there is not exactly one datum present.   |
00281   // Both const & non-const versions, so users can modify LinkData. |
00282   //----------------------------------------------------------------+
00283   virtual const Link* connectLink   (LeftID,   RightID)  const;
00284   virtual       Link* connectLink   (LeftID,   RightID);
00285 
00286   virtual const Link* connectLink   (LeftItr,  RightItr) const;
00287   virtual       Link* connectLink   (LeftItr,  RightItr);
00288 
00289   virtual const Link* shareLinkLeft (LeftID,   LeftID)   const;
00290   virtual       Link* shareLinkLeft (LeftID,   LeftID);
00291 
00292   virtual const Link* shareLinkLeft (LeftItr,  LeftItr)  const;
00293   virtual       Link* shareLinkLeft (LeftItr,  LeftItr);
00294 
00295   virtual const Link* shareLinkRight(RightID,  RightID)  const;
00296   virtual       Link* shareLinkRight(RightID,  RightID);
00297 
00298   virtual const Link* shareLinkRight(RightItr, RightItr) const;
00299   virtual       Link* shareLinkRight(RightItr, RightItr);
00300       
00301  protected:
00302   //-----------------------------------------+
00303   // This stuff is protected, not private,   |
00304   // so derived Lattice classes have access. |
00305   //-----------------------------------------+
00306   //---------------------------------------+
00307   // Typedefs used only by Lattice itself. |
00308   //---------------------------------------+
00309   typedef vector<LeftNode*>          LeftNodes;
00310   typedef vector<RightNode*>         RightNodes;
00311   typedef LeftNodes ::const_iterator LNodeItr;
00312   typedef RightNodes::const_iterator RNodeItr;
00313 
00314   //-----------------+
00315   // Make new nodes. |
00316   //-----------------+
00317   LeftNode*  newLeftNode ( LeftID);
00318   RightNode* newRightNode(RightID);
00319 
00320   //-------------------------+
00321   // identifier --> pointer. |
00322   //-------------------------+
00323   LeftNode*  leftNode ( LeftID) const;
00324   RightNode* rightNode(RightID) const;
00325 
00326   //------------------+
00327   // Topology checks. |
00328   //------------------+
00329   Bool_t checkLNtopo( LeftNode*);
00330   Bool_t checkRNtopo(RightNode*);
00331   Bool_t checkLLtopo(Link&);
00332   Bool_t checkRLtopo(Link&);
00333 
00334   //---------------------+
00335   // Add nodes to links. |
00336   //---------------------+
00337   void  addLeftNodeToLink( LeftID, Link&);
00338   void addRightNodeToLink(RightID, Link&);
00339 
00340   //--------------------------------------------------------+
00341   // Shared implementation of const & non-const algorithms. |
00342   //--------------------------------------------------------+
00343   const Link* cLshared (LeftID,  RightID) const;
00344   const Link* sLLshared(LeftID,  LeftID)  const;
00345   const Link* sLRshared(RightID, RightID) const;
00346 
00347   //--------------------------------------------------------------+
00348   // Member data:                                                 |
00349   //  m_LeftNodes     Container of ->left  nodes in this lattice. |
00350   //  m_RightNodes       "         ->right nodes  "  "      "     |
00351   //  m_Links            "         ->links        "  "      "     |
00352   //  m_VLeftID          "           left IDs     "  "      "     |
00353   //  m_VRightID         "          right IDs     "  "      "     |
00354   //  m_Topology      See LatticeTopology enumerator above.       |
00355   //--------------------------------------------------------------+
00356   LeftNodes&     m_LeftNodes;
00357   RightNodes&    m_RightNodes;
00358   Links&         m_Links;
00359   VectorLeftID&  m_VLeftID;
00360   VectorRightID& m_VRightID;
00361   bool      m_Topology[5];
00362 
00363 private:
00364   // -----------------------------------+
00365   // Disabled constructors & assignment |
00366   // No definitions in the .cc file.    |
00367   //------------------------------------+
00368   LatticeBase(const LatticeBase&);
00369   const LatticeBase& operator = (const LatticeBase&);
00370 };
00371 
00372 #endif /* LATTICE_LATTICEBASE_H */

Generated on Mon Feb 15 11:06:50 2010 for loon by  doxygen 1.3.9.1