File indexing completed on 2024-04-06 12:10:48
0001 #include "PhysicsToBitConverter.h"
0002
0003 namespace l1t {
0004 PhysicsToBitConverter::PhysicsToBitConverter() {
0005 for (int m = 0; m < 2; m++) {
0006 for (int n = 0; n < 6; n++) {
0007 words32bitLink[m][n] = 0;
0008 }
0009 }
0010 for (int m = 0; m < 2; m++) {
0011 for (int n = 0; n < 192; n++) {
0012 bitsLink[m][n] = 0;
0013 }
0014 }
0015 }
0016
0017 void PhysicsToBitConverter::Convert() {
0018 for (int iword = 0; iword < 6; iword++) {
0019 for (int ibit = 0; ibit < 32; ibit++) {
0020
0021
0022 bitsLink[0][ibit + iword * 32] = ReadBitInInt(ibit, words32bitLink[0][iword]);
0023 bitsLink[1][ibit + iword * 32] = ReadBitInInt(ibit, words32bitLink[1][iword]);
0024 }
0025 }
0026 }
0027
0028 void PhysicsToBitConverter::Extract32bitwords() {
0029
0030
0031 for (int ilink = 0; ilink < 2; ilink++) {
0032 for (int iword = 0; iword < 6; iword++) {
0033 words32bitLink[ilink][iword] = BuildDecimalValue(iword * 32, 32, ilink);
0034 }
0035 }
0036 }
0037
0038 int PhysicsToBitConverter::GetObject(rctDataBase::rctObjectType t, int firstindex, int secondindex) {
0039 int mystart = databaseobject.GetIndices(t, firstindex, secondindex);
0040 int mylength = databaseobject.GetLength(t);
0041 int mylink = databaseobject.GetLink(t);
0042
0043 return BuildDecimalValue(mystart, mylength, mylink);
0044 }
0045
0046 void PhysicsToBitConverter::SetObject(rctDataBase::rctObjectType t, int value, int firstindex, int secondindex) {
0047 int mystart = databaseobject.GetIndices(t, firstindex, secondindex);
0048 int mylength = databaseobject.GetLength(t);
0049 int mylink = databaseobject.GetLink(t);
0050
0051 if (value > (pow(2, mylength) - 1))
0052 std::cout << "The value you are trying to set has more bins than expected " << std::endl;
0053 for (int i = 0; i < mylength; i++)
0054 bitsLink[mylink][i + mystart] = (value >> i) & 0x1;
0055 }
0056
0057 int PhysicsToBitConverter::ReadBitInInt(int bit, int value) {
0058 std::bitset<32> foo(value);
0059 return foo[bit];
0060 }
0061
0062 int PhysicsToBitConverter::BuildDecimalValue(int firstbit, int bitlength, int linkid) {
0063 int myvalue = 0;
0064 int counter = 0;
0065
0066 for (int m = firstbit; m < firstbit + bitlength; m++) {
0067 myvalue |= (bitsLink[linkid][m] & (0x1)) << counter;
0068 counter++;
0069 }
0070 return myvalue;
0071 }
0072 }