CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutputMagneticFieldDDToDDL.cc
Go to the documentation of this file.
2 
4 
10 
11 #include <iostream>
12 #include <fstream>
13 #include <string>
14 #include <vector>
15 #include <utility>
16 
17 bool
18 ddsvaluesCmp::operator() ( const DDsvalues_type& sv1, const DDsvalues_type& sv2 )
19 {
20  if( sv1.size() < sv2.size()) return true;
21  if( sv2.size() < sv1.size()) return false;
22  size_t ind = 0;
23  for( ; ind < sv1.size(); ++ind )
24  {
25  if( sv1[ ind ].first < sv2[ ind ].first ) return true;
26  if( sv2[ ind ].first < sv1[ ind ].first ) return false;
27  if( sv1[ ind ].second < sv2[ ind ].second ) return true;
28  if( sv2[ ind ].second < sv1[ ind ].second ) return false;
29  }
30  return false;
31 }
32 
34  : m_fname()
35 {
36  m_rotNumSeed = iConfig.getParameter<int>( "rotNumSeed" );
37  m_fname = iConfig.getUntrackedParameter<std::string>( "fileName" );
38  if( m_fname == "" )
39  {
40  m_xos = &std::cout;
41  }
42  else
43  {
44  m_xos = new std::ofstream( m_fname.c_str());
45  }
46 
47  ( *m_xos ) << "<?xml version=\"1.0\"?>\n";
48  ( *m_xos ) << "<DDDefinition xmlns=\"http://www.cern.ch/cms/DDL\"\n";
49  ( *m_xos ) << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
50  ( *m_xos ) << "xsi:schemaLocation=\"http://www.cern.ch/cms/DDL ../../../DetectorDescription/Schema/DDLSchema.xsd\">\n";
51  ( *m_xos ) << std::fixed << std::setprecision( 18 );
52 }
53 
55 {
56  ( *m_xos ) << "</DDDefinition>\n";
57  ( *m_xos ) << std::endl;
58  m_xos->flush();
59 }
60 
61 void
63 {
64  edm::LogInfo( "OutputMagneticFieldDDToDDL" ) << "OutputMagneticFieldDDToDDL::beginRun";
65 
67  es.get<IdealMagneticFieldRecord>().get( pDD );
68 
69  DDCompactView::DDCompactView::graph_type gra = pDD->graph();
70 
71  // Temporary stores:
72  std::set<DDLogicalPart> lpStore;
73  std::set<DDMaterial> matStore;
74  std::set<DDSolid> solStore;
75 
76  std::map<const DDsvalues_type, std::set<const DDPartSelection*>, ddsvaluesCmp > specStore;
77  std::set<DDRotation> rotStore;
78 
80 
81  std::string rn = m_fname;
82  size_t foundLastDot= rn.find_last_of('.');
83  size_t foundLastSlash= rn.find_last_of('/');
84 
85  if( foundLastSlash > foundLastDot && foundLastSlash != std::string::npos )
86  {
87  edm::LogError( "OutputMagneticFieldDDToDDL" ) << "What? last . before last / in path for filename... this should die...";
88  }
89  if( foundLastDot != std::string::npos && foundLastSlash != std::string::npos )
90  {
91  out.ns_ = rn.substr( foundLastSlash, foundLastDot );
92  }
93  else if ( foundLastDot != std::string::npos )
94  {
95  out.ns_ = rn.substr(0, foundLastDot);
96  }
97  else
98  {
99  edm::LogError( "OutputMagneticFieldDDToDDL" ) << "What? no file name? Attempt at namespace =\"" << out.ns_ << "\" filename was " << m_fname;
100  }
101 
102  edm::LogInfo( "OutputMagneticFieldDDToDDL" ) << "m_fname=" << m_fname << " namespace = " << out.ns_;
103  std::string ns_ = out.ns_;
104 
105  ( *m_xos ) << std::fixed << std::setprecision( 18 );
106 
107  typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator;
108 
109  adjl_iterator git = gra.begin();
110  adjl_iterator gend = gra.end();
111 
113  ( *m_xos) << "<PosPartSection label=\"" << ns_ << "\">\n";
114  git = gra.begin();
115  for( ; git != gend; ++git )
116  {
117  const DDLogicalPart & ddLP = gra.nodeData( git );
118  if( lpStore.find(ddLP) != lpStore.end())
119  {
120  addToSpecStore( ddLP, specStore );
121  }
122  lpStore.insert( ddLP );
123  addToMatStore( ddLP.material(), matStore );
124  addToSolStore( ddLP.solid(), solStore, rotStore );
125  ++i;
126  if( git->size())
127  {
128  // ask for children of ddLP
129  DDCompactView::graph_type::edge_list::const_iterator cit = git->begin();
130  DDCompactView::graph_type::edge_list::const_iterator cend = git->end();
131  for( ; cit != cend; ++cit )
132  {
133  const DDLogicalPart & ddcurLP = gra.nodeData( cit->first );
134  if( lpStore.find(ddcurLP) != lpStore.end())
135  {
136  addToSpecStore( ddcurLP, specStore );
137  }
138  lpStore.insert( ddcurLP );
139  addToMatStore( ddcurLP.material(), matStore );
140  addToSolStore( ddcurLP.solid(), solStore, rotStore );
141  rotStore.insert( gra.edgeData( cit->second )->rot_ );
142  out.position( ddLP, ddcurLP, gra.edgeData( cit->second ), m_rotNumSeed, *m_xos );
143  } // iterate over children
144  } // if (children)
145  } // iterate over graph nodes
146 
147  ( *m_xos ) << "</PosPartSection>\n";
148 
149  ( *m_xos ) << std::scientific << std::setprecision( 18 );
150  std::set<DDMaterial>::const_iterator it( matStore.begin()), ed( matStore.end());
151  ( *m_xos) << "<MaterialSection label=\"" << ns_ << "\">\n";
152  for( ; it != ed; ++it )
153  {
154  if( ! it->isDefined().second ) continue;
155  out.material( *it, *m_xos );
156  }
157  ( *m_xos ) << "</MaterialSection>\n";
158 
159  ( *m_xos ) << "<RotationSection label=\"" << ns_ << "\">\n";
160  ( *m_xos ) << std::fixed << std::setprecision( 18 );
161  std::set<DDRotation>::iterator rit( rotStore.begin()), red( rotStore.end());
162  for( ; rit != red; ++rit )
163  {
164  if( ! rit->isDefined().second ) continue;
165  if( rit->toString() != ":" )
166  {
167  DDRotation r( *rit );
168  out.rotation( r, *m_xos );
169  }
170  }
171  ( *m_xos ) << "</RotationSection>\n";
172 
173  ( *m_xos ) << std::fixed << std::setprecision( 18 );
174  std::set<DDSolid>::const_iterator sit( solStore.begin()), sed( solStore.end());
175  ( *m_xos ) << "<SolidSection label=\"" << ns_ << "\">\n";
176  for( ; sit != sed; ++sit)
177  {
178  if( ! sit->isDefined().second ) continue;
179  out.solid( *sit, *m_xos );
180  }
181  ( *m_xos ) << "</SolidSection>\n";
182 
183  std::set<DDLogicalPart>::iterator lpit( lpStore.begin()), lped( lpStore.end());
184  ( *m_xos ) << "<LogicalPartSection label=\"" << ns_ << "\">\n";
185  for( ; lpit != lped; ++lpit )
186  {
187  if( ! lpit->isDefined().first ) continue;
188  const DDLogicalPart & lp = *lpit;
189  out.logicalPart( lp, *m_xos );
190  }
191  ( *m_xos ) << "</LogicalPartSection>\n";
192 
193  ( *m_xos ) << std::fixed << std::setprecision( 18 );
194  std::map<DDsvalues_type, std::set<const DDPartSelection*> >::const_iterator mit( specStore.begin()), mend( specStore.end());
195  ( *m_xos ) << "<SpecParSection label=\"" << ns_ << "\">\n";
196  for( ; mit != mend; ++mit )
197  {
198  out.specpar( *mit, *m_xos );
199  }
200  ( *m_xos ) << "</SpecParSection>\n";
201 }
202 
203 void
204 OutputMagneticFieldDDToDDL::addToMatStore( const DDMaterial& mat, std::set<DDMaterial> & matStore )
205 {
206  matStore.insert( mat );
207  if( mat.noOfConstituents() != 0 )
208  {
210  int findex( 0 );
211  while( findex < mat.noOfConstituents())
212  {
213  if( matStore.find( mat.constituent( findex ).first ) == matStore.end())
214  {
215  addToMatStore( mat.constituent( findex ).first, matStore );
216  }
217  ++findex;
218  }
219  }
220 }
221 
222 void
223 OutputMagneticFieldDDToDDL::addToSolStore( const DDSolid& sol, std::set<DDSolid> & solStore, std::set<DDRotation>& rotStore )
224 {
225  solStore.insert( sol );
226  if( sol.shape() == ddunion || sol.shape() == ddsubtraction || sol.shape() == ddintersection )
227  {
228  const DDBooleanSolid& bs ( sol );
229  if( solStore.find(bs.solidA()) == solStore.end())
230  {
231  addToSolStore( bs.solidA(), solStore, rotStore );
232  }
233  if( solStore.find( bs.solidB()) == solStore.end())
234  {
235  addToSolStore( bs.solidB(), solStore, rotStore );
236  }
237  rotStore.insert( bs.rotation());
238  }
239 }
240 
241 void
242 OutputMagneticFieldDDToDDL::addToSpecStore( const DDLogicalPart& lp, std::map<const DDsvalues_type, std::set<const DDPartSelection*>, ddsvaluesCmp > & specStore )
243 {
244  std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> >::const_iterator spit( lp.attachedSpecifics().begin()), spend( lp.attachedSpecifics().end());
245  for( ; spit != spend; ++spit )
246  {
247  specStore[ *spit->second ].insert( spit->first );
248  }
249 }
250 
T getParameter(std::string const &) const
void addToSpecStore(const DDLogicalPart &lp, std::map< const DDsvalues_type, std::set< const DDPartSelection * >, ddsvaluesCmp > &specStore)
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="")
void beginRun(edm::Run const &iEvent, edm::EventSetup const &) override
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void specpar(const DDSpecifics &sp, std::ostream &xos)
void addToMatStore(const DDMaterial &mat, std::set< DDMaterial > &matStore)
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
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)
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 addToSolStore(const DDSolid &sol, std::set< DDSolid > &solStore, std::set< DDRotation > &rotStore)
void logicalPart(const DDLogicalPart &lp, std::ostream &xos)
Container::value_type value_type
DDSolid solidA(void) const
Definition: DDSolid.cc:545
tuple out
Definition: dbtoconf.py:99
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
OutputMagneticFieldDDToDDL(const edm::ParameterSet &iConfig)
adj_list::const_iterator const_adj_iterator
Definition: adjgraph.h:125
void material(const DDMaterial &material, std::ostream &xos)
tuple cout
Definition: gather_cfg.py:121
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