File indexing completed on 2024-04-06 12:02:34
0001 #include "CondFormats/SiPixelObjects/interface/SiPixelDbItem.h"
0002
0003 #include <iostream>
0004 #include <algorithm>
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 void SiPixelDbItem::setNoise(short n) {
0027 PackedPixDbType newNoise = (n & packing_.noise_mask) << packing_.noise_shift;
0028 PackedPixDbType oldValue = packedVal_ & (~(packing_.noise_mask << packing_.noise_shift));
0029 packedVal_ = oldValue | newNoise;
0030 }
0031
0032 void SiPixelDbItem::setPedestal(short p) {
0033 PackedPixDbType newPedestal = (p & packing_.pedestal_mask) << packing_.pedestal_shift;
0034 PackedPixDbType oldValue = packedVal_ & (~(packing_.pedestal_mask << packing_.pedestal_shift));
0035 packedVal_ = oldValue | newPedestal;
0036 }
0037
0038 void SiPixelDbItem::setGain(float g) {
0039
0040 int mult_factor = 1 << packing_.gain_shift;
0041 unsigned short gInIntRep = int(g * mult_factor);
0042
0043 PackedPixDbType newGain = (gInIntRep & packing_.gain_mask) << packing_.gain_shift;
0044 PackedPixDbType oldValue = packedVal_ & (~(packing_.gain_mask << packing_.gain_shift));
0045 packedVal_ = oldValue | newGain;
0046 }
0047
0048 void SiPixelDbItem::setStatus(char s) {
0049 PackedPixDbType newStatus = (s & packing_.status_mask) << packing_.status_shift;
0050 PackedPixDbType oldValue = packedVal_ & (~(packing_.status_mask << packing_.status_shift));
0051 packedVal_ = oldValue | newStatus;
0052 }
0053
0054
0055 void SiPixelDbItem::set(short noise, short pedestal, float gain, char status) {
0056
0057 int mult_factor = 1 << packing_.gain_shift;
0058 unsigned short gInIntRep = int(gain * mult_factor);
0059
0060 packedVal_ = (noise << packing_.noise_shift) | (pedestal << packing_.pedestal_shift) |
0061 (gInIntRep << packing_.gain_shift) | (status << packing_.status_shift);
0062 }
0063
0064 SiPixelDbItem::Packing::Packing(int noise_w, int pedestal_w, int gain_w, int status_w)
0065 : noise_width(noise_w), pedestal_width(pedestal_w), status_width(status_w) {
0066
0067
0068
0069
0070 if (noise_w + pedestal_w + gain_w + status_w != 32) {
0071 std::cout << std::endl
0072 << "Error in SiPixelDbItem::Packing constructor:"
0073 << "sum of field widths != 32" << std::endl;
0074
0075 }
0076
0077
0078
0079 noise_shift = 0;
0080 pedestal_shift = noise_shift + noise_w;
0081 gain_shift = pedestal_shift + pedestal_w;
0082 status_shift = gain_shift + gain_w;
0083
0084
0085
0086 PackedPixDbType zero32 = 0;
0087
0088 noise_mask = ~(~zero32 << noise_w);
0089 pedestal_mask = ~(~zero32 << pedestal_w);
0090 gain_mask = ~(~zero32 << gain_w);
0091 status_mask = ~(~zero32 << status_w);
0092 }
0093
0094
0095 SiPixelDbItem::Packing SiPixelDbItem::packing_(8, 8, 8, 8);