Changeset 11483 for trunk/FACT++/src
- Timestamp:
- 07/20/11 10:27:17 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Configuration.cc
r11481 r11483 528 528 ("print-unknown", "Print unrecognized options.") 529 529 ("print-options", "Print options as passed to program.") 530 ("print-wildcards", "Print all options registered with wildcards.") 530 531 ("dont-check", "Do not check validity of options from files and database.") 531 532 ("dont-check-files", "Do not check validity of options from files.") … … 591 592 //for (int j=0; j<options[i].value.size(); j++) 592 593 // cout << "\t = " << options[i].value[j]; 593 594 //cout << "/" << options[i].position_key;595 594 //cout << "/" << options[i].original_tokens[0]; 596 //cout << "/" << options[i].unregistered << endl; 595 596 ostringstream com; 597 598 if (opt.position_key>=0) 599 com << " [position=" << opt.position_key << "]"; 597 600 if (opt.unregistered) 598 cout << " # option unknown"; 601 com << " [unregistered]"; 602 603 if (!com.str().empty()) 604 cout << " # " << com.str(); 605 599 606 cout << endl; 600 607 } … … 963 970 //! options from the default configuration-file and options 964 971 //! from the environment. 965 //! - (15) Fin allyall options which were found and flagged as unrecognized,972 //! - (15) Find all options which were found and flagged as unrecognized, 966 973 //! because they are not in the user-defined list of described 967 974 //! options, are collected and stored in the corresponding 968 975 //! data-members. 969 //! - (16) Before the function returns it check for \b --print-options 976 //! - (16) Find all options which where registered with wildcards and 977 //! store the list in fWildcardOptions. 978 //! - (17) Before the function returns it check for \b --print-options 970 979 //! and \b --print-unknown and performs the corresponding actions. 971 980 //! … … 1058 1067 const string globalfile = path.parent_path().string()+"/fact++.rc"; 1059 1068 1060 cerr << "Reading options from '" << globalfile << "'." << endl;1069 cerr << "Reading global options from '" << globalfile << "'." << endl; 1061 1070 1062 1071 ifstream gfile(globalfile.c_str()); … … 1073 1082 { 1074 1083 fDefaultFile = getfiles["default"].as<string>(); 1075 cerr << "Reading options from '" << fDefaultFile << "'." << endl;1084 cerr << "Reading default options from '" << fDefaultFile << "'." << endl; 1076 1085 } 1077 1086 … … 1109 1118 { 1110 1119 fPriorityFile = getfiles["config"].as<string>(); 1111 cerr << "Reading options from '" << fPriorityFile << "'." << endl;1120 cerr << "Reading config options from '" << fPriorityFile << "'." << endl; 1112 1121 } 1113 1122 … … 1208 1217 // ------------------------ (16) ------------------------- 1209 1218 1219 CreateWildcardOptions(); 1220 1221 // ------------------------ (17) ------------------------- 1222 1210 1223 if (result.count("print-options")) 1211 1224 PrintOptions(); 1212 1225 1226 if (result.count("print-wildcards")) 1227 PrintWildcardOptions(); 1228 1213 1229 if (result.count("print-unknown")) 1214 1230 PrintUnknown(); 1215 1231 1216 1232 return fVariables; 1233 } 1234 1235 // -------------------------------------------------------------------------- 1236 // 1237 //! Create a list of all options which were registered using wildcards 1238 //! 1239 void Configuration::CreateWildcardOptions() 1240 { 1241 po::options_description opts; 1242 1243 for (int i=0; i<2; i++) 1244 { 1245 opts.add(fOptionsCommandline[i]); 1246 opts.add(fOptionsConfigfile[i]); 1247 opts.add(fOptionsEnvironment[i]); 1248 opts.add(fOptionsDatabase[i]); 1249 } 1250 1251 fWildcardOptions.clear(); 1252 1253 typedef map<string,po::variable_value> Vars; 1254 typedef vector<boost::shared_ptr<po::option_description>> Descs; 1255 1256 const Descs &desc = opts.options(); 1257 1258 for (Vars::const_iterator io=fVariables.begin(); io!=fVariables.end(); io++) 1259 { 1260 for (Descs::const_iterator id=desc.begin(); id!=desc.end(); id++) 1261 if ((*id)->match(io->first, false, false, false)==po::option_description::approximate_match) 1262 fWildcardOptions[io->first] = (*id)->long_name(); 1263 } 1264 } 1265 1266 // -------------------------------------------------------------------------- 1267 // 1268 //! Print a list of all options which were registered using wildcards and 1269 //! have not be registered subsequently by access. 1270 //! 1271 void Configuration::PrintWildcardOptions() const 1272 { 1273 cout << "Options registered with wildcards and not yet accessed:" << endl; 1274 1275 size_t max = 0; 1276 for (map<string,string>::const_iterator it=fWildcardOptions.begin(); it!=fWildcardOptions.end(); it++) 1277 if (it->second.length()>max) 1278 max = it->second.length(); 1279 1280 cout.setf(ios_base::left); 1281 for (map<string,string>::const_iterator it=fWildcardOptions.begin(); it!=fWildcardOptions.end(); it++) 1282 cout << setw(max+1) << it->second << " : " << it->first <<endl; 1217 1283 } 1218 1284 -
trunk/FACT++/src/Configuration.h
r11481 r11483 33 33 std::vector<std::string> fUnknownDatabase; /// Storage container for unrecognized options retrieved from the database 34 34 35 std::map<std::string, std::string> fWildcardOptions; /// Options which were registered using wildcards 36 35 37 std::string fPriorityFile; /// File name of the priority configuration file (overwrites option from the databse) 36 38 std::string fDefaultFile; /// File name of the default configuration file (usually {program}.rc) … … 56 58 val=comp; 57 59 } 60 61 /// Helper for Parse to create list of used wildcard options 62 void CreateWildcardOptions(); 58 63 59 64 // Helper functions for PrintOptions and GetOptions … … 112 117 void PrintOptions() const; 113 118 void PrintUnknown() const; 119 void PrintWildcardOptions() const; 120 121 const std::map<std::string,std::string> &GetWildcardOptions() const { return fWildcardOptions; } 114 122 115 123 std::multimap<std::string, std::string> GetOptions() const; … … 118 126 const po::variables_map &Parse(int argc, const char **argv); 119 127 120 bool HasVersion() const128 bool HasVersion() 121 129 { 122 130 return Has("version"); 123 131 } 124 132 125 bool HasHelp() const133 bool HasHelp() 126 134 { 127 135 return Has("help") || Has("help-config") || Has("help-env") || Has("help-database"); 128 136 } 129 137 130 bool HasPrint() const138 bool HasPrint() 131 139 { 132 140 return Has("print-all") || Has("print") || Has("print-default") || 133 141 Has("print-database") || Has("print-config") || 134 142 Has("print-environment") || Has("print-unknown") || 135 Has("print-options") ;143 Has("print-options") || Has("print-wildcards"); 136 144 } 137 145 138 146 // Simplified access to the parsed options 139 147 template<class T> 140 T Get(const std::string &var) const { return fVariables[var].as<T>(); } 141 template<class T> 142 std::vector<T> Vec(const std::string &var) const { return Has(var) ? fVariables[var].as<std::vector<T>>() : std::vector<T>(); } 143 bool Has(const std::string &var) const { return fVariables.count(var)>0; } 148 T Get(const std::string &var) { fWildcardOptions.erase(var); return fVariables[var].as<T>(); } 149 bool Has(const std::string &var) { fWildcardOptions.erase(var); return fVariables.count(var)>0; } 150 151 template<class T> 152 std::vector<T> Vec(const std::string &var) { return Has(var) ? fVariables[var].as<std::vector<T>>() : std::vector<T>(); } 144 153 145 154 template<class T, class S> 146 T Get(const std::string &var, const S &val) const155 T Get(const std::string &var, const S &val) 147 156 { 148 157 std::ostringstream str; … … 152 161 153 162 template<class T> 154 bool Has(const std::string &var, const T &val) const163 bool Has(const std::string &var, const T &val) 155 164 { 156 165 std::ostringstream str; … … 160 169 161 170 template<class T, class S> 162 T GetDef(const std::string &var, const S &val) const171 T GetDef(const std::string &var, const S &val) 163 172 { 164 173 return Has(var, val) ? Get<T>(var, val) : Get<T>(var+"default"); … … 166 175 167 176 template<class T> 168 bool HasDef(const std::string &var, const T &val) const177 bool HasDef(const std::string &var, const T &val) 169 178 { 170 179 return Has(var, val) ? true : Has(var+"default"); 171 180 } 172 173 template<class T> 174 std::map<std::string, T> GetMap(const std::string &var) const181 /* 182 template<class T> 183 std::map<std::string, T> GetMap(const std::string &var) 175 184 { 176 185 const size_t len = var.length(); … … 186 195 187 196 template<class T> 188 std::vector<std::string> GetKeys(const std::string &var) const197 std::vector<std::string> GetKeys(const std::string &var) 189 198 { 190 199 const size_t len = var.length(); … … 198 207 return rc; 199 208 } 200 209 */ 201 210 const std::string &GetName() const { return fName; } 202 211 }; -
trunk/FACT++/src/Main.h
r11481 r11483 2 2 #define FACT_MAIN 3 3 4 #include <map> 4 5 #include <thread> 5 6 #include <functional> … … 41 42 42 43 template<class T, class S> 43 int Main( constConfiguration &conf, bool dummy=false)44 int Main(Configuration &conf, bool dummy=false) 44 45 { 45 46 static T shell(conf.GetName().c_str(), … … 70 71 io_service.Write(now, "| Start: "+now.GetAsStr("%c")); 71 72 io_service.Write(now, "\\----------------------- Options ------------------------"); 72 const multimap<string,string> m ap = conf.GetOptions();73 for (multimap<string,string>::const_iterator it=m ap.begin(); it!=map.end(); it++)73 const multimap<string,string> mmap = conf.GetOptions(); 74 for (multimap<string,string>::const_iterator it=mmap.begin(); it!=mmap.end(); it++) 74 75 io_service.Write(now, ": "+it->first+(it->second.empty()?"":" = ")+it->second); 75 76 io_service.Write(now, "\\------------------- Evaluating options -----------------"); 77 const int rc = io_service.EvalOptions(conf); 76 78 77 const int rc = io_service.EvalConfiguration(conf); 79 const map<string,string> &wco = conf.GetWildcardOptions(); 80 if (wco.size()>0) 81 { 82 io_service.Write(now, "------------- Unrecognized wildcard options -------------", MessageImp::kWarn); 83 84 size_t max = 0; 85 for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++) 86 if (it->second.length()>max) 87 max = it->second.length(); 88 89 for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++) 90 { 91 ostringstream str; 92 str.setf(ios_base::left); 93 str << setw(max+1) << it->second << " : " << it->first; 94 io_service.Write(now, str.str(), MessageImp::kWarn); 95 } 96 return 127; 97 } 98 78 99 io_service.Message("==================== Starting main loop ================="); 79 100 if (rc>=0) -
trunk/FACT++/src/biasctrl.cc
r11481 r11483 537 537 } 538 538 539 int Eval Configuration(constConfiguration &conf)539 int EvalOptions(Configuration &conf) 540 540 { 541 541 SetEndpoint(conf.Get<string>("addr")); -
trunk/FACT++/src/datalogger.cc
r11481 r11483 2336 2336 //! @param conf the configuration object that should be used 2337 2337 //! 2338 int DataLogger::Eval Configuration(constConfiguration& conf)2338 int DataLogger::EvalOptions(Configuration& conf) 2339 2339 { 2340 2340 fDebugIsOn = conf.Get<bool>("debug"); -
trunk/FACT++/src/drivectrl.cc
r11481 r11483 1 #include <boost/bind.hpp> 2 1 3 #include "FACT.h" 2 4 #include "Dim.h" … … 410 412 { 411 413 boost::asio::async_read_until(*this, fBuffer, '\n', 412 b ind(&ConnectionDrive::HandleReceivedReport, this,414 boost::bind(&ConnectionDrive::HandleReceivedReport, this, 413 415 dummy::error, dummy::bytes_transferred)); 414 416 } … … 421 423 422 424 fKeepAlive.expires_from_now(boost::posix_time::seconds(10)); 423 fKeepAlive.async_wait(b ind(&ConnectionDrive::HandleKeepAlive,425 fKeepAlive.async_wait(boost::bind(&ConnectionDrive::HandleKeepAlive, 424 426 this, dummy::error)); 425 427 } … … 834 836 } 835 837 836 int Eval Configuration(constConfiguration &conf)838 int EvalOptions(Configuration &conf) 837 839 { 838 840 SetEndpoint(conf.Get<string>("addr")); -
trunk/FACT++/src/fadctrl.cc
r11481 r11483 1790 1790 1791 1791 template<class V> 1792 bool CheckConfigVal( constConfiguration &conf, V max, const string &name, const string &sub)1792 bool CheckConfigVal(Configuration &conf, V max, const string &name, const string &sub) 1793 1793 { 1794 1794 if (!conf.HasDef(name, sub)) … … 1810 1810 } 1811 1811 1812 int Eval Configuration(constConfiguration &conf)1812 int EvalOptions(Configuration &conf) 1813 1813 { 1814 1814 // ---------- General setup --------- -
trunk/FACT++/src/fscctrl.cc
r11481 r11483 506 506 } 507 507 508 int Eval Configuration(constConfiguration &conf)508 int EvalOptions(Configuration &conf) 509 509 { 510 510 SetEndpoint(conf.Get<string>("addr")); -
trunk/FACT++/src/ftmctrl.cc
r11481 r11483 1971 1971 1972 1972 template<class V> 1973 bool CheckConfigVal( constConfiguration &conf, V max, const string &name, const string &sub)1973 bool CheckConfigVal(Configuration &conf, V max, const string &name, const string &sub) 1974 1974 { 1975 1975 if (!conf.HasDef(name, sub)) … … 1991 1991 } 1992 1992 1993 int Eval Configuration(constConfiguration &conf)1993 int EvalOptions(Configuration &conf) 1994 1994 { 1995 1995 // ---------- General setup ---------- -
trunk/FACT++/src/mcp.cc
r11481 r11483 179 179 int Reset(const EventImp &evt) 180 180 { 181 fRunType = ""; 181 182 return kStateIdle; 182 183 /* … … 200 201 } 201 202 203 string fRunType; 204 202 205 int StartRun(const EventImp &evt) 203 206 { 207 Message("Starting configuration '"+evt.GetString()+"' for new run."); 208 fRunType = evt.GetString(); 204 209 return kStateConfiguring1; 205 210 } … … 225 230 if (fStatusLog.second!=30/*kSM_WaitForRun*/) 226 231 Dim::SendCommand("DATA_LOGGER/WAIT_FOR_RUN_NUMBER"); 227 Dim::SendCommand("FTM_CONTROL/CONFIGURE", "data");232 Dim::SendCommand("FTM_CONTROL/CONFIGURE", fRunType); 228 233 return kStateConfiguring2; 229 234 } … … 236 241 return GetCurrentState(); 237 242 238 Dim::SendCommand("FAD_CONTROL/CONFIGURE", "data");243 Dim::SendCommand("FAD_CONTROL/CONFIGURE", fRunType); 239 244 return kStateConfiguring3; 240 245 } … … 248 253 Message("START DATA TAKING"); 249 254 Fatal("Distribute run-number to start datalogger!"); 250 Fatal("fadctrl should go out of Configured after first event received!"); 251 Fatal("Must configure if FTM should be started or not?"); 255 //Fatal("Must configure if FTM should be started or not?"); 252 256 Dim::SendCommand("FTM_CONTROL/START_RUN"); 253 257 return kStateConfigured; … … 329 333 330 334 331 AddEvent("START", kStateIdle)335 AddEvent("START", "C", kStateIdle) 332 336 (bind(&StateMachineMCP::StartRun, this, placeholders::_1)) 333 337 (""); … … 352 356 } 353 357 354 int Eval Configuration(constConfiguration &conf)358 int EvalOptions(Configuration &conf) 355 359 { 356 360 //SetEndpoint(conf.Get<string>("addr")); … … 401 405 402 406 template<class T> 403 int RunShell( constConfiguration &conf)407 int RunShell(Configuration &conf) 404 408 { 405 409 return Main<T, StateMachineMCP>(conf); -
trunk/FACT++/src/scheduler.cc
r11481 r11483 691 691 } 692 692 693 int Eval Configuration(constConfiguration &conf)693 int EvalOptions(Configuration &conf) 694 694 { 695 695 fDatabase = conf.Get<string>("schedule-database");
Note:
See TracChangeset
for help on using the changeset viewer.