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

Tuple.h

Go to the documentation of this file.
00001 //$Header: /nfs/slac/g/glast/ground/cvs/analysis/analysis/Tuple.h,v 1.2 2001/03/24 00:04:37 burnett Exp $
00002 #ifndef TUPLE_H
00003 #define TUPLE_H
00004 
00005 #include <iostream>
00006 #include <string>
00007 #include <vector>
00008 
00009 class TupleItem  {
00010 private:
00011    friend class Tuple;
00012 public:
00013 
00014     TupleItem(){}
00015     TupleItem(const std::string& name, float x=0);
00016 
00018     TupleItem(const std::string& name, float* x);
00019 
00020     void operator=(float x){
00021       datum=x;
00022 
00023     }
00024     // assign value to the tuple element
00025     
00026     float operator()()const{
00027       return *m_pdatum;
00028 }
00029 
00030     operator float()const{
00031       return *m_pdatum;
00032     }
00033 
00034 public:
00035     std::string name()const{return m_name;}
00036     // extract the value
00037 
00038 
00039     friend std::ostream& operator << (std::ostream&, const TupleItem& );
00040     // print "name=value" for the tupleitem
00041     friend std::istream& operator >> (std::istream&,  Tuple& );
00042 
00043    private:
00044 
00045     float& operator()();
00046     std::string m_name;
00047     float datum;
00048     float* m_pdatum;
00049 };
00050 
00051 
00052 class Tuple : public std::vector<TupleItem* >
00053 {
00054 private:
00055  friend class TupleItem;
00056 
00057  public:
00058 
00059    Tuple(const std::string& title);
00060    Tuple(std::istream& in);
00061    // constructors
00062 
00063    void nextStream(std::istream& in);
00064    // start reading from a new stream. columns must be the same as currently
00065     
00066    void setTitle(const std::string&);
00067    // set title after the fact
00068 
00069    float operator[](unsigned i)const;
00070    // access to value of the ith element (start from 0)
00071 
00072    const char* name(unsigned i)const;
00073    // access to name of the ith element
00074 
00075    int index(const std::string& name)const;
00076    const_iterator find(const std::string& name)const;
00077    // return index of element by name, if found (-1 otherwise)
00078    // return iterator for element with name, end() otherwise
00079 
00080    void fillArray(float array[])const;
00081    // fill the given array from the tuple
00082 
00083    void writeHeader(std::ostream&)const;
00084 
00085 public:
00086    // make a list of the names of the tupleitems
00087 
00088    friend std::istream& operator >> (std::istream&, Tuple&);
00089 
00090 
00091    virtual ~Tuple();
00092    // dtor
00093 
00094    const std::string& title() const {
00095      return m_title;
00096    }
00097 
00098    virtual const TupleItem* tupleItem(const std::string& name)const;
00099    // return pointer to the tuple item by name. Error if not found
00100 
00101    virtual bool nextEvent(){return false;};  // for subclasses
00102  private:
00103 
00104     std::string m_title;
00105 
00106     static Tuple* s_currentTuple;
00107 
00108 
00109 };
00110 
00111 std::ostream& operator << ( std::ostream&, const Tuple&);
00112 
00113 std::istream& operator >> (std::istream&, Tuple&);
00114 // read in values from open stream
00115 
00116 #endif TUPLE_H

Generated at Wed Nov 21 12:20:52 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000