DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
oks_report_equal_objects.cxx
Go to the documentation of this file.
1//
2// DUNE DAQ modification notice:
3// This file has been modified from the original ATLAS oks_utils source for the DUNE DAQ project.
4// Fork baseline commit: c2e7dfc7 (2022-03-30).
5// Renamed since fork: yes (from src/bin/oks_report_equal_objects.cpp to apps/oks_report_equal_objects.cxx).
6//
7
16
17#include <iostream>
18#include <sstream>
19
20#include <map>
21#include <set>
22
23#include <boost/program_options.hpp>
24
25#include "oks/attribute.hpp"
26#include "oks/class.hpp"
27#include "oks/kernel.hpp"
28#include "oks/object.hpp"
29#include "oks/relationship.hpp"
30
31using namespace dunedaq;
32using namespace dunedaq::oks;
34
36{
37 bool operator()(const OksObject* o1, const OksObject* o2) const { return o1->GetId() < o2->GetId(); }
38};
39
40typedef std::set<const OksObject*, SortObjById> ObjsSet;
41
43
44static void
45process_class(const OksClass* c, bool verbose)
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}
127
128namespace po = boost::program_options;
129
130int
131main(int argc, char** argv)
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}
OKS attribute class.
Definition attribute.hpp:94
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
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
const std::string & GetId() const
Definition object.hpp:1290
OksData * GetAttributeValue(const std::string &name) const
Get value of attribute by name.
Definition object.cpp:1852
int main(int argc, char *argv[])
The DUNE-DAQ namespace.
static void process_class(const OksClass *c, bool verbose)
std::set< const OksObject *, SortObjById > ObjsSet
bool operator()(const OksObject *o1, const OksObject *o2) const
Struct OKS data information.
Definition object.hpp:379
Struct OKS data.
Definition object.hpp:510