24 FEevent = FEevent % 512;
42 FEevent = FEevent % 512;
92 }
else if (field ==
'S') {
99 }
else if (field ==
'F') {
280 CMcode = 4 *
m_CM->getLowHigh() + 2 *
m_CM->getProjection() +
m_CM->getLocalAdd();
283 CMcode = 4 *
m_CM->getLowHigh() + 2 * abs(
m_CM->getProjection() - 1) +
m_CM->getLocalAdd();
287 throw std::runtime_error(
"MatrixReadOut::makeHeader: m_CM object does not exist");
295 throw std::runtime_error(
"MatrixReadOut::makeSubHeader: m_CM object does not exist");
305 throw std::runtime_error(
"MatrixReadOut::makeCMABody: m_CM object does not exist");
313 throw std::runtime_error(
"MatrixReadOut::makeFooter: m_CM object does not exist");
346 ubit16 i, j, k, l, ijk, lijk;
350 for (ijk = 0; ijk < 6; ijk++) {
361 if (ijk == 0 || ijk == 2 || ijk == 3)
370 for (lijk = 0; lijk < 32; lijk++) {
375 if (ijk == 3 || ijk == 5) l = lijk + 32;
406 if ((
m_CM->rodat[i][j][k][l / 32] & (1 << (l % 32)))) {
416 IJK = 2 * j + l / 32 + 2;
429 CMABodyval[2] = TIME;
431 CMABodyval[4] = CHANNEL;
442 throw std::runtime_error(
"MatrixReadOut::makeCMABodyHit: m_CM object does not exist");
450 ubit16 BC, TIME, IJK, CHANNEL;
466 for (channel = 0; channel <
m_nchan[0]; channel++) {
467 if (
m_CM->k_readout[
h] & (one << channel)) {
484 CMABodyval[2] = TIME;
486 CMABodyval[4] = CHANNEL;
496 if (
m_CM->highestthRO[
h]) {
500 over_h = over_h << 2;
503 CHANNEL = (over_h | thresh_h);
512 CMABodyval[2] = TIME;
514 CMABodyval[4] = CHANNEL;
524 throw std::runtime_error(
"MatrixReadOut::makeHeader: m_CM object does not exist");
532 headerval[1] = CMcode;
550 CMABodyval[2] = TIME;
552 CMABodyval[4] = CHANNEL;
582 newElement->
hit = newHit;
583 newElement->
next = next;
587 previous->next = newElement;
598 m_MROS.decodeFragment(newHit, field);
608 m_MROS.decodeFragment(p->hit, field);
610 if (hitIJK >
m_MROS.ijk()) {
613 }
else if (hitIJK <
m_MROS.ijk()) {
616 }
else if (hitIJK ==
m_MROS.ijk()) {
617 if (hitBCID >
m_MROS.bcid()) {
620 }
else if (hitBCID <
m_MROS.bcid()) {
623 }
else if (hitBCID ==
m_MROS.bcid()) {
624 if (hitTIME >
m_MROS.time()) {
627 }
else if (hitTIME <
m_MROS.time()) {
630 }
else if (hitTIME ==
m_MROS.time()) {
631 if (hitCHANNEL >
m_MROS.channel()) {
634 }
else if (hitCHANNEL <
m_MROS.channel()) {
638 throw std::runtime_error(
"duplicazione di hit???");
679 *(Body + i) = p->hit;
735 if (!errorDecode && field ==
'H') {
736 stream <<
" -- CMID " <<
m_MROS.cmid();
737 stream <<
" FEL1ID " <<
m_MROS.fel1id();
739 stream <<
" ERROR IN HEADER DECODING ";
748 if (!errorDecode && field ==
'S') {
749 stream <<
" -- FEBCID " <<
m_MROS.febcid();
751 stream <<
" ERROR IN SUBHEADER DECODING ";
762 stream << hex << p->hit << dec;
763 ubit16 errorDecode =
m_MROS.decodeFragment(p->hit, field);
764 if (!errorDecode && field ==
'B') {
765 stream <<
" -- BC " <<
m_MROS.bcid();
766 stream <<
" TIME " <<
m_MROS.time();
768 stream <<
" IJK " <<
m_MROS.ijk();
769 stream <<
" STRIP " <<
m_MROS.channel();
771 stream <<
" OVL " <<
m_MROS.overlap();
772 stream <<
" THR " <<
m_MROS.threshold();
775 stream <<
" ERROR IN BODY DECODING ";
785 stream <<
" -- CODE " << 1;
787 if (!errorDecode && field ==
'F') {
788 stream <<
" CRC " << hex <<
m_MROS.crc() << dec;
790 stream <<
" ERROR IN FOOTER DECODING ";
797 stream << hex <<
m_Header << dec << endl;
801 stream << hex << p->hit << dec << endl;
804 stream << hex <<
m_Footer << dec << endl;
825 if (
m_checkCR && !(output & 0x00000020)) output += 32;
840 ubit16 currIJK, currBCID, currTIME, currCHANNEL;
841 ubit16 nextIJK, nextBCID, nextTIME, nextCHANNEL;
853 m_MROS.decodeFragment(p->hit, field);
857 currCHANNEL =
m_MROS.channel();
861 m_MROS.decodeFragment(pnext->
hit, field);
865 nextCHANNEL =
m_MROS.channel();
870 if (nextIJK < currIJK) {
873 }
else if (nextIJK == currIJK) {
874 if (nextBCID < currBCID) {
877 }
else if (nextBCID == currBCID) {
878 if (nextTIME < currTIME) {
881 }
else if (nextTIME == currTIME) {
882 if (nextCHANNEL <= currCHANNEL) {
890 }
else if (currIJK == 6) {
892 if (nextIJK == currIJK) {
893 if (nextBCID != currBCID || nextTIME != currTIME) {
897 if (nextCHANNEL <= currCHANNEL) {
902 }
else if (nextIJK == 7) {
905 }
else if (currIJK == 7) {
915 if (outTemp > 0 && debugPrint) {
916 cout <<
"checkBodyOrder output= " << output <<
" with " << hex << pnext->
hit << dec << endl;
924 if (debugPrint) cout <<
" CheckBodyOrder; IJK 6 exists but the related IJK 7 has been found " << endl;
925 }
else if (currIJK == 7 && prevIJK != 6) {
927 if (debugPrint) cout <<
" CheckBodyOrder; IJK 7 exists but the related IJK 6 has been found " << endl;
972 const ubit16 ROOffset = 2;
990 stripaddress = CHANNEL;
995 stripaddress = CHANNEL;
1000 stripaddress = CHANNEL;
1005 stripaddress = CHANNEL;
1010 stripaddress = CHANNEL;
1015 stripaddress = CHANNEL;
1017 default:
throw std::runtime_error(
"MatrixReadOut::doMatrix: IJK= " + std::to_string(IJK) +
" out of RANGE");
1022 absTime = 25. * ((float)BCID + ((float)(TIME - ROOffset)) / 8.);
1023 m_CM->putData(sidemat, layer, stripaddress, absTime);
1038 std::cout <<
" makeTestPattern " << std::endl;
1043 vhdlinput.open(
"vhdl.input", ios::app);
1044 if (!vhdlinput) { cout <<
" File for vhdl analysis not opened. " << endl <<
" ==================================" << endl << endl; };
1046 const ubit16 maxchan = 100;
1047 const ubit16 maxtimes = 200;
1048 ubit16 IJ[maxtimes][4], channels[maxtimes][4][maxchan];
1049 float times[maxtimes] = {0};
1051 strcpy(plane[0],
"I0");
1052 strcpy(plane[1],
"I1");
1053 strcpy(plane[2],
"J0");
1054 strcpy(plane[3],
"J1");
1056 for (
ubit16 l = 0; l < maxtimes; l++) {
1057 for (
ubit16 i = 0; i < 4; i++) { IJ[l][i] = 0; }
1060 float timeover = 999999.;
1061 bool completed =
false;
1062 float timelast = -timeover;
1064 std::cout <<
this << std::endl;
1066 while (!completed) {
1067 float timemin = timeover;
1070 int ijk = MRS.
ijk();
1072 float time = ((float)(MRS.
bcid() * 8 + MRS.
time()) - 0.5) * 3.125;
1075 if (time > timelast && time < timemin) timemin = time;
1079 if (timemin == timeover) {
1082 ubit16 this_time_counter = 0;
1085 int ijk = MRS.
ijk();
1088 float time = ((float)(MRS.
bcid() * 8 + MRS.
time()) - 0.5) * 3.125;
1089 if (time == timemin && ntimes < maxtimes) {
1090 if (!this_time_counter) ntimes++;
1091 this_time_counter++;
1097 else if (ijk == 2 || ijk == 3)
1099 else if (ijk == 4 || ijk == 5)
1101 times[ntimes - 1] = time;
1102 if (IJ[ntimes - 1][ijk_index] < maxchan) {
1103 IJ[ntimes - 1][ijk_index]++;
1104 channels[ntimes - 1][ijk_index][IJ[ntimes - 1][ijk_index] - 1] = channel;
1117 vhdlinput <<
" RUN " <<
run <<
" EVENT " << eventNum <<
" CMID " << cmid <<
" WINDOW " << NBunch;
1118 vhdlinput <<
" LINES " << (ntimes + ktimes) << std::endl;
1120 for (
ubit16 l = 0; l < ntimes; l++) {
1121 vhdlinput <<
" TIME " << times[l] <<
" ";
1122 for (
ubit16 i = 0; i < 4; i++) {
1123 vhdlinput << plane[i][0] << plane[i][1] <<
" " << IJ[l][i] <<
" ";
1124 for (
ubit16 j = 0; j < IJ[l][i]; j++) { vhdlinput << channels[l][i][j] <<
" "; }
1126 vhdlinput << std::endl;
unsigned short int ubit16
BaseObject(ObjectType, const std::string &)
void writeRecord(ubit16 thisRecord, bool last)
ubit16 checkCRC8(ubit16 foot)
MatrixReadOut(Matrix *p, ubit16 FEevent, uint NOBXS, DataVersion=MatrixReadOut::Atlas)
MatrixReadOut::DataVersion m_data_version
void setManager(ReadOutManager *boss)
void doMatrix(Matrix *CMpointer)
void readCMABody(ubit16 *Body)
ubit16 m_numberOfWordsInFrag
ubit16 checkBodyOrder(bool debugPrint=false)
MatrixReadOutStructure getFooter()
void displayHeader(std::ostream &stream)
void displayBody(std::ostream &stream)
ReadOutManager * m_myBoss
ubit16 m_addressOfWordScanned
friend class ReadOutManager
void bytestream(std::ostream &stream)
void sortAndMakeNewHit(ubit16 newHit)
void displayFooter(std::ostream &stream)
void writeHeader(ubit16 CMcode)
MatrixReadOutStructure m_MROS
MatrixReadOutStructure getCMAHit(int index)
ubit16 m_numberOfWordsInBody
void display(std::ostream &stream)
void makeTestPattern(ubit16 mode, ubit16 ktimes, int eventNum)
ubit16 m_checkSubHeaderPos
ubit16 readCMABodyCurrent()
MatrixReadOutStructure getHeader()
ubit16 numberOfFragmentWords()
void initialize(uint NOBXS)
void writeCMABody(ubit16 _BC, ubit16 _TIME, ubit16 IJK, ubit16 _STRIP)
ubit16 m_checkSubHeaderNum
void makeNewHit(ubit16 newHit)
void displaySubHeader(std::ostream &stream)
MatrixReadOutStructure getSubHeader()