Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JROOT::JRootComparator Class Reference

ROOT comparator. More...

#include <JRootComparator.hh>

Inheritance diagram for JROOT::JRootComparator:
std::map< std::string, std::shared_ptr< JAbstractComparator > >

Public Member Functions

 JRootComparator ()
 Default constructor.
 
template<class T >
bool operator() (const T &first, const T &second) const
 Compare objects.
 
template<class T >
void operator() (const JType< T > &type)
 Addition of class.
 

Public Attributes

int debug = 0
 debug level
 

Protected Member Functions

bool compare (const JRootWritableClass &first, const JRootWritableClass &second) const
 Compare objects.
 

Detailed Description

ROOT comparator.

Definition at line 80 of file JRootComparator.hh.

Constructor & Destructor Documentation

◆ JRootComparator()

JROOT::JRootComparator::JRootComparator ( )
inline

Default constructor.

Definition at line 87 of file JRootComparator.hh.

88 {
89 using namespace JPP;
90
91 for_each<JRemove<JPrimitiveTypes_t, long double>::typelist>(*this);
92
93 (*this)(JType<std::string>());
94 (*this)(JType<std::size_t>());
95
96#define VALUE_TYPE(__TYPE__) value_type(#__TYPE__, new JObjectComparator<__TYPE__>())
97
98 this->insert(VALUE_TYPE(Char_t));
99 this->insert(VALUE_TYPE(UChar_t));
100 this->insert(VALUE_TYPE(Short_t));
101 this->insert(VALUE_TYPE(UShort_t));
102 this->insert(VALUE_TYPE(Int_t));
103 this->insert(VALUE_TYPE(UInt_t));
104 this->insert(VALUE_TYPE(Long_t));
105 this->insert(VALUE_TYPE(ULong_t));
106 this->insert(VALUE_TYPE(Long64_t));
107 this->insert(VALUE_TYPE(ULong64_t));
108 this->insert(VALUE_TYPE(Float_t));
109 this->insert(VALUE_TYPE(Double_t));
110 this->insert(VALUE_TYPE(TString));
111
112#undef VALUE_TYPE
113 }
#define VALUE_TYPE(__TYPE__)
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for a type holder.
Definition JType.hh:19

Member Function Documentation

◆ operator()() [1/2]

template<class T >
bool JROOT::JRootComparator::operator() ( const T & first,
const T & second ) const
inline

Compare objects.

Parameters
firstfirst object
secondsecond object
Returns
true if objects are equal; else false

Definition at line 124 of file JRootComparator.hh.

125 {
126 using namespace std;
127
128 DEBUG("compare: " << JRootWritableClass(first).getTypename() << ' ' << JRootWritableClass(second).getTypename() << endl << endl);
129
130 return this->compare(JRootWritableClass(first), JRootWritableClass(second));
131 }
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
bool compare(const JRootWritableClass &first, const JRootWritableClass &second) const
Compare objects.

◆ operator()() [2/2]

template<class T >
void JROOT::JRootComparator::operator() ( const JType< T > & type)
inline

Addition of class.

Parameters
typedata type

Definition at line 140 of file JRootComparator.hh.

141 {
142 this->insert(value_type(JRoot::getTypename<T>(), new JObjectComparator<T>()));
143 }
static const char * getTypename()
Get ROOT typename for given template class.
Definition JRoot.hh:138

◆ compare()

bool JROOT::JRootComparator::compare ( const JRootWritableClass & first,
const JRootWritableClass & second ) const
inlineprotected

Compare objects.

Parameters
firstfirst object
secondsecond object
Returns
true if objects are equal; else false

Definition at line 156 of file JRootComparator.hh.

