Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:42

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 /* 
0014  Plugin invocation:
0015  ==================
0016  This plugin behaves like a main program.
0017  Invoke the plugin with something like this:
0018 
0019  geoPluginRun -destroy -plugin DD4hep_XML-In-Memory -input <file name>
0020 
0021 */
0022 // Framework include files
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 /// Plugin function: Test in memory XML parsing of a simple sub detector
0033 /**
0034  *  Factory: DD4hep_XML-In-Memory
0035  *
0036  *  Though there is a file name given, it is read FIRST and then parsed.
0037  *  Similar to a in memory XML string.
0038  *
0039  *  \author  M.Frank
0040  *  \version 1.0
0041  *  \date    20/01/2018
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     /// Help printout describing the basic command line interface
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     // get length of file:
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     // read data as a block:
0071     is.read (buffer,length);
0072     buffer[length] = 0;
0073     /// So here is the actual test: We parse the raw XML string
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)