Project
Loading...
Searching...
No Matches
PadGroupType.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
13
14#include "PadGroupType.h"
15#include "boost/format.hpp"
16#include <stdexcept>
17#include <iostream>
18#include <algorithm>
19#include <iterator>
20
21namespace o2
22{
23namespace mch
24{
25namespace mapping
26{
27namespace impl3
28{
29
30namespace
31{
32int extent(const std::vector<int>& v)
33{
34 auto result = std::minmax_element(begin(v), end(v));
35 return 1 + *result.second - *result.first;
36}
37} // namespace
38
39std::vector<int> validIndices(const std::vector<int>& ids)
40{
41 std::vector<int> v;
42 for (auto i = 0; i < ids.size(); i++) {
43 if (ids[i] >= 0) {
44 v.push_back(i);
45 }
46 }
47 return v;
48}
49
50PadGroupType::PadGroupType(int nofPadsX, int nofPadsY, std::vector<int> ids)
51 : mFastId{std::move(ids)},
52 mFastIndices{validIndices(mFastId)},
53 mNofPads{static_cast<int>(std::count_if(begin(mFastId), end(mFastId), [](int i) { return i >= 0; }))},
54 mNofPadsX{nofPadsX},
55 mNofPadsY{nofPadsY}
56{
57}
58
59int PadGroupType::id(int index) const
60{
61 if (index >= 0 && index < mFastId.size()) {
62 return mFastId[index];
63 }
64 return -1;
65}
66
67bool PadGroupType::hasPadById(int id) const
68{
69 return id != -1 && std::find(begin(mFastId), end(mFastId), id) != end(mFastId);
70}
71
72void dump(std::ostream& os, std::string msg, const std::vector<int>& v)
73{
74 os << boost::format("%4s ") % msg;
75 for (auto value : v) {
76 os << boost::format("%2d ") % value;
77 }
78 os << "\n";
79}
80
81std::ostream& operator<<(std::ostream& os, const PadGroupType& pgt)
82{
83 os << "n=" << pgt.getNofPads() << " nx=" << pgt.getNofPadsX() << " ny=" << pgt.getNofPadsY() << "\n";
84 dump(os, "index", pgt.mFastId);
85 return os;
86}
87
88} // namespace impl3
89} // namespace mapping
90} // namespace mch
91
92} // namespace o2
int32_t i
GLuint64EXT * result
Definition glcorearb.h:5662
GLuint GLuint end
Definition glcorearb.h:469
GLuint * ids
Definition glcorearb.h:647
const GLdouble * v
Definition glcorearb.h:832
GLuint index
Definition glcorearb.h:781
GLsizei const GLfloat * value
Definition glcorearb.h:819
std::ostream & operator<<(std::ostream &os, const o2::dataformats::MeanVertexObject &o)
std::vector< int > validIndices(const std::vector< int > &ids)
void dump(std::ostream &os, const o2::mch::TrackMCH &t)
Enum< T >::Iterator begin(Enum< T >)
Definition Defs.h:173
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
PadGroupType(int nofPadsX, int nofPadsY, std::vector< int > ids)
uint64_t const void const *restrict const msg
Definition x9.h:153