#include <map>#include <string>#include <sstream>#include "Rtypes.h"#include "Util/UtilString.h"#include "Registry/Registry.h"#include "PhysicsNtuple/Mutex.h"Go to the source code of this file.
Namespaces | |
| namespace | Anp |
Classes | |
| struct | Anp::CoordXYZ |
Functions | |
| bool | ReadRegistry (const std::string &filepath, Registry ®, bool quiet=true) |
| const std::pair< std::string, bool > | GetString (const std::string &prefix, const std::string &key, const Registry ®) |
| bool | Read (const Registry ®, const std::string &key, bool &value) |
| bool | Read (const Registry ®, const std::string &key, std::string &value) |
| int | SetKey (Registry ®, const std::string &key, const std::string &value) |
| TDirectory * | GetDir (std::string path, TDirectory *dir) |
| TH1 * | SetDir (TH1 *h, TDirectory *dir, const std::string &name="") |
| Mutex & | GetMainMutex () |
| Mutex & | GetROOTMutex () |
| float | uv2x (float u, float v) |
| float | uv2y (float u, float v) |
| float | xy2u (float x, float y) |
| float | xy2v (float x, float y) |
| double | pi () |
| double | angle (double x, double y) |
| const CoordXYZ | gnumi_to_near (const CoordXYZ pos) |
| const CoordXYZ | near_to_gnumi (const CoordXYZ pos) |
| const CoordXYZ | gnumi_to_far (const CoordXYZ pos) |
| const CoordXYZ | far_to_gnumi (const CoordXYZ pos) |
| template<typename T> | |
| std::vector< T > | ReadList (const Registry ®, const std::string &key, const std::string &sep) |
| template<typename T> | |
| void | PrintList (const std::string &name, const std::vector< T > &lvec) |
|
||||||||||||
|
Definition at line 95 of file Default.cxx. References Anp::angle(), and Anp::pi(). Referenced by Anp::angle(), Anp::FillTrackGeom::Fill(), Anp::PlotTrackGeom::FillProjection(), Anp::PlotTrackGeom::FillRotation(), Anp::PlotTrackGeom::FillXProduct(), and Anp::PlotEvent::Plot(). 00096 {
00097 const double radius = std::sqrt(x*x + y*y);
00098
00099 if(!(radius > 0.0))
00100 {
00101 return 0.0;
00102 }
00103
00104 if(!(+x < radius))
00105 {
00106 return std::acos(+1.0);
00107 }
00108 if(!(-x < radius))
00109 {
00110 return std::acos(-1.0);
00111 }
00112
00113 double angle = std::acos(x/radius);
00114
00115 if(y < 0.0)
00116 {
00117 angle = 2.0 * pi() - angle;
00118 }
00119
00120 return angle;
00121 }
|
|
|
Definition at line 84 of file Default.cxx. References Anp::GNUMICosZ, Anp::GNUMISinZ, Anp::CoordXYZ::y, and Anp::CoordXYZ::z. 00085 {
00086 CoordXYZ new_pos = pos;
00087
00088 new_pos.z = pos.z * GNUMICosZ + pos.y * GNUMISinZ + GNUMIFarZ;
00089 new_pos.y = -pos.z * GNUMISinZ + pos.y * GNUMICosZ;
00090
00091 return new_pos;
00092 }
|
|
||||||||||||
|
Definition at line 377 of file Default.cxx. Referenced by Anp::PlotPur::Add(), Anp::PlotEff::Add(), Anp::FillData::Config(), Anp::PlotKinem::Fill(), Anp::PlotBasic::Fill(), Anp::PlotData::Get(), Anp::SelectCount::GetCount(), Anp::PlotVtx::GetPlot(), Anp::PlotTruth::GetPlot(), Anp::PlotReson::GetPlot(), Anp::PlotFlux::GetPlot(), Anp::PlotShortSelect::Plot(), Anp::PlotShort::Plot(), Anp::PlotShort::PlotStandard(), Anp::SelectTrue::Set(), Anp::SelectKinem::Set(), Anp::SelectCount::Set(), Anp::RunAlgEvent::Set(), Anp::PlotVtx::Set(), Anp::PlotTruth::Set(), Anp::PlotTrackGeom::Set(), Anp::PlotTrack::Set(), Anp::PlotTime::Set(), Anp::PlotSnarl::Set(), Anp::PlotShower::Set(), Anp::PlotShortSelect::Set(), Anp::PlotShort::Set(), Anp::PlotPur::Set(), Anp::PlotPmt::Set(), Anp::PlotKinem::Set(), Anp::PlotFlux::Set(), Anp::PlotEvent::Set(), Anp::PlotEff::Set(), Anp::PlotData::Set(), Anp::PlotBasic::Set(), Anp::FillData::Set(), and Anp::Plot::Data::Set(). 00378 {
00379 //
00380 // Recursively reate directory path in dir
00381 //
00382 if(!dir || path.empty() || path == "/")
00383 {
00384 return dir;
00385 }
00386
00387 // remove trailing slash if present
00388 if(path.substr(path.size() - 1, 1) == "/")
00389 {
00390 path = path.substr(0, path.size() - 1);
00391 }
00392
00393 std::string::size_type pos = path.find_last_of('/');
00394 if(pos != std::string::npos)
00395 {
00396 // recursively walk upward until all slash characters are removed
00397 dir = Anp::GetDir(path.substr(0, pos), dir);
00398
00399 // make directory path of last substring without slash
00400 path = path.substr(pos + 1, path.size() - pos);
00401 }
00402
00403 Anp::Lock<Mutex> lock(Anp::GetROOTMutex());
00404
00405 if(dir -> Get(path.c_str()))
00406 {
00407 return dynamic_cast<TDirectory *>(dir -> Get(path.c_str()));
00408 }
00409
00410 return dir -> mkdir(path.c_str());
00411 }
|
|
|
Definition at line 432 of file Default.cxx. 00433 {
00434 return MAINMutex;
00435 }
|
|
|
Definition at line 438 of file Default.cxx. Referenced by Anp::RunAlgSnarl::Config(). 00439 {
00440 return ROOTMutex;
00441 }
|
|
||||||||||||||||
|
Definition at line 238 of file Default.cxx. References Registry::Get(), and reg. Referenced by Anp::SelectCount::Config(), and PTGuiMainFrame::ProcessMessage(). 00241 {
00242 std::pair<std::string, bool> result(std::string(""), false);
00243
00244 if(prefix.empty() && key.empty())
00245 {
00246 return result;
00247 }
00248
00249 const char *value_char = 0;
00250 if(reg.Get((prefix + key).c_str(), value_char) && value_char)
00251 {
00252 result.first = value_char;
00253 result.second = true;
00254 }
00255 else if(reg.Get(key.c_str(), value_char) && value_char)
00256 {
00257 result.first = value_char;
00258 result.second = true;
00259 }
00260
00261 return result;
00262 }
|
|
|
Definition at line 73 of file Default.cxx. References Anp::GNUMICosZ, Anp::GNUMISinZ, Anp::CoordXYZ::y, and Anp::CoordXYZ::z. 00074 {
00075 CoordXYZ new_pos = pos;
00076
00077 new_pos.z = (pos.z - GNUMIFarZ) * GNUMICosZ - pos.y * GNUMISinZ;
00078 new_pos.y = (pos.z - GNUMIFarZ) * GNUMISinZ + pos.y * GNUMICosZ;
00079
00080 return new_pos;
00081 }
|
|
|
Definition at line 49 of file Default.cxx. References Anp::GNUMICosZ, Anp::GNUMISinZ, Anp::CoordXYZ::x, Anp::CoordXYZ::y, and Anp::CoordXYZ::z. 00050 {
00051 CoordXYZ new_pos;
00052
00053 new_pos.x = pos.x + GNUMINearX;
00054 new_pos.z = (pos.z - GNUMINearZ) * GNUMICosZ + pos.y * GNUMISinZ;
00055 new_pos.y = -(pos.z - GNUMINearZ) * GNUMISinZ + pos.y * GNUMICosZ;
00056
00057 return new_pos;
00058 }
|
|
|
Definition at line 61 of file Default.cxx. References Anp::GNUMICosZ, Anp::GNUMISinZ, Anp::CoordXYZ::x, Anp::CoordXYZ::y, and Anp::CoordXYZ::z. 00062 {
00063 CoordXYZ new_pos;
00064
00065 new_pos.x = pos.x - GNUMINearX;
00066 new_pos.z = pos.z * GNUMICosZ - pos.y * GNUMISinZ + GNUMINearZ;
00067 new_pos.y = pos.z * GNUMISinZ + pos.y * GNUMICosZ;
00068
00069 return new_pos;
00070 }
|
|
|
Definition at line 87 of file Default.h. Referenced by Anp::angle(). 00087 { return 3.1415926536; }
|
|
||||||||||||||||
|
Definition at line 143 of file Default.h. 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 }
|
|
||||||||||||||||
|
Definition at line 303 of file Default.cxx. References Registry::Get(), and reg. 00304 {
00305 const char *value_char = 0;
00306 if(!reg.Get(key.c_str(), value_char) || !value_char)
00307 {
00308 return false;
00309 }
00310
00311 value = std::string(value_char);
00312 return true;
00313 }
|
|
||||||||||||||||
|
||||||||||||||||||||
|
Definition at line 95 of file Default.h. References Registry::Get(), reg, and UtilString::StringTok(). Referenced by Anp::SelectSpill::Init(). 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 }
|
|
||||||||||||||||
|
Definition at line 124 of file Default.cxx. References infile, Registry::KeyExists(), Registry::LockKeys(), Registry::LockValues(), reg, Registry::Set(), Registry::UnLockKeys(), and Registry::UnLockValues(). Referenced by Anp::SelectNuMu::Config(), Anp::SelectKinem::Config(), Anp::Interface::Config(), Anp::DrawSnarl::Config(), and Anp::FiducialCut::Init(). 00125 {
00126 if(!quiet)
00127 {
00128 std::cout << "-------------------------------------------------------------" << std::endl;
00129 std::cout << "Configuraton file:" << std::endl << " " << filepath << std::endl;
00130 std::cout << std::endl;
00131 }
00132
00133 std::ifstream infile(filepath.c_str());
00134 if(!infile || !infile.is_open())
00135 {
00136 std::cerr << "Anp::ReadRegistry - failed to open file: " << filepath << std::endl;
00137 if(quiet)
00138 {
00139 std::cout << "-------------------------------------------------------------" << std::endl;
00140 }
00141 return false;
00142 }
00143
00144 reg.UnLockKeys();
00145 reg.UnLockValues();
00146
00147 while(!infile.eof())
00148 {
00149 std::string line;
00150 std::getline(infile, line);
00151
00152 if(line.empty() || line.find("#",0) != std::string::npos)
00153 {
00154 continue;
00155 }
00156
00157 const std::string::size_type nbeg = line.find_first_of("[", 0);
00158 const std::string::size_type nend = line.find_first_of("]", 0);
00159
00160 if(nbeg == std::string::npos || nend == std::string::npos || !(nbeg < nend))
00161 {
00162 if(!quiet) std::cout << " Failed to parse name" << std::endl;
00163 continue;
00164 }
00165
00166 const std::string::size_type vbeg = line.find_first_of("[", nend + 1);
00167 const std::string::size_type vend = line.find_first_of("]", nend + 1);
00168
00169 if(vbeg == std::string::npos || vend == std::string::npos || !(vbeg < vend))
00170 {
00171 if(!quiet) std::cout << " Failed to parse value" << std::endl;
00172 continue;
00173 }
00174
00175 const std::string::size_type tbeg = line.find_first_of("[", vend + 1);
00176 const std::string::size_type tend = line.find_first_of("]", vend + 1);
00177
00178 if(tbeg == std::string::npos || tend == std::string::npos || !(tbeg < tend))
00179 {
00180 if(!quiet) std::cout << " Failed to parse type" << std::endl;
00181 continue;
00182 }
00183
00184 const std::string name = line.substr(nbeg + 1, nend - nbeg - 1);
00185 const std::string value = line.substr(vbeg + 1, vend - vbeg - 1);
00186 const std::string type = line.substr(tbeg + 1, tend - tbeg - 1);
00187
00188 if(!quiet) std:: cout << " " << name << " = " << value << " (" << type << ")" << std::endl;
00189
00190 if(reg.KeyExists(name.c_str()))
00191 {
00192 std::cerr << "Anp::ReadRegistry - key [" << name << "] already exists" << std::endl;
00193 continue;
00194 }
00195
00196 if(type == "string")
00197 {
00198 reg.Set(name.c_str(), value.c_str());
00199 }
00200 else if(type == "double")
00201 {
00202 const double value_double = std::atof(value.c_str());
00203 reg.Set(name.c_str(), value_double);
00204 }
00205 else if(type == "int")
00206 {
00207 if(value.find(".",0) != std::string::npos)
00208 {
00209 if(!quiet) std::cerr << " Forcing conversion of double to integer" << std::endl;
00210 const int value_int = static_cast<int>(std::atof(value.c_str()));
00211 reg.Set(name.c_str(), value_int);
00212 }
00213 else
00214 {
00215 const int value_int = std::atoi(value.c_str());
00216 reg.Set(name.c_str(), value_int);
00217 }
00218 }
00219 }
00220
00221 if(infile.is_open())
00222 {
00223 infile.close();
00224 }
00225
00226 reg.LockKeys();
00227 reg.LockValues();
00228
00229 if(!quiet)
00230 {
00231 std::cout << "-------------------------------------------------------------" << std::endl;
00232 }
00233
00234 return true;
00235 }
|
|
||||||||||||||||
|
||||||||||||||||
|
Definition at line 316 of file Default.cxx. References Registry::Get(), Registry::GetTypeAsString(), Registry::Key(), Registry::KeysLocked(), Registry::LockKeys(), Registry::LockValues(), reg, Registry::Set(), Registry::UnLockKeys(), Registry::UnLockValues(), and Registry::ValuesLocked(). Referenced by Anp::SelectKinem::GetAlg(). 00317 {
00318 //
00319 // Recursively walk through Registry and add "value" at "key"
00320 //
00321 if(key.empty())
00322 {
00323 cerr << "Anp::SetKey - key string is empty" << endl;
00324 return 0;
00325 }
00326 if(value.empty())
00327 {
00328 cerr << "Anp::SetKey - value string is empty" << endl;
00329 return 0;
00330 }
00331
00332 const bool klock = reg.KeysLocked();
00333 const bool vlock = reg.ValuesLocked();
00334
00335 if(klock) reg.UnLockKeys();
00336 if(vlock) reg.UnLockValues();
00337 reg.Set(key.c_str(), value.c_str());
00338
00339 Registry::RegistryKey rkey = reg.Key();
00340 vector<string> rvec;
00341
00342 const char* charkey = 0;
00343 while( (charkey = rkey()) )
00344 {
00345 if(charkey && reg.GetTypeAsString(charkey) == "Registry")
00346 {
00347 rvec.push_back(charkey);
00348 }
00349 }
00350
00351 int nadd = 1;
00352 for(vector<string>::const_iterator sit = rvec.begin(); sit != rvec.end(); ++sit)
00353 {
00354 const string &skey = *sit;
00355
00356 Registry dreg;
00357 if(!reg.Get(skey.c_str(), dreg))
00358 {
00359 cerr << "SelectKinem::GetAlg - failed to get Registry at: " << skey << endl;
00360 continue;
00361 }
00362
00363 //
00364 // Recursively walk through Registry daughter objects
00365 //
00366 nadd += Anp::SetKey(dreg, key, value);
00367 reg.Set(skey.c_str(), dreg);
00368 }
00369
00370 if(klock) reg.LockKeys();
00371 if(vlock) reg.LockValues();
00372
00373 return nadd;
00374 }
|
|
||||||||||||
|
Definition at line 81 of file Default.h. Referenced by Anp::Vertex::CosX(), and Anp::Vertex::X(). 00081 { return (u - v)*0.707106781; }
|
|
||||||||||||
|
Definition at line 82 of file Default.h. Referenced by Anp::Vertex::CosY(), and Anp::Vertex::Y(). 00082 { return (u + v)*0.707106781; }
|
|
||||||||||||
|
Definition at line 84 of file Default.h. Referenced by Anp::Truth::GetVtx(), and Anp::SelectFiducial::Pass(). 00084 { return (y + x)*0.707106781; }
|
|
||||||||||||
|
Definition at line 85 of file Default.h. Referenced by Anp::Truth::GetVtx(), and Anp::SelectFiducial::Pass(). 00085 { return (y - x)*0.707106781; }
|
1.3.9.1