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

Default.h

Go to the documentation of this file.
00001 #ifndef ANP_DEFAULT_H
00002 #define ANP_DEFAULT_H
00003 
00004 // C++
00005 #include <map>
00006 #include <string>
00007 #include <sstream>
00008 
00009 // ROOT
00010 #include "Rtypes.h"
00011 
00012 // MINOS
00013 #include "Util/UtilString.h"
00014 #include "Registry/Registry.h"
00015 
00016 // Local
00017 #include "PhysicsNtuple/Mutex.h"
00018 
00019 class TH1;
00020 class TDirectory;
00021 class Registry;
00022 
00023 namespace Anp
00024 {
00025    //-------------------------------------------------------------------------------
00026    // Read Registry
00027    //-------------------------------------------------------------------------------   
00028    bool ReadRegistry(const std::string &filepath, Registry &reg, bool quiet = true);
00029 
00030 
00031    const std::pair<std::string, bool> GetString(const std::string &prefix,
00032                                                 const std::string &key,
00033                                                 const Registry &reg);
00034 
00035    bool Read(const Registry &reg, const std::string &key, bool &value);
00036    bool Read(const Registry &reg, const std::string &key, std::string &value);
00037 
00038    int SetKey(Registry &reg, const std::string &key, const std::string &value);
00039    
00040    //-------------------------------------------------------------------------------
00041    // Get if exits and create otherwise TDirectory from path
00042    //-------------------------------------------------------------------------------   
00043    TDirectory* GetDir(std::string path, TDirectory *dir);
00044 
00045    TH1* SetDir(TH1 *h, TDirectory *dir, const std::string &name = "");
00046    
00047    Mutex& GetMainMutex();
00048    Mutex& GetROOTMutex();
00049 
00050    //-------------------------------------------------------------------------------
00051    // Geometry functions
00052    //-------------------------------------------------------------------------------
00053    float uv2x(float u, float v);
00054    float uv2y(float u, float v);
00055 
00056    float xy2u(float x, float y);
00057    float xy2v(float x, float y);   
00058    
00059    double pi();
00060 
00061    double angle(double x, double y);
00062 
00063    struct CoordXYZ
00064    {
00065       CoordXYZ() : x(-1.0e6), y(-1.0e6), z(-1.0e6) {}
00066       double x;
00067       double y;
00068       double z;
00069    };
00070    
00071    const CoordXYZ gnumi_to_near(const CoordXYZ pos);
00072    const CoordXYZ near_to_gnumi(const CoordXYZ pos);
00073 
00074    const CoordXYZ gnumi_to_far(const CoordXYZ pos);
00075    const CoordXYZ far_to_gnumi(const CoordXYZ pos);
00076 }
00077 
00078 //----------------------------------------------------------------------
00079 // inlined global functions
00080 //----------------------------------------------------------------------   
00081 inline float Anp::uv2x(const float u, const float v) { return (u - v)*0.707106781; }
00082 inline float Anp::uv2y(const float u, const float v) { return (u + v)*0.707106781; }
00083 
00084 inline float Anp::xy2u(const float x, const float y) { return (y + x)*0.707106781; }
00085 inline float Anp::xy2v(const float x, const float y) { return (y - x)*0.707106781; }
00086 
00087 inline double Anp::pi() { return 3.1415926536; }
00088 
00089 //--------------------------------------------------------------------------------------------
00090 // templated function that reads registry key and pareses to individual objects
00091 //--------------------------------------------------------------------------------------------
00092 namespace Anp
00093 {
00094    template<typename T>
00095       inline std::vector<T> ReadList(const Registry &reg,
00096                                      const std::string &key,
00097                                      const std::string &sep)
00098    {
00099       std::vector<T> lvec;
00100 
00101       const char *list_char = 0;
00102       if(!reg.Get(key.c_str(), list_char) || !list_char)
00103       {
00104          return lvec;
00105       }
00106       
00107       std::vector<std::string> svec;
00108       UtilString::StringTok(svec, list_char, sep.c_str());
00109       
00110       if(svec.empty())
00111       {
00112          return lvec;
00113       }
00114       
00115       for(unsigned int i = 0; i < svec.size(); ++i)
00116       {
00117          std::stringstream valS;
00118          T valT;
00119          
00120          valS << svec[i];
00121          valS >> valT;
00122          
00123          if(valS.fail())
00124          {
00125             std::cerr << "ReadList<T> - stringstream operator>> failed for: " << svec[i] << std::endl;
00126          }
00127          else
00128          {       
00129             lvec.push_back(valT);
00130          }
00131       }
00132       
00133       return lvec;
00134    }
00135 }
00136 
00137 //--------------------------------------------------------------------------------------------
00138 // templated function that prints list
00139 //--------------------------------------------------------------------------------------------
00140 namespace Anp
00141 {
00142    template<typename T>
00143       void PrintList(const std::string &name,
00144                      const std::vector<T> &lvec)
00145    {
00146       for(unsigned int ipos = 0; ipos < lvec.size(); ++ipos)
00147       {
00148          if(ipos == 0)
00149          {
00150             std::cout << name << " = " << lvec[ipos];
00151          }
00152          else
00153          {
00154             std::cout << ", " << lvec[ipos];
00155          }
00156 
00157          if(ipos + 1 == lvec.size())
00158          {
00159             std::cout << std::endl;
00160          }       
00161       }
00162    }
00163 }
00164 
00165 #endif

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