00001 #include "DetectorDescription/RegressionTest/interface/DDCompareTools.h"
00002 #include "DetectorDescription/Core/interface/DDSolidShapes.h"
00003
00004 DDCompareEPV::DDCompareEPV() : ddco_() { }
00005
00006 DDCompareEPV::DDCompareEPV(const DDCompOptions& ddco) : ddco_(ddco) { }
00007
00008 bool DDCompareEPV::operator()(DDExpandedView& lhs, DDExpandedView& rhs) const {
00009 bool ret(true);
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 std::cout <<"*********FIRST BY firstChild, firstChild, nextSibling, nextSibling*********" << std::endl;
00053 std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
00054 << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
00055 << std::endl;
00056 lhs.firstChild();
00057 rhs.firstChild();
00058 std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
00059 << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
00060 << std::endl;
00061 lhs.firstChild();
00062 rhs.firstChild();
00063 std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
00064 << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
00065 << std::endl;
00066 lhs.nextSibling();
00067 rhs.nextSibling();
00068 std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
00069 << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
00070 << std::endl;
00071 lhs.nextSibling();
00072 rhs.nextSibling();
00073 std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
00074 << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
00075 << std::endl;
00076 lhs.parent();
00077 rhs.parent();
00078 std::cout <<"*********THEN BY next, next, next, next*********" << std::endl;
00079 lhs.parent();
00080 rhs.parent();
00081 std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
00082 << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
00083 << std::endl;
00084 lhs.next();
00085 rhs.next();
00086 std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
00087 << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
00088 << std::endl;
00089 lhs.next();
00090 rhs.next();
00091 std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
00092 << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
00093 << std::endl;
00094 std::cout << lhs.depth() << " depth " << rhs.depth() << std::endl;
00095 lhs.next();
00096 rhs.next();
00097 std::cout << lhs.depth() << " depth " << rhs.depth() << std::endl;
00098 std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
00099 << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
00100 << std::endl;
00101 return ret;
00102 }
00103
00104 DDCompareCPV::DDCompareCPV() : ddco_() { }
00105
00106 DDCompareCPV::DDCompareCPV(const DDCompOptions& ddco) : ddco_(ddco) { }
00107
00108 bool DDCompareCPV::operator()(const DDCompactView& lhs, const DDCompactView& rhs) const {
00109 bool ret(true);
00110
00111 const DDCompactView::graph_type & g1 = lhs.graph();
00112 const DDCompactView::graph_type & g2 = rhs.graph();
00113
00114 typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator;
00115 adjl_iterator git1 = g1.begin();
00116 adjl_iterator gend1 = g1.end();
00117 adjl_iterator git2 = g2.begin();
00118 adjl_iterator gend2 = g2.end();
00119
00120
00121
00122 DDCompactView::graph_type::index_type i=0;
00123
00124 while ( git1 != gend1 && git2 != gend2 && ret ) {
00125 const DDLogicalPart & ddLP1 = g1.nodeData(git1);
00126 const DDLogicalPart & ddLP2 = g2.nodeData(git2);
00127 std::cout << ++i << " P " << ddLP1.name() << " " << ddLP2.name() << std::endl;
00128 if ( ! DDCompareLP(ddco_)(ddLP1, ddLP2) ) {
00129 ret = false;
00130 break;
00131 } else if (git1->size() && git2->size() ) {
00132 DDCompactView::graph_type::edge_list::const_iterator cit1 = git1->begin();
00133 DDCompactView::graph_type::edge_list::const_iterator cend1 = git1->end();
00134 DDCompactView::graph_type::edge_list::const_iterator cit2 = git2->begin();
00135 DDCompactView::graph_type::edge_list::const_iterator cend2 = git2->end();
00136
00137 while ( cit1 != cend1 && cit2 != cend2 ) {
00138 const DDLogicalPart & ddcurLP1 = g1.nodeData(cit1->first);
00139 const DDLogicalPart & ddcurLP2 = g2.nodeData(cit2->first);
00140 std::cout << ++i << " c1--> " << g1.edgeData(cit1->second)->copyno_ << " " << ddcurLP1.name().fullname() << std::endl;
00141 std::cout << ++i << " c2--> " << g2.edgeData(cit2->second)->copyno_ << " " << ddcurLP2.name().fullname() << std::endl;
00142 const DDPosData* p1(g1.edgeData(cit1->second));
00143 const DDPosData* p2(g2.edgeData(cit2->second));
00144
00145
00146
00147
00148
00149
00150
00151
00152 if ( p1->copyno_ != p2->copyno_ ||
00153 ! DDCompareLP(ddco_)(ddcurLP1,ddcurLP2) ) {
00154 std::cout << "Failed to match node (fullname:copy_no): 1: "
00155 << ddcurLP1.name().fullname() << ":" << p1->copyno_ << " 2: "
00156 << ddcurLP2.name().fullname() << ":" << p2->copyno_ << std::endl;
00157 ret = false;
00158 break;
00159 } else if ( ! DDCompareDDTrans()(p1->trans_, p2->trans_) ) {
00160 std::cout << "Failed to match translation " << std::endl;
00161
00162
00163
00164
00165
00166
00167 ret = false;
00168 break;
00169 } else if ( ! DDCompareDDRot(ddco_)(p1->rot_, p2->rot_) ) {
00170 std::cout << "Failed to match rotation " << std::endl;
00171 ret = false;
00172 break;
00173 }
00174 ++cit1;
00175 ++cit2;
00176 }
00177 } else if ( git1->size() != git2->size() ) {
00178 ret = false;
00179 std::cout << "DDCompactViews are different because number of children do not match" << std::endl;
00180 std::cout << "graph1 size of edge_list: " << git1->size() << " and graph2 size of edge_list: " << git2->size() << std::endl;
00181 break;
00182 }
00183 ++git1;
00184 ++git2;
00185 }
00186 return ret;
00187 }
00188
00189 DDCompareLP::DDCompareLP() : ddco_() { }
00190
00191 DDCompareLP::DDCompareLP(const DDCompOptions& ddco) : ddco_(ddco) { }
00192
00193 bool DDCompareLP::operator()(const DDLogicalPart& lhs, const DDLogicalPart& rhs) const {
00194 bool ret(true);
00195
00196 if ( lhs.name().fullname() != rhs.name().fullname() ) {
00197 ret = false;
00198 std::cout << "LogicalPart names do not match " << lhs.name().fullname()
00199 << " and " << rhs.name().fullname() << std::endl;
00200 } else if ( ! DDCompareSolid(ddco_)(lhs.solid(), rhs.solid()) ){
00201 ret = false;
00202 std::cout << "LogicalPart Solids do not match " << lhs.name().fullname()
00203 << " and " << rhs.name().fullname() << std::endl;
00204 }
00205 return ret;
00206 }
00207
00208 DDCompareSolid::DDCompareSolid() : ddco_() { }
00209
00210 DDCompareSolid::DDCompareSolid(const DDCompOptions& ddco) : ddco_(ddco) { }
00211
00212 bool DDCompareSolid::operator()(const DDSolid& lhs, const DDSolid& rhs) const {
00213 bool ret(true);
00214 switch ( lhs.shape() ) {
00215 case dd_not_init:
00216 case ddbox:
00217 case ddtubs:
00218 case ddtrap:
00219 case ddcons:
00220 case ddpolycone_rz:
00221 case ddpolyhedra_rz:
00222 case ddpolycone_rrz:
00223 case ddpolyhedra_rrz:
00224 case ddtorus:
00225 case ddpseudotrap:
00226 case ddtrunctubs:
00227 case ddsphere:
00228 case ddorb:
00229 case ddellipticaltube:
00230 case ddellipsoid:
00231 case ddparallelepiped:
00232 case ddshapeless:
00233 {
00234 if ( lhs.name().fullname() != rhs.name().fullname() ) {
00235 ret = false;
00236 std::cout << "Solid names do not match for solid " << lhs.name().fullname() << " and " << rhs.name().fullname() << std::endl;
00237 } else if ( lhs.shape() != rhs.shape() ) {
00238 ret = false;
00239 std::cout << "Shape types do not match for solids " << lhs.name().fullname()
00240 << " and " << rhs.name().fullname()
00241 << " even though their names match " << std::endl;
00242 } else if ( ! DDCompareDBLVEC()(lhs.parameters(), rhs.parameters()) ) {
00243 ret = false;
00244 std::cout << "Parameters do not match for solids " << lhs.name().fullname()
00245 << " and " << rhs.name().fullname()
00246 << " even though their names and shape type match." << std::endl;
00247 std::cout << "size: " << lhs.parameters().size() << " " << rhs.parameters().size() << std::endl;
00248 }
00249 break;
00250 }
00251 case ddunion:
00252 case ddsubtraction:
00253 case ddintersection:
00254 {
00255 if ( ! DDCompareBoolSol(ddco_)(lhs, rhs) ) {
00256 ret = false;
00257 }
00258 break;
00259 }
00260 case ddreflected:
00261 {
00262 DDReflectionSolid rs1(lhs);
00263 DDReflectionSolid rs2(rhs);
00264 if ( ! DDCompareSolid(ddco_)( rs1.unreflected(), rs2.unreflected()) ) {
00265 ret = false;
00266 std::cout << "Unreflected volumes of DDReflections do not match. Reflections are "
00267 << lhs.name().fullname() << " and " << rhs.name().fullname() << std::endl;
00268 }
00269 break;
00270 }
00271 default:
00272 break;
00273 }
00274 return ret;
00275 }
00276
00277 DDCompareDBLVEC::DDCompareDBLVEC() : tol_(0.0004) { }
00278
00279 DDCompareDBLVEC::DDCompareDBLVEC(double tol) : tol_(tol) { }
00280
00281 bool DDCompareDBLVEC::operator() ( const std::vector<double>& lhs, const std::vector<double>& rhs ) const {
00282 bool ret(true);
00283 if ( lhs.size() != rhs.size() ) {
00284 ret = false;
00285 std::cout << "Size of vectors do not match." << std::endl;
00286 } else {
00287 for ( size_t i = 0; i < lhs.size() ; ++i ) {
00288 if ( std::fabs( lhs[i] - rhs[i] ) > tol_ ) {
00289 ret = false;
00290 std::cout << "Vector content at index " << i << " does not match " ;
00291 std::cout << std::setw(12) << std::fixed << std::setprecision(4) << lhs[i] << " != " << rhs[i] << std::endl;
00292 break;
00293 }
00294 }
00295 }
00296 return ret;
00297 }
00298
00299 DDCompareBoolSol::DDCompareBoolSol() : ddco_() { }
00300
00301 DDCompareBoolSol::DDCompareBoolSol(const DDCompOptions& ddco) : ddco_(ddco) { }
00302 bool DDCompareBoolSol::operator() ( const DDBooleanSolid& lhs, const DDBooleanSolid& rhs ) const {
00303 bool ret(true);
00304 if ( lhs.name().fullname() != rhs.name().fullname() ) {
00305 ret = false;
00306 std::cout << "BooleanSolid names do not match ";
00307 } else if ( lhs.shape() != rhs.shape() ) {
00308 ret = false;
00309 std::cout << "BooleanSolid shape types do not match ";
00310 } else if ( ! DDCompareDBLVEC(ddco_.distTol_)(lhs.parameters(), rhs.parameters()) ) {
00311 ret = false;
00312 std::cout << "BooleanSolid parameters do not match ";
00313 } else if ( ! DDCompareSolid(ddco_)(lhs.solidA(), rhs.solidA()) ) {
00314 ret = false;
00315 std::cout << "BooleanSolid SolidA solids do not match ";
00316 } else if ( ! DDCompareSolid(ddco_)(lhs.solidB(), rhs.solidB()) ) {
00317 ret= false;
00318 std::cout << "BooleanSolid SolidB solids do not match ";
00319 } else if ( ! DDCompareDDTrans(ddco_.distTol_)(lhs.translation(), rhs.translation()) ) {
00320 ret = false;
00321 std::cout << "BooleanSolid Translations do not match ";
00322 } else if ( ! DDCompareDDRot(ddco_)(lhs.rotation(), rhs.rotation()) ) {
00323 ret = false;
00324 std::cout << "BooleanSolid Rotations do not match ";
00325 }
00326 if ( ! ret ) {
00327 std::cout << "for boolean solids "
00328 << lhs.name().fullname() << " and "
00329 << rhs.name().fullname() << std::endl;
00330 }
00331 return ret;
00332 }
00333
00334 DDCompareDDTrans::DDCompareDDTrans() : tol_(0.0004) { }
00335
00336 DDCompareDDTrans::DDCompareDDTrans(double tol) : tol_(tol) { }
00337
00338 bool DDCompareDDTrans::operator() ( const DDTranslation& lhs, const DDTranslation& rhs ) const {
00339 bool ret(true);
00340 if ( std::fabs(lhs.x() - rhs.x()) > tol_
00341 || std::fabs(lhs.y() - rhs.y()) > tol_
00342 || std::fabs(lhs.z() - rhs.z()) > tol_ ) {
00343 ret=false;
00344 }
00345 return ret;
00346 }
00347
00348 DDCompareDDRot::DDCompareDDRot( ) : ddco_() { }
00349
00350 DDCompareDDRot::DDCompareDDRot( const DDCompOptions& ddco ) : ddco_(ddco) { }
00351
00352 bool DDCompareDDRot::operator() ( const DDRotation& lhs, const DDRotation& rhs ) const {
00353 bool ret(true);
00354 if ( ddco_.compRotName_ && lhs.name().fullname() != rhs.name().fullname() ) {
00355 ret = false;
00356 std::cout << "DDRotation names do not match "
00357 << lhs.name().fullname() << " and "
00358 << rhs.name().fullname() << std::endl;
00359 } else if ( ! DDCompareDDRotMat()(*lhs.rotation(), *rhs.rotation()) ) {
00360 ret = false;
00361 std::cout << "DDRotationMatrix values do not match "
00362 << lhs.name().fullname() << " and "
00363 << rhs.name().fullname() << std::endl;
00364 }
00365 return ret;
00366 }
00367
00368 DDCompareDDRotMat::DDCompareDDRotMat() : tol_(0.0004) { }
00369
00370 DDCompareDDRotMat::DDCompareDDRotMat(double tol) : tol_(tol) { }
00371
00372 bool DDCompareDDRotMat::operator() ( const DDRotationMatrix& lhs, const DDRotationMatrix& rhs ) const {
00373 bool ret(true);
00374
00375
00376
00377
00378
00379 double dist = Distance(lhs,rhs);
00380 if ( std::fabs(dist) > tol_ ) {
00381 std::cout << "Rotation matrices do not match." << std::endl;
00382 ret = false;
00383 DD3Vector x, y, z;
00384 std::cout << "FIRST" << std::endl;
00385 lhs.GetComponents(x,y,z);
00386 std::cout << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
00387 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
00388 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
00389 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
00390 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
00391 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
00392 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
00393 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
00394 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z() << std::endl;
00395 std::cout << "SECOND" << std::endl;
00396 rhs.GetComponents(x,y,z);
00397 std::cout << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
00398 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
00399 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
00400 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
00401 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
00402 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
00403 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
00404 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
00405 std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z() << std::endl;
00406 }
00407
00408 return ret;
00409 }
00410
00411