EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeometryExampleBase.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GeometryExampleBase.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
25 
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 int processGeometry(int argc, char* argv[],
31  ActsExamples::IBaseDetector& detector) {
32  // setup and parse options
40 
41  // Add specific options for this geometry
42  detector.addOptions(desc);
43  auto vm = ActsExamples::Options::parse(desc, argc, argv);
44  if (vm.empty()) {
45  return EXIT_FAILURE;
46  }
47 
48  // Now read the standard options
49  auto logLevel = ActsExamples::Options::readLogLevel(vm);
51 
52  // The geometry, material and decoration
53  auto geometry = ActsExamples::Geometry::build(vm, detector);
54  auto tGeometry = geometry.first;
55  auto contextDecorators = geometry.second;
56 
57  // The detectors
58  read_strings subDetectors = vm["geo-detector-volume"].as<read_strings>();
59 
60  auto volumeLogLevel =
61  Acts::Logging::Level(vm["geo-volume-loglevel"].as<size_t>());
62 
63  for (size_t ievt = 0; ievt < nEvents; ++ievt) {
64  // Setup the event and algorithm context
65  ActsExamples::WhiteBoard eventStore(
66  Acts::getDefaultLogger("EventStore#" + std::to_string(ievt), logLevel));
67  size_t ialg = 0;
68 
69  // The geometry context
70  ActsExamples::AlgorithmContext context(ialg, ievt, eventStore);
71 
73  for (auto& cdr : contextDecorators) {
74  if (cdr->decorate(context) != ActsExamples::ProcessCode::SUCCESS)
75  throw std::runtime_error("Failed to decorate event context");
76  }
77 
78  std::string geoContextStr = "";
79  if (contextDecorators.size() > 0) {
80  // We need indeed a context object
81  if (nEvents > 1) {
82  geoContextStr = "_geoContext" + std::to_string(ievt);
83  }
84  }
85 
86  // ---------------------------------------------------------------------------------
87  // Output directory
88  std::string outputDir = vm["output-dir"].template as<std::string>();
89 
90  // OBJ output
91  if (vm["output-obj"].as<bool>()) {
92  // Configure the tracking geometry writer
93  auto tgObjWriterConfig =
95  vm, "ObjTrackingGeometryWriter", volumeLogLevel);
96  auto tgObjWriter =
97  std::make_shared<ActsExamples::ObjTrackingGeometryWriter>(
98  tgObjWriterConfig);
99  // Write the tracking geometry object
100  tgObjWriter->write(context, *tGeometry);
101  }
102 
103  // CSV output
104  if (vm["output-csv"].as<bool>()) {
105  // setup the tracking geometry writer
107  tgCsvWriterConfig.trackingGeometry = tGeometry;
108  tgCsvWriterConfig.outputDir = outputDir;
109  tgCsvWriterConfig.writePerEvent = true;
110  auto tgCsvWriter =
111  std::make_shared<ActsExamples::CsvTrackingGeometryWriter>(
112  tgCsvWriterConfig, logLevel);
113 
114  // Write the tracking geometry object
115  tgCsvWriter->write(context);
116  }
117 
118  // Get the file name from the options
119  std::string materialFileName = vm["mat-output-file"].as<std::string>();
120 
121  if (!materialFileName.empty() and vm["output-root"].template as<bool>()) {
122  // The writer of the indexed material
123  ActsExamples::RootMaterialWriter::Config rmwConfig("MaterialWriter");
124  rmwConfig.fileName = materialFileName + ".root";
125  ActsExamples::RootMaterialWriter rmwImpl(rmwConfig);
126  rmwImpl.write(*tGeometry);
127  }
128 
129  if (!materialFileName.empty() and vm["output-json"].template as<bool>()) {
131  std::string fileName = vm["mat-output-file"].template as<std::string>();
132  // the material writer
134  "JsonGeometryConverter", Acts::Logging::INFO);
135  jmConverterCfg.processSensitives =
136  vm["mat-output-sensitives"].template as<bool>();
137  jmConverterCfg.processApproaches =
138  vm["mat-output-approaches"].template as<bool>();
139  jmConverterCfg.processRepresenting =
140  vm["mat-output-representing"].template as<bool>();
141  jmConverterCfg.processBoundaries =
142  vm["mat-output-boundaries"].template as<bool>();
143  jmConverterCfg.processVolumes =
144  vm["mat-output-volumes"].template as<bool>();
145  jmConverterCfg.processDenseVolumes =
146  vm["mat-output-dense-volumes"].template as<bool>();
147  jmConverterCfg.writeData = vm["mat-output-data"].template as<bool>();
148  jmConverterCfg.processnonmaterial =
149  vm["mat-output-allmaterial"].template as<bool>();
150  // The writer
151  ActsExamples::JsonMaterialWriter jmwImpl(std::move(jmConverterCfg),
152  materialFileName + ".json");
153 
154  jmwImpl.write(*tGeometry);
155  }
156  }
157 
158  return 0;
159 }