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