Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:24

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 // Framework includes
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/DetectorTools.h>
0017 #include <DD4hep/DetFactoryHelper.h>
0018 
0019 using namespace dd4hep::align;
0020 
0021 // ======================================================================================
0022 #include <DDAlign/GlobalAlignmentWriter.h>
0023 long create_global_alignment_xml_file(dd4hep::Detector& description, int argc, char** argv)   {
0024   dd4hep::DetElement top;
0025   std::string output, path = "/world";
0026   bool enable_transactions = false, arg_error = false;
0027   for(int i=1; i<argc;++i) {
0028     if ( argv[i] && (argv[i][0]=='-' || argv[i][0]=='/') ) {
0029       const char* p = ::strchr(argv[i],'=');
0030       if ( p && strncmp(argv[i]+1,"-output",7)==0 )
0031         output = p+1;
0032       else if ( p && strncmp(argv[i]+1,"-path",5)==0 )
0033         path = p+1;
0034       else if ( strncmp(argv[i]+1,"-transactions",5)==0 )
0035         enable_transactions = true;
0036       else
0037         arg_error = true;
0038     }
0039   }
0040 
0041   if ( arg_error || output.empty() || path.empty() )  {
0042     /// Help printout describing the basic command line interface
0043     std::cout <<
0044       "Usage: -plugin <name> -arg [-arg]                                      \n"
0045       "     name:   factory nameDD4hep_GlobalAlignmentWriter                \n\n"
0046       "     -output <string>         Path to the output file generated.       \n"
0047       "     -path   <string>         Path to the detector element for which   \n"
0048       "                              the alignment file should be written.    \n"
0049       "     -transactions            Enable output transactions.              \n"
0050       "\tArguments given: " << dd4hep::arguments(argc,argv) << std::endl << std::flush;
0051     ::exit(EINVAL);
0052   }
0053 
0054   dd4hep::printout(dd4hep::ALWAYS,"AlignmentXmlWriter",
0055                    "++ Writing dd4hep alignment constants of the \"%s\" "
0056                    "DetElement tree to file \"%s\"",
0057                    path.c_str(), output.c_str());
0058   top = dd4hep::detail::tools::findDaughterElement(description.world(),path);
0059   if ( top.isValid() )   {
0060     GlobalAlignmentWriter wr(description);
0061     return wr.write(wr.dump(top,enable_transactions), output);
0062   }
0063   dd4hep::except("AlignmentXmlWriter","++ Invalid top level detector element name: %s",path.c_str());
0064   return 1;
0065 }
0066 DECLARE_APPLY(DD4hep_GlobalAlignmentXmlWriter, create_global_alignment_xml_file)