From d8a071ea6a3d6b0c3dde6d7309af41feef99f355 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Mon, 8 Jun 2015 16:40:08 +0200 Subject: [PATCH 1/5] * Add a new unit test * Use auto * Use range-based for loops * Cleanup commented out code --- .../Core/interface/DDStrVector.h | 5 -- DetectorDescription/Core/src/DDSpecifics.cc | 46 +++++-------------- DetectorDescription/Core/src/DDStrVector.cc | 11 +---- DetectorDescription/Core/src/DDsvalues.cc | 12 +---- DetectorDescription/Core/test/BuildFile.xml | 2 + 5 files changed, 17 insertions(+), 59 deletions(-) diff --git a/DetectorDescription/Core/interface/DDStrVector.h b/DetectorDescription/Core/interface/DDStrVector.h index 2d19386065399..e32136576b978 100644 --- a/DetectorDescription/Core/interface/DDStrVector.h +++ b/DetectorDescription/Core/interface/DDStrVector.h @@ -11,8 +11,6 @@ class DDStrVector; //! output operator for printing ... std::ostream & operator<<(std::ostream & o, const DDStrVector & cons); -//typedef std::vector dd_constant_type; - //! a named constant corresponding to the DDL-XML tag and class DDStrVector : public DDBase* > { @@ -21,9 +19,6 @@ class DDStrVector : public DDBase* > //! size type for the size of the stored values typedef std::vector::size_type size_t; - //! iterator for read-only acces to stored values - //typedef std::vector::const_iterator const_iterator; - //! value type of the managed object typedef std::vector value_type; diff --git a/DetectorDescription/Core/src/DDSpecifics.cc b/DetectorDescription/Core/src/DDSpecifics.cc index 35211f85e3595..51cada6341195 100644 --- a/DetectorDescription/Core/src/DDSpecifics.cc +++ b/DetectorDescription/Core/src/DDSpecifics.cc @@ -1,27 +1,17 @@ #include "DetectorDescription/Core/interface/DDSpecifics.h" -#include "Specific.h" +#include "DetectorDescription/Core/src/Specific.h" #include "DetectorDescription/Base/interface/DDdebug.h" -#include - -// Message logger. -#include "FWCore/MessageLogger/interface/MessageLogger.h" - using DDI::Specific; -//DDBase::StoreT::pointer_type -// DDBase::StoreT::instance_ = 0; - DDSpecifics::DDSpecifics() : DDBase() { } - DDSpecifics::DDSpecifics(const DDName & name) : DDBase() { prep_ = StoreT::instance().create(name); } - DDSpecifics::DDSpecifics(const DDName & name, const selectors_type & partSelections, const DDsvalues_type & svalues, @@ -29,32 +19,26 @@ DDSpecifics::DDSpecifics(const DDName & name, : DDBase() { prep_ = StoreT::instance().create(name, new Specific(partSelections,svalues,doRegex)); - typedef std::vector > > strange_type; - strange_type v; + std::vector > > v; rep().updateLogicalPart(v); - strange_type::iterator it = v.begin(); - for(; it != v.end(); ++it) { - if (it->first.isDefined().second) { - it->first.addSpecifics(it->second); - DCOUT('C', "add specifics to LP: partsel=" << *(it->second.first) ); + for( auto& it : v ) { + if( it.first.isDefined().second ) { + it.first.addSpecifics( it.second ); + DCOUT('C', "add specifics to LP: partsel=" << *( it.second.first )); } else { - std::string serr("Definition of LogicalPart missing! name="); - serr+= it->first.ddname().fullname(); - throw cms::Exception("DDException") << serr; + throw cms::Exception("DDException") << "Definition of LogicalPart missing! name=" + << it.first.ddname().fullname(); } } } - DDSpecifics::~DDSpecifics() { } - -const std::vector & DDSpecifics::selection() const // +const std::vector & DDSpecifics::selection() const { return rep().selection(); } - const DDsvalues_type & DDSpecifics::specifics() const { @@ -79,12 +63,6 @@ std::pair DDSpecifics::node() const return rep().node(); } -// void DDSpecifics::clear() -// { -// StoreT::instance().clear(); -// } - - std::ostream & operator<<( std::ostream & os, const DDSpecifics & sp) { DDBase::def_type defined(sp.isDefined()); @@ -101,15 +79,13 @@ std::ostream & operator<<( std::ostream & os, const DDSpecifics & sp) os << "* specific not declared * "; } return os; - } - std::ostream & operator<<( std::ostream & os, const std::vector & v) { std::vector::const_iterator it = v.begin(); - for (; it!=v.end(); ++it) { - os << *it << std::endl; + for( const auto& it : v ) { + os << it << std::endl; } return os; } diff --git a/DetectorDescription/Core/src/DDStrVector.cc b/DetectorDescription/Core/src/DDStrVector.cc index 9bf9d7499df36..bdb20084c19d6 100644 --- a/DetectorDescription/Core/src/DDStrVector.cc +++ b/DetectorDescription/Core/src/DDStrVector.cc @@ -1,11 +1,7 @@ - #include "DetectorDescription/Core/interface/DDStrVector.h" -// Evaluator - DDStrVector::DDStrVector() : DDBase*>() { } - DDStrVector::DDStrVector(const DDName & name) : DDBase*>() { prep_ = StoreT::instance().create(name); @@ -16,16 +12,14 @@ DDStrVector::DDStrVector(const DDName & name,std::vector* vals) prep_ = StoreT::instance().create(name,vals); } - std::ostream & operator<<(std::ostream & os, const DDStrVector & cons) { os << "DDStrVector name=" << cons.name(); if(cons.isDefined().second) { os << " size=" << cons.size() << " vals=( "; - DDStrVector::value_type::const_iterator it(cons.values().begin()), ed(cons.values().end()); - for(; it & sp, DDValue & toFetch, std::vector & result) { unsigned int count = 0; - std::vector::const_iterator it(sp.begin()), ed(sp.end()); - for (; it != ed; ++it) { - if (DDfetch(*it, toFetch)) { + for( const auto & it : sp ) { + if (DDfetch( it, toFetch)) { result.push_back(toFetch); ++count; } } return count; } - -/* -DDValue DDsvalues_type::operator[](const unsigned int& i) const -{ - return DDValue(i); -} -*/ diff --git a/DetectorDescription/Core/test/BuildFile.xml b/DetectorDescription/Core/test/BuildFile.xml index 33659cd73eaad..40b970d85f204 100644 --- a/DetectorDescription/Core/test/BuildFile.xml +++ b/DetectorDescription/Core/test/BuildFile.xml @@ -4,6 +4,8 @@ + + From 999f353e56264316f31acaf645632ff94d691368 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Mon, 8 Jun 2015 17:10:15 +0200 Subject: [PATCH 2/5] * add test --- DetectorDescription/Core/src/DDMap.cc | 7 +-- .../Core/test/DDStrVector.cppunit.cc | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 DetectorDescription/Core/test/DDStrVector.cppunit.cc diff --git a/DetectorDescription/Core/src/DDMap.cc b/DetectorDescription/Core/src/DDMap.cc index 269b58888d920..5e82fc17ec1a4 100644 --- a/DetectorDescription/Core/src/DDMap.cc +++ b/DetectorDescription/Core/src/DDMap.cc @@ -2,7 +2,6 @@ DDMap::DDMap() : DDBase() { } - DDMap::DDMap(const DDName & name) : DDBase() { prep_ = StoreT::instance().create(name); @@ -13,16 +12,14 @@ DDMap::DDMap(const DDName & name,dd_map_type* vals) prep_ = StoreT::instance().create(name,vals); } - std::ostream & operator<<(std::ostream & os, const DDMap & cons) { os << "DDMap name=" << cons.name(); if(cons.isDefined().second) { os << " size=" << cons.size() << " vals=( "; - DDMap::value_type::const_iterator it(cons.values().begin()), ed(cons.values().end()); - for(; it != ed; ++it) { - os << it->first << '=' << it->second << ' '; + for( const auto& it : cons.values()) { + os << it.first << '=' << it.second << ' '; } os << ')'; } diff --git a/DetectorDescription/Core/test/DDStrVector.cppunit.cc b/DetectorDescription/Core/test/DDStrVector.cppunit.cc new file mode 100644 index 0000000000000..bd225852971a3 --- /dev/null +++ b/DetectorDescription/Core/test/DDStrVector.cppunit.cc @@ -0,0 +1,48 @@ +#include "DetectorDescription/Core/interface/DDStrVector.h" +#include + +class testDDStrVector : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(testDDStrVector); + CPPUNIT_TEST(checkAgaistOld); + CPPUNIT_TEST_SUITE_END(); +public: + void setUp(){} + void tearDown() {} + void buildIt(); + void testloading(); + void checkAgaistOld(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(testDDStrVector); + +void +testDDStrVector::buildIt() { + auto strVec = new std::vector; + strVec->push_back("One"); + strVec->push_back("Two"); + strVec->push_back("Three"); + + DDStrVector testVec( "TestVector", strVec ); + std::cerr << testVec << std::endl; +} + +void +testDDStrVector::testloading() { + auto strVec = new std::vector; + strVec->push_back("One"); + strVec->push_back("Two"); + strVec->push_back("Three"); + + DDStrVector testVec( "TestVector", strVec ); + std::ostringstream os; + os << testVec; + std::string str("DDStrVector name=GLOBAL:TestVector size=3 vals=( One Two Three )"); + if (os.str()!=str) std::cerr << "not the same!" << std::endl; + CPPUNIT_ASSERT (os.str()==str); +} + +void +testDDStrVector::checkAgaistOld() { + buildIt(); + testloading(); +} From f867e11eed8390b3c921fcca7579554dcfa47b97 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 10 Jun 2015 09:34:52 +0200 Subject: [PATCH 3/5] * Remove unimplemented functions * Remove commented out code * Use range-based for loop * Remove unneeded typedefs --- .../Core/interface/DDSpecifics.h | 14 +-- DetectorDescription/Core/interface/DDValue.h | 2 +- DetectorDescription/Core/src/DDSpecifics.cc | 10 +- DetectorDescription/Core/src/LogicalPart.cc | 47 ++------ DetectorDescription/Core/src/Solid.cc | 8 +- DetectorDescription/Core/src/Specific.cc | 72 +++-------- DetectorDescription/Core/src/Specific.h | 20 +-- .../RegressionTest/test/tutorial.cc | 114 +----------------- 8 files changed, 51 insertions(+), 236 deletions(-) diff --git a/DetectorDescription/Core/interface/DDSpecifics.h b/DetectorDescription/Core/interface/DDSpecifics.h index 6cd9a5577a9b6..0290d4eda62aa 100644 --- a/DetectorDescription/Core/interface/DDSpecifics.h +++ b/DetectorDescription/Core/interface/DDSpecifics.h @@ -1,7 +1,6 @@ #ifndef DDSpecifics_h #define DDSpecifics_h - #include #include #include @@ -11,8 +10,6 @@ #include "DetectorDescription/Core/interface/DDsvalues.h" #include "DetectorDescription/Core/interface/DDExpandedView.h" -//#include "DetectorDescription/Core/interface/DDExpandedView.h" - class DDSpecifics; class DDPartSelection; class DDNodes; @@ -64,9 +61,9 @@ class DDSpecifics : public DDBase bla, bla, bla */ DDSpecifics(const DDName & name, - const selectors_type & partSelections, - const DDsvalues_type & svalues, - bool doRegex=true); + const std::vector & partSelections, + const DDsvalues_type & svalues, + bool doRegex=true); ~DDSpecifics(); @@ -76,13 +73,8 @@ class DDSpecifics : public DDBase //! Reference to the user-data attached to all nodes selected by the selections-strings given through selection const DDsvalues_type & specifics() const; - //! Calculates all expanded-nodes which are selected by the selection-strings - bool nodes(DDNodes & nds) const; - //! Calculates the geometrical history of a fully specified PartSelector std::pair node() const; - -/* static void clear(); */ }; #endif diff --git a/DetectorDescription/Core/interface/DDValue.h b/DetectorDescription/Core/interface/DDValue.h index 3d20cda54c18c..808a18385feee 100644 --- a/DetectorDescription/Core/interface/DDValue.h +++ b/DetectorDescription/Core/interface/DDValue.h @@ -86,6 +86,7 @@ class DDValue //! A DDValue a is smaller than a DDValue b if (a.id() value_; }; -private: void init( const std::string & ); using Names = tbb::concurrent_vector>; diff --git a/DetectorDescription/Core/src/DDSpecifics.cc b/DetectorDescription/Core/src/DDSpecifics.cc index 51cada6341195..f757568050d1b 100644 --- a/DetectorDescription/Core/src/DDSpecifics.cc +++ b/DetectorDescription/Core/src/DDSpecifics.cc @@ -13,7 +13,7 @@ DDSpecifics::DDSpecifics(const DDName & name) : DDBase() } DDSpecifics::DDSpecifics(const DDName & name, - const selectors_type & partSelections, + const std::vector & partSelections, const DDsvalues_type & svalues, bool doRegex) : DDBase() @@ -45,10 +45,10 @@ const DDsvalues_type & DDSpecifics::specifics() const return rep().specifics(); } -bool DDSpecifics::nodes(DDNodes & result) const -{ - return rep().nodes(result); -} +// bool DDSpecifics::nodes(DDNodes & result) const +// { +// return rep().nodes(result); +// } /** node() will only work, if - there is only one PartSelection std::string diff --git a/DetectorDescription/Core/src/LogicalPart.cc b/DetectorDescription/Core/src/LogicalPart.cc index 750f48381cdb8..c7818a8062090 100644 --- a/DetectorDescription/Core/src/LogicalPart.cc +++ b/DetectorDescription/Core/src/LogicalPart.cc @@ -1,10 +1,7 @@ - #include #include "DetectorDescription/Core/src/LogicalPart.h" #include "DetectorDescription/Core/interface/DDPartSelection.h" #include "DetectorDescription/Base/interface/DDdebug.h" -//#include "DetectorDescription/Core/interface/DDSpecifics.h" - using DDI::LogicalPart; @@ -14,12 +11,12 @@ LogicalPart::LogicalPart(const DDMaterial & m, : material_(m), solid_(s), cat_(c), weight_(0), specifics_(0), hasDDValue_(1,false) { } - - - const DDMaterial & LogicalPart::material() const { return material_; } + const DDSolid & LogicalPart::solid() const { return solid_; } + DDEnums::Category LogicalPart::category() const { return cat_; } + void LogicalPart::stream(std::ostream & os) { os << std::endl << " mat=" << material().ddname() << std::endl << " solid=" << solid(); @@ -36,10 +33,8 @@ void LogicalPart::addSpecifics(const std::pairbegin(); - DDsvalues_type::const_iterator ed = s.second->end(); - for (; it != ed; ++it) { - unsigned int id = it->first; + for( const auto& it : *s.second ) { + unsigned int id = it.first; if ( id < hasDDValue_.size() ) { hasDDValue_[id] = true; } @@ -71,7 +66,6 @@ void LogicalPart::removeSpecifics(const std::pair LogicalPart::specifics() const { std::vector result; @@ -83,12 +77,10 @@ std::vector LogicalPart::specifics() const void LogicalPart::specificsV(std::vector & result) const { typedef std::vector > sp_type; - sp_type::const_iterator it = specifics_.begin(); - sp_type::const_iterator ed = specifics_.end(); - for (; it != ed; ++it) { - const DDPartSelection & ps = *(it->first); + for( const auto& it : specifics_ ) { + const DDPartSelection & ps = *(it.first); if (ps.size()==1 && ps[0].selectionType_==ddanylogp) { - result.push_back(it->second); + result.push_back(it.second); } } } @@ -99,31 +91,16 @@ DDsvalues_type LogicalPart::mergedSpecifics() const { return merged; } - void LogicalPart::mergedSpecificsV(DDsvalues_type & merged) const { merged.clear(); - std::vector unmerged; specificsV(unmerged); + std::vector unmerged; + specificsV(unmerged); if (unmerged.size()==1) { merged = *(unmerged[0]); } else if (unmerged.size()>1) { - std::vector::const_iterator it = unmerged.begin(); - std::vector::const_iterator ed = unmerged.end(); - for (; it != ed; ++it) { - merge(merged, **it); + for( const auto& it : unmerged ) { + merge(merged, *it); } } } - - -/* -const std::vector & LogicalPart::partSelections(const DDValue &) const{ - static std::vector empty_; - std::vector * result_ = ∅ - std::map >::const_iterator it = valToPartsel_.find(v); - if (it != valToPartsel_.end()) { - result = &(it->second); - } - return *result; -} -*/ diff --git a/DetectorDescription/Core/src/Solid.cc b/DetectorDescription/Core/src/Solid.cc index 69f0724b3ad33..5965659d6ceaf 100644 --- a/DetectorDescription/Core/src/Solid.cc +++ b/DetectorDescription/Core/src/Solid.cc @@ -1,10 +1,8 @@ #include "DetectorDescription/Core/src/Solid.h" -#include +#include void DDI::Solid::stream(std::ostream & os) const { - std::vector::const_iterator i = p_.begin(); - std::vector::const_iterator e = p_.end(); - for (; i != e ; ++i) - os << *i << ' '; + for( const auto& i : p_ ) + os << i << ' '; } diff --git a/DetectorDescription/Core/src/Specific.cc b/DetectorDescription/Core/src/Specific.cc index b2f6af3d7c5bd..46ef2b42e7115 100644 --- a/DetectorDescription/Core/src/Specific.cc +++ b/DetectorDescription/Core/src/Specific.cc @@ -1,9 +1,6 @@ #include "DetectorDescription/Core/src/Specific.h" #include "DetectorDescription/Core/interface/DDCompactView.h" - -// Message logger. #include "FWCore/MessageLogger/interface/MessageLogger.h" - #include namespace DDI { @@ -16,9 +13,8 @@ namespace DDI { valid_(false), doRegex_(doRegex) { - std::vector::const_iterator it = selections.begin(); - for(; it != selections.end(); ++it) { - createPartSelections(*it); + for( const auto& it : selections ) { + createPartSelections( it ); } } @@ -28,18 +24,16 @@ namespace DDI { { } void Specific::createPartSelections(const std::string & selString) - { - + { std::vector regv; std::vector temp; DDTokenize2(selString,regv); if (!regv.size()) throw cms::Exception("DDException") << "Could not evaluate the selection-std::string ->" << selString << "<-"; - std::vector::const_iterator it = regv.begin(); std::pair res; - for (; it != regv.end(); ++it) { + for( const auto& it : regv ) { std::vector lpv; - res = DDIsValid(it->ns_,it->nm_,lpv,doRegex_); + res = DDIsValid( it.ns_, it.nm_, lpv, doRegex_ ); if (!res.first) { std::string msg("Could not process q-name of a DDLogicalPart, reason:\n"+res.second); msg+="\nSpecPar selection is:\n" + selString + "\n"; @@ -47,21 +41,16 @@ namespace DDI { edm::LogError("Specific") << msg; break; //EXIT for loop } - //edm::LogInfo ("Specific") << "call addSelectionLevel" << std::endl; - addSelectionLevel(lpv,it->copyno_,it->selectionType_,temp); + addSelectionLevel( lpv, it.copyno_, it.selectionType_, temp ); } if ( res.first ) { // i.e. it wasn't "thrown" out of the loop - std::vector::const_iterator iit = temp.begin(); partSelections_.reserve(temp.size() + partSelections_.size()); - for (; iit != temp.end(); ++iit) { - partSelections_.push_back(*iit); - //edm::LogInfo ("Specific") << *iit << std::endl; + for( const auto& iit : temp ) { + partSelections_.push_back( iit ); } } } - - void Specific::addSelectionLevel(std::vector & lpv, int copyno, ddselection_type st, std::vector & selv) { @@ -72,7 +61,6 @@ namespace DDI { typedef std::vector::size_type ps_sizetype; ps_sizetype ps_sz = selv.size(); lpv_sizetype lpv_sz = lpv.size(); - //edm::LogInfo ("Specific") << "lpv_sz=" << lpv_sz << std::endl; lpv_sizetype lpv_i = 0; std::vector result; for (; lpv_i < lpv_sz; ++lpv_i) { @@ -81,8 +69,6 @@ namespace DDI { result.push_back(*ps_it); } } - //edm::LogInfo ("Specific") << "result-size=" << result.size() << std::endl; - //ps_sizetype ps_sz = result.size(); ps_sizetype ps_i = 0; for(lpv_i=0; lpv_i < lpv_sz; ++lpv_i) { for(ps_i = ps_sz*lpv_i; ps_i < ps_sz*(lpv_i+1); ++ps_i) { @@ -96,33 +82,27 @@ namespace DDI { { return partSelections_; } - - + void Specific::stream(std::ostream & os) const { - // os << " no output available yet, sorry. "; os << " Size: " << specifics_.size() << std::endl; os << "\tSelections:" << std::endl; - partsel_type::const_iterator pit(partSelections_.begin()), pend(partSelections_.end()); - for (;pit!=pend;++pit) { - os << *pit << std::endl; + for( const auto& pit : partSelections_ ) { + os << pit << std::endl; } - - DDsvalues_type::const_iterator vit(specifics_.begin()), ved(specifics_.end()); - for (;vit!=ved;++vit) { - const DDValue & v = vit->second; + for( const auto& vit : specifics_ ) { + const DDValue & v = vit.second; os << "\tParameter name= \"" << v.name() << "\" " << std::endl; os << "\t\t Value pairs: " << std::endl; size_t s=v.size(); size_t i=0; if ( v.isEvaluated() ) { - for (; i& vs = v.strings(); - for (; i > >& result) const { if (partSelections_.size()) { - partsel_type::const_iterator it = partSelections_.begin(); const DDsvalues_type* sv = (&specifics_); - for (; it != partSelections_.end(); ++it) { - DDLogicalPart logp = it->back().lp_; - /*if (!logp.isDefined().second) { - throw DDException("Specific::updateLogicalPart(..): LogicalPart not defined, name=" + std::string(logp.ddname())); - }*/ - const DDPartSelection * ps = (&(*it)); + for( const auto& it : partSelections_ ) { + DDLogicalPart logp = it.back().lp_; + const DDPartSelection * ps = (&it); assert(ps); assert(sv); std::pair pssv(ps,sv); @@ -198,14 +174,4 @@ namespace DDI { } return std::make_pair(result,e); } - - - Specific::~Specific() - { - // DDsvalues_type::iterator it = specifics_.begin(); - // for (; it != specifics_.end(); ++it) { - // it->second.clear(); - // } - } - } diff --git a/DetectorDescription/Core/src/Specific.h b/DetectorDescription/Core/src/Specific.h index a67217d61c5a0..e3c5b35ee6ebd 100644 --- a/DetectorDescription/Core/src/Specific.h +++ b/DetectorDescription/Core/src/Specific.h @@ -19,17 +19,14 @@ namespace DDI { class Specific { public: - typedef std::vector partsel_type; - typedef std::vector selectors_type; - Specific(const std::vector & selections, const DDsvalues_type & specs, - bool doRegex=true) ; + bool doRegex=true) ; Specific(const std::vector & selections, const DDsvalues_type & specs); - ~Specific();// { } + ~Specific() { } const std::vector & selection() const; @@ -39,24 +36,19 @@ namespace DDI { const DDsvalues_type & specifics() const { return specifics_; } - //! CURRENTLY NOT IMPLEMENTED! - bool nodes(DDNodes &) const { return false; } - //! gives the geometrical history of a fully specified PartSelector std::pair node() const; void stream(std::ostream &) const; protected: - void createPartSelections(const std::string & selString); - void addSelectionLevel(std::vector & lpv, int copyno, ddselection_type st, - std::vector & selv); - //std::vector selection_; + void createPartSelections(const std::string & selString); + void addSelectionLevel(std::vector & lpv, int copyno, ddselection_type st, + std::vector & selv); DDsvalues_type specifics_; - partsel_type partSelections_; + std::vector partSelections_; bool valid_; bool doRegex_; }; - } #endif // DDI_Specific_h diff --git a/DetectorDescription/RegressionTest/test/tutorial.cc b/DetectorDescription/RegressionTest/test/tutorial.cc index 2ae134e595c80..e8b817186a582 100644 --- a/DetectorDescription/RegressionTest/test/tutorial.cc +++ b/DetectorDescription/RegressionTest/test/tutorial.cc @@ -236,8 +236,6 @@ void tutorial() // The same, but creating a reference to it: DDLogicalPart root = cpv.root(); - - DDLogicalPart world = root; //(DDName("CMS","cms")); std::cout << "The world volume is described by following solid:" << std::endl; std::cout << world.solid() << std::endl << std::endl; @@ -245,24 +243,6 @@ void tutorial() std::cout << "The world volume is filled with following material:" << std::endl; std::cout << worldMaterial << std::endl << std::endl; - // example navigation: list all daughters of the world: - DDCompactView::logchild_type logPartsChildren; - typedef DDCompactView::graph_type::const_edge_range NR; // type of range of neightbours - // range of itors to std::pair - //NR children; - /* - children = cpvGraph.nodes(world); - if (children.first != children.second) { // yes, there were some neighbors of DDLogicalPart world - std::cout << world << " has following direct children:" << std::endl; - for (; children.first != children.second; ++(children.first)) { - std::cout << " " << cpvGraph.nodeData(children.first->first) - << " copyno=" << children.first->second->copyno_ - << " rot=" << children.first->second->rot_ << std::endl; - } - } - */ - std::cout << std::endl; - // Of course, if the names are well known (from the XML) one can always // obtain direct access: // (note the implicit usage of the default namespace! Whenever reference @@ -272,37 +252,6 @@ void tutorial() DDLogicalPart endcapXtal("ECalEndcapCrystal"); DDLogicalPart endcapBasket("ECalEndcapE7"); - // For example, we weigh the crystal - // (currently one has to use DDCompactView to calculate the weight, - // in future DDLogicalPart.weight() will do it. In fact, - // DDLogicalPart.weight() can be used after DDCompactView.weight(..) - // was used - it returns the cached weight!) - //std::cout << "Some weight calculation: " << std::endl; - /* - if (endcapXtal.solid()) { - std::cout << " The weight of " << endcapXtal << " is " - << cpv.weight(endcapXtal)/kg - << " kg." << std::endl; - } - - // Or the crystal container (note, that all -expanded- children are considered - // when calculating weight ... - if (endcapBasket.solid()) { - std::cout << " The weight of " << endcapBasket << " is " - << cpv.weight(endcapBasket)/kg - << " kg." << std::endl; - } - - // Or the whole thing ... - DDLogicalPart endcap("ECalEndcap"); - - if (endcap.solid()) { - std::cout << " The weight of " << endcap << " is " - << cpv.weight(endcap)/(1000*kg) << " tons." - << std::endl << std::endl; - } - */ - // Let's switch from the CompactView to the ExpandedView // interfaced through DDExpandedView // The expanded view is a tree of DDExpandedNode s. The usual tree @@ -321,9 +270,6 @@ void tutorial() clock_t StartT, EndT; StartT = clock(); while(exv.next()) { // loop over the !whole! ExpandedView ... - //if (exv.logicalPart() == endcapXtal) { - // ++xtalCount; - //} if (exv.logicalPart().category()==DDEnums::sensitive) { ++sensVolCount; } @@ -335,47 +281,6 @@ void tutorial() << std::endl << "out of " << overall << " expanded nodes! " << std::endl << std::endl; - - // Now please have a look at spec-par.xml in DDD/DDCore/test - // where several specific datasets were attached to some of the - // endcap crystal. - // We will try to retrieve this attached information: - // First we try to find the 'single-boy' (look at spec-pars.xml, - // the tag using name="JustMe" addresses only one single crystal - // in one of the two ECal-Endcaps) - DDNodes result; - DDSpecifics spec1(DDName("JustMe","spec-pars.xml")); - std::cout << "Looking for " << spec1 << std::endl; - if (spec1.nodes(result)) { // fills the DDNodes-std::vector, if corresponding nodes are found - std::cout << "There are " << result.size() << " nodes which match the selection " - << spec1.selection() << std::endl; - dump_nodes(result); - } - // The data attached to this node are the data specified wiht spec1: - /* - std::cout << "Data-set attached: " << std::endl; - DDsvalues_type::const_iterator dataIt = spec1.specifics().begin(); - for(; dataIt != spec1.specifics().end(); ++ dataIt) - std::cout << " name=[" << DDValue(dataIt->first) << "] value[0]=[" << dataIt->second[0] << "]" - << std::endl << std::endl; - - std::cout << std::endl << std::endl; - result.clear(); - */ - - // Now let's find all nodes in the ExpandedView which correspond to - // the selection specified in - // of file spec-pars.xml - /* - DDSpecifics spec2(DDName("all-xtal-in-endcap2","spec-pars.xml")); - std::cout << "Looking for " << spec2 << std::endl; - if (spec2.nodes(result)) { // fills the DDNodes-std::vector, if corresponding nodes are found - std::cout << "There are " << result.size() << " nodes which match the selection " - << spec2.selection() << std::endl; - //dump_nodes(result); - } - std::cout << std::endl; - */ // Test the SCOPE DDCompactView ccv; @@ -397,9 +302,7 @@ void tutorial() } std::cout << "counted " << si << " nodes in the scope " << std::endl << std::endl; - // test the filter - //bool doIt=true; std::map cop; cop["=="] = DDCompOp::equals; @@ -465,17 +368,7 @@ void tutorial() const DDFilter & fi = *filter; query.addFilter( fi, vecF[loop].first ); } - - //const std::vector & res = query.exec(); - // std::vector::const_iterator rit = res.begin(); - /* - for (; rit != res.end(); ++rit) { - std::cout << *rit << std::endl; - } - */ std::cout << "The Scope is now: " << std::endl << scope << std::endl; - //std::cout << "The query-result contains " << res.size() << " nodes." << std::endl; - std::string ans; ans = ""; DDCompactView aaaaa; @@ -540,8 +433,7 @@ void tutorial() } else { std::cout << "no match!" << std::endl; - } - + } } } } @@ -760,8 +652,6 @@ void tutorial() while (exx.next() && n_c--) { dumpHistory(exx.geoHistory()); - } - - + } } From 99bcc342c61d6943d60d5c9abc2de22525e97ccb Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 10 Jun 2015 12:18:13 +0200 Subject: [PATCH 4/5] * Remove unused iterator --- DetectorDescription/Core/src/DDSpecifics.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/DetectorDescription/Core/src/DDSpecifics.cc b/DetectorDescription/Core/src/DDSpecifics.cc index f757568050d1b..e44154c3583d6 100644 --- a/DetectorDescription/Core/src/DDSpecifics.cc +++ b/DetectorDescription/Core/src/DDSpecifics.cc @@ -83,7 +83,6 @@ std::ostream & operator<<( std::ostream & os, const DDSpecifics & sp) std::ostream & operator<<( std::ostream & os, const std::vector & v) { - std::vector::const_iterator it = v.begin(); for( const auto& it : v ) { os << it << std::endl; } From 49e1bb380a552923e4c95a79ae170491c8c8bc3f Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Fri, 12 Jun 2015 13:40:50 +0200 Subject: [PATCH 5/5] * Clean up --- .../src/DDCoreToDDXMLOutput.cc | 24 ++-- .../OfflineDBLoader/src/GeometryInfoDump.cc | 117 +----------------- 2 files changed, 12 insertions(+), 129 deletions(-) diff --git a/DetectorDescription/OfflineDBLoader/src/DDCoreToDDXMLOutput.cc b/DetectorDescription/OfflineDBLoader/src/DDCoreToDDXMLOutput.cc index 7214ac8c41d2d..23d3117c46de4 100644 --- a/DetectorDescription/OfflineDBLoader/src/DDCoreToDDXMLOutput.cc +++ b/DetectorDescription/OfflineDBLoader/src/DDCoreToDDXMLOutput.cc @@ -397,19 +397,15 @@ DDCoreToDDXMLOutput::specpar( const DDSpecifics& sp, std::ostream& xos ) xos << "" << std::endl; // ========... all the selection strings out as strings by using the DDPartSelection's std::ostream function... - const std::vector sels = sp.selection(); - std::vector::const_iterator psit = sels.begin(); - std::vector::const_iterator psendit = sels.end(); - for(; psit != psendit ; ++psit) + for( const auto& psit : sp.selection()) { - xos << "" << std::endl; + xos << "" << std::endl; } // ========= ... and iterate over all DDValues... - DDsvalues_type::const_iterator vit(sp.specifics().begin()), ved(sp.specifics().end()); - for(; vit != ved; ++vit) + for( const auto& vit : sp.specifics()) { - const DDValue & v = vit->second; + const DDValue & v = vit.second; size_t s=v.size(); size_t i=0; // ============ ... all actual values with the same name @@ -445,18 +441,14 @@ void DDCoreToDDXMLOutput::specpar( const std::pair" << std::endl; - std::set::const_iterator psit = pssv.second.begin(); - std::set::const_iterator psendit = pssv.second.end(); - for (; psit != psendit; ++psit) { - xos << "" << std::endl; + for( const auto& psit : pssv.second ) { + xos << "" << std::endl; } // ========= ... and iterate over all DDValues... - - DDsvalues_type::const_iterator vit(pssv.first.begin()), ved(pssv.first.end()); - for(; vit != ved; ++vit) + for( const auto& vit : pssv.first ) { - const DDValue & v = vit->second; + const DDValue & v = vit.second; size_t s=v.size(); size_t i=0; // ============ ... all actual values with the same name diff --git a/DetectorDescription/OfflineDBLoader/src/GeometryInfoDump.cc b/DetectorDescription/OfflineDBLoader/src/GeometryInfoDump.cc index 81f43d45bfc4b..79c913bb2ef13 100644 --- a/DetectorDescription/OfflineDBLoader/src/GeometryInfoDump.cc +++ b/DetectorDescription/OfflineDBLoader/src/GeometryInfoDump.cc @@ -64,21 +64,18 @@ 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()); -// <<<<<<< GeometryInfoDump.cc DDCompactView::DDCompactView::graph_type gra = cpv.graph(); std::set 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; - git = gra.begin(); for (; git != gend; ++git) { const DDLogicalPart & ddLP = gra.nodeData(git); if ( lpStore.find(ddLP) != lpStore.end() && ddLP.attachedSpecifics().size() != 0 ) { dump << ddLP.toString() << ": "; dumpSpec( ddLP.attachedSpecifics(), dump ); - // dumpSpec( ddLP.valueToPartSelectors(), dump ); } lpStore.insert(ddLP); @@ -86,130 +83,24 @@ void GeometryInfoDump::dumpInfo ( bool dumpHistory, bool dumpSpecs, bool dumpPos if (git->size()) { // 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(); - for (; cit != cend; ++cit) + for( const auto& cit : *git ) { - const DDLogicalPart & ddcurLP = gra.nodeData(cit->first); + const DDLogicalPart & ddcurLP = gra.nodeData(cit.first); if (lpStore.find(ddcurLP) != lpStore.end() && ddcurLP.attachedSpecifics().size() != 0 ) { dump << ddcurLP.toString() << ": "; dumpSpec( ddcurLP.attachedSpecifics(), dump ); - // dumpSpec( ddcurLP.valueToPartSelectors(), dump ); } lpStore.insert(ddcurLP); } // iterate over children } // if (children) } // iterate over graph nodes dump.close(); -// ======= -// DDCompactView::DDCompactView::graph_type gra = cpv.graph(); -// std::vector > specStore; -// std::set 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; -// git = gra.begin(); -// for (; git != gend; ++git) -// { -// const DDLogicalPart & ddLP = gra.nodeData(git); -// if ( lpStore.find(ddLP) != lpStore.end() && ddLP.attachedSpecifics().size() != 0 ) { -// dump << ddLP.toString() << " : " << std::endl; -// specStore.reserve(specStore.size()+ddLP.attachedSpecifics().size()); -// std::copy(ddLP.attachedSpecifics().begin(), ddLP.attachedSpecifics().end(), std::back_inserter(specStore));//, specStore.end()); // -// std::vector >::const_iterator bit(ddLP.attachedSpecifics().begin()), eit(ddLP.attachedSpecifics().end()); -// for ( ; bit != eit; ++bit ) { -// // DDsvalues_type is typedef std::vector< std::pair > DDsvalues_type; -// DDsvalues_type::iterator bsit(bit->second->begin()), bseit(bit->second->end()); -// for ( ; bsit != bseit; ++bsit ) { -// dump << bsit->second.name() << " "; -// dump << ( bsit->second.isEvaluated() ? "evaluated" : "NOT eval." ); -// const std::vector& strs = bsit->second.strings(); -// std::vector ldbls; -// ldbls.resize(strs.size(), 0.0); -// if ( bsit->second.isEvaluated() ) { -// ldbls = bsit->second.doubles(); -// } -// if ( strs.size() != ldbls.size() ) std::cout << "CRAP! " << bsit->second.name() << " does not have equal number of doubles and strings." << std::endl; -// size_t sdind(0); -// for ( ; sdind != strs.size() ; ++sdind ) { -// dump << " [" << strs[sdind] << "," << ldbls[sdind] << "]"; -// } -// } -// dump << std::endl; -// } -// } -// lpStore.insert(ddLP); - -// ++i; -// if (git->size()) -// { -// // 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(); -// for (; cit != cend; ++cit) -// { -// const DDLogicalPart & ddcurLP = gra.nodeData(cit->first); -// if (lpStore.find(ddcurLP) != lpStore.end() && ddcurLP.attachedSpecifics().size() != 0 ) { -// specStore.reserve(specStore.size()+ddcurLP.attachedSpecifics().size()); -// std::copy(ddcurLP.attachedSpecifics().begin(), ddcurLP.attachedSpecifics().end(), std::back_inserter(specStore)); -// std::vector >::const_iterator bit(ddcurLP.attachedSpecifics().begin()), eit(ddcurLP.attachedSpecifics().end()); -// dump << ddcurLP.toString() << " : " << std::endl; -// for ( ; bit != eit; ++bit ) { -// DDsvalues_type::iterator bsit(bit->second->begin()), bseit(bit->second->end()); -// for ( ; bsit != bseit; ++bsit ) { -// dump << bsit->second.name() << " "; -// dump << ( bsit->second.isEvaluated() ? "evaluated" : "NOT eval." ); -// const std::vector& strs = bsit->second.strings(); -// std::vector ldbls; -// ldbls.resize(strs.size(), 0.0); -// if ( bsit->second.isEvaluated() ) { -// ldbls = bsit->second.doubles(); -// } -// if ( strs.size() != ldbls.size() ) std::cout << "CRAP! " << bsit->second.name() << " does not have equal number of doubles and strings." << std::endl; -// size_t sdind(0); -// for ( ; sdind != strs.size() ; ++sdind ) { -// dump << " [" << strs[sdind] << "," << ldbls[sdind] << "]"; -// } -// dump << std::endl; -// } -// dump << std::endl; -// } -// } -// lpStore.insert(ddcurLP); -// } // iterate over children -// } // if (children) -// } // iterate over graph nodes -// std::vector >::iterator spit(specStore.begin()), spend (specStore.end()); -// for (; spit != spend; ++spit) { -// if ( !spit->isDefined().second ) continue; -// const DDSpecifics & sp = *spit; -// dump << sp << std::endl; -// } -// dump.close(); -// >>>>>>> 1.12 } -// <<<<<<< GeometryInfoDump.cc - -// ======= -// if ( dumpSpecs ) { -// DDSpecifics::iterator spit(DDSpecifics::begin()), spend(DDSpecifics::end()); -// // ======= For each DDSpecific... -// std::string dsname = "dumpSpecs" + fname; -// std::ofstream dump(dsname.c_str()); -// for (; spit != spend; ++spit) { -// if ( !spit->isDefined().second ) continue; -// const DDSpecifics & sp = *spit; -// dump << sp << std::endl; -// } -// dump.close(); -// } -// >>>>>>> 1.12 } void GeometryInfoDump::dumpSpec( const std::vector >& attspec, std::ostream& dump) { std::vector >::const_iterator bit(attspec.begin()), eit(attspec.end()); - for ( ; bit != eit; ++bit ) { + for( ; bit != eit; ++bit ) { // DDPartSelection is a std::vector std::vector::const_iterator psit(bit->first->begin()), pseit(bit->first->end()); for ( ; psit != pseit; ++psit ) { @@ -242,7 +133,7 @@ void GeometryInfoDump::dumpSpec( const std::vector > DDsvalues_type; DDsvalues_type::const_iterator bsit(bit->second->begin()), bseit(bit->second->end()); - for ( ; bsit != bseit; ++bsit ) { + for( ; bsit != bseit; ++bsit ) { dump << bsit->second.name() << " "; dump << ( bsit->second.isEvaluated() ? "eval " : "NOT eval " ); size_t sdind(0);