DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
oks_check_schema.cxx File Reference
#include "CLI/CLI.hpp"
#include "logging/Logging.hpp"
#include "oks/class.hpp"
#include "oks/file.hpp"
#include "oks/kernel.hpp"
#include "oks/relationship.hpp"
#include <fmt/core.h>
#include <string>
Include dependency graph for oks_check_schema.cxx:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program to do some simple integrity checks on a schema file

This is part of the DUNE DAQ Application Framework, copyright 2025. Licensing/copyright details are in the COPYING file that you should have received with this code.

Definition in file oks_check_schema.cxx.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 24 of file oks_check_schema.cxx.

24 {
25 enum Exitcode : int {SUCCESS, BADCMD, NOFILE, LOADFAIL, BADRELATIONSHIP};
26
27 CLI::App app{"Check consistency of OKS schema file\n"+
28 fmt::format("Return codes: {} Success, file is OK\n", Exitcode::SUCCESS)+
29 fmt::format(" {} Bad command line\n", Exitcode::BADCMD)+
30 fmt::format(" {} Failed to find file\n", Exitcode::NOFILE)+
31 fmt::format(" {} Failed to load file -- invalid schema\n", Exitcode::LOADFAIL)+
32 fmt::format(" {} File contains relationship to non loaded class\n", Exitcode::BADRELATIONSHIP)
33 };
34
35 std::string filename;
36 app.add_option("-f,--file", filename, "Schema file")
37 ->required();
38
39 CLI11_PARSE(app, argc, argv);
40
41 OksKernel kernel;
42 try {
43 const auto file = kernel.load_file(filename);
44 if (file == nullptr) {
45 TLOG() << "Failed to load " << filename;
46 return Exitcode::LOADFAIL;
47 }
48 }
49 catch (FailedLoadFile& fail) {
50 TLOG() << fail.what() << "\n";
51 return Exitcode::LOADFAIL;
52 }
53 catch (CanNotOpenFile& fail) {
54 TLOG() << fail.what() << "\n";
55 return Exitcode::NOFILE;
56 }
57 catch (std::exception& exc) {
58 TLOG() << exc.what() << "\n";
59 return Exitcode::LOADFAIL;
60 }
61
62 for (auto [name, oks_class] : kernel.classes()) {
63 auto relationships = oks_class->direct_relationships();
64 if (relationships != nullptr) {
65 for (auto rel: *relationships) {
66 auto rel_class = rel->get_class_type();
67 if (rel_class == nullptr) {
68 TLOG() << "Error class '" << name
69 << "' has relationship '" << rel->get_name()
70 << "' to a class '" << rel->get_type()
71 << "' that is not loaded\n";
72 return Exitcode::BADRELATIONSHIP;
73 }
74 }
75 }
76 // Could check super-classes but we wouldn't have got past the
77 // load if they referred to a missing class.
78 }
79
80 return 0;
81}
Cannot open file.
Definition kernel.hpp:135
Cannot load file.
Definition kernel.hpp:56
Provides interface to the OKS kernel.
Definition kernel.hpp:577
OksFile * load_file(const std::string &name, bool bind=true)
Load OKS database file.
Definition kernel.cpp:1788
const OksClass::Map & classes() const
Get classes.
Definition kernel.hpp:1767
virtual const char * what() const noexcept
#define TLOG(...)
Definition macro.hpp:22