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