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 impl4
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),
54 [](int i) { return i >= 0; }))},
55 mNofPadsX{nofPadsX},
56 mNofPadsY{nofPadsY}
57{
58}
59
60int PadGroupType::id(int index) const
61{
62 if (index >= 0 && index < mFastId.size()) {
63 return mFastId[index];
64 }
65 return -1;
66}
67
68bool PadGroupType::hasPadById(int id) const
69{
70 return id != -1 &&
71 std::find(begin(mFastId), end(mFastId), id) != end(mFastId);
72}
73
74void dump(std::ostream& os, std::string msg, const std::vector<int>& v)
75{
76 os << boost::format("%4s ") % msg;
77 for (auto value : v) {
78 os << boost::format("%2d ") % value;
79 }
80 os << "\n";
81}
82
83std::ostream& operator<<(std::ostream& os, const PadGroupType& pgt)
84{
85 os << "n=" << pgt.getNofPads() << " nx=" << pgt.getNofPadsX()
86 << " ny=" << pgt.getNofPadsY() << "\n";
87 dump(os, "index", pgt.mFastId);
88 return os;
89}
90
91} // namespace impl4
92} // namespace mapping
93} // namespace mch
94
95} // 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