dump_SCTDAL_rdb.cpp

00001   // *** this file is generated by genconfig ***
00002 
00003 #include "config/ConfigObject.h"
00004 #include "rdbconfig/RdbConfiguration.h"
00005 
00006 #include "Barrel.h"
00007 #include "Channel.h"
00008 #include "Crate.h"
00009 #include "Geography.h"
00010 #include "GeographyMUR.h"
00011 #include "Partition.h"
00012 #include "Power.h"
00013 #include "PowerCard.h"
00014 #include "PowerChannel.h"
00015 #include "PowerCrate.h"
00016 #include "PowerParam.h"
00017 #include "Rod.h"
00018 #include "RodMUR.h"
00019 #include "RodModule.h"
00020 #include "RodRModule.h"
00021 #include "Row.h"
00022 #include "SCT_Chip.h"
00023 #include "SCT_Module.h"
00024 #include "Slave.h"
00025 #include "Tim.h"
00026 
00027   // db implementation-specific headrers prologue
00028 
00029 #include <ipc/core.h>
00030 
00031 
00032 static void usage(const char * s)
00033 {
00034   std::cout << s << " -d db-name -c class-name [-q query | -i object-id] [-t]\n"
00035     "\n"
00036     "Options/Arguments:\n"
00037     "  -d | --data db-name            mandatory name of the database\n"
00038     "  -c | --class-name class-name   mandatory name of class\n"
00039     "  -q | --query query             optional query to select class objects\n"
00040     "  -i | --object-id object-id     optional identity to select one object\n"
00041     "  -t | --init-children           all referenced objects are inited (is used\n"
00042     "                                 for debug purposes and performance measurements)\n"
00043     "  -h | --help                    print this message\n"
00044     "\n"
00045     "Description:\n"
00046     "  The program prints out object(s) of given class.\n"
00047     "  If no query or object id is provided, all objects of the class are printed.\n"
00048     "  It is automatically generated by genconfig utility.\n"
00049     "\n";
00050 }
00051 
00052 static void no_param(const char * s)
00053 {
00054   std::cerr << "ERROR: no parameter for " << s << " provided\n\n";
00055   exit (EXIT_FAILURE);
00056 }
00057 
00058 int main(int argc, char *argv[])
00059 {
00060     // db implementation-specific main function prologue
00061 
00062   IPCCore::init(argc, argv);
00063 
00064     // parse parameters
00065 
00066   const char * db_name = 0;
00067   const char * object_id = 0;
00068   const char * query = "";
00069   std::string class_name;
00070   bool init_children = false;
00071 
00072   for(int i = 1; i < argc; i++) {
00073     const char * cp = argv[i];
00074     if(!strcmp(cp, "-h") || !strcmp(cp, "--help")) {
00075       usage(argv[0]);
00076       return 0;
00077     }
00078     if(!strcmp(cp, "-t") || !strcmp(cp, "--init-children")) {
00079       init_children = true;
00080     }
00081     else if(!strcmp(cp, "-d") || !strcmp(cp, "--data")) {
00082       if(++i == argc) { no_param(cp); } else { db_name = argv[i]; }
00083     }
00084     else if(!strcmp(cp, "-c") || !strcmp(cp, "--class-name")) {
00085       if(++i == argc) { no_param(cp); } else { class_name = argv[i]; }
00086     }
00087     else if(!strcmp(cp, "-i") || !strcmp(cp, "--object-id")) {
00088       if(++i == argc) { no_param(cp); } else { object_id = argv[i]; }
00089     }
00090     else if(!strcmp(cp, "-q") || !strcmp(cp, "--query")) {
00091       if(++i == argc) { no_param(cp); } else { query = argv[i]; }
00092     }
00093     else {
00094       std::cerr << "ERROR: bad parameter " << cp << std::endl;
00095       usage(argv[0]);
00096       return (EXIT_FAILURE);
00097     }
00098   }
00099 
00100   if(db_name == 0) {
00101     std::cerr << "ERROR: no database name provided\n";
00102     return (EXIT_FAILURE);
00103   }
00104 
00105   if(class_name.empty()) {
00106     std::cerr << "ERROR: no class name provided\n";
00107     return (EXIT_FAILURE);
00108   }
00109 
00110   if(*query != 0 && object_id != 0) {
00111     std::cerr << "ERROR: only one parameter -i or -q can be provided\n";
00112     return (EXIT_FAILURE);
00113   }
00114 
00115 
00116   RdbConfiguration impl_conf;
00117 
00118   {
00119     ::Configuration conf(db_name, &impl_conf);
00120 
00121     if(!conf.loaded()) {
00122       std::cerr << "Can not load database: " << db_name << std::endl;
00123       return (EXIT_FAILURE);
00124     }
00125 
00126     std::vector< ::ConfigObject > objects;
00127   
00128     if(object_id) {
00129       ::ConfigObject obj;
00130       if(conf.get(class_name, object_id, obj) == false) {
00131         std::cerr << "Can not get object \'" << object_id << "\' of class \'" << class_name << "\'\n";
00132         return (EXIT_FAILURE);
00133       }
00134       objects.push_back(obj);
00135     }
00136     else {
00137       if(conf.get(class_name, objects, query) == false) {
00138         std::cerr << "Can not get objects of class \'" << class_name << "\'\n";
00139         return (EXIT_FAILURE);
00140       }
00141     }
00142     
00143     for(std::vector< ::ConfigObject >::iterator i = objects.begin(); i != objects.end(); ++i) {
00144       if(class_name == "Barrel") {
00145         std::cout << *conf.get<SCTDAL::Barrel>(*i, init_children) << std::endl;
00146       }
00147       else if(class_name == "Channel") {
00148         std::cout << *conf.get<SCTDAL::Channel>(*i, init_children) << std::endl;
00149       }
00150       else if(class_name == "Crate") {
00151         std::cout << *conf.get<SCTDAL::Crate>(*i, init_children) << std::endl;
00152       }
00153       else if(class_name == "Geography") {
00154         std::cout << *conf.get<SCTDAL::Geography>(*i, init_children) << std::endl;
00155       }
00156       else if(class_name == "GeographyMUR") {
00157         std::cout << *conf.get<SCTDAL::GeographyMUR>(*i, init_children) << std::endl;
00158       }
00159       else if(class_name == "Partition") {
00160         std::cout << *conf.get<SCTDAL::Partition>(*i, init_children) << std::endl;
00161       }
00162       else if(class_name == "Power") {
00163         std::cout << *conf.get<SCTDAL::Power>(*i, init_children) << std::endl;
00164       }
00165       else if(class_name == "PowerCard") {
00166         std::cout << *conf.get<SCTDAL::PowerCard>(*i, init_children) << std::endl;
00167       }
00168       else if(class_name == "PowerChannel") {
00169         std::cout << *conf.get<SCTDAL::PowerChannel>(*i, init_children) << std::endl;
00170       }
00171       else if(class_name == "PowerCrate") {
00172         std::cout << *conf.get<SCTDAL::PowerCrate>(*i, init_children) << std::endl;
00173       }
00174       else if(class_name == "PowerParam") {
00175         std::cout << *conf.get<SCTDAL::PowerParam>(*i, init_children) << std::endl;
00176       }
00177       else if(class_name == "Rod") {
00178         std::cout << *conf.get<SCTDAL::Rod>(*i, init_children) << std::endl;
00179       }
00180       else if(class_name == "RodMUR") {
00181         std::cout << *conf.get<SCTDAL::RodMUR>(*i, init_children) << std::endl;
00182       }
00183       else if(class_name == "RodModule") {
00184         std::cout << *conf.get<SCTDAL::RodModule>(*i, init_children) << std::endl;
00185       }
00186       else if(class_name == "RodRModule") {
00187         std::cout << *conf.get<SCTDAL::RodRModule>(*i, init_children) << std::endl;
00188       }
00189       else if(class_name == "Row") {
00190         std::cout << *conf.get<SCTDAL::Row>(*i, init_children) << std::endl;
00191       }
00192       else if(class_name == "SCT_Chip") {
00193         std::cout << *conf.get<SCTDAL::SCT_Chip>(*i, init_children) << std::endl;
00194       }
00195       else if(class_name == "SCT_Module") {
00196         std::cout << *conf.get<SCTDAL::SCT_Module>(*i, init_children) << std::endl;
00197       }
00198       else if(class_name == "Slave") {
00199         std::cout << *conf.get<SCTDAL::Slave>(*i, init_children) << std::endl;
00200       }
00201       else if(class_name == "Tim") {
00202         std::cout << *conf.get<SCTDAL::Tim>(*i, init_children) << std::endl;
00203       }
00204       else {
00205         std::cerr << "ERROR: do not know how to dump object of " << class_name << " class\n";
00206         return (EXIT_FAILURE);
00207       }
00208     }
00209   }
00210 
00211   return 0;
00212 }

Generated on Mon Feb 6 14:01:19 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6