Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PixelChanneldentifier::thePacking constexpr #28617

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 35 additions & 38 deletions DataFormats/SiPixelDetId/interface/PixelChannelIdentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,17 @@
#include <utility>
#include "FWCore/Utilities/interface/GCC11Compatibility.h"

class PixelChannelIdentifier {
public:
typedef unsigned int PackedDigiType;
typedef unsigned int ChannelType;

static std::pair<int, int> channelToPixel(int ch) {
int row = (ch >> thePacking.column_width) & thePacking.row_mask;
int col = ch & thePacking.column_mask;
return std::pair<int, int>(row, col);
}

static int pixelToChannel(int row, int col) { return (row << thePacking.column_width) | col; }

namespace pixelchanelidentifierimpl {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Packing class had to be removed from within PixelChannelIdentifier for a technicality about C++ and constexpr. You can not declare a constexpr member data where the type is defined within the class. The reason is the class is not defined until its closing }; and that includes classes defined within it. The last bit is you can't use constexpr on an undefined type. Declaring Packing outside of PixelChannelIdentifier makes use Packing is fully defined when the compiler reaches the constexpr.

/**
* Pack the pixel information to use less memory
*/

class Packing {
public:
using PackedDigiType = unsigned int;

// Constructor: pre-computes masks and shifts from field widths
// gcc4.8: sorry, unimplemented: use of the value of the object being constructed in a constant expression
// no constexpr yet....
Packing(unsigned int row_w, unsigned int column_w, unsigned int time_w, unsigned int adc_w)
constexpr Packing(unsigned int row_w, unsigned int column_w, unsigned int time_w, unsigned int adc_w)
: row_width(row_w),
column_width(column_w),
adc_width(adc_w),
Expand All @@ -43,37 +31,46 @@ class PixelChannelIdentifier {
max_column(column_mask),
max_adc(adc_mask) {}

int row_width;
int column_width;
int adc_width;
const int row_width;
const int column_width;
const int adc_width;

int row_shift;
int column_shift;
int time_shift;
int adc_shift;
const int row_shift;
const int column_shift;
const int time_shift;
const int adc_shift;

PackedDigiType row_mask;
PackedDigiType column_mask;
PackedDigiType time_mask;
PackedDigiType adc_mask;
PackedDigiType rowcol_mask;
const PackedDigiType row_mask;
const PackedDigiType column_mask;
const PackedDigiType time_mask;
const PackedDigiType adc_mask;
const PackedDigiType rowcol_mask;

int max_row;
int max_column;
int max_adc;
const int max_row;
const int max_column;
const int max_adc;
};
} // namespace pixelchanelidentifierimpl

class PixelChannelIdentifier {
public:
//#ifndef CMS_NOCXX11
static Packing packing() { return Packing(8, 9, 4, 11); }
typedef unsigned int PackedDigiType;
typedef unsigned int ChannelType;

static const Packing thePacking;
static std::pair<int, int> channelToPixel(int ch) {
int row = (ch >> thePacking.column_width) & thePacking.row_mask;
int col = ch & thePacking.column_mask;
return std::pair<int, int>(row, col);
}

static int pixelToChannel(int row, int col) { return (row << thePacking.column_width) | col; }

using Packing = pixelchanelidentifierimpl::Packing;

//#else
//static constexpr Packing packing() { return Packing(8, 9, 4, 11);}
public:
constexpr static Packing packing() { return Packing(8, 9, 4, 11); }

//static constexpr Packing thePacking = packing();
//#endif
constexpr static Packing thePacking = {11, 11, 0, 10};
};

#endif
32 changes: 0 additions & 32 deletions DataFormats/SiPixelDetId/src/PixelChannelIdentifier.cc

This file was deleted.