createAddresses.cxx

00001 #include "config.h"
00002 #include "Options.h"
00003 #include "Address.h"
00004 #include <rcudb/Server.h>
00005 #include <rcudb/Sql.h>
00006 #include <iostream>
00007 #include <sstream>
00008 #include <stdexcept>
00009 
00010 
00011 //____________________________________________________________________
00012 int 
00013 main(int argc, char** argv)
00014 {
00015   using namespace RcuConf;
00016   Option<bool>        hOpt('h', "help",    "Show this help", false,false);
00017   Option<bool>        VOpt('V', "version", "Show version number", false,false);
00018   Option<std::string> cOpt('c', "connection", "Database connection url", 
00019                            "mysql://config@localhost/RCU");
00020   CommandLine cl("");
00021   cl.Add(hOpt);
00022   cl.Add(VOpt);
00023   cl.Add(cOpt);
00024 
00025   if (!cl.Process(argc, argv)) return 1;
00026   if (hOpt.IsSet()) {
00027     cl.Help();
00028     return 0;
00029   }
00030   if (VOpt.IsSet()) {
00031     std::cout << "raw2root version " << VERSION << std::endl;
00032     return 0;
00033   }
00034 
00035   
00036   std::string con = cOpt;
00037   try {
00038     RcuDb::Server* server = RcuDb::Server::Connect(con);
00039     if (!server) 
00040       throw std::runtime_error("Failed to open connection to server!");
00041   
00042 
00043     // This is for the FMD!
00044     unsigned int boards[]    = { 0, 0x1, 0x10, 0x11 };
00045     unsigned int nchips      = 3;
00046     
00047     for (unsigned iboard = 0; iboard < 4; iboard++) {
00048       unsigned int board = boards[iboard];
00049       for (unsigned int chip = 0; chip < nchips; chip++) {
00050         unsigned int nchannels = (chip == 1 ? 8 : 16);
00051         for (unsigned int channel = 0; channel < nchannels; channel++) {
00052           Address a(board, chip, channel);
00053           if (!a.Insert(*server)) {
00054             std::stringstream s;
00055             s << "Failed to insert address: " << server->ErrorString();
00056             throw std::runtime_error(s.str());
00057           }
00058         }
00059       }
00060     }
00061     
00062     Address::List addrs;
00063     if (!Address::Select(addrs, *server, "")) {
00064       std::stringstream s;
00065       s << "Failed to get addresss: " << server->ErrorString();
00066       throw std::runtime_error(s.str());
00067     }    
00068     for (Address::List::iterator i = addrs.begin(); i != addrs.end(); ++i)
00069       (*i)->Print();
00070   }
00071   catch (std::exception& e) {
00072     std::cerr << e.what() << std::endl;
00073     return 1;
00074   }
00075   return 0;
00076 }
00077 
00078       
00079 
00080 
Top of page Last update Fri Apr 27 01:54:15 2007
Copyright © 2004 Christian Holm Created by DoxyGen 1.3.5