00001 #include "config.h"
00002 #include "Options.h"
00003 #include "Rcu.h"
00004 #include "Altro.h"
00005 #include "Bc.h"
00006 #include "Fmd.h"
00007 #include <rcudb/Server.h>
00008 #include <rcudb/Sql.h>
00009 #include <iostream>
00010 #include <sstream>
00011 #include <stdexcept>
00012
00013
00014 template <typename T>
00015 void
00016 createComponent(RcuDb::Server& s, const std::string& name)
00017 {
00018 if (T::Create(s)) return;
00019 std::stringstream errstr;
00020 errstr << "Failed to create parameters for " << name << ": "
00021 << s.ErrorString() << std::endl;
00022 throw std::runtime_error(errstr.str());
00023 }
00024
00025
00026 int
00027 main(int argc, char** argv)
00028 {
00029 using namespace RcuConf;
00030 Option<bool> hOpt('h', "help", "Show this help", false,false);
00031 Option<bool> VOpt('V', "version", "Show version number", false,false);
00032 Option<bool> fOpt('f', "fmd", "Use FMD", false,false);
00033 Option<std::string> cOpt('c', "connection", "Database connection url",
00034 "mysql://config@localhost/RCU");
00035 CommandLine cl("");
00036 cl.Add(hOpt);
00037 cl.Add(VOpt);
00038 cl.Add(fOpt);
00039 cl.Add(cOpt);
00040
00041 if (!cl.Process(argc, argv)) return 1;
00042 if (hOpt.IsSet()) {
00043 cl.Help();
00044 return 0;
00045 }
00046 if (VOpt.IsSet()) {
00047 std::cout << "raw2root version " << VERSION << std::endl;
00048 return 0;
00049 }
00050
00051 try {
00052 std::string con = cOpt;
00053 RcuDb::Server* server = RcuDb::Server::Connect(con);
00054 if (!server)
00055 throw std::runtime_error("Failed to open connection to server!");
00056
00057 createComponent<Rcu>(*server, "RCU");
00058 if (fOpt.IsSet())
00059 createComponent<Fmd>(*server, "FMD");
00060 else
00061 createComponent<Bc>(*server, "BC");
00062 createComponent<Altro>(*server, "ALTRO");
00063
00064 Parameter::List params;
00065 if (!Parameter::Select(params, *server, "")) {
00066 std::stringstream s;
00067 s << "Failed to get parameters: " << server->ErrorString();
00068 throw std::runtime_error(s.str());
00069 }
00070
00071 for (Parameter::List::iterator i = params.begin(); i != params.end(); ++i)
00072 (*i)->Print();
00073 }
00074 catch (std::exception& e) {
00075 std::cerr << e.what() << std::endl;
00076 return 1;
00077 }
00078 return 0;
00079 }
00080
00081
00082
00083