Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

ValBase.h

Go to the documentation of this file.
00001 
00008 #ifndef ValBase_h
00009 #define ValBase_h
00010 
00011 #include "GaudiKernel/AlgTool.h"
00012 #include "GaudiKernel/IIncidentListener.h"
00013 
00014 #include "AnalysisNtuple/IValsTool.h"
00015 #include <string>
00016 #include <vector>
00017 #include <map>
00018 #include <cmath>  // for M_PI, among others
00019 
00020 class IIncidentSvc;
00021 class IDataProviderSvc;
00022 
00029 namespace {
00030 
00031 // LSR 14-Jul-08 code for ntuple types
00032 
00033     enum valType {DOUBLE, FLOAT, INT, UINT, ULONG64, STRING};
00034     class TypedPointer 
00035     {
00036     public:  
00037         TypedPointer(valType type, void* pointer, int dim=1) : m_type(type), 
00038             m_pointer(pointer), m_dim(dim)
00039         {}
00040         ~TypedPointer() {}
00041 
00042         valType getType()       { return    m_type; }
00043         void* getPointer()      { return    m_pointer; }
00044         int getDim()            { return    m_dim; }
00045 
00046 // LSR 14-Jul-08 code for ntuple types
00047 
00048         void setVal(unsigned int val)   { 
00049             *(reinterpret_cast<unsigned int*>(getPointer())) = val; 
00050         }
00051         void setVal(unsigned long long val)   { 
00052             *(reinterpret_cast<unsigned long long*>(getPointer())) = val; 
00053         }
00054         void setVal(int val)    { *(reinterpret_cast<int*>(getPointer())) = val; }
00055         void setVal(float val)  { *(reinterpret_cast<float*>(getPointer())) = val; }
00056         void setVal(double val) { *(reinterpret_cast<double*>(getPointer())) = val; }
00057 
00058     private:
00059         valType m_type;
00060         void*   m_pointer;
00061         int     m_dim;
00062     };
00063 }
00064 
00065 class ValBase : public IValsTool,  public AlgTool,  virtual public IIncidentListener
00066 {
00067 public:
00068     typedef std::pair<std::string, TypedPointer*> valPair;
00069     typedef std::vector<valPair*> valMap;
00070     typedef valMap::iterator mapIter;
00071     typedef valMap::const_iterator constMapIter;
00072 
00073     ValBase(const std::string& type, 
00074         const std::string& name, 
00075         const IInterface* parent);
00076     
00077     ~ValBase(); 
00079     virtual void zeroVals();
00080 
00081 // LSR 14-Jul-08 code for ntuple types
00083     virtual void addItem(std::string varName, double* pValue);
00084     virtual void addItem(std::string varName, float* pValue);
00085     virtual void addItem(std::string varName, int* pValue);
00086     virtual void addItem(std::string varName, unsigned int* pValue);
00087     virtual void addItem(std::string varName, unsigned long long* pValue);
00088     virtual void addItem(std::string varName, char* pValue);
00089     virtual StatusCode doCalcIfNotDone();
00090  
00091 // LSR 14-Jul-08 code for ntuple types
00093     virtual StatusCode getVal(std::string varName, double& value, int check = CALC);
00094     virtual StatusCode getVal(std::string varName, float& value, int check = CALC);
00095     virtual StatusCode getVal(std::string varName, int& value, int check = CALC);
00096     virtual StatusCode getVal(std::string varName, unsigned int& value, int check = CALC);
00097     virtual StatusCode getVal(std::string varName, unsigned long long& value, int check = CALC);
00098     virtual StatusCode getVal(std::string varName, std::string& value, int check = CALC);
00100  
00101 // LSR 14-Jul-08 code for ntuple types
00102     virtual StatusCode getValCheck(std::string varName, double& value);
00103     virtual StatusCode getValCheck(std::string varName, float& value);
00104     virtual StatusCode getValCheck(std::string varName, int& value);
00105     virtual StatusCode getValCheck(std::string varName, unsigned int& value);
00106     virtual StatusCode getValCheck(std::string varName, unsigned long long& value);
00107     virtual StatusCode getValCheck(std::string varName, std::string& value);
00108 
00109     virtual bool getArrayArg(std::string varName, std::string& baseName,
00110         int& dim);
00111     virtual std::string getFullName(std::string varName, int dim);
00112    
00114     virtual void announceBadName(std::string varName);
00116     virtual StatusCode browse(MsgStream log, const std::string varName = "");
00118     virtual void handle(const Incident& inc);
00120     virtual IValsTool::Visitor::eVisitorRet traverse(IValsTool::Visitor * v,
00121         const bool checkCalc);
00122     virtual int getCalcCount() { return m_calcCount;}
00123     
00125     virtual StatusCode calculate();
00126     
00127     // common initialization
00128     virtual StatusCode initialize();
00129 
00131     virtual void setLoadOrder(int index) { m_loadOrder = index; }
00132     virtual bool isLoaded()              { return m_loadOrder>-1; }
00133     virtual int  getLoadOrder()          { return m_loadOrder; }
00134     
00135 protected:
00136     StatusCode getTypedPointer(std::string varName, TypedPointer*& ptr, int check);
00137 
00139 
00141     static double sign(double x) { return x>0 ? 1.: -1. ;}
00143     static double globalToLocal(double x, double pitch, int n) {
00144         double xNorm = x/pitch + 0.5*n;
00145         return sign(x)*(fmod(fabs(xNorm),1.0) - 0.5)*pitch ;
00146     }
00147 
00148     static double circleFraction(double r) {
00149         double rl = (fabs(r) < 1.) ? fabs(r):1.; 
00150         double a_slice = 2.*(M_PI/4. - rl*sqrt(std::max(0.0,1.-rl*rl))/2. - asin(rl)/2.);
00151         double in_frac = 1.-a_slice/M_PI;
00152         if(r < 0.) in_frac = a_slice/M_PI;
00153         return in_frac;
00154     }
00155 
00156     static double circleFractionSimpson(double r, double angle_factor) {
00157         double slice_0 = circleFraction(r);
00158         double slice_p = circleFraction(r+angle_factor);
00159         double slice_m = circleFraction(r-angle_factor);
00160         return (slice_p + 4.*slice_0 + slice_m)/6.;
00161     }
00162 
00163     void printHeader(MsgStream& log);
00164     void setAnaTupBit();
00165     
00167     valMap m_ntupleMap;
00169     IIncidentSvc* m_incSvc;
00171     IDataProviderSvc* m_pEventSvc;
00173     bool m_newEvent;
00176     int m_check;
00177 
00179     int m_calcCount;
00180 
00182     int m_loadOrder;
00183 
00186     static const int s_badVal;
00187 
00188 
00189 };
00190 #endif

Generated on Mon Dec 1 20:09:05 2008 by doxygen 1.3.3