3 #include <unordered_set> 57 string description=
"DiaDes: Diagnoser computation\nLAAS-CNRS, 2006-2012, 7 avenue du Colonel Roche, Toulouse, France\nContact: yannick.pencole@laas.fr\n\nUsage: diagnoser\n\t [--with-silent-closure]\n\t [--no-failures | --failures evt1 [evt2 ...]]\n\t [--observables obs1 [obs2 ...]]\n\t [--hd filename1]\n\t [--dot filename2]\n\tinfile.des_comp \n\n\nCompute an explicit representation of the diagnoser from the model \ninfile.des_comp and saves it into modelName.diagnoser (diades format). \nThe diagnoser can be extended with the silent closure or not. \nIf --no-failures is set, it returns a state observer. If --observables \n(resp. --failures) is set, then only the listed events are considered as observable \n(resp. faulty). The tag --hd exports the diagnoser is HyDiag format, the tag --dot \nexports the diagnoser in graphviz format, the tag --cpp exports the diagnoser \nin standalone and compilable C++ file. The option --help displays this message";
95 int main(
int argc,
char * argv[])
97 verbose<VbOutput>(
"DiaDes: Diagnoser computation\n");
98 verbose<VbOutput>(
"LAAS-CNRS, 2006-2012, 7 avenue du Colonel Roche, Toulouse, France\n");
99 verbose<VbOutput>(
"Contact: yannick.pencole@laas.fr\n");
108 unordered_set<Event> failures;
109 unordered_set<Event> observables;
120 if(getOption<Option>(argv[index],
options,currentOption))
122 if(
isSet[currentOption])
128 isSet[currentOption] =
true;
132 switch(currentOption)
153 index,events[currentOption]);
154 if(events[currentOption].empty())
160 for(
const string & obs : events[currentOption])
162 failures.insert(EventFactory::factory()->getEvent(obs));
173 index,events[currentOption]);
174 if(events[currentOption].empty())
180 for(
const string & obs : events[currentOption])
182 observables.insert(EventFactory::factory()->getEvent(obs));
193 if(files.size() != 1)
197 hdfileName=*(files.begin());
206 if(files.size() != 1)
210 dotfileName=*(files.begin());
219 if(files.size() != 1)
223 cppfileName=*(files.begin());
247 if(infileName.empty())
249 getParameter<string>(argc,argv,index,infileName);
263 if(infileName.empty())
268 verbose<VbOutput>(
"Model loading... ");
272 if(!modl->importDesCompModel(infileName))
279 log<LgProcess>(
"The main function caught the following exception: \n\t%1%") % e.what();
284 { verbose<VbOutput>(
"%1% success.\n") % modl->name(); }
300 for(unordered_set<Event>::const_iterator obsIt = observables.begin();
301 obsIt != observables.end(); ++obsIt)
303 newMask.
addMask(*obsIt,*obsIt);
305 modl->setMask(newMask);
308 verbose<VbOutput>(
"Computation of the diagnoser with the following parameters: \n");
311 for (unordered_set<Event>::const_iterator i=failures.begin(); i!=failures.end(); ++i)
313 verbose<VbOutput>(
"Failure: %1%\n") % *i;
316 i!=modl->mask().observableEnd();
319 verbose<VbOutput>(
"Observable: %1%\n") % *i;
324 verbose<VbOutput>(
"Processing, please wait...");
328 verbose<VbOutput>(
"Done.\n");
329 verbose<VbOutput>(
"Number of states: %1%\nNumber of transitions: %2%")
330 % diag->numberOfStates()
331 % diag->numberOfTransitions();
336 verbose<VbOutput>(
"Export in Hydiag format: ");
338 if(!diag->diagnoser2hd(hdfileName,exportHdLog))
340 string msg = exportHdLog +
"\nExport failure";
343 verbose<VbOutput>(
"%1% Done.\n") % hdfileName;
350 verbose<VbOutput>(
"Export in dot format: ");
352 if(!diag->diagnoser2dot(dotfileName,exportDotLog))
354 string msg = exportDotLog +
"\nExport failure";
357 verbose<VbOutput>(
"%1% Done.\n") % hdfileName;
363 verbose<VbOutput>(
"Export in c++ format: %1%.hh and %1%.cc") % cppfileName;
366 verbose<VbOutput>(
"Done.\n");
369 verbose<VbOutput>(
"Save the diagnoser in %1%.diagnoser.\n") % diag->name();
390 stringstream logStream;
391 if(infileName.size() <= goodSuffix.size())
393 logStream <<
"Error: incorrect input file name, it should be something like 'filename" <<
fileExtensions[0] <<
"' but it is " << infileName <<
".";
398 string suffix = infileName.substr(infileName.size()-goodSuffix.size(),infileName.size()-1);
399 if(suffix != goodSuffix)
401 logStream <<
"Error: incorrect input file name, it should be something like 'filename" <<
fileExtensions[0] <<
"' but it is " << infileName <<
".";
406 ifstream file(infileName.c_str());
410 logStream <<
"Error: the file '" << infileName <<
"' does not exist.";
417 getline(file,fakeName);
418 result = !file.eof();
421 logStream <<
"Error: the file '" << infileName <<
"' seems to be empty.";
430 logStream <<
"Error: Impossible to get the number of states in the file '"<< infileName <<
"'.";
432 result = !file.eof();
434 while(result && (i < number))
440 logStream <<
"Error: Impossible to get state number " << i <<
" in file '" << infileName <<
"'.";
442 result = !file.eof();
449 result = !file.eof();
452 logStream <<
"Error: Impossible to get the number of fault events in file '" << infileName <<
"'.";
455 while(result && (i < number))
461 logStream <<
"Error: Impossible to get fault event number " << i <<
"in file '" << infileName <<
"'.";
463 failures.insert(EventFactory::factory()->getEvent(fakeName +
"." + label));
464 result = !file.eof();
475 log =
"In getFailuresFromFileModel method, \n" + logStream.str();
Some utilities to deal with the command line.
vector< bool > isSet(numberOfOptions, false)
size_t printCommandLineError(const string &msg)
unsigned numberOfFileExtensions
vector< string > options(numberOfOptions)
set< Event >::const_iterator ObservableEventIterator
An observable Component defined as a automaton.
bool fileSuffixOk(const string &modelFile, const string &suffix)
void saveLog(Logger logger, ostream &os)
vector< string > fileExtensions(numberOfFileExtensions)
int main(int argc, char *argv[])
void generateCppCode(const ClassicalDiagnoser &diagnoser, const string &filename)
void addMask(const Event &e, const Event &obs)
Log log(Logger logger, const string &msg)
bool getFailuresFromFileModel(const string &infileName, unordered_set< Event > &failures, string &log)
void printUsage(const po::options_description &desc)