00001 #include "DetectorDescription/Core/interface/DDStreamer.h"
00002
00003 #include "DetectorDescription/Base/interface/Singleton.h"
00004 #include "DetectorDescription/Core/interface/DDMaterial.h"
00005 #include "DetectorDescription/Core/interface/DDSolid.h"
00006 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00007 #include "DetectorDescription/Core/interface/DDTransform.h"
00008 #include "DetectorDescription/Core/interface/DDRoot.h"
00009 #include "DetectorDescription/Core/interface/DDSpecifics.h"
00010 #include "DetectorDescription/Core/interface/DDValue.h"
00011 #include "DetectorDescription/Base/interface/DDdebug.h"
00012 #include "DetectorDescription/Core/interface/DDConstant.h"
00013 #include "DetectorDescription/Core/interface/DDPartSelection.h"
00014 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00015
00016
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018
00019 #include<iomanip>
00020
00021 DDStreamer::DDStreamer()
00022 : cpv_(0), o_(0), i_(0)
00023 {
00024 }
00025
00026 DDStreamer::DDStreamer(std::ostream & os)
00027 : cpv_(0), o_(0), i_(0)
00028 {
00029 if (os) {
00030 o_ = &os;
00031 }
00032 else {
00033 throw cms::Exception("DDException") << "DDStreamer::DDStreamer(std::ostream&): not valid std::ostream";
00034 }
00035 }
00036
00037 DDStreamer::DDStreamer(std::istream & is)
00038 : cpv_(0), o_(0), i_(0)
00039 {
00040 if (is) {
00041 i_ = &is;
00042 }
00043 else {
00044 throw cms::Exception("DDException") << "DDStreamer::DDStreamer(std::ostream&): not valid std::ostream";
00045 }
00046 }
00047
00048 DDStreamer::~DDStreamer() {}
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 std::string dd_get_delimit(std::istream & is, char d)
00066 {
00067 std::string nm;
00068 char i;
00069 while ((i=is.get()) && i != d) ;
00070 while ((i=is.get()) && i != d) {
00071 nm = nm + i;
00072 }
00073 return nm;
00074 }
00075
00076 DDName dd_get_name_string(std::istream & is)
00077 {
00078 std::string nm(dd_get_delimit(is,'"')) ;
00079 return DDName(nm,
00080 dd_get_delimit(is,'"'));
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 }
00091
00092 DDName dd_get_name(std::istream & is)
00093 {
00094 size_t id(0);
00095 is >> id;
00096 return DDName(id);
00097 }
00098
00099 void nameout_strings(std::ostream & o, const DDName & n)
00100 {
00101 o << '"' << n.name() << '"' << ' ' << '"' << n.ns() << '"' ;
00102 }
00103
00104 void nameout(std::ostream & o, const DDName & n)
00105 {
00106 o << n.id();
00107 }
00108
00109
00110 void DDStreamer::write()
00111 {
00112 if (o_ && *o_) {
00113 write(*o_);
00114 }
00115 else {
00116 throw cms::Exception("DDException") << "DDStreamer::write(): bad std::ostream";
00117 }
00118 }
00119
00120 void DDStreamer::read()
00121 {
00122 if (i_ && *i_) {
00123 read(*i_);
00124 }
00125 else {
00126 throw cms::Exception("DDException") << "DDStreamer::read(): bad std::istream";
00127 }
00128 }
00129
00130 void DDStreamer::write(std::ostream & os)
00131 {
00132 o_=&os;
00133 std::streamsize prec(os.precision());
00134 os << std::setprecision(26) << std::scientific;
00135 names_write();
00136 vars_write();
00137
00138 materials_write();
00139 solids_write();
00140 parts_write();
00141
00142 pos_write();
00143 specs_write();
00144
00145 rots_write();
00146
00147
00148 os << resetiosflags((std::ios_base::fmtflags)0);
00149 os << std::setprecision(prec);
00150 }
00151
00152
00153 void DDStreamer::read(std::istream & is)
00154 {
00155
00156 i_=&is;
00157 names_read();
00158 vars_read();
00159
00160 materials_read();
00161 solids_read();
00162 parts_read();
00163
00164 pos_read();
00165 specs_read();
00166 rots_read();
00167 }
00168
00169
00170 void DDStreamer::names_write()
00171 {
00172 DCOUT('Y', "DDStreamer::names_write()");
00173 std::ostream & os = *o_;
00174 DDName::IdToName & ids = DDI::Singleton<DDName::IdToName>::instance();
00175
00176 DDName::IdToName::const_iterator it(ids.begin()), ed(ids.end());
00177 os << ids.size() << std::endl;
00178 size_t count(0);
00179 for (; it != ed; ++it) {
00180 os << '"' << (*it)->first.first << '"' << ' '
00181 << '"' << (*it)->first.second << '"' << ' '
00182 << count << std::endl;
00183 ++count;
00184 }
00185
00186 }
00187
00188
00189 void DDStreamer::names_read()
00190 {
00191 DCOUT('Y', "DDStreamer::names_read()");
00192 std::istream & is = *i_;
00193 DDName::IdToName & ids = DDI::Singleton<DDName::IdToName>::instance();
00194 DDName::Registry & reg = DDI::Singleton<DDName::Registry>::instance();
00195
00196 size_t s;
00197 is >> s;
00198 ids.clear();
00199
00200 reg.clear();
00201 size_t i(0);
00202
00203 for (; i<s; ++i) {
00204 std::string nm(dd_get_delimit(is,'"'));
00205 std::string ns(dd_get_delimit(is,'"'));
00206 size_t id(0);
00207 is >> id;
00208 DDName::defineId(std::make_pair(nm,ns),id);
00209 }
00210 }
00211
00212
00213 template<class T>
00214 size_t dd_count(const T & )
00215 {
00216 size_t result(0);
00217 typename T::template iterator<T> it(T::begin()), ed(T::end());
00218 for (; it!=ed; ++it) {
00219 if (it->isDefined().second) {
00220 ++result;
00221 }
00222 }
00223 return result;
00224 }
00225
00226
00227 struct double_binary
00228 {
00229 explicit double_binary(double d) : val_(d) { }
00230 double_binary() : val_(0) { }
00231 double val_;
00232 };
00233
00234 typedef double_binary B;
00235
00236 std::ostream & operator<<(std::ostream & os, double_binary b)
00237 {
00238 const char * d = (const char *)(&(b.val_));
00239
00240
00241 os.write(d,sizeof(double));
00242 return os;
00243 }
00244
00245
00246 inline std::istream & operator>>(std::istream & is, double_binary & b)
00247 {
00248 char * d = (char *)(&(b.val_));
00249
00250 is.read(d,sizeof(double));
00251 return is;
00252 }
00253
00254
00255 void DDStreamer::materials_write()
00256 {
00257 DCOUT('Y', "DDStreamer::materials_write()");
00258 std::ostream & os = *o_;
00259 DDMaterial::iterator<DDMaterial> it(DDMaterial::begin()), ed(DDMaterial::end());
00260 size_t no = dd_count(DDMaterial());
00261 os << no << std::endl;
00262 for (; it != ed; ++it) {
00263 if (! it->isDefined().second) continue;
00264 const DDMaterial & m = *it;
00265 os << "--Material: " << m.name() << " @ " ;
00266 nameout(os,m.name());
00267 DCOUT('y', "write-material=" << m.name());
00268 os << ' ' << m.z() << ' ' << m.a() << ' ' << m.density() << ' ';
00269
00270 int noc = m.noOfConstituents();
00271 os << noc;
00272 int j=0;
00273 for (; j<noc; ++j) {
00274 DCOUT('y', " write-const-material=" << m.constituent(j).first.name());
00275 os << ' ';
00276 nameout(os,m.constituent(j).first.name());
00277 os << ' ' << m.constituent(j).second;
00278 }
00279 os << std::endl;
00280 }
00281 }
00282
00283
00284 void DDStreamer::materials_read()
00285 {
00286 DCOUT('Y', "DDStreamer::materials_read()");
00287 std::istream & is = *i_;
00288
00289 size_t n=0;
00290 is >> n;
00291 size_t i=0;
00292 for (; i < n; ++i) {
00293 is.ignore(1000,'@');
00294 DDName dn = dd_get_name(is);
00295 double z(0), a(0), d(0);
00296 is >> z;
00297 is >> a;
00298 is >> d;
00299 int comp(0);
00300 is >> comp;
00301 if (comp) {
00302 DDMaterial m(dn,d);
00303 DCOUT('y', "read-comp-material=" << m.name());
00304 int j=0;
00305 for(; j<comp; ++j) {
00306 DDName cname(dd_get_name(is));
00307 double fm(0);
00308 is >> fm;
00309 DDMaterial constituent(cname);
00310 DCOUT('y', " read-composite=" << constituent.name());
00311 m.addMaterial(constituent,fm);
00312 }
00313 }
00314 else {
00315 DDMaterial m(dn,z,a,d);
00316 DCOUT('y', "read-elem-material=" << m.name());
00317 }
00318 }
00319 }
00320
00321 void dd_stream_booleans(std::ostream& os, DDSolid s, DDSolidShape )
00322 {
00323 DDBooleanSolid b(s);
00324 DDRotation temprot = b.rotation();
00325 if(!temprot.isDefined().second) {
00326 temprot = DDRotation();
00327 edm::LogError("DDStreamer") << "DDStreamer::dd_stream_booleans(): solid=" << s.name() << " has no rotation. Using unit-rot." << std::endl;
00328 }
00329 nameout(os,temprot.name());
00330
00331 os << ' ' << B(b.translation().x())
00332 << B(b.translation().y())
00333 << B(b.translation().z()) << ' ';
00334 nameout(os,b.solidA().name());
00335 os << ' ';
00336 nameout(os,b.solidB().name());
00337 }
00338
00339 void dd_stream_reflected(std::ostream & os, DDSolid s)
00340 {
00341 DDReflectionSolid ref(s);
00342 nameout(os,ref.unreflected().name());
00343 }
00344
00345 void DDStreamer::solids_write()
00346 {
00347 DCOUT('Y', "DDStreamer::solids_write()");
00348 std::ostream & os = *o_;
00349 DDSolid::iterator<DDSolid> it(DDSolid::begin()), ed(DDSolid::end());
00350 size_t no = dd_count(DDSolid());
00351 os << no << std::endl;
00352 for (; it != ed; ++it) {
00353 if (! it->isDefined().second) continue;
00354 const DDSolid & s = *it;
00355 DCOUT('y', "write-solid=" << s << " enum=" << s.shape());
00356 os << "--Solid: " << s.name() << ' ' << DDSolidShapesName::name(s.shape()) << " @ ";
00357 nameout(os,s.name());
00358 os << ' ' << s.shape() << ' ';
00359 switch (s.shape()) {
00360 case ddunion: case ddsubtraction: case ddintersection:
00361 dd_stream_booleans(os, s, s.shape());
00362 break;
00363 case ddreflected:
00364 dd_stream_reflected(os, s);
00365 break;
00366 default:
00367 size_t ps = s.parameters().size();
00368 os << ps;
00369 const std::vector<double> & p = s.parameters();
00370 os << ' ';
00371 os.write((char*)(&(*p.begin())),ps*sizeof(double));
00372
00373
00374
00375
00376
00377
00378 }
00379 os << std::endl;
00380 }
00381 }
00382
00383
00384
00385 void dd_get_boolean_params(std::istream & is, DDRotation & r, DDTranslation & t, DDSolid & a, DDSolid & b)
00386 {
00387 DDName n = dd_get_name(is);
00388 r = DDRotation(n);
00389
00390 B x,y,z;
00391 char cr = is.get();
00392 if(cr != ' ')
00393 throw cms::Exception("DDException") << "DDStreamer::get_boolean_param(): inconsistent sequence! no blank delimiter before trans!";
00394 is >> x;
00395 is >> y;
00396 is >> z;
00397 t = DDTranslation(x.val_,y.val_,z.val_);
00398 n = dd_get_name(is);
00399 a = DDSolid(n);
00400 n = dd_get_name(is);
00401 b = DDSolid(n);
00402 DCOUT('y', "boolean-par: rot=" << r.name() << " t=" << t << " a=" << a.name() << " b=" << b.name());
00403 }
00404
00405 void DDStreamer::solids_read()
00406 {
00407 DCOUT('Y', "DDStreamer::solids_read()");
00408 std::istream & is = *i_;
00409
00410 size_t n=0;
00411 is >> n;
00412 size_t i=0;
00413 for (; i < n; ++i) {
00414 is.ignore(1000,'@');
00415 DDName dn = dd_get_name(is);
00416
00417 size_t sp(0);
00418 is >> sp;
00419 DDSolidShape shape = DDSolidShape(sp);
00420
00421
00422 if ( (shape==ddunion) | (shape==ddsubtraction) || (shape==ddintersection) ) {
00423 DDRotation r;
00424 DDTranslation t;
00425 DDSolid a;
00426 DDSolid b;
00427 dd_get_boolean_params(is,r,t,a,b);
00428 switch (shape) {
00429 case ddunion:
00430 DDSolidFactory::unionSolid(dn,a,b,t,r);
00431 break;
00432 case ddintersection:
00433 DDSolidFactory::intersection(dn,a,b,t,r);
00434 break;
00435 case ddsubtraction:
00436 DDSolidFactory::subtraction(dn,a,b,t,r);
00437 break;
00438 default:
00439 throw cms::Exception("DDException") << "DDStreamer::solids_read(): messed up in boolean solid reading!";
00440 }
00441 }
00442
00443
00444 else if (shape==ddreflected) {
00445 DDName ref_nm = dd_get_name(is);
00446 DDSolidFactory::reflection(dn,ref_nm);
00447 }
00448 else if ( (shape==ddbox ) ||
00449 (shape==ddtrap) ||
00450 (shape==ddcons) ||
00451 (shape==ddtubs) ||
00452 (shape==ddpolycone_rz) ||
00453 (shape==ddpolycone_rrz) ||
00454 (shape==ddpolyhedra_rz) ||
00455 (shape==ddpolyhedra_rrz) ||
00456 (shape==ddpseudotrap) ||
00457 (shape==ddshapeless) )
00458 {
00459
00460 size_t npars(0);
00461 is >> npars;
00462
00463 std::vector<double> p(npars);
00464 if(npars) {
00465
00466 char c;
00467 c = is.get();
00468 if (c != ' ') {
00469 edm::LogError("DDStreamer") << "delimiter: " << c << std::endl;
00470 throw cms::Exception("DDException") << "DDStreamer::solids_read(): wrong separator in atomic for atomic solids parameters";
00471 }
00472 is.read((char*)&(*(p.begin())),npars*sizeof(double));
00473
00474
00475
00476
00477
00478
00479
00480
00481 }
00482 DDSolid so = DDSolid(dn,shape,p);
00483 DCOUT('y', "read-solid=" << so);
00484 }
00485 else {
00486 edm::LogError("DDStreamer") << "wrong solid enum: " << shape << std::endl;
00487 throw cms::Exception("DDException") << "Error in DDStreamer::solids_read(), wrong shape-enum!";
00488 }
00489 }
00490 }
00491
00492 void DDStreamer::parts_write()
00493 {
00494 DCOUT('Y', "DDStreamer::parts_write()");
00495 std::ostream & os = *o_;
00496 DDLogicalPart::iterator<DDLogicalPart> it(DDLogicalPart::begin()), ed(DDLogicalPart::end());
00497 size_t no = dd_count(DDLogicalPart());
00498 os << no << std::endl;
00499 for (; it != ed; ++it) {
00500 if (! it->isDefined().second) continue;
00501 const DDLogicalPart & lp = *it;
00502 os << "--Part: " << lp.name() << " @ ";
00503 nameout(os,lp.name());
00504 os << ' ' << lp.category() << ' ';
00505 nameout(os,lp.material().name());
00506 os << ' ';
00507 nameout(os,lp.solid().name());
00508 os << std::endl;
00509 }
00510 }
00511
00512
00513 void DDStreamer::parts_read()
00514 {
00515 DCOUT('Y', "DDStreamer::parts_read()");
00516 std::istream & is = *i_;
00517
00518 size_t n=0;
00519 is >> n;
00520 size_t i=0;
00521 for (; i < n; ++i) {
00522 is.ignore(1000,'@');
00523 DDName dn = dd_get_name(is);
00524 size_t cat(0);
00525 is >> cat;
00526 DDEnums::Category categ = DDEnums::Category(cat);
00527 DDName mat = dd_get_name(is);
00528 DDName sol = dd_get_name(is);
00529 DDLogicalPart lp(dn,mat,sol,categ);
00530 DCOUT('y', "read-lp=" << lp);
00531 }
00532 }
00533
00534 void dd_rot_bin_out(std::ostream & os, const DDRotationMatrix & rm)
00535 {
00536 double v[9];
00537 rm.GetComponents(v,v+9);
00538 for (int i=0;i<9;i++)
00539 os << B(v[i]);
00540 }
00541
00542 void dd_rot_out(std::ostream & os, const DDRotation & r) {
00543 os << "--Rot: " << r.name() << " @ ";
00544 nameout(os,r.name());
00545 os << ' ';
00546 const DDRotationMatrix & rm = *(r.rotation());
00547 DCOUT('y', "write-rots=" << r.name());
00548
00549
00550
00551
00552
00553 dd_rot_bin_out(os,rm);
00554 os << std::endl;
00555 }
00556
00557 void DDStreamer::rots_write()
00558 {
00559 DCOUT('Y', "DDStreamer::rots_write()");
00560 std::ostream & os = *o_;
00561 DDRotation::iterator<DDRotation> it(DDRotation::begin()), ed(DDRotation::end());
00562 size_t no = dd_count(DDRotation());
00563 os << no << std::endl;
00564
00565 for (; it != ed; ++it) {
00566 if (! it->isDefined().second) continue;
00567 const DDRotation & r = *it;
00568
00569
00570
00571 dd_rot_out(os,r);
00572 }
00573 }
00574
00575
00576 void dd_rot_bin_in(std::istream & is, DDRotationMatrix & r)
00577 {
00578 double v[9];
00579 B w;
00580 for (int i=0; i<9;i++) {
00581 is >> w; v[i]=w.val_;
00582 }
00583 r.SetComponents(v,v+9);
00584 }
00585
00586 void DDStreamer::rots_read()
00587 {
00588 DCOUT('Y', "DDStreamer::rots_read()");
00589 std::istream & is = *i_;
00590
00591 size_t n=0;
00592 is >> n;
00593 size_t i=0;
00594 for (; i < n; ++i) {
00595 is.ignore(1000,'@');
00596 DDName dn = dd_get_name(is);
00597 char c = is.get();
00598 if (c != ' ') {
00599 throw cms::Exception("DDException") << "DDStreamer::rots_read(): inconsitency! no blank separator found!";
00600 }
00601
00602 DDRotationMatrix * rm = new DDRotationMatrix();
00603 dd_rot_bin_in(is,*rm);
00604 DDRotation ddr = DDRotation(dn,rm);
00605 DCOUT('y',"read-rots=" << ddr.name());
00606 }
00607 }
00608
00609 void DDStreamer::pos_write()
00610 {
00611 DCOUT('Y', "DDStreamer::pos_write()");
00612 DDCompactView cpv;
00613 const DDCompactView::graph_type & g = cpv.graph();
00614 DDCompactView::graph_type::const_iterator it = g.begin_iter();
00615 DDCompactView::graph_type::const_iterator ed = g.end_iter();
00616 std::ostream & os = *o_;
00617
00618 DDLogicalPart rt = DDRootDef::instance().root();
00619 os << "--Root: @ ";
00620 nameout(os,rt.name());
00621 os << std::endl;
00622
00623 DDCompactView::graph_type::const_iterator iit = g.begin_iter();
00624 DDCompactView::graph_type::const_iterator eed = g.end_iter();
00625 size_t count(0);
00626 for(; iit != eed; ++iit) {
00627 ++count;
00628 }
00629 os << count << std::endl;
00630 count=0;
00631 DDName unit_rot_name;
00632 DDRotationMatrix unit_rot;
00633 for(; it != ed; ++it) {
00634 os << "--Pos[" << count << "]: @ "; ++count;
00635
00636 nameout(os, it->from().name());
00637 os << ' ';
00638 nameout(os, it->to().name());
00639 os << ' ' << it->edge()->copyno_;
00640 const DDTranslation & tr = it->edge()->translation();
00641
00642 os << ' ' << B(tr.x()) << B(tr.y()) << B(tr.z());
00643 const DDRotation & ro = it->edge()->rot_;
00644 os << ' ';
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654 if (ro.name() == unit_rot_name) {
00655 if(ro.isDefined().second) {
00656 if(*(ro.rotation()) != unit_rot) {
00657 os << "a ";
00658 dd_rot_bin_out(os,*(ro.rotation()));
00659 }
00660 else {
00661 os << "u ";
00662 }
00663 }
00664 }
00665 else {
00666 os << "r ";
00667 nameout(os, ro.name());
00668 }
00669 os << std::endl;
00670 }
00671
00672 }
00673
00674
00675 void DDStreamer::pos_read()
00676 {
00677 DCOUT('Y', "DDStreamer::pos_read()");
00678 std::istream & is = *i_;
00679 is.ignore(1000,'@');
00680 DDName rtname = dd_get_name(is);
00681 DDLogicalPart root(rtname);
00682 DCOUT('y', "root is: " << root.name());
00683 DDRootDef::instance().set(root);
00684 size_t n=0;
00685 is >> n;
00686 size_t i=0;
00687 DDCompactView cpv;
00688 DDCompactView::graph_type & g = const_cast<DDCompactView::graph_type&>(cpv.graph());
00689
00690
00691 if (g.size()) {
00692 edm::LogWarning("DDStreamer") << std::endl;
00693 edm::LogWarning("DDStreamer") << "DDStreamer::pos_read(): The CompactView already contains some position information." << std::endl
00694 << " It may cause an inconsistent geometry representation!" << std::endl << std::endl;
00695 throw cms::Exception("DDException") << "DDStreamer::pos_read() failed; CompactView has already been populated by another data source";
00696 }
00697 for (; i < n; ++i) {
00698 is.ignore(1000,'@');
00699 DDName from(dd_get_name(is));
00700 DDName to(dd_get_name(is));
00701 std::string cp;
00702 is >> cp;
00703 char cr = is.get();
00704 if (cr != ' ') throw cms::Exception("DDException") << "DDStreamer::pos_read(): inconsistent sequence! no blank delimiter found!";
00705
00706 B x,y,z;
00707 is >> x;
00708 is >> y;
00709 is >> z;
00710 DDTranslation t(x.val_,y.val_,z.val_);
00711 is.ignore();
00712 char rottype = is.get();
00713 DDRotationMatrix * matrix(0);
00714
00715 DDRotation rot;
00716 switch(rottype) {
00717 case 'a':
00718 is.ignore();
00719 matrix = new DDRotationMatrix;
00720 dd_rot_bin_in(is,*matrix);
00721 rot = DDanonymousRot(matrix);
00722 break;
00723 case 'u':
00724 break;
00725 case 'r':
00726 rot = DDRotation(dd_get_name(is));
00727 break;
00728 default:
00729 std::string message = "DDStreamer::pos_read(): could not determine type of rotation\n";
00730 throw cms::Exception("DDException") << message;
00731 }
00732
00733 cpv.position(DDLogicalPart(to),DDLogicalPart(from),cp,t,rot);
00734 DCOUT('y', " pos-read: f=" << from << " to=" << to << " t=" << t << " r=" << rot);
00735 }
00736 }
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773 void DDStreamer::specs_write()
00774 {
00775 DCOUT('Y', "DDStreamer::specs_write()");
00776 std::ostream & os = *o_;
00777 DDSpecifics::iterator<DDSpecifics> it(DDSpecifics::begin()), ed(DDSpecifics::end());
00778 size_t no = dd_count(DDSpecifics());
00779 os << no << std::endl;
00780 for (; it != ed; ++it) {
00781 if (! it->isDefined().second) continue;
00782 const DDSpecifics & sp = *it;
00783 os << "--Spec: @ ";
00784 nameout(os,sp.name());
00785 os << ' ' << sp.selection().size() << std::endl;
00786 std::vector<DDPartSelection>::const_iterator sit(sp.selection().begin()), sed(sp.selection().end());
00787 for (; sit != sed; ++sit) {
00788 os << *sit << std::endl;
00789 }
00790 os << sp.specifics().size() << std::endl;
00791 DDsvalues_type::const_iterator vit(sp.specifics().begin()), ved(sp.specifics().end());
00792 for (; vit != ved; ++vit) {
00793 const DDValue & v = vit->second;
00794 os << ' ' << '"' << v.name() << '"' << ' ';
00795 if (v.isEvaluated()) {
00796 os << 1 << ' ';
00797 }
00798 else {
00799 os << 0 << ' ';
00800 }
00801 os << v.size() << ' ';
00802 if (v.isEvaluated()) {
00803 size_t s=v.size();
00804 size_t i=0;
00805 for (; i<s; ++i) {
00806 os << '"' << v[i].first << '"' << ' ' << v[i].second << ' ';
00807 }
00808 }
00809 else {
00810 size_t s=v.size();
00811 size_t i=0;
00812 const std::vector<std::string> & vs = v.strings();
00813 for (; i<s; ++i) {
00814 os << '"' << vs[i] << '"' << ' ';
00815 }
00816 }
00817 os << std::endl;
00818
00819 }
00820 }
00821 }
00822
00823 void DDStreamer::specs_read()
00824 {
00825 DCOUT('Y', "DDStreamer::specs_read()");
00826 std::istream & is = *i_;
00827
00828 size_t n=0;
00829 is >> n;
00830 size_t i=0;
00831 for (; i < n; ++i) {
00832 is.ignore(1000,'@');
00833 DDName sn(dd_get_name(is));
00834 size_t nps(0);
00835 is >> nps;
00836 size_t ii=0;
00837 std::vector<std::string> ps;
00838 is.ignore(100,'\n');
00839 for (; ii < nps; ++ii) {
00840 std::string s;
00841 getline(is,s);
00842 DCOUT('y', "specs-ps=" << s);
00843 ps.push_back(s);
00844 }
00845 is >> nps;
00846 ii=0;
00847 DDsvalues_type sv;
00848 for(; ii<nps; ++ii) {
00849 std::string name = dd_get_delimit(is,'"');
00850 bool evl(false);
00851 is >> evl;
00852 size_t no(0);
00853 is >> no;
00854 std::vector<DDValuePair> valv;
00855 DDValue result;
00856 if (evl) {
00857 size_t iii=0;
00858 for(; iii<no; ++iii) {
00859 std::string strv = dd_get_delimit(is,'"');
00860 double dblv(0);
00861 is >> dblv;
00862 DDValuePair valp(strv,dblv);
00863 valv.push_back(valp);
00864 }
00865 result = DDValue(name,valv);
00866 result.setEvalState(true);
00867 }
00868 else {
00869 size_t iii=0;
00870 for(; iii<no; ++iii) {
00871 std::string strv = dd_get_delimit(is,'"');
00872 DDValuePair valp(strv,0);
00873 valv.push_back(valp);
00874 }
00875 result = DDValue(name,valv);
00876 result.setEvalState(false);
00877 }
00878 sv.push_back(DDsvalues_Content_type(result,result));
00879 }
00880 std::sort(sv.begin(),sv.end());
00881 DDSpecifics sp(sn,ps,sv,false);
00882 DCOUT('y', " specs-read: " << sp);
00883 }
00884 }
00885
00886
00887 void DDStreamer::vars_write()
00888 {
00889 std::ostream & os = *o_;
00890 ExprEvalInterface & ev = ExprEvalSingleton::instance();
00891 ClhepEvaluator * eval = dynamic_cast<ClhepEvaluator*>(&ev);
00892 if (eval){
00893 const std::vector<std::string> & vars = eval->variables();
00894 const std::vector<std::string> & vals = eval->values();
00895 if (vars.size() != vals.size()) {
00896 throw cms::Exception("DDException") << "DDStreamer::vars_write(): different size of variable names & values!";
00897 }
00898 size_t i(0), s(vars.size());
00899 os << s << std::endl;
00900 for (; i<s; ++i) {
00901 os << '"' << vars[i] << '"' << ' '
00902 << '"' << vals[i] << '"' << std::endl;
00903 }
00904 }
00905 else {
00906 throw cms::Exception("DDException") << "DDStreamer::vars_write(): expression-evaluator is not a ClhepEvaluator-implementation!";
00907 }
00908 }
00909
00910
00911 void DDStreamer::vars_read()
00912 {
00913 DCOUT('Y', "DDStreamer::vars_read()");
00914 std::istream & is = *i_;
00915 ExprEvalInterface & ev = ExprEvalSingleton::instance();
00916 ClhepEvaluator * eval = dynamic_cast<ClhepEvaluator*>(&ev);
00917 if (eval){
00918 size_t n(0);
00919 is >> n;
00920 size_t i(0);
00921
00922 for(; i<n; ++i) {
00923 std::string name(dd_get_delimit(is,'"'));
00924 std::string value(dd_get_delimit(is,'"'));
00925 eval->set(name,value);
00926 }
00927 }
00928 else {
00929 throw cms::Exception("DDException") << "DDStreamer::vars_write(): expression-evaluator is not a ClhepEvaluator-implementation!";
00930 }
00931 DDConstant::createConstantsFromEvaluator();
00932 }
00933
00934