Project
Loading...
Searching...
No Matches
ITSDataSimulator.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
17
18#include <boost/program_options.hpp>
19#include <iostream>
20#include <string>
21
22namespace bpo = boost::program_options;
23using namespace o2::itsmft;
24
25std::vector<PixelData> ITSDataSimulator::generateChipData()
26{
27 std::vector<PixelData> vec;
28 uint32_t numOfPixels = rand() % mMaxPixelsPerChip;
29 while (vec.size() < numOfPixels) {
30 int row = rand() % SegmentationAlpide::NRows;
31 int col = rand() % SegmentationAlpide::NCols;
32 PixelData pixel(row, col);
33 vec.push_back(pixel);
34 }
35 std::sort(vec.begin(), vec.end());
36 if (!mDoErrors) {
37 // If errors are disabled, chips should not contain
38 // pixels fired multiple times
39 auto iter = std::unique(vec.begin(), vec.end());
40 vec.erase(iter, vec.end());
41 }
42 return vec;
43}
44
46{
47 // Generate the chip data
48 std::map<uint32_t, std::vector<PixelData>> chipData;
49 while (chipData.size() < mNumberOfChips) {
50 uint32_t chipID = rand() % MaxChipID;
51 if (!chipData.contains(chipID)) {
52 chipData.emplace(chipID, generateChipData());
53 }
54 }
55
56 if (mDoDigits) {
57 std::vector<Digit> digVec;
58 for (auto const& chip : chipData) {
59 uint32_t chipID = chip.first;
60 const std::vector<PixelData>& pixels = chip.second;
61 for (auto pixel : pixels) {
62 Digit dig(chipID, pixel.getRow(), pixel.getCol());
63 digVec.push_back(dig);
64 }
65 }
66 // TODO: Save the digits to a file
67 }
68}
69
70int main(int argc, char** argv)
71{
72 bpo::variables_map vm;
73 bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
74 "Simulates ALPIDE data\n");
75 bpo::options_description opt_hidden("");
76 bpo::options_description opt_all;
77 bpo::positional_options_description opt_pos;
78
79 try {
80 auto add_option = opt_general.add_options();
81 add_option("help,h", "Print this help message");
82 add_option("verbosity,v", bpo::value<uint32_t>()->default_value(0),
83 "verbosity level [0 = no output]");
84 add_option("digits",
85 bpo::value<bool>()->default_value(false)->implicit_value(true),
86 "generate the data in the digits format");
87 add_option("enable-errors",
88 bpo::value<bool>()->default_value(false)->implicit_value(true),
89 "enable additon of errors to the raw data");
90 add_option("seed", bpo::value<int32_t>()->default_value(0),
91 "random seed for data generation");
92 add_option(
93 "max-pixels-per-chip", bpo::value<uint32_t>()->default_value(100),
94 ("maximum number of fired pixels per chip (0 - " +
96 ")")
97 .c_str());
98 add_option("number-of-chip", bpo::value<uint32_t>()->default_value(10),
99 ("number of chips to be present in the data (0 - " +
101 .c_str());
102 add_option("configKeyValues", bpo::value<std::string>()->default_value(""),
103 "comma-separated configKeyValues");
104
105 opt_all.add(opt_general).add(opt_hidden);
106 bpo::store(bpo::command_line_parser(argc, argv)
107 .options(opt_all)
108 .positional(opt_pos)
109 .run(),
110 vm);
111
112 if (vm.count("help")) {
113 std::cout << opt_general << std::endl;
114 exit(0);
115 }
116
117 if (vm["max-pixels-per-chip"].as<uint32_t>() >
119 std::cerr << "Invalid max pixels per chip, valid range (0, "
120 << ITSDataSimulator::MaxPixelsPerChip << ")" << std::endl;
121 exit(1);
122 }
123
124 if (vm["number-of-chip"].as<uint32_t>() > ITSDataSimulator::MaxChipID) {
125 std::cerr << "Invalid number of chips, valid range (0, "
126 << ITSDataSimulator::MaxChipID << ")" << std::endl;
127 exit(1);
128 }
129
130 bpo::notify(vm);
131 } catch (bpo::error& e) {
132 std::cerr << "ERROR: " << e.what() << std::endl
133 << std::endl;
134 std::cerr << opt_general << std::endl;
135 exit(1);
136 } catch (std::exception& e) {
137 std::cerr << e.what() << ", application will now exit" << std::endl;
138 exit(2);
139 }
140
141 ITSDataSimulator simulator(
142 vm["seed"].as<int32_t>(), vm["number-of-chip"].as<uint32_t>(),
143 vm["max-pixels-per-chip"].as<uint32_t>(), vm["digits"].as<bool>(),
144 vm["enable-errors"].as<bool>());
145
146 simulator.simulate();
147}
Definition of the ITSMFT digit.
Infrastructure to simulate ALPIDE chip data.
uint32_t col
Definition RawData.h:4
Digit class for the ITS.
Definition Digit.h:30
static const uint32_t MaxPixelsPerChip
static const uint32_t MaxChipID
std::vector< PixelData > generateChipData()
< single pixel datum, with possibility to set a flag of pixel being masked out
Definition PixelData.h:33
GLint GLint GLsizei GLint GLenum GLenum const void * pixels
Definition glcorearb.h:275
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
#define main
std::vector< o2::ctf::BufferType > vec
std::vector< int > row