Skip to content

Commit

Permalink
Cleanup DD Compact View
Browse files Browse the repository at this point in the history
  • Loading branch information
ianna committed May 23, 2018
1 parent e638a27 commit 5de0710
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 124 deletions.
12 changes: 4 additions & 8 deletions DetectorDescription/Core/interface/DDCompactView.h
Expand Up @@ -81,14 +81,10 @@ Updated: Michael Case [ MEC ] 2010-02-11
these will be accessed via the DDCompactView.
*/
class DDCompactView
{

{
public:

//! type of representation of the compact-view (acyclic directed multigraph)
/** Nodes are instances of DDLogicalPart, edges are pointers to instances of DDPosData */
typedef math::Graph<DDLogicalPart,DDPosData*> graph_type;

using Graph = math::Graph<DDLogicalPart, DDPosData* >;

//! Creates a compact-view
explicit DDCompactView();

Expand All @@ -98,7 +94,7 @@ class DDCompactView
~DDCompactView();

//! Provides read-only access to the data structure of the compact-view.
const graph_type & graph() const;
const Graph & graph() const;

//! returns the DDLogicalPart representing the root of the geometrical hierarchy
const DDLogicalPart & root() const;
Expand Down
14 changes: 7 additions & 7 deletions DetectorDescription/Core/src/DDCheck.cc
Expand Up @@ -45,8 +45,8 @@ bool DDCheckLP( const DDLogicalPart & lp , std::ostream & os )


// checks PosData* if it contains sensfull stuff ...
//:void DDCheckPD(const DDLogicalPart & lp, graph_type::neighbour_type & nb, std::ostream & os)
bool DDCheckPD(const DDLogicalPart & lp, DDCompactView::graph_type::edge_range nb, const DDCompactView::graph_type & g, std::ostream & os)
//:void DDCheckPD(const DDLogicalPart & lp, Graph::neighbour_type & nb, std::ostream & os)
bool DDCheckPD(const DDLogicalPart & lp, DDCompactView::Graph::edge_range nb, const DDCompactView::Graph & g, std::ostream & os)
{
bool result = false;
if (nb.first != nb.second) {
Expand Down Expand Up @@ -90,10 +90,10 @@ bool DDCheckConnect(const DDCompactView & cpv, std::ostream & os)
<< " (multiple-)connected LogicalParts with root=" << cpv.root().ddname() << std::endl;

// Pass 2:
DDCompactView::graph_type & g = const_cast<DDCompactView::graph_type&>(cpv.graph());
DDCompactView::Graph & g = const_cast<DDCompactView::Graph&>(cpv.graph());

int uc = 0;
DDCompactView::graph_type::adj_list::size_type it = 0;
DDCompactView::Graph::adj_list::size_type it = 0;

for(; it < g.size(); ++it) {
if (! visited[g.nodeData(it)] ) {
Expand Down Expand Up @@ -121,13 +121,13 @@ bool DDCheckConnect(const DDCompactView & cpv, std::ostream & os)
bool DDCheckAll(const DDCompactView & cpv, std::ostream & os)
{
bool result = false;
// const_cast because graph_type does not provide const_iterators!
DDCompactView::graph_type & g = const_cast<DDCompactView::graph_type&>(cpv.graph());
// const_cast because Graph does not provide const_iterators!
DDCompactView::Graph & g = const_cast<DDCompactView::Graph&>(cpv.graph());

// basic debuggger
std::map< std::pair<std::string,std::string>, int > lp_names;

DDCompactView::graph_type::adj_list::size_type it = 0;
DDCompactView::Graph::adj_list::size_type it = 0;
for(; it < g.size(); ++it) {
const DDLogicalPart & lp = g.nodeData(it);
lp_names[std::make_pair(lp.name().ns(),lp.name().name())]++;
Expand Down
2 changes: 1 addition & 1 deletion DetectorDescription/Core/src/DDCompactView.cc
Expand Up @@ -56,7 +56,7 @@ DDCompactView::~DDCompactView()
by an instance of class Graph<DDLogicalPart, DDPosData*).
Graph provides methods for navigating its content.
*/
const DDCompactView::graph_type & DDCompactView::graph() const
const DDCompactView::Graph & DDCompactView::graph() const
{
return rep_->graph();
}
Expand Down
12 changes: 7 additions & 5 deletions DetectorDescription/OfflineDBLoader/plugins/OutputDDToDDL.cc
Expand Up @@ -103,7 +103,10 @@ OutputDDToDDL::beginRun( const edm::Run&, edm::EventSetup const& es )
edm::ESTransientHandle<DDCompactView> pDD;
es.get<IdealGeometryRecord>().get( pDD );

DDCompactView::DDCompactView::graph_type gra = pDD->graph();
using Graph = DDCompactView::Graph;
using adjl_iterator = Graph::const_adj_iterator;

const auto& gra = pDD->graph();
// temporary stores:
std::set<DDLogicalPart> lpStore;
std::set<DDMaterial> matStore;
Expand Down Expand Up @@ -133,12 +136,11 @@ OutputDDToDDL::beginRun( const edm::Run&, edm::EventSetup const& es )
std::string ns_ = out.ns_;

(*m_xos) << std::fixed << std::setprecision(18);
typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator;

adjl_iterator git = gra.begin();
adjl_iterator gend = gra.end();

DDCompactView::graph_type::index_type i=0;
Graph::index_type i=0;
(*m_xos) << "<PosPartSection label=\"" << ns_ << "\">" << std::endl;
git = gra.begin();
for( ; git != gend; ++git ) {
Expand All @@ -152,8 +154,8 @@ OutputDDToDDL::beginRun( const edm::Run&, edm::EventSetup const& es )
++i;
if( !git->empty()) {
// ask for children of ddLP
DDCompactView::graph_type::edge_list::const_iterator cit = git->begin();
DDCompactView::graph_type::edge_list::const_iterator cend = git->end();
auto cit = git->begin();
auto cend = git->end();
for( ; cit != cend; ++cit ) {
const DDLogicalPart & ddcurLP = gra.nodeData( cit->first );
if( lpStore.find( ddcurLP ) != lpStore.end()) {
Expand Down
Expand Up @@ -105,7 +105,7 @@ OutputMagneticFieldDDToDDL::beginRun( const edm::Run&, edm::EventSetup const& es
edm::ESTransientHandle<DDCompactView> pDD;
es.get<IdealMagneticFieldRecord>().get( pDD );

DDCompactView::DDCompactView::graph_type gra = pDD->graph();
const auto& gra = pDD->graph();

// Temporary stores:
std::set<DDLogicalPart> lpStore;
Expand Down Expand Up @@ -143,12 +143,13 @@ OutputMagneticFieldDDToDDL::beginRun( const edm::Run&, edm::EventSetup const& es

( *m_xos ) << std::fixed << std::setprecision( 18 );

typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator;
using Graph = DDCompactView::Graph;
using adjl_iterator = Graph::const_adj_iterator;

adjl_iterator git = gra.begin();
adjl_iterator gend = gra.end();

DDCompactView::graph_type::index_type i=0;
Graph::index_type i=0;
( *m_xos) << "<PosPartSection label=\"" << ns_ << "\">\n";
git = gra.begin();
for( ; git != gend; ++git )
Expand All @@ -165,8 +166,8 @@ OutputMagneticFieldDDToDDL::beginRun( const edm::Run&, edm::EventSetup const& es
if( !git->empty())
{
// ask for children of ddLP
DDCompactView::graph_type::edge_list::const_iterator cit = git->begin();
DDCompactView::graph_type::edge_list::const_iterator cend = git->end();
auto cit = git->begin();
auto cend = git->end();
for( ; cit != cend; ++cit )
{
const DDLogicalPart & ddcurLP = gra.nodeData( cit->first );
Expand Down
8 changes: 5 additions & 3 deletions DetectorDescription/OfflineDBLoader/src/GeometryInfoDump.cc
Expand Up @@ -15,6 +15,9 @@
#include <set>
#include <vector>

using Graph = DDCompactView::Graph;
using adjl_iterator = Graph::const_adj_iterator;

GeometryInfoDump::GeometryInfoDump () { }

GeometryInfoDump::~GeometryInfoDump () { }
Expand Down Expand Up @@ -65,12 +68,11 @@ void GeometryInfoDump::dumpInfo ( bool dumpHistory, bool dumpSpecs, bool dumpPos
// final destination of the DDSpecifics
std::string dsname = "dumpSpecs" + fname;
std::ofstream dump(dsname.c_str());
DDCompactView::DDCompactView::graph_type gra = cpv.graph();
const auto& gra = cpv.graph();
std::set<DDLogicalPart> lpStore;
typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator;
adjl_iterator git = gra.begin();
adjl_iterator gend = gra.end();
DDCompactView::graph_type::index_type i=0;
Graph::index_type i=0;
for (; git != gend; ++git)
{
const DDLogicalPart & ddLP = gra.nodeData(git);
Expand Down
11 changes: 6 additions & 5 deletions DetectorDescription/Parser/test/dumpDDCompactView.cpp
Expand Up @@ -23,7 +23,8 @@

int main(int argc, char *argv[])
{
typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator;
using Graph = DDCompactView::Graph;
using adjl_iterator = Graph::const_adj_iterator;

// Copied from example stand-alone program in Message Logger July 18, 2007
std::string const kProgramName = argv[0];
Expand Down Expand Up @@ -92,17 +93,17 @@ int main(int argc, char *argv[])
// cpv.setRoot(DDLogicalPart(DDName("cms:World")));

std::cout << "edge size of produce graph:" << cpv.graph().edge_size() << std::endl;
const DDCompactView::graph_type& gt = cpv.graph();
const auto& gt = cpv.graph();
adjl_iterator git = gt.begin();
adjl_iterator gend = gt.end();

DDCompactView::graph_type::index_type i=0;
Graph::index_type i=0;
for (; git != gend; ++git) {
const DDLogicalPart & ddLP = gt.nodeData(git);
std::cout << ++i << " P " << ddLP.name() << std::endl;
if (!git->empty()) {
DDCompactView::graph_type::edge_list::const_iterator cit = git->begin();
DDCompactView::graph_type::edge_list::const_iterator cend = git->end();
auto cit = git->begin();
auto cend = git->end();
for (; cit != cend; ++cit) {
const DDLogicalPart & ddcurLP = gt.nodeData(cit->first);
std::cout << ++i << " c--> " << gt.edgeData(cit->second)->copyno() << " " << ddcurLP.name() << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion DetectorDescription/Parser/test/dumpDDExpandedView.cpp
Expand Up @@ -70,7 +70,7 @@ int main(int argc, char *argv[])
std::cout << "main::initialize DDL parser\n";

DDCompactView cpv;
DDLParser myP(cpv);// = DDLParser::instance();
DDLParser myP(cpv);

std::cout << "main::about to start parsing main configuration... \n";
FIPConfiguration dp(cpv);
Expand Down
84 changes: 15 additions & 69 deletions DetectorDescription/RegressionTest/src/DDCompareTools.cc
Expand Up @@ -20,48 +20,7 @@ DDCompareEPV::DDCompareEPV(const DDCompOptions& ddco) : ddco_(ddco) { }

bool DDCompareEPV::operator()(DDExpandedView& lhs, DDExpandedView& rhs) const {
bool ret(true);
/* struct DDCompareCPVGraph : public std::binary_function<DDCompactView::graph_type, DDCompactView::graph_type, bool> { */
/* bool operator()(const DDCompactView::graph_type& lhs, const DDCompactView::graph_type& rhs) const { */
/* bool ret; */
// const graph<DDLogicalPart, DDPosData*>& g1= lhs;
// graph<DDLogicalPart, DDPosData*>::const_iterator beg1 = g1.begin();
//DDCompactView::graph_type::const_iterator beg1 = lhs.begin();
/* std::cout << "size of lhs = " << lhs.edge_size() << std::endl; */
/* std::cout << "size of rhs = " << rhs.edge_size() << std::endl; */
/* std::cout << "iterating over lhs edges?" << std::endl; */
/* graph<DDLogicalPart, DDPosData*>::const_iterator beg1(lhs), end1(lhs); */
/* beg1 = lhs.begin_iter(); */
/* end1 = lhs.end_iter(); */
/* size_t countem(0); */
/* for ( ; beg1 != end1 ; ++beg1 ) { */
/* ++countem; */
/* } */
/* std::cout << "between lhs.begin_iter() and lhs.end_iter() there are " << countem << std::endl; */
/* graph<DDLogicalPart,DDPosData*>::const_edge_range cer = lhs.graph().edges(lhs.root()); */
/* graph<DDLogicalPart,DDPosData*>::adj_iterator i = const_edge_range.first */
// DDExpandedView v1(lhs), v2(rhs);
// if (v1.next()) std::cout << "v1 is true" << std::endl;
// if (v2.next()) std::cout << "v2 is true" << std::endl;
// DDNodeComparator ddnc;
//if ( ddnc (v1, v2) ) {
// ret = true;
//}
/* while (v1.next()) { */
/* if (v2.next()) { */
/* std::cout << v1.logicalPart().name().name() << ":" << v1.copyno() */
/* << " !=? " << v2.logicalPart().name().name() << ":" << v2.copyno() */
/* << std::endl; */

/* if ( v1.logicalPart().name().name() != v2.logicalPart().name().name() ) { */
/* std::cout << v1.logicalPart().name().name() << ":" << v1.copyno() */
/* << " !=? " << v2.logicalPart().name().name() << ":" << v2.copyno() */
/* << std::endl; */
/* // std::cout << v1.logicalPart().name().name() << " !=? " << v2.logicalPart().name().name() << std::endl; */
/* ret=false; */
/* break; */
/* } */
/* } */
/* } */

std::cout <<"*********FIRST BY firstChild, firstChild, nextSibling, nextSibling*********" << std::endl;
std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
<< " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
Expand Down Expand Up @@ -121,19 +80,19 @@ DDCompareCPV::DDCompareCPV(const DDCompOptions& ddco) : ddco_(ddco) { }
bool DDCompareCPV::operator()(const DDCompactView& lhs, const DDCompactView& rhs) const {
bool ret(true);

const DDCompactView::graph_type & g1 = lhs.graph();
const DDCompactView::graph_type & g2 = rhs.graph();
const auto & g1 = lhs.graph();
const auto & g2 = rhs.graph();

using Graph = DDCompactView::Graph;
using adjl_iterator = Graph::const_adj_iterator;

typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator;
adjl_iterator git1 = g1.begin();
adjl_iterator gend1 = g1.end();
adjl_iterator git2 = g2.begin();
adjl_iterator gend2 = g2.end();
/* std::cout << "uniqueness test: " << &(*git1) << " != " << &(*git2) */
/* << " and " << &(*gend1) << " != " << &(*gend2) << std::endl; */
// DDCompactView::graph_type::const_iterator bit = g1.begin_iter();
DDCompactView::graph_type::index_type i=0;
// for (; git1 != gend1; ++git1) {

Graph::index_type i=0;

while ( git1 != gend1 && git2 != gend2 && ret ) {
const DDLogicalPart & ddLP1 = g1.nodeData(git1);
const DDLogicalPart & ddLP2 = g2.nodeData(git2);
Expand All @@ -142,26 +101,19 @@ bool DDCompareCPV::operator()(const DDCompactView& lhs, const DDCompactView& rhs
ret = false;
break;
} else if (!git1->empty() && !git2->empty() ) {
DDCompactView::graph_type::edge_list::const_iterator cit1 = git1->begin();
DDCompactView::graph_type::edge_list::const_iterator cend1 = git1->end();
DDCompactView::graph_type::edge_list::const_iterator cit2 = git2->begin();
DDCompactView::graph_type::edge_list::const_iterator cend2 = git2->end();
//for (; cit != cend; ++cit) {
auto cit1 = git1->begin();
auto cend1 = git1->end();
auto cit2 = git2->begin();
auto cend2 = git2->end();

while ( cit1 != cend1 && cit2 != cend2 ) {
const DDLogicalPart & ddcurLP1 = g1.nodeData(cit1->first);
const DDLogicalPart & ddcurLP2 = g2.nodeData(cit2->first);
std::cout << ++i << " c1--> " << g1.edgeData(cit1->second)->copyno() << " " << ddcurLP1.name().fullname() << std::endl;
std::cout << ++i << " c2--> " << g2.edgeData(cit2->second)->copyno() << " " << ddcurLP2.name().fullname() << std::endl;
const DDPosData* p1(g1.edgeData(cit1->second));
const DDPosData* p2(g2.edgeData(cit2->second));
// if ( g1.edgeData(cit1->second)->copyno_ != g2.edgeData(cit2->second)->copyno_
// if ( p1->copyno_ != p2->copyno_
// || ddcurLP1.name().fullname() != ddcurLP2.name().fullname() ) {
// std::cout << "Failed to match node (fullname:copy_no): 1: "
// << ddcurLP1.name().fullname() << ":" << p1->copyno_ << " 2: "
// << ddcurLP2.name().fullname() << ":" << p2->copyno_ << std::endl;
// ret = false;
// break;

if ( p1->copyno() != p2->copyno() ||
! DDCompareLP(ddco_)(ddcurLP1,ddcurLP2) ) {
std::cout << "Failed to match node (fullname:copy_no): 1: "
Expand All @@ -171,12 +123,6 @@ bool DDCompareCPV::operator()(const DDCompactView& lhs, const DDCompactView& rhs
break;
} else if ( ! DDCompareDDTrans()(p1->trans(), p2->trans()) ) {
std::cout << "Failed to match translation " << std::endl;
// std::cout << "1: " << std::setw(12) << std::fixed << std::setprecision(4) << p1->trans_.x();
// std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << p1->trans_.y();
// std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << p1->trans_.z() << std::endl;
// std::cout << "2: " << std::setw(12) << std::fixed << std::setprecision(4) << p2->trans_.x();
// std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << p2->trans_.y();
// std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << p2->trans_.z() << std::endl;
ret = false;
break;
} else if ( ! DDCompareDDRot(ddco_)(p1->ddrot(), p2->ddrot()) ) {
Expand Down
5 changes: 2 additions & 3 deletions DetectorDescription/RegressionTest/src/DDErrorDetection.cc
Expand Up @@ -88,16 +88,15 @@ const std::map<std::string, std::set<DDLogicalPart> > & DDErrorDetection::lp_cpv
static std::map<std::string, std::set<DDLogicalPart> > result_;
if (!result_.empty()) return result_;

// DDCompactView cpv;
const DDCompactView::graph_type & g = cpv.graph();
const auto & g = cpv.graph();

std::map<std::string, std::set<DDLogicalPart> >::const_iterator it(lp_err::instance().begin()),
ed(lp_err::instance().end());
for (; it != ed; ++it) {
std::set<DDLogicalPart>::const_iterator sit(it->second.begin()), sed(it->second.end());
for( ; sit != sed; ++sit) {
const DDLogicalPart & lp = *sit;
DDCompactView::graph_type::const_edge_range er = g.edges(lp);
auto er = g.edges(lp);
if (g.nodeIndex(lp).second) {
result_.insert(make_pair(lp.ddname().fullname(), std::set<DDLogicalPart>()));
}
Expand Down
4 changes: 2 additions & 2 deletions DetectorDescription/RegressionTest/src/ddstats.cc
Expand Up @@ -42,13 +42,13 @@ void ddstats(std::ostream & os)
int noSolidP(0); // accumulative number of solid-parameters

// fetch the acyclic multigraph
const DDCompactView::graph_type & g = cpv.graph();
const auto & g = cpv.graph();

DDExpandedView exv(cpv);
while (exv.next()) ++noExpNodes;

// iterate over the adjacency-list
DDCompactView::graph_type::const_adj_iterator it = g.begin();
auto it = g.begin();
for(; it != g.end(); ++it) {
++noNodes;
noEdges += it->size();
Expand Down
9 changes: 4 additions & 5 deletions DetectorDescription/RegressionTest/test/tutorial.cc
Expand Up @@ -101,12 +101,11 @@ void debugHistory(const DDGeoHistory & h)

void goPersistent(const DDCompactView & cv, const std::string& file) {
std::ofstream f(file.c_str());
typedef DDCompactView::graph_type graph_t;
const graph_t & g = cv.graph();
const auto & g = cv.graph();
unsigned int node = 0;
graph_t::const_adj_iterator it = g.begin();
auto it = g.begin();
for (; it != g.end(); ++it) {
graph_t::const_edge_iterator eit = it->begin();
auto eit = it->begin();
for (; eit != it->end(); ++eit) {
unsigned int eindex = eit->first;
int copyno = g.edgeData(eit->second)->copyno();
Expand Down Expand Up @@ -254,7 +253,7 @@ void tutorial()
// DDD/DDCore/interface/graph.h

// First one takes the graph representation of CompactView
const DDCompactView::graph_type & cpvGraph = cpv.graph();
const auto & cpvGraph = cpv.graph();

// Using the Graph.h interface, some basic information is available:
std::cout << "CompactView, basic information: " << std::endl
Expand Down

0 comments on commit 5de0710

Please sign in to comment.