CMS 3D CMS Logo

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::beginJob( edm::EventSetup const& es) 
00037 {
00038   std::cout<<"WriteOneGeometryFromXML::beginJob"<<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::ESHandle<DDCompactView> pDD;
00050 
00051   es.get<IdealGeometryRecord>().get(label_, pDD );
00052 
00053   DDCompactView::graph_type gra = pDD->graph();
00054 
00055   DDDToPersFactory dddFact;    
00056   DDMaterial::iterator<DDMaterial> it(DDMaterial::begin()), ed(DDMaterial::end());
00057   PMaterial* pm;
00058   for (; it != ed; ++it) {
00059     if (! it->isDefined().second) continue;
00060     pm = dddFact.material ( *it );
00061     pgeom->pMaterials.push_back ( *pm );
00062     delete pm;
00063   }
00064 
00065   DDRotation::iterator<DDRotation> rit(DDRotation::begin()), red(DDRotation::end());
00066   PRotation* pr;
00067   DDRotation rotn(DDName("IDENTITYDB","generatedForDB"));
00068   if ( !rotn.isDefined().second ) {
00069     DDRotationMatrix* rotID = new DDRotationMatrix();
00070     DDRotation mydr = DDrot (DDName("IDENTITYDB","generatedForDB"), rotID);
00071     pr = dddFact.rotation ( mydr );
00072     pgeom->pRotations.push_back ( *pr );
00073   }
00074   for (; rit != red; ++rit) {
00075     if (! rit->isDefined().second) continue;
00076     // if it is the identity...
00077     if ( *(rit->matrix()) == *(rotn.matrix()) ) continue;
00078     pr = dddFact.rotation( *rit );
00079     pgeom->pRotations.push_back ( *pr );
00080   } 
00081 
00082 
00083   DDSolid::iterator<DDSolid> sit(DDSolid::begin()), sed(DDSolid::end());
00084   PSolid* ps;
00085   for (; sit != sed; ++sit) {
00086     if (! sit->isDefined().second) continue;  
00087     ps = dddFact.solid( *sit );
00088     pgeom->pSolids.push_back( *ps );
00089     delete ps;
00090   }
00091 
00092   // Discovered during validation:  If a user declares
00093   // a LogicalPart in the DDD XML and does not position it
00094   // in the graph, it will NOT be stored to the database
00095   // subsequently SpecPars (see below) that use wildcards
00096   // that may have selected the orphaned LogicalPart node
00097   // will be read into the DDD from the DB (not by this
00098   // code, but in the system) and so DDSpecifics will
00099   // throw a DDException.
00100   typedef graph_type::const_adj_iterator adjl_iterator;
00101   adjl_iterator git = gra.begin();
00102   adjl_iterator gend = gra.end();    
00103     
00104   graph_type::index_type i=0;
00105   PLogicalPart* plp;
00106   for (; git != gend; ++git) 
00107     {
00108       const DDLogicalPart & ddLP = gra.nodeData(git);
00109       //        std::cout << ddLP << std::endl;
00110       plp = dddFact.logicalPart ( ddLP  );
00111       pgeom->pLogicalParts.push_back( *plp );
00112       delete plp;
00113       ++i;
00114       if (git->size()) 
00115         {
00116           // ask for children of ddLP  
00117           graph_type::edge_list::const_iterator cit  = git->begin();
00118           graph_type::edge_list::const_iterator cend = git->end();
00119           PPosPart* ppp;
00120           for (; cit != cend; ++cit) 
00121             {
00122               const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
00123               ppp = dddFact.position ( ddLP, ddcurLP, gra.edgeData(cit->second), *pgeom, rotNumSeed_ );
00124               //                std::cout << "okay after the factory..." << std::endl;
00125               pgeom->pPosParts.push_back( *ppp );
00126               //                std::cout << "okay after the push_back" << std::endl;
00127               delete ppp;
00128               //                std::cout << "okay after the delete..." << std::endl;
00129             } // iterate over children
00130         } // if (children)
00131     } // iterate over graph nodes  
00132   
00133   std::vector<std::string> partSelections;
00134   std::map<std::string, std::vector<std::pair<std::string, double> > > values;
00135   std::map<std::string, int> isEvaluated;
00136   
00137   PSpecPar* psp;
00138 
00139   DDSpecifics::iterator<DDSpecifics> spit(DDSpecifics::begin()), spend(DDSpecifics::end());
00140 
00141   // ======= For each DDSpecific...
00142   for (; spit != spend; ++spit) {
00143     if ( !spit->isDefined().second ) continue;  
00144     psp = dddFact.specpar( *spit );
00145     pgeom->pSpecPars.push_back( *psp );
00146     delete psp;
00147   } 
00148   std::cout <<" did the static work? is there a size to this string storage? " << std::endl;
00149   std::cout << " dddFact.pstrs.pStrings.size() = " << dddFact.pstrs.pStrings.size() << std::endl;
00150   pgeom->pStrings = dddFact.pstrs.pStrings;
00151   pgeom->pStartNode = DDRootDef::instance().root().toString();
00152 
00153   if ( mydbservice->isNewTagRequest("IdealGeometryRecord") ) {
00154     //    mydbservice->newValidityForNewPayload<PIdealGeometry>(pgeom, mydbservice->endOfTime(), callbackToken);
00155     mydbservice->createNewIOV<PIdealGeometry>(pgeom
00156                                               , mydbservice->beginOfTime()
00157                                               , mydbservice->endOfTime()
00158                                               , "IdealGeometryRecord");
00159   } else {
00160     std::cout << "Tag is already present." << std::endl;
00161   }
00162 }
00163 
00164 #include "FWCore/Framework/interface/MakerMacros.h"
00165 DEFINE_FWK_MODULE(WriteOneGeometryFromXML);

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