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
00047
00048
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
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
00093
00094
00095
00096
00097
00098
00099
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
00110 plp = dddFact.logicalPart ( ddLP );
00111 pgeom->pLogicalParts.push_back( *plp );
00112 delete plp;
00113 ++i;
00114 if (git->size())
00115 {
00116
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
00125 pgeom->pPosParts.push_back( *ppp );
00126
00127 delete ppp;
00128
00129 }
00130 }
00131 }
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
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
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);