Project
Loading...
Searching...
No Matches
field-uniform-exporter.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include <boost/program_options.hpp>
16#include <boost/program_options/options_description.hpp>
17#include <boost/program_options/variables_map.hpp>
18#include <Field/MagneticField.h>
19#include <memory>
20
22
23namespace bpo = boost::program_options;
24using namespace o2::gpu;
25
26template <std::size_t MAX_DIM1_SEGMENTS, std::size_t MAX_DIM2_SEGMENTS, std::size_t MAX_DIM3_SEGMENTS>
28{
29 file.write(reinterpret_cast<char*>(&segments.MinZ), sizeof(segments.MinZ));
30 file.write(reinterpret_cast<char*>(&segments.MaxZ), sizeof(segments.MaxZ));
31 file.write(reinterpret_cast<char*>(&segments.MultiplicativeFactor), sizeof(segments.MultiplicativeFactor));
32
33 file.write(reinterpret_cast<char*>(&NSegDim1), sizeof(std::int32_t));
34
35 file.write(reinterpret_cast<char*>(segments.SegDim1), NSegDim1 * sizeof(segments.SegDim1[0]));
36
37 file.write(reinterpret_cast<char*>(segments.BegSegDim2), NSegDim1 * sizeof(segments.BegSegDim2[0]));
38 file.write(reinterpret_cast<char*>(segments.NSegDim2), NSegDim1 * sizeof(segments.NSegDim2[0]));
39
40 file.write(reinterpret_cast<char*>(&NSegDim2), sizeof(std::int32_t));
41
42 file.write(reinterpret_cast<char*>(segments.SegDim2), NSegDim2 * sizeof(segments.SegDim2[0]));
43
44 file.write(reinterpret_cast<char*>(segments.BegSegDim3), NSegDim2 * sizeof(segments.BegSegDim3[0]));
45 file.write(reinterpret_cast<char*>(segments.NSegDim3), NSegDim2 * sizeof(segments.NSegDim3[0]));
46
47 file.write(reinterpret_cast<char*>(&NSegDim3), sizeof(std::int32_t));
48
49 file.write(reinterpret_cast<char*>(segments.SegDim3), NSegDim3 * sizeof(segments.SegDim3[0]));
50 file.write(reinterpret_cast<char*>(segments.SegID), NSegDim3 * sizeof(segments.SegID[0]));
51}
52
53template <std::size_t DIMENSIONS, std::size_t MAX_PARAMETERIZATIONS, std::size_t MAX_ROWS, std::size_t MAX_COLUMNS, std::size_t MAX_COEFFICIENTS>
54void saveParams(std::ofstream& file, int32_t numberOfParametrization, int32_t Nrows, int32_t Ncolums, int32_t Ncoeffs, GPUDisplayMagneticField::ParametrizationUniform<MAX_PARAMETERIZATIONS, MAX_ROWS, MAX_COLUMNS, MAX_COEFFICIENTS>& param)
55{
56 file.write(reinterpret_cast<char*>(&numberOfParametrization), sizeof(std::int32_t));
57
58 file.write(reinterpret_cast<char*>(param.BOffsets), DIMENSIONS * numberOfParametrization * sizeof(float));
59 file.write(reinterpret_cast<char*>(param.BScales), DIMENSIONS * numberOfParametrization * sizeof(float));
60 file.write(reinterpret_cast<char*>(param.BMin), DIMENSIONS * numberOfParametrization * sizeof(float));
61 file.write(reinterpret_cast<char*>(param.BMax), DIMENSIONS * numberOfParametrization * sizeof(float));
62
63 file.write(reinterpret_cast<char*>(param.NRows), DIMENSIONS * numberOfParametrization * sizeof(float));
64 file.write(reinterpret_cast<char*>(param.ColsAtRowOffset), DIMENSIONS * numberOfParametrization * sizeof(float));
65 file.write(reinterpret_cast<char*>(param.CofsAtRowOffset), DIMENSIONS * numberOfParametrization * sizeof(float));
66
67 file.write(reinterpret_cast<char*>(&Nrows), sizeof(std::int32_t));
68
69 file.write(reinterpret_cast<char*>(param.NColsAtRow), Nrows * sizeof(int32_t));
70 file.write(reinterpret_cast<char*>(param.CofsAtColOffset), Nrows * sizeof(int32_t));
71
72 file.write(reinterpret_cast<char*>(&Ncolums), sizeof(int32_t));
73
74 file.write(reinterpret_cast<char*>(param.NCofsAtCol), Ncolums * sizeof(int32_t));
75 file.write(reinterpret_cast<char*>(param.AtColCoefOffset), Ncolums * sizeof(int32_t));
76
77 file.write(reinterpret_cast<char*>(&Ncoeffs), sizeof(int32_t));
78
79 file.write(reinterpret_cast<char*>(param.Coeffs), Ncoeffs * sizeof(float));
80}
81
82int32_t main(int argc, char** argv)
83{
84 bpo::options_description options("Field Uniform exporter options");
85
86 float l3Cur, diCur, beamenergy;
87 bool uniform;
88 std::string beamtype, filename;
89
90 options.add_options()(
91 "help,h", "produce help message")(
92 "l3current,l", bpo::value<decltype(l3Cur)>()->default_value(30000.f), "current of the L3 magnet")(
93 "dipolecurrent,d", bpo::value<decltype(diCur)>()->default_value(6000.f), "current of the Dipole magnet")(
94 "beamenergy,b", bpo::value<decltype(beamenergy)>()->default_value(7000.f), "beam energy")(
95 "beamtype,t", bpo::value<decltype(beamtype)>()->default_value("pp"), "beam type")(
96 "uniform,u", bpo::value<decltype(uniform)>()->default_value(false), "uniform")(
97 "filename,f", bpo::value<decltype(beamtype)>()->default_value("field.uniform"), "output filename");
98
99 using namespace bpo::command_line_style;
100 auto style = (allow_short | short_allow_adjacent | short_allow_next | allow_long | long_allow_adjacent | long_allow_next | allow_sticky | allow_dash_for_short);
101 bpo::variables_map varmap;
102 try {
103 bpo::store(
104 bpo::command_line_parser(argc, argv)
105 .options(options)
106 .style(style)
107 .run(),
108 varmap);
109 } catch (std::exception const& e) {
110 LOGP(error, "error parsing options of {}: {}", argv[0], e.what());
111 return 1;
112 }
113
114 if (varmap.count("help")) {
115 LOG(info) << options << std::endl;
116 return 0;
117 }
118
119 l3Cur = varmap["l3current"].as<decltype(l3Cur)>();
120 diCur = varmap["dipolecurrent"].as<decltype(diCur)>();
121 beamenergy = varmap["beamenergy"].as<decltype(beamenergy)>();
122 beamtype = varmap["beamtype"].as<decltype(beamtype)>();
123 uniform = varmap["uniform"].as<decltype(uniform)>();
124 filename = varmap["filename"].as<decltype(filename)>();
125
126 const auto field = std::unique_ptr<o2::field::MagneticField>(o2::field::MagneticField::createFieldMap(-l3Cur, -diCur, 0, uniform, beamenergy, beamtype.c_str()));
127 const auto gpufield = std::make_unique<GPUDisplayMagneticField>(field.get());
128
129 auto file = std::ofstream(filename, std::ios::out | std::ios::binary);
130
131 saveSegments(file, gpufield->mSolSegDim1, gpufield->mSolSegDim2, gpufield->mSolSegDim3, *gpufield->mSolenoidSegments);
132 saveSegments(file, gpufield->mDipSegDim1, gpufield->mDipSegDim2, gpufield->mDipSegDim3, *gpufield->mDipoleSegments);
133 saveParams<o2::gpu::GPUDisplayMagneticField::DIMENSIONS>(file, gpufield->mSolParametrizations, gpufield->mSolRows, gpufield->mSolColumns, gpufield->mSolCoefficients, *gpufield->mSolenoidParameterization);
134 saveParams<o2::gpu::GPUDisplayMagneticField::DIMENSIONS>(file, gpufield->mDipParametrizations, gpufield->mDipRows, gpufield->mDipColumns, gpufield->mDipCoefficients, *gpufield->mDipoleParameterization);
135
136 file.close();
137
138 return 0;
139}
Definition of the MagF class.
static MagneticField * createFieldMap(float l3Current=-30000., float diCurrent=-6000., Int_t convention=0, Bool_t uniform=kFALSE, float beamenergy=7000, const Char_t *btype="pp", const std::string path=std::string(gSystem->Getenv("VMCWORKDIR"))+std::string("/Common/maps/mfchebKGI_sym.root"))
void saveSegments(std::ofstream &file, int32_t NSegDim1, int32_t NSegDim2, int32_t NSegDim3, GPUDisplayMagneticField::SegmentsUniform< MAX_DIM1_SEGMENTS, MAX_DIM2_SEGMENTS, MAX_DIM3_SEGMENTS > &segments)
void saveParams(std::ofstream &file, int32_t numberOfParametrization, int32_t Nrows, int32_t Ncolums, int32_t Ncoeffs, GPUDisplayMagneticField::ParametrizationUniform< MAX_PARAMETERIZATIONS, MAX_ROWS, MAX_COLUMNS, MAX_COEFFICIENTS > &param)
GLuint segments
Definition glcorearb.h:4946
GLenum GLfloat param
Definition glcorearb.h:271
std::string filename()
#define main
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"