CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutputDDToDDL.cc
Go to the documentation of this file.
1 #include "OutputDDToDDL.h"
2 
4 
10 
11 #include <iostream>
12 #include <fstream>
13 #include <string>
14 #include <vector>
15 #include <utility>
16 
17 bool ddsvaluesCmp::operator() ( const DDsvalues_type& sv1, const DDsvalues_type& sv2 ) {
18  if ( sv1.size() < sv2.size() ) return true;
19  if ( sv2.size() < sv1.size() ) return false;
20  size_t ind = 0;
21  for (; ind < sv1.size(); ++ind) {
22  if ( sv1[ind].first < sv2[ind].first ) return true;
23  if ( sv2[ind].first < sv1[ind].first ) return false;
24  if ( sv1[ind].second < sv2[ind].second ) return true;
25  if ( sv2[ind].second < sv1[ind].second ) return false;
26  }
27  return false;
28 }
29 
31 {
32  // std::cout<<"OutputDDToDDL::OutputDDToDDL"<<std::endl;
33  rotNumSeed_ = iConfig.getParameter<int>("rotNumSeed");
34  fname_ = iConfig.getUntrackedParameter<std::string>("fileName");
35  if ( fname_ == "" ) {
36  xos_ = &std::cout;
37  } else {
38  xos_ = new std::ofstream(fname_.c_str());
39  }
40  (*xos_) << "<?xml version=\"1.0\"?>" << std::endl;
41  (*xos_) << "<DDDefinition xmlns=\"http://www.cern.ch/cms/DDL\"" << std::endl;
42  (*xos_) << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" << std::endl;
43  (*xos_) << "xsi:schemaLocation=\"http://www.cern.ch/cms/DDL ../../../DetectorDescription/Schema/DDLSchema.xsd\">" << std::endl;
44  (*xos_) << std::fixed << std::setprecision(18);
45 }
47 {
48  (*xos_) << "</DDDefinition>" << std::endl;
49  (*xos_) << std::endl;
50  xos_->flush();
51 
52 }
53 
54 void
56 {
57  std::cout<<"OutputDDToDDL::beginRun"<<std::endl;
58 
60 
61  es.get<IdealGeometryRecord>().get( pDD );
62 
63  DDCompactView::DDCompactView::graph_type gra = pDD->graph();
64  // temporary stores:
65  std::set<DDLogicalPart> lpStore;
66  std::set<DDMaterial> matStore;
67  std::set<DDSolid> solStore;
68  // 2009-08-19: MEC: I've tried this with set<DDPartSelection> and
69  // had to write operator< for DDPartSelection and DDPartSelectionLevel
70  // the output from such an effort is different than this one.
71  std::map<const DDsvalues_type, std::set<const DDPartSelection*>, ddsvaluesCmp > specStore;
72  std::set<DDRotation> rotStore;
73 
75 
76  std::string rn = fname_;
77  size_t foundLastDot= rn.find_last_of('.');
78  size_t foundLastSlash= rn.find_last_of('/');
79  if ( foundLastSlash > foundLastDot && foundLastSlash != std::string::npos) {
80  std::cout << "What? last . before last / in path for filename... this should die..." << std::endl;
81  }
82  if ( foundLastDot != std::string::npos && foundLastSlash != std::string::npos ) {
83  out.ns_ = rn.substr(foundLastSlash,foundLastDot);
84  } else if ( foundLastDot != std::string::npos ) {
85  out.ns_ = rn.substr(0, foundLastDot);
86  } else {
87  std::cout << "What? no file name? Attempt at namespace =\"" << out.ns_ << "\" filename was " << fname_ << std::endl;
88  }
89  std::cout << "fname_=" << fname_ << " namespace = " << out.ns_ << std::endl;
90  std::string ns_ = out.ns_;
91 
92  (*xos_) << std::fixed << std::setprecision(18);
94 
95  adjl_iterator git = gra.begin();
96  adjl_iterator gend = gra.end();
97 
99  (*xos_) << "<PosPartSection label=\"" << ns_ << "\">" << std::endl;
100  git = gra.begin();
101  for (; git != gend; ++git)
102  {
103  const DDLogicalPart & ddLP = gra.nodeData(git);
104  if ( lpStore.find(ddLP) != lpStore.end() ) {
105  addToSpecStore(ddLP, specStore);
106  }
107  lpStore.insert(ddLP);
108  addToMatStore( ddLP.material(), matStore );
109  addToSolStore( ddLP.solid(), solStore, rotStore );
110  ++i;
111  if (git->size())
112  {
113  // ask for children of ddLP
114  DDCompactView::graph_type::edge_list::const_iterator cit = git->begin();
115  DDCompactView::graph_type::edge_list::const_iterator cend = git->end();
116  for (; cit != cend; ++cit)
117  {
118  const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
119  if (lpStore.find(ddcurLP) != lpStore.end()) {
120  addToSpecStore(ddcurLP, specStore);
121  }
122  lpStore.insert(ddcurLP);
123  addToMatStore(ddcurLP.material(), matStore);
124  addToSolStore(ddcurLP.solid(), solStore, rotStore);
125  rotStore.insert(gra.edgeData(cit->second)->rot_);
126  out.position(ddLP, ddcurLP, gra.edgeData(cit->second), rotNumSeed_, *xos_);
127  } // iterate over children
128  } // if (children)
129  } // iterate over graph nodes
130  // std::cout << "specStore.size() = " << specStore.size() << std::endl;
131 
132  (*xos_) << "</PosPartSection>" << std::endl;
133 
134  (*xos_) << std::scientific << std::setprecision(18);
135  std::set<DDMaterial>::const_iterator it(matStore.begin()), ed(matStore.end());
136  (*xos_) << "<MaterialSection label=\"" << ns_ << "\">" << std::endl;
137  for (; it != ed; ++it) {
138  if (! it->isDefined().second) continue;
139  out.material(*it, *xos_);
140  }
141  (*xos_) << "</MaterialSection>" << std::endl;
142 
143  (*xos_) << "<RotationSection label=\"" << ns_ << "\">" << std::endl;
144  (*xos_) << std::fixed << std::setprecision(18);
145  std::set<DDRotation>::iterator rit(rotStore.begin()), red(rotStore.end());
146  for (; rit != red; ++rit) {
147  if (! rit->isDefined().second) continue;
148  if ( rit->toString() != ":" ) {
149  DDRotation r(*rit);
150  out.rotation(r, *xos_);
151  }
152  }
153  (*xos_) << "</RotationSection>" << std::endl;
154 
155  (*xos_) << std::fixed << std::setprecision(18);
156  std::set<DDSolid>::const_iterator sit(solStore.begin()), sed(solStore.end());
157  (*xos_) << "<SolidSection label=\"" << ns_ << "\">" << std::endl;
158  for (; sit != sed; ++sit) {
159  if (! sit->isDefined().second) continue;
160  out.solid(*sit, *xos_);
161  }
162  (*xos_) << "</SolidSection>" << std::endl;
163 
164  std::set<DDLogicalPart>::iterator lpit(lpStore.begin()), lped(lpStore.end());
165  (*xos_) << "<LogicalPartSection label=\"" << ns_ << "\">" << std::endl;
166  for (; lpit != lped; ++lpit) {
167  if (! lpit->isDefined().first) continue;
168  const DDLogicalPart & lp = *lpit;
169  out.logicalPart(lp, *xos_);
170  }
171  (*xos_) << "</LogicalPartSection>" << std::endl;
172 
173  (*xos_) << std::fixed << std::setprecision(18);
174  std::map<DDsvalues_type, std::set<const DDPartSelection*> >::const_iterator mit(specStore.begin()), mend (specStore.end());
175  (*xos_) << "<SpecParSection label=\"" << ns_ << "\">" << std::endl;
176  for (; mit != mend; ++mit) {
177  out.specpar ( *mit, *xos_ );
178  }
179  (*xos_) << "</SpecParSection>" << std::endl;
180 
181 }
182 
183 void OutputDDToDDL::addToMatStore( const DDMaterial& mat, std::set<DDMaterial> & matStore) {
184  matStore.insert(mat);
185  if ( mat.noOfConstituents() != 0 ) {
187  int findex(0);
188  while ( findex < mat.noOfConstituents() ) {
189  if ( matStore.find(mat.constituent(findex).first) == matStore.end() ) {
190  addToMatStore( mat.constituent(findex).first, matStore );
191  }
192  ++findex;
193  }
194  }
195 }
196 
197 void OutputDDToDDL::addToSolStore( const DDSolid& sol, std::set<DDSolid> & solStore, std::set<DDRotation>& rotStore ) {
198  solStore.insert(sol);
199  if ( sol.shape() == ddunion || sol.shape() == ddsubtraction || sol.shape() == ddintersection ) {
200  const DDBooleanSolid& bs (sol);
201  if ( solStore.find(bs.solidA()) == solStore.end()) {
202  addToSolStore(bs.solidA(), solStore, rotStore);
203  }
204  if ( solStore.find(bs.solidB()) == solStore.end()) {
205  addToSolStore(bs.solidB(), solStore, rotStore);
206  }
207  rotStore.insert(bs.rotation());
208  }
209 }
210 
211 void OutputDDToDDL::addToSpecStore( const DDLogicalPart& lp, std::map<const DDsvalues_type, std::set<const DDPartSelection*>, ddsvaluesCmp > & specStore ) {
212  std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> >::const_iterator spit(lp.attachedSpecifics().begin()), spend(lp.attachedSpecifics().end());
213  for ( ; spit != spend; ++spit ) {
214  specStore[*spit->second].insert(spit->first);
215  }
216 }
217 
void beginRun(edm::Run const &iEvent, edm::EventSetup const &) override
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void rotation(DDRotation &rotation, std::ostream &xos, const std::string &rotn="")
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void addToSpecStore(const DDLogicalPart &lp, std::map< const DDsvalues_type, std::set< const DDPartSelection * >, ddsvaluesCmp > &specStore)
void addToMatStore(const DDMaterial &mat, std::set< DDMaterial > &matStore)
void specpar(const DDSpecifics &sp, std::ostream &xos)
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
std::vector< double >::size_type index_type
Definition: adjgraph.h:15
void addToSolStore(const DDSolid &sol, std::set< DDSolid > &solStore, std::set< DDRotation > &rotStore)
A DDSolid represents the shape of a part.
Definition: DDSolid.h:35
DDSolid solidB(void) const
Definition: DDSolid.cc:550
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:66
U second(std::pair< T, U > const &p)
std::string fname_
Definition: OutputDDToDDL.h:41
DDRotation rotation(void) const
Definition: DDSolid.cc:535
void position(const DDLogicalPart &parent, const DDLogicalPart &child, DDPosData *edgeToChild, int &rotNameSeed, std::ostream &xos)
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
std::maps an index to a DDValue. The index corresponds to the index assigned to the name of the std::...
Definition: DDsvalues.h:19
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:89
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:88
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:144
void logicalPart(const DDLogicalPart &lp, std::ostream &xos)
DDSolid solidA(void) const
Definition: DDSolid.cc:545
const T & get() const
Definition: EventSetup.h:56
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:83
std::ostream * xos_
Definition: OutputDDToDDL.h:42
OutputDDToDDL(const edm::ParameterSet &iConfig)
adj_list::const_iterator const_adj_iterator
Definition: adjgraph.h:125
void material(const DDMaterial &material, std::ostream &xos)
struct @578 fname_
tuple cout
Definition: gather_cfg.py:145
void solid(const DDSolid &solid, std::ostream &xos)
const std::vector< std::pair< const DDPartSelection *, const DDsvalues_type * > > & attachedSpecifics(void) const
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
Definition: Run.h:43