Analysis Software
Documentation for sPHENIX simulation 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-2021 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 
28 
29 #include <memory>
30 #include <string>
31 #include <vector>
32 
33 int processGeometry(int argc, char* argv[],
35  // setup and parse options
44  desc,
45  ActsExamples::OutputFormat::Root | ActsExamples::OutputFormat::Json |
46  ActsExamples::OutputFormat::Cbor | ActsExamples::OutputFormat::Csv |
47  ActsExamples::OutputFormat::Obj);
48 
49  // Add specific options for this geometry
50  detector.addOptions(desc);
51  auto vm = ActsExamples::Options::parse(desc, argc, argv);
52  if (vm.empty()) {
53  return EXIT_FAILURE;
54  }
55 
56  // Now read the standard options
58  size_t nEvents =
60 
61  // The geometry, material and decoration
62  auto geometry = ActsExamples::Geometry::build(vm, detector);
63  auto tGeometry = geometry.first;
64  auto contextDecorators = geometry.second;
65 
66  // The detectors
67  auto volumeLogLevel =
68  Acts::Logging::Level(vm["geo-volume-loglevel"].as<size_t>());
69 
70  for (size_t ievt = 0; ievt < nEvents; ++ievt) {
71  // Setup the event and algorithm context
72  ActsExamples::WhiteBoard eventStore(
73  Acts::getDefaultLogger("EventStore#" + std::to_string(ievt), logLevel));
74  size_t ialg = 0;
75 
76  // The geometry context
77  ActsExamples::AlgorithmContext context(ialg, ievt, eventStore);
78 
80  for (auto& cdr : contextDecorators) {
81  if (cdr->decorate(context) != ActsExamples::ProcessCode::SUCCESS) {
82  throw std::runtime_error("Failed to decorate event context");
83  }
84  }
85 
86  std::string geoContextStr = "";
87  if (!contextDecorators.empty()) {
88  // We need indeed a context object
89  if (nEvents > 1) {
90  geoContextStr = "_geoContext" + std::to_string(ievt);
91  }
92  }
93 
94  // ---------------------------------------------------------------------------------
95  // Output directory
96  std::string outputDir = vm["output-dir"].template as<std::string>();
97 
98  // OBJ output
99  if (vm["output-obj"].as<bool>()) {
100  // Configure the tracking geometry writer
101  auto tgObjWriterConfig =
103  tgObjWriterConfig.outputDir = outputDir;
104  auto tgObjWriter =
105  std::make_shared<ActsExamples::ObjTrackingGeometryWriter>(
106  tgObjWriterConfig, volumeLogLevel);
107  // Write the tracking geometry object
108  tgObjWriter->write(context, *tGeometry);
109  }
110 
111  // CSV output
112  if (vm["output-csv"].as<bool>()) {
113  // setup the tracking geometry writer
115  tgCsvWriterConfig.trackingGeometry = tGeometry;
116  tgCsvWriterConfig.outputDir = outputDir;
117  tgCsvWriterConfig.writePerEvent = true;
118  auto tgCsvWriter =
119  std::make_shared<ActsExamples::CsvTrackingGeometryWriter>(
120  tgCsvWriterConfig, logLevel);
121 
122  // Write the tracking geometry object
123  tgCsvWriter->write(context);
124  }
125 
126  // JSON output
127  if (vm["output-json"].as<bool>()) {
128  auto sJsonWriterConfig =
130  sJsonWriterConfig.trackingGeometry = tGeometry;
131  sJsonWriterConfig.outputDir = outputDir;
132  sJsonWriterConfig.writePerEvent = true;
133  auto sJsonWriter = std::make_shared<ActsExamples::JsonSurfacesWriter>(
134  sJsonWriterConfig, logLevel);
135 
136  // Write the tracking geometry object
137  sJsonWriter->write(context);
138  }
139 
140  // Get the file name from the options
141  std::string materialFileName = vm["mat-output-file"].as<std::string>();
142 
143  if (!materialFileName.empty() and vm["output-root"].template as<bool>()) {
144  // The writer of the indexed material
146  rmwConfig.filePath = materialFileName + ".root";
147  ActsExamples::RootMaterialWriter rmwImpl(rmwConfig, logLevel);
148  rmwImpl.write(*tGeometry);
149  }
150 
151  if (!materialFileName.empty() and (vm["output-json"].template as<bool>() or
152  vm["output-cbor"].template as<bool>())) {
153  // the material writer
155  jmConverterCfg.processSensitives =
156  vm["mat-output-sensitives"].template as<bool>();
157  jmConverterCfg.processApproaches =
158  vm["mat-output-approaches"].template as<bool>();
159  jmConverterCfg.processRepresenting =
160  vm["mat-output-representing"].template as<bool>();
161  jmConverterCfg.processBoundaries =
162  vm["mat-output-boundaries"].template as<bool>();
163  jmConverterCfg.processVolumes =
164  vm["mat-output-volumes"].template as<bool>();
165  jmConverterCfg.processDenseVolumes =
166  vm["mat-output-dense-volumes"].template as<bool>();
167  jmConverterCfg.processNonMaterial =
168  vm["mat-output-allmaterial"].template as<bool>();
169  jmConverterCfg.context = context.geoContext;
170  // The writer
172  jmWriterCfg.converterCfg = std::move(jmConverterCfg);
173  jmWriterCfg.fileName = materialFileName;
174  ActsExamples::JsonFormat format = ActsExamples::JsonFormat::NoOutput;
175  if (vm["output-json"].template as<bool>()) {
176  format = format | ActsExamples::JsonFormat::Json;
177  }
178  if (vm["output-cbor"].template as<bool>()) {
179  format = format | ActsExamples::JsonFormat::Cbor;
180  }
181  jmWriterCfg.writeFormat = format;
182 
183  ActsExamples::JsonMaterialWriter jmwImpl(jmWriterCfg, logLevel);
184 
185  jmwImpl.write(*tGeometry);
186  }
187  }
188 
189  return 0;
190 }