CMS 3D CMS Logo

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