DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
oks_report_equal_objects.cxx File Reference
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <boost/program_options.hpp>
#include "oks/attribute.hpp"
#include "oks/class.hpp"
#include "oks/kernel.hpp"
#include "oks/object.hpp"
#include "oks/relationship.hpp"
Include dependency graph for oks_report_equal_objects.cxx:

Go to the source code of this file.

Classes

struct  SortObjById

Typedefs

typedef std::set< const OksObject *, SortObjById > ObjsSet

Functions

static void process_class (const OksClass *c, bool verbose)
int main (int argc, char **argv)

Typedef Documentation

◆ ObjsSet

typedef std::set<const OksObject*, SortObjById> ObjsSet

Definition at line 40 of file oks_report_equal_objects.cxx.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 131 of file oks_report_equal_objects.cxx.

132{
133 std::vector<std::string> files;
134 std::string class_name;
135 bool verbose(false);
136
137 try {
138 po::options_description desc("This program is loading OKS data files and searching for equal object.\nUsage: "
139 "oks_report_equal_objects [options] [-f] file+ ");
140
141 desc.add_options()(
142 "class,c", po::value<std::string>(&class_name), "If defined, only compare objects of this class")(
143 "files,f", po::value<std::vector<std::string>>(&files), "Names of input OKS files")(
144 "verbose,v", "Run in verbose mode")("help,h", "Print help message");
145
146 po::positional_options_description p;
147 p.add("files", -1);
148
149 po::variables_map vm;
150 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
151 po::notify(vm);
152
153 if (vm.count("help")) {
154 std::cout << desc << std::endl;
155 return EXIT_SUCCESS;
156 }
157 if (vm.count("verbose")) {
158 verbose = true;
159 }
160
161 if (files.empty()) {
162 throw std::runtime_error("Missing application name");
163 }
164 } catch (std::exception& ex) {
165 std::cerr << "ERROR: " << ex.what() << std::endl;
166 return EXIT_FAILURE;
167 }
168
169 try {
170 OksKernel kernel;
172 kernel.set_silence_mode(!verbose);
173
174 for (std::vector<std::string>::const_iterator i = files.begin(); i != files.end(); ++i) {
175 kernel.load_file(*i);
176 }
177
178 if (!class_name.empty()) {
179 if (OksClass* c = kernel.find_class(class_name)) {
180 process_class(c, verbose);
181 return 0;
182 } else {
183 std::cerr << "ERROR: cannot find class \'" << class_name << '\'' << std::endl;
184 return EXIT_FAILURE;
185 }
186 }
187
188 for (OksClass::Map::const_iterator i = kernel.classes().begin(); i != kernel.classes().end(); ++i) {
189 process_class(i->second, verbose);
190 }
191 } catch (oks::exception& ex) {
192 std::cerr << "ERROR: " << ex.what() << std::endl;
193 return EXIT_FAILURE;
194 }
195
196 return 0;
197}
The OKS class.
Definition class.hpp:223
Provides interface to the OKS kernel.
Definition kernel.hpp:615
OksFile * load_file(const std::string &name, bool bind=true)
Load OKS database file.
Definition kernel.cpp:1625
const OksClass::Map & classes() const
Get classes.
Definition kernel.hpp:1711
void set_silence_mode(const bool b)
Set status of silence mode. To switch 'On'/'Off' use the method's parameter:
Definition kernel.hpp:730
void set_test_duplicated_objects_via_inheritance_mode(const bool b)
Set status of test inherited duplicated objects mode. To switch 'On'/'Off' use the method's parameter...
Definition kernel.hpp:782
OksClass * find_class(const std::string &class_name) const
Find class by name (C++ string).
Definition kernel.hpp:1754
static void process_class(const OksClass *c, bool verbose)

◆ process_class()

void process_class ( const OksClass * c,
bool verbose )
static

Definition at line 45 of file oks_report_equal_objects.cxx.

46{
47 bool printed_class(false);
48
49 if (verbose) {
50 std::cout << "* processing class \'" << c->get_name() << "\'" << std::endl;
51 printed_class = true;
52 }
53
54 const OksObject::Map* objects = c->objects();
55 if (!objects || objects->empty()) {
56 if (verbose) {
57 std::cout << " no objects" << std::endl;
58 }
59 return;
60 }
61
62 std::multimap<std::string, const OksObject*> vals;
63
64 const std::list<OksAttribute*>* alist = c->all_attributes();
65 const std::list<OksRelationship*>* rlist = c->all_relationships();
66
67 OksDataInfo di(0, (const OksAttribute*)(0));
68
69 for (OksObject::Map::const_iterator i = objects->begin(); i != objects->end(); ++i) {
70 const OksObject* o(i->second);
71 std::ostringstream s;
72 OksData* d(o->GetAttributeValue(&di));
73
74 if (alist) {
75 for (std::list<OksAttribute*>::const_iterator j = alist->begin(); j != alist->end(); ++j, ++d) {
76 s << (*j)->get_name() << *d << '\n';
77 }
78 }
79
80 if (rlist) {
81 for (std::list<OksRelationship*>::const_iterator j = rlist->begin(); j != rlist->end(); ++j, ++d) {
82 s << (*j)->get_name() << *d << '\n';
83 }
84 }
85
86 s << std::ends;
87
88 vals.insert(std::make_pair(s.str(), o));
89 }
90
91 std::string last;
92 const OksObject* prev(0);
93
94 for (std::multimap<std::string, const OksObject*>::iterator i = vals.begin(); i != vals.end();) {
95 if (last == i->first) {
96 ObjsSet equal_objs;
97 equal_objs.insert(prev);
98 equal_objs.insert(i->second);
99 ++i;
100 for (; i != vals.end(); ++i) {
101 if (last == i->first) {
102 equal_objs.insert(i->second);
103 } else {
104 if (!printed_class) {
105 std::cout << "* found equal objects in class \'" << c->get_name() << "\'" << std::endl;
106 printed_class = true;
107 }
108
109 std::cout << " # the following " << equal_objs.size() << " objects are equal:\n";
110 for (ObjsSet::const_iterator j = equal_objs.begin(); j != equal_objs.end(); ++j) {
111 std::cout << " - " << (*j) << " from \'" << (*j)->get_file()->get_full_file_name() << "\'\n";
112 }
113
114 last = i->first;
115 prev = i->second;
116 ++i;
117 break;
118 }
119 }
120 } else {
121 last = i->first;
122 prev = i->second;
123 ++i;
124 }
125 }
126}
OKS attribute class.
Definition attribute.hpp:94
OksObject describes instance of OksClass.
Definition object.hpp:1144
std::unordered_map< const std::string *, OksObject *, oks::hash_str, oks::equal_str > Map
Definition object.hpp:1170
std::set< const OksObject *, SortObjById > ObjsSet
Struct OKS data information.
Definition object.hpp:379
Struct OKS data.
Definition object.hpp:510