157 {
158 using namespace std;
159
160 if (first .is_valid() &&
161 second.is_valid()) {
162
163 const_iterator i1 = this->find(first .getTypename());
164 const_iterator i2 = this->find(second.getTypename());
165
166 if (i1 != this->end() &&
167 i2 != this->end() &&
168 i1 == i2) {
169
170 if (!i1->second->equals(first.getAddress(), second.getAddress())) {
171 return false;
172 }
173
174 } else if (first .getClass() != NULL &&
175 second.getClass() != NULL) {
176
177 if (first .getClass()->GetCollectionType() != ROOT::ESTLType::kNotSTL && first .getClass()->GetCollectionProxy() != NULL &&
178 second.getClass()->GetCollectionType() != ROOT::ESTLType::kNotSTL && second.getClass()->GetCollectionProxy() != NULL) {
179
180 std::unique_ptr<TVirtualCollectionProxy> p1(first .getClass()->GetCollectionProxy()->Generate());
181 std::unique_ptr<TVirtualCollectionProxy> p2(second.getClass()->GetCollectionProxy()->Generate());
182
183 p1->PushProxy(const_cast<char*>(first .getAddress()));
184 p2->PushProxy(const_cast<char*>(second.getAddress()));
185
186 TDictionary* d1 = TDictionary::GetDictionary(p1->GetType() == EDataType::kNoType_t ? p1->GetValueClass()->GetName() : TDataType::GetTypeName(p1->GetType()));
187 TDictionary* d2 = TDictionary::GetDictionary(p2->GetType() == EDataType::kNoType_t ? p2->GetValueClass()->GetName() : TDataType::GetTypeName(p2->GetType()));
188
189 DEBUG("proxy: " << p1->GetCollectionClass()->GetName() << " " << d1->GetName() << "(" << p1->Size() << ");" << endl);
190 DEBUG("proxy: " << p2->GetCollectionClass()->GetName() << " " << d2->GetName() << "(" << p2->Size() << ");" << endl);
191
192 if (p1->Size() != p2->Size()) {
193 return false;
194 }
195
196 for (UInt_t i = 0; (i != p1->Size() &&
197 i != p2->Size()); ++i) {
198
199 DEBUG("index: " << d1->GetName() << "[" << i << "] " << endl);
200 //DEBUG("index: " << d2->GetName() << "[" << i << "] " << endl);
201
202 const JRootWritableClass w1(d1, (char*) p1->At(i));
203 const JRootWritableClass w2(d2, (char*) p2->At(i));
204
205 if (!this->compare(w1, w2)) {
206 return false;
207 }
208 }
209
210 } else {
211
212 if (first .getClass()->GetListOfBases() != NULL &&
213 second.getClass()->GetListOfBases() != NULL) {
214
215 std::unique_ptr<TIterator> i1(first .getClass()->GetListOfBases()->MakeIterator());
216 std::unique_ptr<TIterator> i2(second.getClass()->GetListOfBases()->MakeIterator());
217
218 for (const TBaseClass *p1, *p2; ((p1 = (const TBaseClass*) i1->Next()) != NULL &&
219 (p2 = (const TBaseClass*) i2->Next()) != NULL); ) {
220
221 if (JRoot::is_class(p1->GetName()) &&
222 JRoot::is_class(p2->GetName())) {
223
224 DEBUG("base: " << p1->GetName() << endl);
225 //DEBUG("base: " << p2->GetName() << endl);
226
227 if (!this->compare(first.get(*p1), second.get(*p2))) {
228 return false;
229 }
230 }
231 }
232 }
233
234 if (first .getClass()->GetListOfDataMembers() != NULL &&
235 second.getClass()->GetListOfDataMembers() != NULL) {
236
237 std::unique_ptr<TIterator> i1(first .getClass()->GetListOfDataMembers()->MakeIterator());
238 std::unique_ptr<TIterator> i2(second.getClass()->GetListOfDataMembers()->MakeIterator());
239
240 for (const TDataMember *p1, *p2; ((p1 = (const TDataMember*) i1->Next()) != NULL &&
241 (p2 = (const TDataMember*) i2->Next()) != NULL); ) {
242
243
244 if (JRoot::is_class(p1->GetName()) &&
245 JRoot::is_class(p2->GetName())) {
246
247 DEBUG("member: " << p1->GetTrueTypeName() << " " << p1->GetName() << ";" << endl);
248 //DEBUG("member: " << p2->GetTrueTypeName() << " " << p2->GetName() << ";" << endl);
249
250 if (!this->compare(first.get(*p1), second.get(*p2))) {
251 return false;
252 }
253 }
254 }
255 }
256 }
257 }
258 }
259
260 return true;
261 }
TPaveText * p1
bool is_valid(const json &js)
Check validity of JSon data.
static bool is_class(const char *const name)
Check name of class against internal ROOT class names.
Definition JRoot.hh:30

Member Data Documentation

◆ debug

int JROOT::JRootComparator::debug = 0

debug level

Definition at line 146 of file JRootComparator.hh.


The documentation for this class was generated from the following file: