Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:55:08

0001 #include <exception>
0002 #include <iostream>
0003 #include <memory>
0004 #include <string>
0005 #include <vector>
0006 
0007 #include "DetectorDescription/Core/interface/DDCompactView.h"
0008 #include "DetectorDescription/Parser/interface/DDLElementRegistry.h"
0009 #include "DetectorDescription/Parser/src/DDLElementaryMaterial.h"
0010 #include "FWCore/ParameterSetReader/interface/ParameterSetReader.h"
0011 #include "FWCore/PluginManager/interface/PresenceFactory.h"
0012 #include "FWCore/PluginManager/interface/ProblemTracker.h"
0013 #include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
0014 #include "FWCore/ServiceRegistry/interface/ServiceToken.h"
0015 #include "FWCore/Utilities/interface/Exception.h"
0016 #include "FWCore/Utilities/interface/Presence.h"
0017 
0018 int main(int argc, char* argv[]) {
0019   // Copied from example stand-alone program in Message Logger July 18, 2007
0020   std::string const kProgramName = argv[0];
0021   int rc = 0;
0022 
0023   try {
0024     // A.  Instantiate a plug-in manager first.
0025     edm::AssertHandler ah;
0026 
0027     // B.  Load the message service plug-in.  Forget this and bad things happen!
0028     //     In particular, the job hangs as soon as the output buffer fills up.
0029     //     That's because, without the message service, there is no mechanism for
0030     //     emptying the buffers.
0031     std::shared_ptr<edm::Presence> theMessageServicePresence;
0032     theMessageServicePresence =
0033         std::shared_ptr<edm::Presence>(edm::PresenceFactory::get()->makePresence("SingleThreadMSPresence").release());
0034 
0035     // C.  Manufacture a configuration and establish it.
0036     std::string config =
0037         "import FWCore.ParameterSet.Config as cms\n"
0038         "process = cms.Process('TEST')\n"
0039         "process.maxEvents = cms.untracked.PSet(\n"
0040         "    input = cms.untracked.int32(5)\n"
0041         ")\n"
0042         "process.source = cms.Source('EmptySource')\n"
0043         "process.JobReportService = cms.Service('JobReportService')\n"
0044         "process.InitRootHandlers = cms.Service('InitRootHandlers')\n"
0045         // "process.MessageLogger = cms.Service('MessageLogger')\n"
0046         "process.m1 = cms.EDProducer('IntProducer',\n"
0047         "    ivalue = cms.int32(11)\n"
0048         ")\n"
0049         "process.out = cms.OutputModule('PoolOutputModule',\n"
0050         "    fileName = cms.untracked.string('testStandalone.root')\n"
0051         ")\n"
0052         "process.p = cms.Path(process.m1)\n"
0053         "process.e = cms.EndPath(process.out)\n";
0054 
0055     // D.  Create the services.
0056     std::unique_ptr<edm::ParameterSet> params;
0057     edm::makeParameterSets(config, params);
0058     edm::ServiceToken tempToken(edm::ServiceRegistry::createServicesFromConfig(std::move(params)));
0059 
0060     // E.  Make the services available.
0061     edm::ServiceRegistry::Operate operate(tempToken);
0062 
0063     // END Copy from example stand-alone program in Message Logger July 18, 2007
0064 
0065     std::cout << "Create DDLElementaryMaterial m" << std::endl;
0066     DDCompactView cpv;
0067     DDLElementRegistry locreg;
0068     DDLElementaryMaterial m(&locreg);
0069     //  <ElementaryMaterial name="Carbon" density="2.265*g/cm3" symbol=" " atomicWeight="12.011*g/mole" atomicNumber="6"/>
0070 
0071     std::cout << "Initialize names" << std::endl;
0072     std::vector<std::string> names;
0073     names.emplace_back("name");
0074     names.emplace_back("density");
0075     names.emplace_back("atomicWeight");
0076     names.emplace_back("atomicNumber");
0077 
0078     std::cout << "Initialize values" << std::endl;
0079     std::vector<std::string> values;
0080     values.emplace_back("Carbon");
0081     values.emplace_back("2.265*g/cm3");
0082     values.emplace_back("12.011*g/mole");
0083     values.emplace_back("6");
0084 
0085     std::cout << "Initialize element name and namespace" << std::endl;
0086     std::string element = "ElementaryMaterial";
0087     std::string nmspc = "test";
0088 
0089     std::cout << "Load Attributes " << std::endl;
0090     m.loadAttributes(element, names, values, nmspc, cpv);
0091 
0092     std::cout << "Process Element " << std::endl;
0093     m.processElement(element, nmspc, cpv);
0094   }
0095   //  Deal with any exceptions that may have been thrown.
0096   catch (cms::Exception& e) {
0097     std::cout << "cms::Exception caught in " << kProgramName << "\n" << e.explainSelf();
0098     rc = 1;
0099   } catch (std::exception& e) {
0100     std::cout << "Standard library exception caught in " << kProgramName << "\n" << e.what();
0101     rc = 1;
0102   } catch (...) {
0103     std::cout << "Unknown exception caught in " << kProgramName;
0104     rc = 2;
0105   }
0106   std::cout << "Done!!!" << std::endl;
0107   return rc;
0108 }