DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
oks_report_equal_objects.cxx File Reference
#include <iostream>
#include <sstream>
#include <set>
#include <map>
#include <boost/program_options.hpp>
#include "oks/kernel.hpp"
#include "oks/class.hpp"
#include "oks/object.hpp"
#include "oks/attribute.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 *, SortObjByIdObjsSet
 

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 35 of file oks_report_equal_objects.cxx.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 130 of file oks_report_equal_objects.cxx.

131{
132 std::vector<std::string> files;
133 std::string class_name;
134 bool verbose(false);
135
136 try {
137 po::options_description desc("This program is loading OKS data files and searching for equal object.\nUsage: oks_report_equal_objects [options] [-f] file+ ");
138
139 desc.add_options()
140 ("class,c" , po::value<std::string>(&class_name) , "If defined, only compare objects of this class")
141 ("files,f" , po::value<std::vector<std::string> >(&files) , "Names of input OKS files")
142 ("verbose,v" , "Run in verbose mode")
143 ("help,h" , "Print help message")
144 ;
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")) { std::cout << desc << std::endl; return EXIT_SUCCESS; }
154 if(vm.count("verbose")) { verbose = true; }
155
156 if(files.empty()) { throw std::runtime_error("Missing application name" ); }
157 }
158 catch(std::exception& ex) {
159 std::cerr << "ERROR: " << ex.what() << std::endl;
160 return EXIT_FAILURE;
161 }
162
163 try {
164 OksKernel kernel;
166 kernel.set_silence_mode(!verbose);
167
168 for(std::vector<std::string>::const_iterator i = files.begin(); i != files.end(); ++i) {
169 kernel.load_file(*i);
170 }
171
172 if(!class_name.empty()) {
173 if(OksClass * c = kernel.find_class(class_name)) {
174 process_class(c, verbose);
175 return 0;
176 }
177 else {
178 std::cerr << "ERROR: cannot find class \'" << class_name << '\'' << std::endl;
179 return EXIT_FAILURE;
180 }
181 }
182
183 for(OksClass::Map::const_iterator i = kernel.classes().begin(); i != kernel.classes().end(); ++i) {
184 process_class(i->second, verbose);
185 }
186 }
187 catch(oks::exception& ex) {
188 std::cerr << "ERROR: " << ex.what() << std::endl;
189 return EXIT_FAILURE;
190 }
191
192 return 0;
193}
The OKS class.
Definition class.hpp:200
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
void set_silence_mode(const bool b)
Set status of silence mode. To switch 'On'/'Off' use the method's parameter:
Definition kernel.hpp:698
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:756
OksClass * find_class(const std::string &class_name) const
Find class by name (C++ string).
Definition kernel.hpp:1814
static volatile sig_atomic_t run
static void process_class(const OksClass *c, bool verbose)

◆ process_class()

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

Definition at line 40 of file oks_report_equal_objects.cxx.

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