CMS 3D CMS Logo

DDStreamer.cc
Go to the documentation of this file.
2 
3 #include <stddef.h>
4 #include <algorithm>
5 #include <string>
6 #include <utility>
7 #include <vector>
8 
34 
35 #include<iomanip>
36 
38  : o_(0), i_(0)
39  {
40  }
41 
42 DDStreamer::DDStreamer(std::ostream & os)
43  : o_(0), i_(0)
44 {
45  if (os) {
46  o_ = &os;
47  }
48  else {
49  throw cms::Exception("DDException") << "DDStreamer::DDStreamer(std::ostream&): not valid std::ostream";
50  }
51 }
52 
53 DDStreamer::DDStreamer(std::istream & is)
54  : o_(0), i_(0)
55 {
56  if (is) {
57  i_ = &is;
58  }
59  else {
60  throw cms::Exception("DDException") << "DDStreamer::DDStreamer(std::ostream&): not valid std::ostream";
61  }
62 }
63 
65 /*
66 DDName dd_get_name(std::istream & is)
67 {
68  size_t nm(0), ns(0);
69  is >> nm;
70  is >> ns;
71  return DDName(std::make_pair(nm,ns));
72 }
73 
74 void nameout(std::ostream & o, const DDName & n)
75 {
76  o << n.id().first << ' ' << n.id().second;
77 }
78 */
79 
80 
81 std::string dd_get_delimit(std::istream & is, char d)
82 {
83  std::string nm;
84  char i;
85  while ((i=is.get()) && i != d) ;
86  while ((i=is.get()) && i != d) {
87  nm = nm + i;
88  }
89  return nm;
90 }
91 
92 DDName dd_get_name_string(std::istream & is)
93 {
94  std::string nm(dd_get_delimit(is,'"')) ;
95  return DDName(nm,
96  dd_get_delimit(is,'"'));
97 /*
98  char i;
99  while ((i=is.get()) && i != '"') ;
100  while ((i=is.get()) && i != '"') {
101  nm = nm + i;
102  }
103  std::pair<std::string,std::string> p = DDSplit(nm);
104  return DDName(p.first,p.second);
105 */
106 }
107 
108 DDName dd_get_name(std::istream & is)
109 {
110  size_t id(0);
111  is >> id;
112  return DDName(id);
113 }
114 
115 void nameout_strings(std::ostream & o, const DDName & n)
116 {
117  o << '"' << n.name() << '"' << ' ' << '"' << n.ns() << '"' ;
118 }
119 
120 void nameout(std::ostream & o, const DDName & n)
121 {
122  o << n.id();
123 }
124 
125 
127 {
128  if (o_ && *o_) {
129  write(*o_);
130  }
131  else {
132  throw cms::Exception("DDException") << "DDStreamer::write(): bad std::ostream";
133  }
134 }
135 
137 {
138  if (i_ && *i_) {
139  read(*i_);
140  }
141  else {
142  throw cms::Exception("DDException") << "DDStreamer::read(): bad std::istream";
143  }
144 }
145 
146 void DDStreamer::write(std::ostream & os)
147 {
148  o_=&os;
149  std::streamsize prec(os.precision());
150  os << std::setprecision(26) << std::scientific;
151  names_write();
152  vars_write();
153 
154  materials_write();
155  solids_write();
156  parts_write();
157 
158  pos_write();
159  specs_write();
160 
161  rots_write();
162  //os << DDI::Singleton<DDName::IdToName>::instance().size() << std::endl;
163  //names_write();
164  os << resetiosflags((std::ios_base::fmtflags)0);
165  os << std::setprecision(prec);
166 }
167 
168 
169 void DDStreamer::read(std::istream & is)
170 {
171 
172  i_=&is;
173  names_read();
174  vars_read();
175 
176  materials_read();
177  solids_read();
178  parts_read();
179 
180  pos_read();
181  specs_read();
182  rots_read();
183 }
184 
185 
187 {
188  std::ostream & os = *o_;
190 
191  DDName::IdToName::const_iterator it(ids.begin()), ed(ids.end());
192  os << ids.size() << std::endl;
193  size_t count(0);
194  for (; it != ed; ++it) {
195  os << '"' << (*it)->first.first << '"' << ' '
196  << '"' << (*it)->first.second << '"' << ' '
197  << count << std::endl;
198  ++count;
199  }
200 
201 }
202 
203 
205 {
206  std::istream & is = *i_;
209 
210  size_t s;
211  is >> s;
212  ids.clear();
213  //ids.resize(s);
214  reg.clear();
215  size_t i(0);
216  //std::string nm; getline(is,nm);
217  for (; i<s; ++i) {
218  std::string nm(dd_get_delimit(is,'"'));
219  std::string ns(dd_get_delimit(is,'"'));
220  size_t id(0);
221  is >> id;
222  DDName::defineId(std::make_pair(nm,ns),id);
223  }
224 }
225 
226 
227 template<class T>
228 size_t dd_count(const T & /*dummy*/)
229 {
230  size_t result(0);
231  typename T::template iterator<T> it(T::begin()), ed(T::end());
232  for (; it!=ed; ++it) {
233  if (it->isDefined().second) {
234  ++result;
235  }
236  }
237  return result;
238 }
239 
240 
242 {
243  explicit double_binary(double d) : val_(d) { }
244  double_binary() : val_(0) { }
245  double val_;
246 };
247 
248 typedef double_binary B;
249 
250 std::ostream & operator<<(std::ostream & os, double_binary b)
251 {
252  const char * d = (const char *)(&(b.val_));
253  //size_t s(sizeof(double)), i(0);
254  //os << '(';
255  os.write(d,sizeof(double));
256  return os;
257 }
258 
259 
260 inline std::istream & operator>>(std::istream & is, double_binary & b)
261 {
262  char * d = (char *)(&(b.val_));
263  //size_t s(sizeof(double)), i(0);
264  is.read(d,sizeof(double));
265  return is;
266 }
267 
268 
270 {
271  std::ostream & os = *o_;
272  DDMaterial::iterator<DDMaterial> it(DDMaterial::begin()), ed(DDMaterial::end());
273  size_t no = dd_count(DDMaterial());
274  os << no << std::endl;
275  for (; it != ed; ++it) {
276  if (! it->isDefined().second) continue;
277  const DDMaterial & m = *it;
278  os << "--Material: " << m.name() << " @ " ;
279  nameout(os,m.name());
280  os << ' ' << m.z() << ' ' << m.a() << ' ' << m.density() << ' ';
281 
282  int noc = m.noOfConstituents();
283  os << noc;
284  int j=0;
285  for (; j<noc; ++j) {
286  os << ' ';
287  nameout(os,m.constituent(j).first.name());
288  os << ' ' << m.constituent(j).second;
289  }
290  os << std::endl;
291  }
292 }
293 
294 
296 {
297  std::istream & is = *i_;
298  //DDMaterial::clear();
299  size_t n=0;
300  is >> n;
301  size_t i=0;
302  for (; i < n; ++i) { // Materials
303  is.ignore(1000,'@');
304  DDName dn = dd_get_name(is);
305  double z(0), a(0), d(0);
306  is >> z;
307  is >> a;
308  is >> d;
309  int comp(0);
310  is >> comp; // composites
311  if (comp) { // composite material
312  DDMaterial m(dn,d);
313  int j=0;
314  for(; j<comp; ++j) {
315  DDName cname(dd_get_name(is));
316  double fm(0);
317  is >> fm;
318  DDMaterial constituent(cname);
319  m.addMaterial(constituent,fm);
320  }
321  }
322  else { // elementary material
323  DDMaterial m(dn,z,a,d);
324  }
325  }
326 }
327 
328 void dd_stream_booleans(std::ostream& os, DDSolid s, DDSolidShape /*sh*/)
329 {
330  DDBooleanSolid b(s);
331  DDRotation temprot = b.rotation();
332  if(!temprot.isDefined().second) {
333  temprot = DDRotation();
334  edm::LogError("DDStreamer") << "DDStreamer::dd_stream_booleans(): solid=" << s.name() << " has no rotation. Using unit-rot." << std::endl;
335  }
336  nameout(os,temprot.name());
337  // binary output of the translation std::vector
338  os << ' ' << B(b.translation().x()) // << ' '
339  << B(b.translation().y()) // << ' '
340  << B(b.translation().z()) << ' ';
341  nameout(os,b.solidA().name());
342  os << ' ';
343  nameout(os,b.solidB().name());
344 }
345 
346 void dd_stream_reflected(std::ostream & os, DDSolid s)
347 {
348  DDReflectionSolid ref(s);
349  nameout(os,ref.unreflected().name());
350 }
351 
353 {
354  std::ostream & os = *o_;
355  DDSolid::iterator<DDSolid> it(DDSolid::begin()), ed(DDSolid::end());
356  size_t no = dd_count(DDSolid());
357  os << no << std::endl;
358  for (; it != ed; ++it) {
359  if (! it->isDefined().second) continue;
360  const DDSolid & s = *it;
361  os << "--Solid: " << s.name() << ' ' << DDSolidShapesName::name(s.shape()) << " @ ";
362  nameout(os,s.name());
363  os << ' ' << s.shape() << ' ';
364  switch (s.shape()) {
365  case ddunion: case ddsubtraction: case ddintersection:
366  dd_stream_booleans(os, s, s.shape());
367  break;
368  case ddreflected:
369  dd_stream_reflected(os, s);
370  break;
371  default:
372  size_t ps = s.parameters().size();
373  os << ps;
374  const std::vector<double> & p = s.parameters();
375  os << ' ';
376  os.write((char*)(&(*p.begin())),ps*sizeof(double));
377  /*
378  std::vector<double>::const_iterator it(p.begin()), ed(p.end());
379  for (; it != ed; ++it) {
380  os << ' ' << *it;
381  }
382  */
383  }
384  os << std::endl;
385  }
386 }
387 
388 
389 
390 void dd_get_boolean_params(std::istream & is, DDRotation & r, DDTranslation & t, DDSolid & a, DDSolid & b)
391 {
392  DDName n = dd_get_name(is);
393  r = DDRotation(n);
394  //double x(0), y(0), z(0);
395  B x,y,z;
396  char cr = is.get();
397  if(cr != ' ')
398  throw cms::Exception("DDException") << "DDStreamer::get_boolean_param(): inconsistent sequence! no blank delimiter before trans!";
399  is >> x;
400  is >> y;
401  is >> z;
402  t = DDTranslation(x.val_,y.val_,z.val_);
403  n = dd_get_name(is);
404  a = DDSolid(n);
405  n = dd_get_name(is);
406  b = DDSolid(n);
407 }
408 
410 {
411  std::istream & is = *i_;
412  //DDSolid::clear();
413  size_t n=0;
414  is >> n;
415  size_t i=0;
416  for (; i < n; ++i) { // Solids
417  is.ignore(1000,'@');
418  DDName dn = dd_get_name(is);
419 
420  size_t sp(0);
421  is >> sp;
422  DDSolidShape shape = DDSolidShape(sp);
423 
424  // boolean solids
425  if ( (shape==ddunion) | (shape==ddsubtraction) || (shape==ddintersection) ) {
426  DDRotation r;
428  DDSolid a;
429  DDSolid b;
430  dd_get_boolean_params(is,r,t,a,b);
431  switch (shape) {
432  case ddunion:
433  DDSolidFactory::unionSolid(dn,a,b,t,r);
434  break;
435  case ddintersection:
436  DDSolidFactory::intersection(dn,a,b,t,r);
437  break;
438  case ddsubtraction:
439  DDSolidFactory::subtraction(dn,a,b,t,r);
440  break;
441  default:
442  throw cms::Exception("DDException") << "DDStreamer::solids_read(): messed up in boolean solid reading!";
443  }
444  }
445 
446  // reflection solids
447  else if (shape==ddreflected) {
448  DDName ref_nm = dd_get_name(is);
449  DDSolidFactory::reflection(dn,ref_nm);
450  }
451  else if ( (shape==ddbox ) ||
452  (shape==ddtrap) ||
453  (shape==ddcons) ||
454  (shape==ddtubs) ||
455  (shape==ddcuttubs) ||
456  (shape==ddpolycone_rz) ||
457  (shape==ddpolycone_rrz) ||
458  (shape==ddpolyhedra_rz) ||
459  (shape==ddpolyhedra_rrz) ||
460  (shape==ddpseudotrap) ||
461  (shape==ddshapeless) )
462  {
463  // read in the solid's parameters
464  size_t npars(0);
465  is >> npars;
466 
467  std::vector<double> p(npars);
468  if(npars) {
469  //edm::LogError("DDStreamer") << npars << flush << std::endl;
470  char c;
471  c = is.get();
472  if (c != ' ') {
473  edm::LogError("DDStreamer") << "delimiter: " << c << std::endl;
474  throw cms::Exception("DDException") << "DDStreamer::solids_read(): wrong separator in atomic for atomic solids parameters";
475  }
476  is.read((char*)&(*(p.begin())),npars*sizeof(double));
477  /*
478  size_t i(0);
479  for(; i< npars; ++i) {
480  double d(0);
481  is >> d;
482  p.push_back(d);
483  }
484  */
485  }
486  DDSolid so = DDSolid(dn,shape,p);
487  }
488  else {
489  edm::LogError("DDStreamer") << "wrong solid enum: " << shape << std::endl;
490  throw cms::Exception("DDException") << "Error in DDStreamer::solids_read(), wrong shape-enum!";
491  }
492  }
493 }
494 
496 {
497  std::ostream & os = *o_;
498  DDLogicalPart::iterator<DDLogicalPart> it(DDLogicalPart::begin()), ed(DDLogicalPart::end());
499  size_t no = dd_count(DDLogicalPart());
500  os << no << std::endl;
501  for (; it != ed; ++it) {
502  if (! it->isDefined().second) continue;
503  const DDLogicalPart & lp = *it;
504  os << "--Part: " << lp.name() << " @ ";
505  nameout(os,lp.name());
506  os << ' ' << lp.category() << ' ';
507  nameout(os,lp.material().name());
508  os << ' ';
509  nameout(os,lp.solid().name());
510  os << std::endl;
511  }
512 }
513 
514 
516 {
517  std::istream & is = *i_;
518  //DDLogicalPart::clear();
519  size_t n=0;
520  is >> n;
521  size_t i=0;
522  for (; i < n; ++i) { // LogicalParts
523  is.ignore(1000,'@');
524  DDName dn = dd_get_name(is);
525  size_t cat(0);
526  is >> cat;
528  DDName mat = dd_get_name(is);
529  DDName sol = dd_get_name(is);
530  DDLogicalPart lp(dn,mat,sol,categ);
531  }
532 }
533 
534 void dd_rot_bin_out(std::ostream & os, const DDRotationMatrix & rm)
535 {
536  double v[9];
537  rm.GetComponents(v,v+9);
538  for (int i=0;i<9;i++)
539  os << B(v[i]);
540 }
541 
542 void dd_rot_out(std::ostream & os, const DDRotation & r) {
543  os << "--Rot: " << r.name() << " @ ";
544  nameout(os,r.name());
545  os << ' ';
546  const DDRotationMatrix & rm = *(r.rotation());
547 /*
548  os << ' ' << B(rep.xx_) << ' ' << B(rep.xy_) << ' ' << B(rep.xz_) << ' '
549  << B(rep.yx_) << ' ' << B(rep.yy_) << ' ' << B(rep.yz_) << ' '
550  << B(rep.zx_) << ' ' << B(rep.zy_) << ' ' << B(rep.zz_) << std::endl;
551 */
552  dd_rot_bin_out(os,rm);
553  os << std::endl;
554 }
555 
557 {
558  std::ostream & os = *o_;
559  DDRotation::iterator<DDRotation> it(DDRotation::begin()), ed(DDRotation::end());
560  size_t no = dd_count(DDRotation());
561  os << no << std::endl;
562  //DDName ano;
563  for (; it != ed; ++it) {
564  if (! it->isDefined().second) continue;
565  const DDRotation & r = *it;
566  //if (r.name().id() == ano.id()) {
567  // continue;
568  //}
569  dd_rot_out(os,r);
570  }
571 }
572 
573 
574 void dd_rot_bin_in(std::istream & is, DDRotationMatrix & r)
575 {
576  double v[9];
577  B w;
578  for (int i=0; i<9;i++) {
579  is >> w; v[i]=w.val_;
580  }
581  r.SetComponents(v,v+9);
582 }
583 
585 {
586  std::istream & is = *i_;
587  //DDRotation::clear();
588  size_t n=0;
589  is >> n;
590  size_t i=0;
591  for (; i < n; ++i) { // Rotations
592  is.ignore(1000,'@');
593  DDName dn = dd_get_name(is);
594  char c = is.get();
595  if (c != ' ') {
596  throw cms::Exception("DDException") << "DDStreamer::rots_read(): inconsitency! no blank separator found!";
597  }
598 
600  dd_rot_bin_in(is,*rm);
601  DDRotation ddr = DDRotation(dn,rm);
602  }
603 }
604 
606 {
607  DDCompactView cpv;
608  const DDCompactView::graph_type & g = cpv.graph();
609  DDCompactView::graph_type::const_iterator it = g.begin_iter();
610  DDCompactView::graph_type::const_iterator ed = g.end_iter();
611  std::ostream & os = *o_;
612  // first the root
613  DDLogicalPart rt = DDRootDef::instance().root();
614  os << "--Root: @ ";
615  nameout(os,rt.name());
616  os << std::endl;
617  //os << g.edge_size() << std::endl;
618  DDCompactView::graph_type::const_iterator iit = g.begin_iter();
619  DDCompactView::graph_type::const_iterator eed = g.end_iter();
620  size_t count(0);
621  for(; iit != eed; ++iit) {
622  ++count;
623  }
624  os << count << std::endl;
625  count=0;
626  DDName unit_rot_name;
627  DDRotationMatrix unit_rot;
628  for(; it != ed; ++it) {
629  os << "--Pos[" << count << "]: @ "; ++count;
630  //const DDLogicalPart & fr = it->from();
631  nameout(os, it->from().name());
632  os << ' ';
633  nameout(os, it->to().name());
634  os << ' ' << it->edge()->copyno_;
635  const DDTranslation & tr = it->edge()->translation();
636  //os << ' ' << B(tr.x()) << ' ' << B(tr.y()) << ' ' << B(tr.z());
637  os << ' ' << B(tr.x()) << B(tr.y()) << B(tr.z());
638  const DDRotation & ro = it->edge()->rot_;
639  os << ' ';
640  /* if it's an anonymous rotation stemming from an AlgoPosPart
641  then it's id must be the one of a unit rotation AND
642  it must be defined at this point AND it must not be the
643  unit rotation.
644  A character identifier is issues to mark the type of the rotation:
645  a ... anonymous rotation, followed by the binary numbers of the matrix
646  u ... unit-rotation matrix, no values following
647  r ... regular defined rotation-matrix (named rotation matrix) followed by name-id
648  */
649  if (ro.name() == unit_rot_name) {
650  if(ro.isDefined().second) {
651  if(*(ro.rotation()) != unit_rot) {
652  os << "a ";
653  dd_rot_bin_out(os,*(ro.rotation()));
654  }
655  else {
656  os << "u ";
657  }
658  }
659  }
660  else {
661  os << "r ";
662  nameout(os, ro.name());
663  }
664  os << std::endl;
665  }
666 
667 }
668 
669 
671 {
672  std::istream & is = *i_;
673  is.ignore(1000,'@');
674  DDName rtname = dd_get_name(is);
675  DDLogicalPart root(rtname);
676  DDRootDef::instance().set(root);
677  size_t n=0;
678  is >> n;
679  size_t i=0;
680  DDCompactView cpv;
682  // DDPositioner pos_(&cpv);
683  //LogDebug << "===== GRAPH SIZE = " << g.size() << " ======" << std::endl << std::endl;
684  if (g.size()) {
685  edm::LogWarning("DDStreamer") << std::endl;
686  edm::LogWarning("DDStreamer") << "DDStreamer::pos_read(): The CompactView already contains some position information." << std::endl
687  << " It may cause an inconsistent geometry representation!" << std::endl << std::endl;
688  throw cms::Exception("DDException") << "DDStreamer::pos_read() failed; CompactView has already been populated by another data source";
689  }
690  for (; i < n; ++i) { // Positions
691  is.ignore(1000,'@');
692  DDName from(dd_get_name(is));
693  DDName to(dd_get_name(is));
694  std::string cp;
695  is >> cp;
696  char cr = is.get();
697  if (cr != ' ') throw cms::Exception("DDException") << "DDStreamer::pos_read(): inconsistent sequence! no blank delimiter found!";
698  //double x,y,z;
699  B x,y,z;
700  is >> x;
701  is >> y;
702  is >> z;
703  DDTranslation t(x.val_,y.val_,z.val_);
704  is.ignore();
705  char rottype = is.get();
707  //DDName rotname;
708  DDRotation rot;
709  switch(rottype) {
710  case 'a': // anonymous rotation
711  is.ignore();
712  matrix = new DDRotationMatrix;
713  dd_rot_bin_in(is,*matrix);
714  rot = DDanonymousRot(matrix);
715  break;
716  case 'u': // unit rotation
717  break;
718  case 'r': // regular (named) rotation
719  rot = DDRotation(dd_get_name(is));
720  break;
721  default:
722  std::string message = "DDStreamer::pos_read(): could not determine type of rotation\n";
723  throw cms::Exception("DDException") << message;
724  }
725  //DDName rot(dd_get_name(is));
726  cpv.position(DDLogicalPart(to),DDLogicalPart(from),cp,t,rot);
727  }
728 }
729 
730 /*
731 void dd_ps_out(std::ostream & os, DDPartSelection* p)
732 {
733  size_t i(0),j(p->size());
734  os << ' ' << j << ' ';
735  for (; i<j; ++i) {
736  nameout(os,(*p)[j].lp_.name());
737  os << ' ';
738 
739  }
740 }
741 
742 void DDStreamer::specs_write()
743 {
744  std::ostream & os = *o_;
745  DDLogicalPart::iterator<DDLogicalPart> it(DDLogicalPart::begin()), ed(DDLogicalPart::end());
746  size_t no = DDLogicalPart::size();
747  os << no << std::endl;
748  for (; it != ed; ++it) {
749  const DDLogicalPart & lp = *it;
750  const std::vector< std::pair<DDPartSelection*,DDsvalues_type> > & sp = lp.attachedSpecifics();
751  if ((size_t s = sp.size())) {
752  os << "--Specs " << lp.name() << " @ " << s << ' ';
753  size_t j=0;
754  for (; j<s; ++j) {
755  dd_ps_out(os,s[j].first);
756  DDsvalues_type* sv = s[j].second;
757  os << ' ' << sv->size() << ' ';
758  dd_sv_out(os,sv);
759  }
760  }
761 }
762 */
763 
765 {
766  std::ostream & os = *o_;
767  DDSpecifics::iterator<DDSpecifics> it(DDSpecifics::begin()), ed(DDSpecifics::end());
768  size_t no = dd_count(DDSpecifics());
769  os << no << std::endl;
770  for (; it != ed; ++it) {
771  if (! it->isDefined().second) continue;
772  const DDSpecifics & sp = *it;
773  os << "--Spec: @ ";
774  nameout(os,sp.name());
775  os << ' ' << sp.selection().size() << std::endl;
776  std::vector<DDPartSelection>::const_iterator sit(sp.selection().begin()), sed(sp.selection().end());
777  for (; sit != sed; ++sit) {
778  os << *sit << std::endl;
779  }
780  os << sp.specifics().size() << std::endl;
781  DDsvalues_type::const_iterator vit(sp.specifics().begin()), ved(sp.specifics().end());
782  for (; vit != ved; ++vit) {
783  const DDValue & v = vit->second;
784  os << ' ' << '"' << v.name() << '"' << ' ';
785  if (v.isEvaluated()) {
786  os << 1 << ' ';
787  }
788  else {
789  os << 0 << ' ';
790  }
791  os << v.size() << ' ';
792  if (v.isEvaluated()) {
793  size_t s=v.size();
794  size_t i=0;
795  for (; i<s; ++i) {
796  os << '"' << v[i].first << '"' << ' ' << v[i].second << ' ';
797  }
798  }
799  else {
800  size_t s=v.size();
801  size_t i=0;
802  const std::vector<std::string> & vs = v.strings();
803  for (; i<s; ++i) {
804  os << '"' << vs[i] << '"' << ' ';
805  }
806  }
807  os << std::endl;
808 
809  }
810  }
811 }
812 
814 {
815  std::istream & is = *i_;
816  //DDSpecifics::clear();
817  size_t n=0;
818  is >> n;
819  size_t i=0;
820  for (; i < n; ++i) { // Specifics
821  is.ignore(1000,'@');
822  DDName sn(dd_get_name(is));
823  size_t nps(0);
824  is >> nps;
825  size_t ii=0;
826  std::vector<std::string> ps;
827  is.ignore(100,'\n');
828  for (; ii < nps; ++ii) {
829  std::string s;
830  getline(is,s);
831  ps.push_back(s);
832  }
833  is >> nps;
834  ii=0;
835  DDsvalues_type sv;
836  for(; ii<nps; ++ii) {
837  std::string name = dd_get_delimit(is,'"');
838  bool evl(false);
839  is >> evl;
840  size_t no(0);
841  is >> no;
842  std::vector<DDValuePair> valv;
843  DDValue result;
844  if (evl) {
845  size_t iii=0;
846  for(; iii<no; ++iii) {
847  std::string strv = dd_get_delimit(is,'"');
848  double dblv(0);
849  is >> dblv;
850  DDValuePair valp(strv,dblv);
851  valv.push_back(valp);
852  }
853  result = DDValue(name,valv);
854  result.setEvalState(true);
855  }
856  else {
857  size_t iii=0;
858  for(; iii<no; ++iii) {
859  std::string strv = dd_get_delimit(is,'"');
860  DDValuePair valp(strv,0);
861  valv.push_back(valp);
862  }
863  result = DDValue(name,valv);
864  result.setEvalState(false);
865  }
866  sv.push_back(DDsvalues_Content_type(result,result));
867  }
868  std::sort(sv.begin(),sv.end());
869  DDSpecifics sp(sn,ps,sv,false);
870  }
871 }
872 
873 
875 {
876  std::ostream & os = *o_;
878  ClhepEvaluator * eval = dynamic_cast<ClhepEvaluator*>(&ev);
879  if (eval){
880  const std::vector<std::string> & vars = eval->variables();
881  const std::vector<std::string> & vals = eval->values();
882  if (vars.size() != vals.size()) {
883  throw cms::Exception("DDException") << "DDStreamer::vars_write(): different size of variable names & values!";
884  }
885  size_t i(0), s(vars.size());
886  os << s << std::endl;
887  for (; i<s; ++i) {
888  os << '"' << vars[i] << '"' << ' '
889  << '"' << vals[i] << '"' << std::endl;
890  }
891  }
892  else {
893  throw cms::Exception("DDException") << "DDStreamer::vars_write(): expression-evaluator is not a ClhepEvaluator-implementation!";
894  }
895 }
896 
897 
899 {
900  std::istream & is = *i_;
902  ClhepEvaluator * eval = dynamic_cast<ClhepEvaluator*>(&ev);
903  if (eval){
904  size_t n(0);
905  is >> n;
906  size_t i(0);
907 
908  for(; i<n; ++i) {
911  eval->set(name,value);
912  }
913  }
914  else {
915  throw cms::Exception("DDException") << "DDStreamer::vars_write(): expression-evaluator is not a ClhepEvaluator-implementation!";
916  }
918 }
919 
920 
void materials_write()
write all instances of DDMaterial
Definition: DDStreamer.cc:269
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54
id_type id() const
Definition: DDName.h:58
void solids_write()
write all instances of DDSolid
Definition: DDStreamer.cc:352
adj_list::size_type size() const
Definition: adjgraph.h:201
double a() const
returns the atomic mass
Definition: DDMaterial.cc:97
void dd_stream_reflected(std::ostream &os, DDSolid s)
Definition: DDStreamer.cc:346
const DDRotationMatrix * rotation() const
Returns the read-only rotation-matrix.
Definition: DDTransform.h:88
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:146
def_type isDefined() const
Definition: DDBase.h:110
void read()
populate DDD transient objects from the std::istream refetrred to by member i_
Definition: DDStreamer.cc:136
const N & name() const
Definition: DDBase.h:78
void dd_get_boolean_params(std::istream &is, DDRotation &r, DDTranslation &t, DDSolid &a, DDSolid &b)
Definition: DDStreamer.cc:390
const double w
Definition: UKUtility.cc:23
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
DDEnums::Category category(void) const
Returns the categorization of the DDLogicalPart (sensitive detector element, cable, ...)
double_binary B
Definition: DDStreamer.cc:248
void pos_write()
write the graph structure of DDCompactView::graph()
Definition: DDStreamer.cc:605
void dd_rot_bin_in(std::istream &is, DDRotationMatrix &r)
Definition: DDStreamer.cc:574
DDSolidShape
Definition: DDSolidShapes.h:6
const graph_type & graph() const
Provides read-only access to the data structure of the compact-view.
void position(const DDLogicalPart &self, const DDLogicalPart &parent, std::string copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=NULL)
void vars_write()
write the dictionary of ClhepEvaluator
Definition: DDStreamer.cc:874
void specs_write()
write all instances of DDSpecifics
Definition: DDStreamer.cc:764
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:104
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:16
void names_read()
read all instances of DDName
Definition: DDStreamer.cc:204
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:195
bool ev
std::string dd_get_delimit(std::istream &is, char d)
Definition: DDStreamer.cc:81
void parts_write()
write all instances of DDLogicalPart
Definition: DDStreamer.cc:495
virtual ~DDStreamer()
does nothing; usefull only if another streamer derives from DDStreamer
Definition: DDStreamer.cc:64
DDTranslation translation(void) const
Definition: DDSolid.cc:542
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
void dd_rot_bin_out(std::ostream &os, const DDRotationMatrix &rm)
Definition: DDStreamer.cc:534
type of data representation of DDCompactView
Definition: DDCompactView.h:90
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
std::ostream & operator<<(std::ostream &os, double_binary b)
Definition: DDStreamer.cc:250
A DDSolid represents the shape of a part.
Definition: DDSolid.h:37
DDSolid solidB(void) const
Definition: DDSolid.cc:554
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
DDRotation DDanonymousRot(DDRotationMatrix *rot)
Defines a anonymous rotation or rotation-reflection matrix.
Definition: DDRotation.cc:187
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:64
DDName dd_get_name(std::istream &is)
Definition: DDStreamer.cc:108
void vars_read()
read the dictionlary of ClhepEvaluator
Definition: DDStreamer.cc:898
bool isEvaluated(void) const
true, if values are numerical evaluated; else false.
Definition: DDValue.cc:201
std::map< std::pair< std::string, std::string >, id_type > Registry
Definition: DDName.h:24
int addMaterial(const DDMaterial &m, double fm)
adds a material to the mixture proportional to its fraction-mass fm.
Definition: DDMaterial.cc:75
void write()
stream all DDD transient objects to the std::ostream referred to by member o_
Definition: DDStreamer.cc:126
static value_type & instance()
double z() const
retruns the atomic number
Definition: DDMaterial.cc:103
void solids_read()
read all instances of DDSolid
Definition: DDStreamer.cc:409
std::istream * i_
Definition: DDStreamer.h:126
static const char *const name(DDSolidShape s)
Definition: DDSolidShapes.h:22
DDSolid unreflected(void) const
Definition: DDSolid.cc:287
def cat(path)
Definition: eostools.py:400
double_binary(double d)
Definition: DDStreamer.cc:243
static DDSolid intersection(const DDName &name, const DDSolid &a, const DDSolid &b, const DDTranslation &t, const DDRotation &r)
Definition: DDSolid.cc:785
DDRotation rotation(void) const
Definition: DDSolid.cc:536
void dd_stream_booleans(std::ostream &os, DDSolid s, DDSolidShape)
Definition: DDStreamer.cc:328
void dd_rot_out(std::ostream &os, const DDRotation &r)
Definition: DDStreamer.cc:542
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:20
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:91
void specs_read()
read all instances of
Definition: DDStreamer.cc:813
Category
Definition: DDEnums.h:7
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
const std::vector< std::string > & variables() const
access to the clhep-implementation of the dictionary variables
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:140
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
const_iterator begin_iter() const
Definition: adjgraph.h:190
#define end
Definition: vmac.h:37
const std::vector< std::string > & values() const
static void defineId(const std::pair< std::string, std::string > &, id_type id)
register pre-defined ids
Definition: DDName.cc:66
std::istream & operator>>(std::istream &is, double_binary &b)
Definition: DDStreamer.cc:260
ii
Definition: cuy.py:588
const std::vector< std::string > & strings() const
a reference to the std::string-valued values stored in the given instance of DDValue ...
Definition: DDValue.h:61
size_t dd_count(const T &)
Definition: DDStreamer.cc:228
DDSolid solidA(void) const
Definition: DDSolid.cc:548
void rots_read()
read all instances of DDRotation
Definition: DDStreamer.cc:584
void names_write()
write all instances of DDName
Definition: DDStreamer.cc:186
void parts_read()
read all instances of DDLogicalPart
Definition: DDStreamer.cc:515
std::vector< Registry::const_iterator > IdToName
Definition: DDName.h:25
void pos_read()
read the graph structure for DDCompactView::graph()
Definition: DDStreamer.cc:670
double density() const
returns the density
Definition: DDMaterial.cc:109
static DDSolid subtraction(const DDName &name, const DDSolid &a, const DDSolid &b, const DDTranslation &t, const DDRotation &r)
Definition: DDSolid.cc:776
static void createConstantsFromEvaluator()
creates all DDConstants from the variables of the ClhepEvaluator
Definition: DDConstant.cc:38
double b
Definition: hdecay.h:120
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:85
const DDsvalues_type & specifics() const
Reference to the user-data attached to all nodes selected by the selections-strings given through sel...
Definition: DDSpecifics.cc:49
static DDSolid reflection(const DDName &name, const DDSolid &s)
Definition: DDSolid.cc:942
void materials_read()
read all instances of DDMaterial
Definition: DDStreamer.cc:295
std::ostream * o_
Definition: DDStreamer.h:125
DDName dd_get_name_string(std::istream &is)
Definition: DDStreamer.cc:92
#define begin
Definition: vmac.h:30
void nameout(std::ostream &o, const DDName &n)
Definition: DDStreamer.cc:120
double a
Definition: hdecay.h:121
void rots_write()
write all instances of DDRotation
Definition: DDStreamer.cc:556
void set(const std::string &ns, const std::string &name, const std::string &exprValue)
unsigned int size() const
the size of the stored value-pairs (std::string,double)
Definition: DDValue.h:68
static DDSolid unionSolid(const DDName &name, const DDSolid &a, const DDSolid &b, const DDTranslation &t, const DDRotation &r)
Definition: DDSolid.cc:767
DDStreamer()
constructs a streamer object with yet undefined std::istream and std::ostream
Definition: DDStreamer.cc:37
Definition: sp.h:21
rm
Definition: submit.py:76
long double T
void nameout_strings(std::ostream &o, const DDName &n)
Definition: DDStreamer.cc:115
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
DDsvalues_type::value_type DDsvalues_Content_type
Definition: DDsvalues.h:21
Interface to attach user specific data to nodes in the expanded-view.
Definition: DDSpecifics.h:42
const_iterator end_iter() const
Definition: adjgraph.h:192
const std::vector< DDPartSelection > & selection() const
Gives a reference to the collection of part-selections.
Definition: DDSpecifics.cc:44