diff --git a/DDCore/src/InstanceCount.cpp b/DDCore/src/InstanceCount.cpp index 3436585807ba5f9e9e7587fbd13495b4e882e99c..4c53afb8d9aef0d52db7b527d00af2f0e49c0a5e 100644 --- a/DDCore/src/InstanceCount.cpp +++ b/DDCore/src/InstanceCount.cpp @@ -129,7 +129,7 @@ void InstanceCount::decrement(const std::type_info& typ) { on_exit_destructors(); } -/// Force dump of counters +/// Force dump of counter void InstanceCount::dump(int typ) { bool need_footer = false; if ((typ & STRING) && s_strCounts.get()) { @@ -139,12 +139,21 @@ void InstanceCount::dump(int typ) { cout << "+----------+---------+---------+-------------------------------------------+" << endl; cout << "| Total | Max | Leaking | Type identifier |" << endl; cout << "+----------+---------+---------+-------------------------------------------+" << endl; + long tot_instances=0, max_instances=0, now_instances=0; for ( const auto& i : *s_strCounts ) { cout << "|" << setw(10) << i.second->total() - << "|" << setw(9) << i.second->maximum() - << "|" << setw(9) << i.second->value() + << "|" << setw(9) << i.second->maximum() + << "|" << setw(9) << i.second->value() << "|" << i.first->substr(0,80) << endl; + tot_instances += i.second->total(); + max_instances += i.second->maximum(); + now_instances += i.second->value(); } + cout << "+----------+---------+---------+-------------------------------------------+" << endl; + cout << "|" << setw(10) << tot_instances + << "|" << setw(9) << max_instances + << "|" << setw(9) << now_instances + << "|" << "Grand total (Sum of all counters)" << endl; need_footer = true; } } @@ -155,14 +164,23 @@ void InstanceCount::dump(int typ) { cout << "+----------+---------+---------+-------------------------------------------+" << endl; cout << "| Total | Max | Leaking | Type identifier |" << endl; cout << "+----------+---------+---------+-------------------------------------------+" << endl; + long tot_instances=0, max_instances=0, now_instances=0; for ( const auto& i : *s_typCounts ) { string nam = typeName(*(i.first)); if ( nam.length() > 80 ) nam = nam.substr(0,80)+" ..."; cout << "|" << setw(10) << i.second->total() - << "|" << setw(9) << i.second->maximum() - << "|" << setw(9) << i.second->value() + << "|" << setw(9) << i.second->maximum() + << "|" << setw(9) << i.second->value() << "|" << nam << endl; + tot_instances += i.second->total(); + max_instances += i.second->maximum(); + now_instances += i.second->value(); } + cout << "+----------+---------+---------+-------------------------------------------+" << endl; + cout << "|" << setw(10) << tot_instances + << "|" << setw(9) << max_instances + << "|" << setw(9) << now_instances + << "|" << "Grand total (Sum of all counters)" << endl; need_footer = true; } } diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp index 2d361546d12b390c6900f055816e4d8a96c9fc83..f6103b1e1e8d52672f346e0e242104446c5fc646 100644 --- a/DDCore/src/VolumeManager.cpp +++ b/DDCore/src/VolumeManager.cpp @@ -247,14 +247,17 @@ namespace DD4hep { for (size_t i = nodes.size(); i > 1; --i) { // Omit the placement of the parent DetElement TGeoMatrix* m = nodes[i-1]->GetMatrix(); context->toWorld.MultiplyLeft(m); + //::printf("Element [%d]: ",int(i)); m->Print(); } // context->volID = ids; // context->path = nodes; context->toDetector = context->toWorld; context->toDetector.MultiplyLeft(nodes[0]->GetMatrix()); - context->toWorld.MultiplyLeft(&parent.nominal().worldTransformation()); + //context->toWorld.MultiplyLeft(&parent.nominal().worldTransformation()); + context->toWorld.MultiplyLeft(&e.nominal().worldTransformation()); if ( !section.adoptPlacement(context) || m_debug ) { print_node(sd, parent, e, n, code, nodes); + //context->toWorld.Print(); } m_entries.insert(code.first); diff --git a/DDCore/src/plugins/VolumeMgrTest.cpp b/DDCore/src/plugins/VolumeMgrTest.cpp index 3b11aaa3f9629954d2bf5ec5c0ad8462d1c09cf9..0619c70747a01f0f2584555d43e7bfa51c612415 100644 --- a/DDCore/src/plugins/VolumeMgrTest.cpp +++ b/DDCore/src/plugins/VolumeMgrTest.cpp @@ -18,6 +18,7 @@ #include "DD4hep/IDDescriptor.h" #include "DD4hep/VolumeManager.h" #include "DD4hep/DetectorTools.h" +#include "DD4hep/MatrixHelpers.h" #include "DD4hep/objects/VolumeManagerInterna.h" // C/C++ include files @@ -102,7 +103,7 @@ void VolIDTest::checkVolume(DetElement detector, PlacedVolume pv, const VolIDs& VolumeManager::Context* mgr_ctxt = 0; try { - vid = m_iddesc.encode(child_ids); + vid = m_iddesc.encode(child_ids); top_sdet = m_mgr.lookupDetector(vid); det_elem = m_mgr.lookupDetElement(vid); mgr_ctxt = m_mgr.lookupContext(vid); @@ -167,38 +168,66 @@ void VolIDTest::checkVolume(DetElement detector, PlacedVolume pv, const VolIDs& try { if ( pv.volume().isSensitive() ) { TGeoHMatrix trafo; - //for (size_t i = chain.size(); i > 1; --i) { - for (size_t i = 0; i<chain.size(); ++i ) { + for (size_t i = chain.size()-1; i > 0; --i) { + //for (size_t i = 0; i<chain.size(); ++i ) { const TGeoMatrix* mat = chain[i]->GetMatrix(); trafo.MultiplyLeft(mat); } + for (size_t i = chain.size(); i > 0; --i) { + const TGeoMatrix* mat = chain[i-1]->GetMatrix(); + ::printf("Placement [%d] VolID:%s\t\t",int(i),chain[i-1].volIDs().str().c_str()); + mat->Print(); + } + ::printf("Computed Trafo (from placements):\t\t"); + trafo.Print(); + det_elem = m_mgr.lookupDetElement(vid); + ::printf("DetElement Trafo: %s [%s]\t\t", + det_elem.path().c_str(),volumeID(det_elem.volumeID()).c_str()); + det_elem.nominal().worldTransformation().Print(); + ::printf("VolumeMgr Trafo: %s [%s]\t\t",det_elem.path().c_str(),volumeID(vid).c_str()); + m_mgr.worldTransformation(vid).Print(); + if ( 0 == mgr_ctxt ) { + printout(ERROR,m_det.name(),"VOLUME_MANAGER FAILED: Could not find entry for vid:%s.", + volumeID(vid).c_str()); + } if ( pv.ptr() == det_elem.placement().ptr() ) { - for (size_t i = chain.size(); i > 0; --i) { - const TGeoMatrix* mat = chain[i-1]->GetMatrix(); - ::printf("Placement [%d] VolID:%s\t\t",int(i),chain[i-1].volIDs().str().c_str()); - mat->Print(); + // The computed transformation 'trafo' MUST be equal to: + // m_mgr.worldTransformation(vid) AND det_elem.nominal().worldTransformation() + int res1 = _matrixEqual(trafo, det_elem.nominal().worldTransformation()); + int res2 = _matrixEqual(trafo, m_mgr.worldTransformation(vid)); + if ( res1 != MATRICES_EQUAL || res2 != MATRICES_EQUAL ) { + printout(ERROR,m_det.name(),"DETELEMENT_PLACEMENT FAILED: World transformation DIFFER."); } - ::printf("Computed Trafo (from placements):\t\t"); - trafo.Print(); - det_elem = m_mgr.lookupDetElement(vid); - ::printf("DetElement Trafo: %s [%s]\t\t", - det_elem.path().c_str(),volumeID(det_elem.volumeID()).c_str()); - det_elem.nominal().worldTransformation().Print(); - ::printf("VolumeMgr Trafo: %s \t\t",det_elem.path().c_str()); - m_mgr.worldTransformation(vid).Print(); - int ii=1; - DetElement par = det_elem; - while( (par.isValid()) ) { - const TGeoMatrix* mat = par.placement()->GetMatrix(); - ::printf("Element placement [%d] VolID:%s %s\t\t",int(ii), - par.placement().volIDs().str().c_str(), par.path().c_str()); - mat->Print(); - par = par.parent(); - ++ii; + else { + printout(ERROR,m_det.name(),"DETELEMENT_PLACEMENT: PASSED. All matrices equal: %s", + volumeID(vid).c_str()); } } else { + // The computed transformation 'trafo' MUST be equal to: + // m_mgr.worldTransformation(vid) + // The det_elem.nominal().worldTransformation() however is DIFFERENT! + int res2 = _matrixEqual(trafo, m_mgr.worldTransformation(vid)); + if ( res2 != MATRICES_EQUAL ) { + printout(ERROR,m_det.name(),"VOLUME_PLACEMENT FAILED: World transformation DIFFER."); + } + else { + printout(ERROR,m_det.name(),"VOLUME_PLACEMENT: PASSED. All matrices equal: %s", + volumeID(vid).c_str()); + } } +#if 0 + int ii=1; + DetElement par = det_elem; + while( (par.isValid()) ) { + const TGeoMatrix* mat = par.placement()->GetMatrix(); + ::printf("Element placement [%d] VolID:%s %s\t\t",int(ii), + par.placement().volIDs().str().c_str(), par.path().c_str()); + mat->Print(); + par = par.parent(); + ++ii; + } +#endif } } catch(const exception& ex) { @@ -229,8 +258,8 @@ void VolIDTest::walkVolume(DetElement detector, PlacedVolume pv, VolIDs ids, con child_ids.insert(child_ids.end(), place.volIDs().begin(), place.volIDs().end()); //bool is_sensitive = place.volume().isSensitive(); //if ( is_sensitive || !child_ids.empty() ) { - checkVolume(detector, place, child_ids, child_chain); - //} + checkVolume(detector, place, child_ids, child_chain); + //} walkVolume(detector, place, child_ids, child_chain, depth+1, mx_depth); } } @@ -249,8 +278,8 @@ void VolIDTest::walk(DetElement detector, VolIDs ids, const Chain& chain, size_t child_chain.push_back(pv); child_ids.insert(child_ids.end(), pv.volIDs().begin(), pv.volIDs().end()); //if ( is_sensitive ) { - checkVolume(detector, pv, child_ids, child_chain); - //} + checkVolume(detector, pv, child_ids, child_chain); + //} walkVolume(detector, pv, child_ids, child_chain, depth+1, mx_depth); } } diff --git a/examples/ClientTests/CMakeLists.txt b/examples/ClientTests/CMakeLists.txt index 11ef904ea0131b3ddf5b54aa1410308443824f4b..1e9055b0e24c20314f2c36b7431650a4c15b32da 100644 --- a/examples/ClientTests/CMakeLists.txt +++ b/examples/ClientTests/CMakeLists.txt @@ -41,7 +41,9 @@ dd4hep_add_test_reg( ClientTests_MultiPlace -input file:${CMAKE_CURRENT_SOURCE_DIR}/compact/SiBarrelMultiSensitiveLongVolID.xml -volmgr -destroy -plugin DD4hepVolumeMgrTest SiTrackerBarrel - REGEX_PASS "Volume:component1_1 IDDesc:OK \\[S\\] vid:00200668000000ff system:00ff barrel:0000 layer:0001 module:0033 sensor:0001") + REGEX_PASS "Volume:component1_1 IDDesc:OK \\[S\\] vid:00200668000000ff system:00ff barrel:0000 layer:0001 module:0033 sensor:0001" + REGEX_FAIL "FAILED: World transformation DIFFER" + ) # # Test long volume IDs exceeding 32 bit addressing of the form: <id>system:32,barrel:16:-5....</id> dd4hep_add_test_reg( ClientTests_Bitfield64_LongVoldID @@ -50,7 +52,9 @@ dd4hep_add_test_reg( ClientTests_Bitfield64_LongVoldID -input file:${CMAKE_CURRENT_SOURCE_DIR}/compact/SiBarrelMultiSensitiveLongVolID.xml -volmgr -destroy -plugin DD4hepVolumeMgrTest SiTrackerBarrel - REGEX_PASS "Volume:component1_1 IDDesc:OK \\[S\\] vid:00200668000000ff system:00ff barrel:0000 layer:0001 module:0033 sensor:0001") + REGEX_PASS "Volume:component1_1 IDDesc:OK \\[S\\] vid:00200668000000ff system:00ff barrel:0000 layer:0001 module:0033 sensor:0001" + REGEX_FAIL "FAILED: World transformation DIFFER" + ) # # Test readout strings of the form: <id>system:8,barrel:-2</id> dd4hep_add_test_reg( ClientTests_Bitfield64_BarrelSides