CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/GeometryReaders/XMLIdealGeometryESSource/src/XMLIdealGeometryESProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    XMLIdealGeometryESProducer
00004 // Class:      XMLIdealGeometryESProducer
00005 // 
00013 //
00014 // Original Author:  Mike Case
00015 //         Created:  Fri Jan 16 01:45:49 CET 2009
00016 
00017 
00018 
00019 // system include files
00020 #include <memory>
00021 #include "boost/shared_ptr.hpp"
00022 
00023 // user include files
00024 #include "FWCore/Framework/interface/ModuleFactory.h"
00025 #include "FWCore/Framework/interface/ESProducer.h"
00026 
00027 #include "FWCore/Framework/interface/ESHandle.h"
00028 #include "FWCore/Framework/interface/ESTransientHandle.h"
00029 
00030 #include "DetectorDescription/Core/interface/DDCompactView.h"
00031 #include "DetectorDescription/Core/interface/DDRoot.h"
00032 #include "DetectorDescription/Parser/interface/DDLParser.h"
00033 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00034 #include "Geometry/Records/interface/GeometryFileRcd.h"
00035 #include "CondFormats/Common/interface/FileBlob.h"
00036 
00037 #include "DetectorDescription/Core/interface/DDMaterial.h"
00038 #include "DetectorDescription/Core/interface/DDSolid.h"
00039 #include "DetectorDescription/Core/interface/DDSpecifics.h"
00040 #include "DetectorDescription/Base/interface/DDRotationMatrix.h"
00041 
00042 #include "DetectorDescription/Core/src/Material.h"
00043 #include "DetectorDescription/Core/src/Solid.h"
00044 #include "DetectorDescription/Core/src/LogicalPart.h"
00045 #include "DetectorDescription/Core/src/Specific.h"
00046 
00047 //
00048 // class decleration
00049 //
00050 
00051 class XMLIdealGeometryESProducer : public edm::ESProducer {
00052 public:
00053   XMLIdealGeometryESProducer(const edm::ParameterSet&);
00054   ~XMLIdealGeometryESProducer();
00055   
00056   typedef std::auto_ptr<DDCompactView> ReturnType;
00057   
00058   ReturnType produce(const IdealGeometryRecord&);
00059 private:
00060   // ----------member data ---------------------------
00061   std::string rootDDName_; // this must be the form namespace:name
00062   std::string label_;
00063     // 2009-07-09 memory patch
00064     // for copying and protecting DD Store's after parsing is complete.
00065     DDI::Store<DDName, DDI::Material*> matStore_;
00066     DDI::Store<DDName, DDI::Solid*> solidStore_;
00067     DDI::Store<DDName, DDI::LogicalPart*> lpStore_;
00068     DDI::Store<DDName, DDI::Specific*> specStore_;
00069     DDI::Store<DDName, DDRotationMatrix*> rotStore_;    
00070 };
00071 
00072 //
00073 // constants, enums and typedefs
00074 //
00075 
00076 //
00077 // static data member definitions
00078 //
00079 
00080 //
00081 // constructors and destructor
00082 //
00083 XMLIdealGeometryESProducer::XMLIdealGeometryESProducer(const edm::ParameterSet& iConfig)
00084   :   rootDDName_(iConfig.getParameter<std::string>("rootDDName")),
00085       label_(iConfig.getParameter<std::string>("label"))
00086 {
00087    //the following line is needed to tell the framework what
00088    // data is being produced
00089    setWhatProduced(this);
00090    //now do what ever other initialization is needed
00091 }
00092 
00093 
00094 XMLIdealGeometryESProducer::~XMLIdealGeometryESProducer()
00095 {
00096  
00097    // do anything here that needs to be done at desctruction time
00098    // (e.g. close files, deallocate resources etc.)
00099 
00100 }
00101 
00102 
00103 //
00104 // member functions
00105 //
00106 
00107 // ------------ method called to produce the data  ------------
00108 XMLIdealGeometryESProducer::ReturnType
00109 XMLIdealGeometryESProducer::produce(const IdealGeometryRecord& iRecord)
00110 {
00111    using namespace edm::es;
00112 
00113    edm::ESTransientHandle<FileBlob> gdd;
00114    iRecord.getRecord<GeometryFileRcd>().get( label_, gdd );
00115 //    if ( gdd.isValid() ) {
00116 //      std::cout << "gdd.isValid()" << std::endl; 
00117 //      if (gdd.product() != 0) {
00118 //        std::cout << "object address is not zero" << std::endl;
00119 //      } else {
00120 //        std::cout << "object address is zero" << std::endl;
00121 //      }
00122 //    } else {
00123 //      std::cout << "gdd is NOT valid" << std::endl;
00124 //    }
00125    DDName ddName(rootDDName_);
00126    DDLogicalPart rootNode(ddName);
00127    DDRootDef::instance().set(rootNode);
00128    ReturnType returnValue(new DDCompactView(rootNode));
00129    DDLParser parser(*returnValue);
00130    parser.getDDLSAX2FileHandler()->setUserNS(true);
00131    parser.clearFiles();
00132    
00133    std::vector<unsigned char>* tb = (*gdd).getUncompressedBlob();
00134    
00135    parser.parse(*tb, tb->size()); 
00136    
00137    delete tb;
00138    
00139    //std::cout << "In XMLIdealGeometryESProducer::produce" << std::endl;
00140    returnValue->lockdown();
00141 
00142    return returnValue ;
00143 }
00144 
00145 //define this as a plug-in
00146 DEFINE_FWK_EVENTSETUP_MODULE(XMLIdealGeometryESProducer);