CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DetectorDescription/OfflineDBLoader/bin/stubs/WriteOneGeometryFromXML.cc

Go to the documentation of this file.
00001 #include "WriteOneGeometryFromXML.h"
00002 
00003 #include <FWCore/ServiceRegistry/interface/Service.h>
00004 #include <CondCore/DBOutputService/interface/PoolDBOutputService.h>
00005 #include <FWCore/Framework/interface/ESHandle.h>
00006 
00007 #include <DetectorDescription/Core/interface/DDMaterial.h>
00008 #include <DetectorDescription/Core/interface/DDTransform.h>
00009 #include <DetectorDescription/Core/interface/DDSolid.h>
00010 #include <DetectorDescription/Core/interface/DDLogicalPart.h>
00011 #include <DetectorDescription/Core/interface/DDSpecifics.h>
00012 #include <DetectorDescription/Core/interface/DDRoot.h>
00013 #include <DetectorDescription/Core/interface/DDName.h>
00014 #include <DetectorDescription/Core/interface/DDPosData.h>
00015 #include <DetectorDescription/PersistentDDDObjects/interface/DDDToPersFactory.h>
00016 
00017 #include <Geometry/Records/interface/IdealGeometryRecord.h>
00018 
00019 #include <iostream>
00020 #include <string>
00021 #include <vector>
00022 #include <map>
00023 
00024 WriteOneGeometryFromXML::WriteOneGeometryFromXML(const edm::ParameterSet& iConfig) : label_()
00025 {
00026   std::cout<<"WriteOneGeometryFromXML::WriteOneGeometryFromXML"<<std::endl;
00027   rotNumSeed_ = iConfig.getParameter<int>("rotNumSeed");
00028 }
00029 
00030 WriteOneGeometryFromXML::~WriteOneGeometryFromXML()
00031 {
00032   std::cout<<"WriteOneGeometryFromXML::~WriteOneGeometryFromXML"<<std::endl;
00033 }
00034 
00035 void
00036 WriteOneGeometryFromXML::beginRun( const edm::Run&, edm::EventSetup const& es) 
00037 {
00038   std::cout<<"WriteOneGeometryFromXML::beginRun"<<std::endl;
00039   PIdealGeometry* pgeom = new PIdealGeometry;
00040   edm::Service<cond::service::PoolDBOutputService> mydbservice;
00041   if( !mydbservice.isAvailable() ){
00042     std::cout<<"PoolDBOutputService unavailable"<<std::endl;
00043     return;
00044   }
00045 
00046   //  std::cout << "About to do...   size_t callbackToken=mydbservice->callbackToken(\"PIdealGeometry\");" << std::endl;
00047   //  size_t callbackToken=mydbservice->callbackToken("PIdealGeometry");
00048   //  std::cout << "Got back token " << callbackToken << std::endl;
00049   edm::ESTransientHandle<DDCompactView> pDD;
00050 
00051   es.get<IdealGeometryRecord>().get(label_, pDD );
00052   if (pDD.isValid()) 
00053     std::cout << "DD is Valid" << std::endl;
00054   
00055   DDCompactView::DDCompactView::graph_type gra = pDD->graph();
00056 
00057   DDDToPersFactory dddFact;    
00058   DDMaterial::iterator<DDMaterial> it(DDMaterial::begin()), ed(DDMaterial::end());
00059   PMaterial* pm;
00060   for (; it != ed; ++it) {
00061     if (! it->isDefined().second) continue;
00062     pm = dddFact.material ( *it );
00063     pgeom->pMaterials.push_back ( *pm );
00064     delete pm;
00065   }
00066 
00067   DDRotation::iterator<DDRotation> rit(DDRotation::begin()), red(DDRotation::end());
00068   PRotation* pr;
00069   DDRotation rotn(DDName("IDENTITYDB","generatedForDB"));
00070   if ( !rotn.isDefined().second ) {
00071     DDRotationMatrix* rotID = new DDRotationMatrix();
00072     DDRotation mydr = DDrot (DDName("IDENTITYDB","generatedForDB"), rotID);
00073     pr = dddFact.rotation ( mydr );
00074     pgeom->pRotations.push_back ( *pr );
00075   }
00076   for (; rit != red; ++rit) {
00077     if (! rit->isDefined().second) continue;
00078     // if it is the identity...
00079     if ( *(rit->matrix()) == *(rotn.matrix()) ) continue;
00080     pr = dddFact.rotation( *rit );
00081     pgeom->pRotations.push_back ( *pr );
00082   } 
00083 
00084 
00085   DDSolid::iterator<DDSolid> sit(DDSolid::begin()), sed(DDSolid::end());
00086   PSolid* ps;
00087   for (; sit != sed; ++sit) {
00088     if (! sit->isDefined().second) continue;  
00089     ps = dddFact.solid( *sit );
00090     pgeom->pSolids.push_back( *ps );
00091     delete ps;
00092   }
00093 
00094   // Discovered during validation:  If a user declares
00095   // a LogicalPart in the DDD XML and does not position it
00096   // in the graph, it will NOT be stored to the database
00097   // subsequently SpecPars (see below) that use wildcards
00098   // that may have selected the orphaned LogicalPart node
00099   // will be read into the DDD from the DB (not by this
00100   // code, but in the system) and so DDSpecifics will
00101   // throw a DDException.
00102   typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator;
00103   adjl_iterator git = gra.begin();
00104   adjl_iterator gend = gra.end();    
00105     
00106   DDCompactView::graph_type::index_type i=0;
00107   PLogicalPart* plp;
00108   for (; git != gend; ++git) 
00109     {
00110       const DDLogicalPart & ddLP = gra.nodeData(git);
00111       //        std::cout << ddLP << std::endl;
00112       plp = dddFact.logicalPart ( ddLP  );
00113       pgeom->pLogicalParts.push_back( *plp );
00114       delete plp;
00115       ++i;
00116       if (git->size()) 
00117         {
00118           // ask for children of ddLP  
00119           DDCompactView::graph_type::edge_list::const_iterator cit  = git->begin();
00120           DDCompactView::graph_type::edge_list::const_iterator cend = git->end();
00121           PPosPart* ppp;
00122           for (; cit != cend; ++cit) 
00123             {
00124               const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
00125               ppp = dddFact.position ( ddLP, ddcurLP, gra.edgeData(cit->second), *pgeom, rotNumSeed_ );
00126               //                std::cout << "okay after the factory..." << std::endl;
00127               pgeom->pPosParts.push_back( *ppp );
00128               //                std::cout << "okay after the push_back" << std::endl;
00129               delete ppp;
00130               //                std::cout << "okay after the delete..." << std::endl;
00131             } // iterate over children
00132         } // if (children)
00133     } // iterate over graph nodes  
00134   
00135   std::vector<std::string> partSelections;
00136   std::map<std::string, std::vector<std::pair<std::string, double> > > values;
00137   std::map<std::string, int> isEvaluated;
00138   
00139   PSpecPar* psp;
00140 
00141   DDSpecifics::iterator<DDSpecifics> spit(DDSpecifics::begin()), spend(DDSpecifics::end());
00142 
00143   // ======= For each DDSpecific...
00144   for (; spit != spend; ++spit) {
00145     if ( !spit->isDefined().second ) continue;  
00146     psp = dddFact.specpar( *spit );
00147     pgeom->pSpecPars.push_back( *psp );
00148     delete psp;
00149   } 
00150   std::cout <<" did the static work? is there a size to this string storage? " << std::endl;
00151   std::cout << " dddFact.pstrs.pStrings.size() = " << dddFact.pstrs.pStrings.size() << std::endl;
00152   pgeom->pStrings = dddFact.pstrs.pStrings;
00153   pgeom->pStartNode = DDRootDef::instance().root().toString();
00154 
00155   if ( mydbservice->isNewTagRequest("IdealGeometryRecord") ) {
00156     //    mydbservice->newValidityForNewPayload<PIdealGeometry>(pgeom, mydbservice->endOfTime(), callbackToken);
00157     mydbservice->createNewIOV<PIdealGeometry>(pgeom
00158                                               , mydbservice->beginOfTime()
00159                                               , mydbservice->endOfTime()
00160                                               , "IdealGeometryRecord");
00161   } else {
00162     std::cout << "Tag is already present." << std::endl;
00163   }
00164 }
00165 
00166 #include "FWCore/Framework/interface/MakerMacros.h"
00167 DEFINE_FWK_MODULE(WriteOneGeometryFromXML);