CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DetectorDescription/OfflineDBLoader/src/GeometryInfoDump.cc

Go to the documentation of this file.
00001 #include <DetectorDescription/OfflineDBLoader/interface/GeometryInfoDump.h>
00002 
00003 #include <DetectorDescription/Core/interface/DDValue.h>
00004 #include <DetectorDescription/Core/interface/DDSpecifics.h>
00005 #include <DetectorDescription/Core/interface/DDPartSelection.h>
00006 #include "DetectorDescription/Core/interface/DDName.h"
00007 
00008 #include <fstream>
00009 #include <cmath>
00010 #include <iomanip>
00011 #include <vector>
00012 #include <map>
00013 #include <sstream>
00014 #include <set>
00015 
00016 GeometryInfoDump::GeometryInfoDump () { }
00017 
00018 GeometryInfoDump::~GeometryInfoDump () { }
00019   
00020 
00021 void GeometryInfoDump::dumpInfo ( bool dumpHistory, bool dumpSpecs, bool dumpPosInfo
00022                                   , const DDCompactView& cpv, std::string fname, int nVols ) {
00023   fname = "dump" + fname;
00024   DDExpandedView epv(cpv);
00025   std::cout << "Top Most LogicalPart =" << epv.logicalPart() << std::endl;
00026   if ( dumpHistory || dumpPosInfo) {
00027     if ( dumpPosInfo ) {
00028       std::cout << "After the GeoHistory in the output file dumpGeoHistoryOnRead you will see x, y, z, r11, r12, r13, r21, r22, r23, r31, r32, r33" << std::endl;
00029     }
00030     typedef DDExpandedView::nav_type nav_type;
00031     typedef std::map<nav_type,int> id_type;
00032     id_type idMap;
00033     int id=0;
00034     std::ofstream dump(fname.c_str());
00035     bool notReachedDepth(true);
00036     do {
00037       nav_type pos = epv.navPos();
00038       idMap[pos]=id;
00039       //      dump << id 
00040       dump << " - " << epv.geoHistory();
00041       DD3Vector x, y, z;
00042       epv.rotation().GetComponents(x,y,z);
00043       if ( dumpPosInfo ) {
00044         dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.translation().x();
00045         dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.translation().y();
00046         dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.translation().z();
00047         //             dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().thetaX()/deg;
00048         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().phiX()/deg;
00049         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().thetaY()/deg;
00050         //             dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().phiY()/deg;
00051         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().thetaZ()/deg;
00052         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().phiZ()/deg;
00053         
00054         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().xx();
00055         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().xy();
00056         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().xz();
00057         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().yx();
00058         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().yy();
00059         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().yz();
00060         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().zx();
00061         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().zy();
00062         //          dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().zz();
00063         
00064         dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
00065         dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
00066         dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
00067         dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
00068         dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
00069         dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
00070         dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
00071         dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
00072         dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z();
00073       }
00074       dump << std::endl;;
00075       ++id;
00076       if ( nVols != 0 && id > nVols ) notReachedDepth = false;
00077     } while (epv.next() && notReachedDepth);
00078     dump.close();
00079   }
00080   if ( dumpSpecs ) {
00081     // dump specifics at every compact-view nodes to have the most detailed "true" 
00082     // final destination of the DDSpecifics
00083     std::string dsname = "dumpSpecs" + fname;
00084     std::ofstream dump(dsname.c_str());
00085 // <<<<<<< GeometryInfoDump.cc
00086     DDCompactView::DDCompactView::graph_type gra = cpv.graph();
00087     std::set<DDLogicalPart> lpStore;
00088     typedef  DDCompactView::graph_type::const_adj_iterator adjl_iterator;
00089     adjl_iterator git = gra.begin();
00090     adjl_iterator gend = gra.end();        
00091     DDCompactView::graph_type::index_type i=0;
00092     git = gra.begin();
00093     for (; git != gend; ++git) 
00094     {
00095       const DDLogicalPart & ddLP = gra.nodeData(git);
00096       if ( lpStore.find(ddLP) != lpStore.end() && ddLP.attachedSpecifics().size() != 0 ) {
00097         dump << ddLP.toString() << ": ";
00098         dumpSpec( ddLP.attachedSpecifics(), dump );
00099         //      dumpSpec( ddLP.valueToPartSelectors(), dump );
00100       }
00101       lpStore.insert(ddLP);
00102 
00103       ++i;
00104       if (git->size()) 
00105         {
00106           // ask for children of ddLP  
00107           DDCompactView::graph_type::edge_list::const_iterator cit  = git->begin();
00108           DDCompactView::graph_type::edge_list::const_iterator cend = git->end();
00109           for (; cit != cend; ++cit) 
00110             {
00111               const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
00112               if (lpStore.find(ddcurLP) != lpStore.end() && ddcurLP.attachedSpecifics().size() != 0 ) {
00113                 dump << ddcurLP.toString() << ": ";
00114                 dumpSpec( ddcurLP.attachedSpecifics(), dump );
00115                 //              dumpSpec( ddcurLP.valueToPartSelectors(), dump );
00116               }
00117               lpStore.insert(ddcurLP);
00118             } // iterate over children
00119         } // if (children)
00120     } // iterate over graph nodes  
00121     dump.close();
00122 // =======
00123 //     DDCompactView::DDCompactView::graph_type gra = cpv.graph();
00124 //     std::vector<std::pair< DDPartSelection*, DDsvalues_type* > > specStore;
00125 //     std::set<DDLogicalPart> lpStore;
00126 //     typedef  DDCompactView::graph_type::const_adj_iterator adjl_iterator;
00127 //     adjl_iterator git = gra.begin();
00128 //     adjl_iterator gend = gra.end();        
00129 //     DDCompactView::graph_type::index_type i=0;
00130 //     git = gra.begin();
00131 //     for (; git != gend; ++git) 
00132 //     {
00133 //       const DDLogicalPart & ddLP = gra.nodeData(git);
00134 //       if ( lpStore.find(ddLP) != lpStore.end() && ddLP.attachedSpecifics().size() != 0 ) {
00135 //      dump << ddLP.toString() << " : " << std::endl;
00136 //      specStore.reserve(specStore.size()+ddLP.attachedSpecifics().size());
00137 //      std::copy(ddLP.attachedSpecifics().begin(), ddLP.attachedSpecifics().end(), std::back_inserter(specStore));//, specStore.end()); //
00138 //      std::vector<std::pair< DDPartSelection*, DDsvalues_type*> >::const_iterator bit(ddLP.attachedSpecifics().begin()), eit(ddLP.attachedSpecifics().end());
00139 //      for ( ; bit != eit; ++bit ) {
00140 //        // DDsvalues_type is typedef std::vector< std::pair<unsigned int, DDValue> > DDsvalues_type;  
00141 //        DDsvalues_type::iterator bsit(bit->second->begin()), bseit(bit->second->end());
00142 //        for ( ; bsit != bseit; ++bsit ) {
00143 //          dump << bsit->second.name() << " ";
00144 //          dump << ( bsit->second.isEvaluated() ?  "evaluated" : "NOT eval." );
00145 //          const std::vector<std::string>& strs = bsit->second.strings();
00146 //          std::vector<double> ldbls;
00147 //          ldbls.resize(strs.size(), 0.0);
00148 //          if ( bsit->second.isEvaluated() ) {
00149 //            ldbls = bsit->second.doubles();
00150 //          }
00151 //          if ( strs.size() != ldbls.size() ) std::cout << "CRAP! " << bsit->second.name() << " does not have equal number of doubles and strings." << std::endl;
00152 //          size_t sdind(0);
00153 //          for ( ; sdind != strs.size() ; ++sdind ) {
00154 //            dump << " [" << strs[sdind] << "," << ldbls[sdind] << "]";
00155 //          }
00156 //        }
00157 //        dump << std::endl;
00158 //      }
00159 //       }
00160 //       lpStore.insert(ddLP);
00161 
00162 //       ++i;
00163 //       if (git->size()) 
00164 //      {
00165 //        // ask for children of ddLP  
00166 //        DDCompactView::graph_type::edge_list::const_iterator cit  = git->begin();
00167 //        DDCompactView::graph_type::edge_list::const_iterator cend = git->end();
00168 //        for (; cit != cend; ++cit) 
00169 //          {
00170 //            const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
00171 //            if (lpStore.find(ddcurLP) != lpStore.end() && ddcurLP.attachedSpecifics().size() != 0 ) {
00172 //              specStore.reserve(specStore.size()+ddcurLP.attachedSpecifics().size());
00173 //              std::copy(ddcurLP.attachedSpecifics().begin(), ddcurLP.attachedSpecifics().end(), std::back_inserter(specStore));
00174 //              std::vector<std::pair< DDPartSelection*, DDsvalues_type*> >::const_iterator bit(ddcurLP.attachedSpecifics().begin()), eit(ddcurLP.attachedSpecifics().end());
00175 //              dump << ddcurLP.toString() << " : " << std::endl;
00176 //              for ( ; bit != eit; ++bit ) {
00177 //                DDsvalues_type::iterator bsit(bit->second->begin()), bseit(bit->second->end());
00178 //                for ( ; bsit != bseit; ++bsit ) {
00179 //                  dump << bsit->second.name() << " ";
00180 //                  dump << ( bsit->second.isEvaluated() ? "evaluated" : "NOT eval." );
00181 //                  const std::vector<std::string>& strs = bsit->second.strings();
00182 //                  std::vector<double> ldbls;
00183 //                  ldbls.resize(strs.size(), 0.0);
00184 //                  if ( bsit->second.isEvaluated() ) {
00185 //                    ldbls = bsit->second.doubles();
00186 //                  }
00187 //                  if ( strs.size() != ldbls.size() ) std::cout << "CRAP! " << bsit->second.name() << " does not have equal number of doubles and strings." << std::endl;
00188 //                  size_t sdind(0);
00189 //                  for ( ; sdind != strs.size() ; ++sdind ) {
00190 //                    dump << " [" << strs[sdind] << "," << ldbls[sdind] << "]";
00191 //                  }
00192 //                  dump << std::endl;
00193 //                }
00194 //                dump << std::endl;
00195 //              }
00196 //            }
00197 //            lpStore.insert(ddcurLP);
00198 //          } // iterate over children
00199 //      } // if (children)
00200 //     } // iterate over graph nodes  
00201 //     std::vector<std::pair<DDPartSelection*, DDsvalues_type*> >::iterator spit(specStore.begin()), spend (specStore.end());
00202 //     for (; spit != spend; ++spit) {
00203 //       if ( !spit->isDefined().second ) continue;  
00204 //       const DDSpecifics & sp = *spit;
00205 //       dump << sp << std::endl;
00206 //     }
00207 //     dump.close();
00208 // >>>>>>> 1.12
00209    }
00210 // <<<<<<< GeometryInfoDump.cc
00211   
00212 // =======
00213 //   if ( dumpSpecs ) {
00214 //     DDSpecifics::iterator<DDSpecifics> spit(DDSpecifics::begin()), spend(DDSpecifics::end());
00215 //     // ======= For each DDSpecific...
00216 //     std::string dsname = "dumpSpecs" + fname;
00217 //     std::ofstream dump(dsname.c_str());
00218 //     for (; spit != spend; ++spit) {
00219 //       if ( !spit->isDefined().second ) continue;  
00220 //       const DDSpecifics & sp = *spit;
00221 //       dump << sp << std::endl;
00222 //     }
00223 //     dump.close();
00224 //   }
00225 // >>>>>>> 1.12
00226  }
00227 
00228 void GeometryInfoDump::dumpSpec( const std::vector<std::pair< DDPartSelection*, DDsvalues_type*> >& attspec, std::ostream& dump) {
00229   std::vector<std::pair< DDPartSelection*, DDsvalues_type*> >::const_iterator bit(attspec.begin()), eit(attspec.end());
00230   for ( ; bit != eit; ++bit ) {
00231     //  DDPartSelection is a std::vector<DDPartSelectionLevel>
00232     std::vector<DDPartSelectionLevel>::iterator psit(bit->first->begin()), pseit(bit->first->end());
00233     for ( ; psit != pseit; ++psit ) {
00234       switch ( psit->selectionType_ ) {
00235       case ddunknown:
00236         throw cms::Exception("DetectorDescriptionSpecPar") << "Can not have an unknown selection type!";
00237         break;
00238       case ddanynode:
00239         dump << "//*";
00240         break;
00241       case ddanychild:
00242         dump << "/*";
00243         break;
00244       case ddanylogp:
00245         dump << "//" << psit->lp_.toString();
00246         break;
00247       case ddanyposp:
00248         dump << "//" << psit->lp_.toString() << "[" << psit->copyno_ << "]" ;
00249         break;
00250       case ddchildlogp:
00251         dump << "/" << psit->lp_.toString();
00252         break;
00253       case ddchildposp:
00254         dump << "/" << psit->lp_.toString() << "[" << psit->copyno_ << "]" ;
00255         break;
00256       default:
00257         throw cms::Exception("DetectorDescriptionSpecPar") << "Can not end up here! default of switch on selectionTyp_";
00258       }
00259     }
00260     dump << " ";
00261     // DDsvalues_type is typedef std::vector< std::pair<unsigned int, DDValue> > DDsvalues_type;
00262     DDsvalues_type::iterator bsit(bit->second->begin()), bseit(bit->second->end());
00263     for ( ; bsit != bseit; ++bsit ) { 
00264       dump << bsit->second.name() << " ";
00265       dump << ( bsit->second.isEvaluated() ?  "eval " : "NOT eval " );
00266       size_t sdind(0);
00267       for ( ; sdind != bsit->second.strings().size() ; ++sdind ) {
00268         if (bsit->second.isEvaluated()) {
00269           dump << bsit->second.doubles()[sdind] ;
00270         } else {
00271           dump << bsit->second.strings()[sdind] ;
00272         }
00273         if (sdind != bsit->second.strings().size() - 1) dump << ", ";
00274       }
00275       if ( bsit->second.strings().size() > 0 && bsit + 1 != bseit ) dump << " | ";
00276     }
00277     if ( bit->second->size() > 0 && bit + 1 != eit) dump << " | ";
00278   }
00279   dump << std::endl;
00280 }