Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbNTupleBase.hh

Go to the documentation of this file.
00001 #ifndef CDB_NTUPLE_BASE_HH
00002 #define CDB_NTUPLE_BASE_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbNTupleBase.hh,v 1.5 2004/04/02 07:41:27 gapon Exp $
00006 
00007 #include "CdbBase/CdbCommon.hh"
00008 
00009 #include <string>
00010 #include <vector>
00011 
00012 /// A base class for abstract n-tuples.
00013 /**
00014   * This class provides common metadata infrastructure for an abstract n-tuple
00015   * template class to prevent code bloat at the template level.
00016   *
00017   * Notes:
00018   *
00019   * - The number of columns is specified through the class's constructor.
00020   *
00021   * - The names of columns (either generated by default or explicitly passed to the corresponding
00022   *   constructor of n-tuple) can be used when doing queries on values of elements of the n-tuple.
00023   */
00024 class CdbNTupleBase {
00025 
00026 private:
00027 
00028   /// The default constructor (NOT IMPLEMENTED)
00029   /**
00030     * This constructor is disabled since we need to know the width of
00031     * the n-tuple.
00032     */
00033     CdbNTupleBase( );
00034 
00035 protected:
00036 
00037   /// The constructor
00038   /**
00039     * The constructor will assign default names to the columns. These names will be derived
00040     * from relative locations of the corresponding columns in a row. For example, for an n-tuple
00041     * of the width of 4 we would have:
00042     *
00043     *   "#0" "#1" "#2" "#3"
00044     */
00045     CdbNTupleBase( unsigned int       theNumberOfColumns,
00046                    const std::string& theName,
00047                    const std::string& theDescription );
00048 
00049   /// The constructor
00050   /**
00051     * This constructor can be used to specify custom names of columns. The vector of names
00052     * passed as the first parameter can be of any length, where it would be shorter or longer
00053     * than the width of n-tuple.
00054     *
00055     * Columns naming rules:
00056     *
00057     * (1) Names passed in the vector must be unique.
00058     *
00059     * (2) Names begining with the '#' symbol are considered as "system" names.
00060     *     Using system names is generally prohibited, except just one case described
00061     *     by the rule (3) below.
00062     *
00063     * (3) The default system names assigned by the above defined constructor can only be used
00064     *     if their naming follows the same rules. A run-time assertion will happen in case
00065     *     of violation of this rule.
00066     *
00067     * (4) If the vector is shorter then elements of the vector will be used to name the first
00068     *     the rest of names will be filled with default names derived from relative position of
00069     *     the corresponding column in a row. See the above defined constructor's description
00070     *     for details.
00071     *
00072     * (5) If the vector is longer - then the rest of the vector will be simply ignored.
00073     *     No correctness checks for names in the rest of the vector would be performed.
00074     */
00075     CdbNTupleBase( unsigned int                    theNumberOfColumns,
00076                    const std::vector<std::string>& theCollumnNames,
00077                    const std::string&              theName,
00078                    const std::string&              theDescription );
00079 
00080   /// The copy constructor
00081   /**
00082     * Copy the local context.
00083     */
00084     CdbNTupleBase( const CdbNTupleBase& theOther );
00085 
00086   /// The assignment operator
00087   /**
00088     * Copy the local context.
00089     */
00090     CdbNTupleBase& operator=( const CdbNTupleBase& theOther );
00091 
00092 public:
00093 
00094   /// The destructor
00095   /**
00096     * Just to enforce the virtual destructor.
00097     */
00098     virtual ~CdbNTupleBase( );
00099 
00100   /// Get the current width (the number of columns) of n-tuple
00101 
00102     unsigned int columns( ) const;
00103 
00104   /// The name of the n-tuple
00105 
00106     std::string name( ) const;
00107 
00108   /// The name can also be dynamically assigned
00109 
00110     void set_name( const std::string& theName );
00111 
00112   /// The description of the n-tuple
00113 
00114     std::string description( ) const;
00115 
00116   /// The description can also be dynamically assigned
00117 
00118     void set_description( const std::string& theDescription );
00119 
00120   /// Get a vector with all column names
00121   /**
00122     * The order of names in the vector will be exactly the same as it's
00123     * defined in an tuple.
00124     */
00125     void column_names( std::vector<std::string>& theVectorOfNames ) const;
00126 
00127   /// Get the name of specified column number
00128   /**
00129     * The column must fit into the n-tuple's width.
00130     * The method would return CdbStatus::NotFound if it couldn't fine the column.
00131     */
00132     CdbStatus column_name( unsigned int theNumber,
00133                            std::string& theName ) const;
00134 
00135   /// Get the number of specified column name
00136   /**
00137     * The column with specified name must be known.
00138     * The method would return CdbStatus::NotFound if it couldn't fine the column.
00139     */
00140     CdbStatus column_number( const std::string& theName,
00141                              unsigned int&      theNumber ) const;
00142 
00143   /// Set the name of specified column
00144   /**
00145     * The column must fit into the n-tuple's width.
00146     */
00147     CdbStatus set_column_name( unsigned int       theNumber,
00148                                const std::string& theName );
00149 
00150 public:
00151 
00152   /// Check if specified name correspond to so called "system" names of columns
00153   /**
00154     * The rules for how these default system names will look alike are described
00155     * in the documentation for constructors of the class.
00156     *
00157     * @see CdbNTupleBase::CdbNTupleBase
00158     */
00159     static bool is_system_name( const std::string& theName );
00160 
00161   /// Get the default column name for specified column number
00162   /**
00163     * The rules for how these default names will look alike are described
00164     * in the documentation for constructors of the class.
00165     *
00166     * @see CdbNTupleBase::CdbNTupleBase
00167     */
00168     static std::string default_column_name( unsigned int theNumber );
00169 
00170 private:
00171 
00172   // Parameters of the n-tuple
00173 
00174     unsigned int _ncol;
00175 
00176     std::string _name;
00177     std::string _description;
00178 
00179     std::vector<std::string> _columns;
00180 };
00181 
00182 #endif // CDB_NTUPLE_BASE_HH
00183 

Generated on Mon Dec 5 18:22:07 2005 for CDB by doxygen1.3-rc3