Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
Analysis Software
Deprecated List
Modules
Namespaces
Classes
Files
File List
acts
blob
sPHENIX
Alignment
CI
cmake
Core
docs
Examples
Algorithms
Detectors
Framework
Io
Csv
EDM4hep
HepMC3
Json
include
ActsExamples
Io
Json
JsonDigitizationConfig.hpp
JsonGeometryList.hpp
JsonMaterialWriter.hpp
JsonSpacePointWriter.hpp
JsonSurfacesReader.hpp
JsonSurfacesWriter.hpp
src
NuclearInteractions
Obj
Performance
Root
Svg
Python
Run
Scripts
Fatras
Plugins
Tests
acts-fatras
analysis
analysis_tpc_prototype
coresoftware
Doxygen_Assist
g4exampledetector
GenFit
JETSCAPE
KFParticle
macros
online_distribution
OnlMon
prototype
pythia6
rcdaq
RDBC
tutorials
doxygen_mainpage.h
File Members
Examples
External Links
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
JsonSpacePointWriter.hpp
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file JsonSpacePointWriter.hpp
1
// This file is part of the Acts project.
2
//
3
// Copyright (C) 2017 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
12
13
#pragma once
14
15
#include "
ActsExamples/EventData/GeometryContainers.hpp
"
16
#include "
ActsExamples/Framework/WriterT.hpp
"
17
#include "
ActsExamples/Utilities/Paths.hpp
"
18
19
#include <fstream>
20
21
namespace
ActsExamples {
22
32
template
<
class
T>
33
class
JsonSpacePointWriter
:
public
WriterT
<GeometryIdMultimap<T>> {
34
public
:
35
struct
Config
{
36
std::string
collection
;
37
std::string
outputDir
;
38
size_t
outputPrecision
= 6;
39
};
40
41
JsonSpacePointWriter
(
const
Config
&
cfg
,
42
Acts::Logging::Level
level
=
Acts::Logging::INFO
);
43
44
protected
:
45
ActsExamples::ProcessCode
writeT
(
46
const
ActsExamples::AlgorithmContext
& context,
47
const
GeometryIdMultimap<T>
& spacePoints)
override
;
48
49
private
:
50
// since class itself is templated, base class template must be fixed
51
using
Base
=
WriterT<GeometryIdMultimap<T>
>;
52
53
Config
m_cfg
;
54
};
55
56
}
// namespace ActsExamples
57
58
template
<
class
T>
59
ActsExamples::JsonSpacePointWriter<T>::JsonSpacePointWriter
(
60
const
ActsExamples::JsonSpacePointWriter<T>::Config
&
cfg
,
61
Acts::Logging::Level
level
)
62
:
Base
(cfg.collection,
"JsonSpacePointWriter"
, level),
m_cfg
(cfg) {
63
if
(
m_cfg
.
collection
.empty()) {
64
throw
std::invalid_argument(
"Missing input collection"
);
65
}
66
}
67
68
template
<
class
T>
69
ActsExamples::ProcessCode
ActsExamples::JsonSpacePointWriter<T>::writeT
(
70
const
ActsExamples::AlgorithmContext
& context,
71
const
GeometryIdMultimap<T>
& spacePoints) {
72
// open per-event file
73
std::string
path
=
perEventFilepath
(
m_cfg
.outputDir,
"spacepoints.json"
,
74
context.
eventNumber
);
75
std::ofstream
os
(path,
std::ofstream::out
| std::ofstream::trunc);
76
if
(!os) {
// NOLINT(readability-implicit-bool-conversion)
77
throw
std::ios_base::failure(
"Could not open '"
+ path +
"' to write"
);
78
}
79
80
os << std::setprecision(
m_cfg
.outputPrecision);
81
os <<
"{\n"
;
82
83
bool
firstVolume =
true
;
84
for
(
auto
& volumeData : spacePoints) {
85
geo_id_value volumeID = volumeData.first;
86
87
if
(!firstVolume)
88
os <<
",\n"
;
89
os <<
" \"SpacePoints_"
<< volumeID <<
"\" : [\n"
;
90
91
bool
firstPoint =
true
;
92
for
(
auto
& layerData : volumeData.second) {
93
for
(
auto
& moduleData : layerData.second) {
94
for
(
auto
&
data
: moduleData.second) {
95
// set the comma correctly
96
if
(!firstPoint)
97
os <<
",\n"
;
98
// write the space point
99
os <<
" ["
<<
data
.x() <<
", "
<<
data
.y() <<
", "
<<
data
.z()
100
<<
"]"
;
101
firstPoint =
false
;
102
}
103
}
104
}
105
os <<
"]"
;
106
firstVolume =
false
;
107
}
108
os <<
"\n}\n"
;
109
110
return
ProcessCode::SUCCESS
;
111
}
acts
blob
sPHENIX
Examples
Io
Json
include
ActsExamples
Io
Json
JsonSpacePointWriter.hpp
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:17:38
using
1.8.2 with
sPHENIX GitHub integration