CMS 3D CMS Logo

DDStreamer.cc

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

Generated on Tue Jun 9 17:32:16 2009 for CMSSW by  doxygen 1.5.4