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
18#include <iostream>
19#include <sstream>
20
21#include <set>
22#include <map>
23
24#include <boost/program_options.hpp>
25
26#include "oks/kernel.hpp"
27#include "oks/class.hpp"
28#include "oks/object.hpp"
29#include "oks/attribute.hpp"
30#include "oks/relationship.hpp"
31
32using namespace dunedaq;
33using namespace dunedaq::oks;
35
37 bool operator() (const OksObject * o1, const OksObject * o2) const {
38 return o1->GetId() < o2->GetId();
39 }
40};
41
42typedef std::set<const OksObject *, SortObjById> ObjsSet;
43
45
46
47static void process_class(const OksClass *c, bool verbose)
48{
49 bool printed_class(false);
50
51 if(verbose) {
52 std::cout << "* processing class \'" << c->get_name() << "\'" << std::endl;
53 printed_class = true;
54 }
55
56 const OksObject::Map * objects = c->objects();
57 if(!objects || objects->empty()) {
58 if(verbose) {
59 std::cout << " no objects" << std::endl;
60 }
61 return;
62 }
63
64 std::multimap<std::string, const OksObject *> vals;
65
66 const std::list<OksAttribute *> * alist = c->all_attributes();
67 const std::list<OksRelationship *> * rlist = c->all_relationships();
68
69 OksDataInfo di(0, (const OksAttribute *)(0));
70
71 for(OksObject::Map::const_iterator i = objects->begin(); i != objects->end(); ++i) {
72 const OksObject * o(i->second);
73 std::ostringstream s;
74 OksData * d(o->GetAttributeValue(&di));
75
76 if(alist) {
77 for(std::list<OksAttribute *>::const_iterator j = alist->begin(); j != alist->end(); ++j, ++d) {
78 s << (*j)->get_name() << *d << '\n';
79 }
80 }
81
82 if(rlist) {
83 for(std::list<OksRelationship *>::const_iterator j = rlist->begin(); j != rlist->end(); ++j, ++d) {
84 s << (*j)->get_name() << *d << '\n';
85 }
86 }
87
88 s << std::ends;
89
90 vals.insert(std::make_pair(s.str(), o));
91 }
92
93 std::string last;
94 const OksObject * prev(0);
95
96 for(std::multimap<std::string, const OksObject *>::iterator i = vals.begin(); i != vals.end(); ) {
97 if(last == i->first) {
98 ObjsSet equal_objs;
99 equal_objs.insert(prev);
100 equal_objs.insert(i->second);
101 ++i;
102 for(; i != vals.end(); ++i) {
103 if(last == i->first) {
104 equal_objs.insert(i->second);
105 }
106 else {
107 if(!printed_class) {
108 std::cout << "* found equal objects in class \'" << c->get_name() << "\'" << std::endl;
109 printed_class = true;
110 }
111
112 std::cout << " # the following " << equal_objs.size() << " objects are equal:\n";
113 for(ObjsSet::const_iterator j = equal_objs.begin(); j != equal_objs.end(); ++j) {
114 std::cout << " - " << (*j) << " from \'" << (*j)->get_file()->get_full_file_name() << "\'\n";
115 }
116
117 last = i->first;
118 prev = i->second;
119 ++i;
120 break;
121 }
122 }
123 }
124 else {
125 last = i->first;
126 prev = i->second;
127 ++i;
128 }
129 }
130}
131
132
133
134namespace po = boost::program_options;
135
136int
137main(int argc, char **argv)
138{
139 std::vector<std::string> files;
140 std::string class_name;
141 bool verbose(false);
142
143 try {
144 po::options_description desc("This program is loading OKS data files and searching for equal object.\nUsage: oks_report_equal_objects [options] [-f] file+ ");
145
146 desc.add_options()
147 ("class,c" , po::value<std::string>(&class_name) , "If defined, only compare objects of this class")
148 ("files,f" , po::value<std::vector<std::string> >(&files) , "Names of input OKS files")
149 ("verbose,v" , "Run in verbose mode")
150 ("help,h" , "Print help message")
151 ;
152
153 po::positional_options_description p;
154 p.add("files", -1);
155
156 po::variables_map vm;
157 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
158 po::notify(vm);
159
160 if(vm.count("help")) { std::cout << desc << std::endl; return EXIT_SUCCESS; }
161 if(vm.count("verbose")) { verbose = true; }
162
163 if(files.empty()) { throw std::runtime_error("Missing application name" ); }
164 }
165 catch(std::exception& ex) {
166 std::cerr << "ERROR: " << ex.what() << std::endl;
167 return EXIT_FAILURE;
168 }
169
170 try {
171 OksKernel kernel;
173 kernel.set_silence_mode(!verbose);
174
175 for(std::vector<std::string>::const_iterator i = files.begin(); i != files.end(); ++i) {
176 kernel.load_file(*i);
177 }
178
179 if(!class_name.empty()) {
180 if(OksClass * c = kernel.find_class(class_name)) {
181 process_class(c, verbose);
182 return 0;
183 }
184 else {
185 std::cerr << "ERROR: cannot find class \'" << class_name << '\'' << std::endl;
186 return EXIT_FAILURE;
187 }
188 }
189
190 for(OksClass::Map::const_iterator i = kernel.classes().begin(); i != kernel.classes().end(); ++i) {
191 process_class(i->second, verbose);
192 }
193 }
194 catch(oks::exception& ex) {
195 std::cerr << "ERROR: " << ex.what() << std::endl;
196 return EXIT_FAILURE;
197 }
198
199 return 0;
200}
OKS attribute class.
The OKS class.
Definition class.hpp:205
Provides interface to the OKS kernel.
Definition kernel.hpp:582
OksFile * load_file(const std::string &name, bool bind=true)
Load OKS database file.
Definition kernel.cpp:1793
const OksClass::Map & classes() const
Get classes.
Definition kernel.hpp:1772
void set_silence_mode(const bool b)
Set status of silence mode. To switch 'On'/'Off' use the method's parameter:
Definition kernel.hpp:703
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:761
OksClass * find_class(const std::string &class_name) const
Find class by name (C++ string).
Definition kernel.hpp:1819
OksObject describes instance of OksClass.
Definition object.hpp:841
std::unordered_map< const std::string *, OksObject *, oks::hash_str, oks::equal_str > Map
Definition object.hpp:870
const std::string & GetId() const
Definition object.hpp:1000
OksData * GetAttributeValue(const std::string &name) const
Get value of attribute by name.
Definition object.cpp:1924
static volatile sig_atomic_t run
Including Qt Headers.
Definition module.cpp:16
int main(int argc, char **argv)
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:347
the structure to pass common parameters to various read() methods of OksData and OksObject class
Definition object.hpp:454