File indexing completed on 2025-01-18 09:14:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include "DD4hep/Printout.h"
0024 #include "DD4hep/Factories.h"
0025 #include "DD4hep/DetectorLoad.h"
0026 #include <fstream>
0027 #include <cerrno>
0028
0029 using namespace std;
0030 using namespace dd4hep;
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 static int XML_In_Memory (Detector& detector, int argc, char** argv) {
0044 string input;
0045 bool arg_error = false;
0046 for(int i=0; i<argc && argv[i]; ++i) {
0047 if ( 0 == ::strncmp("-input",argv[i],4) )
0048 input = argv[++i];
0049 else
0050 arg_error = true;
0051 }
0052 if ( arg_error || input.empty() ) {
0053
0054 cout <<
0055 "Usage: -plugin <name> -arg [-arg] \n"
0056 " name: factory name DD4hep_AlignmentExample_read_xml \n"
0057 " -input <string> Geometry file \n"
0058 "\tArguments given: " << arguments(argc,argv) << endl << flush;
0059 ::exit(EINVAL);
0060 }
0061 ifstream is (input, ifstream::binary);
0062 if (is) {
0063
0064 is.seekg (0, is.end);
0065 int length = is.tellg();
0066 is.seekg (0, is.beg);
0067 char* buffer = new char[length+1];
0068 printout(INFO,"Read","Read a total of %ld charactors from %s.",
0069 length, input.c_str());
0070
0071 is.read (buffer,length);
0072 buffer[length] = 0;
0073
0074 DetectorLoad loader(detector);
0075 loader.processXMLString(buffer,0);
0076 return 1;
0077 }
0078 printout(INFO,"Read","FAILED to load xml data from %s [%s].",
0079 input.c_str(), ::strerror(errno));
0080 return 0;
0081 }
0082
0083 DECLARE_APPLY(DD4hep_XML_InMemory,XML_In_Memory)