test
CMS 3D CMS Logo

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