DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
AlignmentsPlugins.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework includes
15 #include <DD4hep/Printout.h>
16 #include <DD4hep/DetectorTools.h>
18 
19 using namespace dd4hep::align;
20 
21 // ======================================================================================
23 long create_global_alignment_xml_file(dd4hep::Detector& description, int argc, char** argv) {
25  std::string output, path = "/world";
26  bool enable_transactions = false, arg_error = false;
27  for(int i=1; i<argc;++i) {
28  if ( argv[i] && (argv[i][0]=='-' || argv[i][0]=='/') ) {
29  const char* p = ::strchr(argv[i],'=');
30  if ( p && strncmp(argv[i]+1,"-output",7)==0 )
31  output = p+1;
32  else if ( p && strncmp(argv[i]+1,"-path",5)==0 )
33  path = p+1;
34  else if ( strncmp(argv[i]+1,"-transactions",5)==0 )
35  enable_transactions = true;
36  else
37  arg_error = true;
38  }
39  }
40 
41  if ( arg_error || output.empty() || path.empty() ) {
43  std::cout <<
44  "Usage: -plugin <name> -arg [-arg] \n"
45  " name: factory nameDD4hep_GlobalAlignmentWriter \n\n"
46  " -output <string> Path to the output file generated. \n"
47  " -path <string> Path to the detector element for which \n"
48  " the alignment file should be written. \n"
49  " -transactions Enable output transactions. \n"
50  "\tArguments given: " << dd4hep::arguments(argc,argv) << std::endl << std::flush;
51  ::exit(EINVAL);
52  }
53 
54  dd4hep::printout(dd4hep::ALWAYS,"AlignmentXmlWriter",
55  "++ Writing dd4hep alignment constants of the \"%s\" "
56  "DetElement tree to file \"%s\"",
57  path.c_str(), output.c_str());
58  top = dd4hep::detail::tools::findDaughterElement(description.world(),path);
59  if ( top.isValid() ) {
60  GlobalAlignmentWriter wr(description);
61  return wr.write(wr.dump(top,enable_transactions), output);
62  }
63  dd4hep::except("AlignmentXmlWriter","++ Invalid top level detector element name: %s",path.c_str());
64  return 1;
65 }
66 DECLARE_APPLY(DD4hep_GlobalAlignmentXmlWriter, create_global_alignment_xml_file)
dd4hep::Detector::world
virtual DetElement world() const =0
Return reference to the top-most (world) detector element.
dd4hep::align::GlobalAlignmentWriter::write
long write(xml::Document doc, const std::string &output) const
Write the XML document structure to a file.
Definition: GlobalAlignmentWriter.cpp:135
dd4hep::align::GlobalAlignmentWriter
Write aligment data to XML data file.
Definition: GlobalAlignmentWriter.h:36
DECLARE_APPLY
#define DECLARE_APPLY(name, func)
Definition: Factories.h:281
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::detail::tools::findDaughterElement
DetElement findDaughterElement(DetElement parent, const std::string &subpath)
Find DetElement as child of a parent by its relative or absolute path.
Definition: DetectorTools.cpp:219
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::align::GlobalAlignmentWriter::dump
xml::Document dump(DetElement element, bool enable_transactions=false) const
Dump one full DetElement subtree into a newly created document.
Definition: GlobalAlignmentWriter.cpp:123
DetectorTools.h
GlobalAlignmentWriter.h
create_global_alignment_xml_file
long create_global_alignment_xml_file(dd4hep::Detector &description, int argc, char **argv)
Definition: AlignmentsPlugins.cpp:23
DetFactoryHelper.h
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
Printout.h
dd4hep::align
Namespace for implementation details of the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:31