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;
730 if (!errorDecode && field ==
'H') {
731 stream <<
" -- CMID " <<
m_MROS.cmid();
732 stream <<
" FEL1ID " <<
m_MROS.fel1id();
734 stream <<
" ERROR IN HEADER DECODING ";
743 if (!errorDecode && field ==
'S') {
744 stream <<
" -- FEBCID " <<
m_MROS.febcid();
746 stream <<
" ERROR IN SUBHEADER DECODING ";
757 stream << hex << p->hit << dec;
758 ubit16 errorDecode =
m_MROS.decodeFragment(p->hit, field);
759 if (!errorDecode && field ==
'B') {
760 stream <<
" -- BC " <<
m_MROS.bcid();
761 stream <<
" TIME " <<
m_MROS.time();
763 stream <<
" IJK " <<
m_MROS.ijk();
764 stream <<
" STRIP " <<
m_MROS.channel();
766 stream <<
" OVL " <<
m_MROS.overlap();
767 stream <<
" THR " <<
m_MROS.threshold();
770 stream <<
" ERROR IN BODY DECODING ";
780 stream <<
" -- CODE " << 1;
782 if (!errorDecode && field ==
'F') {
783 stream <<
" CRC " << hex <<
m_MROS.crc() << dec;
785 stream <<
" ERROR IN FOOTER DECODING ";
792 stream << hex <<
m_Header << dec << endl;
796 stream << hex << p->hit << dec << endl;
799 stream << hex <<
m_Footer << dec << endl;
820 if (
m_checkCR && !(output & 0x00000020)) output += 32;
835 ubit16 currIJK, currBCID, currTIME, currCHANNEL;
836 ubit16 nextIJK, nextBCID, nextTIME, nextCHANNEL;
848 m_MROS.decodeFragment(p->hit, field);
852 currCHANNEL =
m_MROS.channel();
856 m_MROS.decodeFragment(pnext->
hit, field);
860 nextCHANNEL =
m_MROS.channel();
865 if (nextIJK < currIJK) {
868 }
else if (nextIJK == currIJK) {
869 if (nextBCID < currBCID) {
872 }
else if (nextBCID == currBCID) {
873 if (nextTIME < currTIME) {
876 }
else if (nextTIME == currTIME) {
877 if (nextCHANNEL <= currCHANNEL) {
885 }
else if (currIJK == 6) {
887 if (nextIJK == currIJK) {
888 if (nextBCID != currBCID || nextTIME != currTIME) {
892 if (nextCHANNEL <= currCHANNEL) {
897 }
else if (nextIJK == 7) {
900 }
else if (currIJK == 7) {
910 if (outTemp > 0 && debugPrint) {
911 cout <<
"checkBodyOrder output= " << output <<
" with " << hex << pnext->
hit << dec << endl;
919 if (debugPrint) cout <<
" CheckBodyOrder; IJK 6 exists but the related IJK 7 has been found " << endl;
920 }
else if (currIJK == 7 && prevIJK != 6) {
922 if (debugPrint) cout <<
" CheckBodyOrder; IJK 7 exists but the related IJK 6 has been found " << endl;
967 const ubit16 ROOffset = 2;
985 stripaddress = CHANNEL;
990 stripaddress = CHANNEL;
995 stripaddress = CHANNEL;
1000 stripaddress = CHANNEL;
1005 stripaddress = CHANNEL;
1010 stripaddress = CHANNEL;
1012 default:
throw std::runtime_error(
"MatrixReadOut::doMatrix: IJK= " + std::to_string(IJK) +
" out of RANGE");
1017 absTime = 25. * ((float)BCID + ((float)(TIME - ROOffset)) / 8.);
1018 m_CM->putData(sidemat, layer, stripaddress, absTime);
1033 std::cout <<
" makeTestPattern " << std::endl;
1038 vhdlinput.open(
"vhdl.input", ios::app);
1039 if (!vhdlinput) { cout <<
" File for vhdl analysis not opened. " << endl <<
" ==================================" << endl << endl; };
1041 const ubit16 maxchan = 100;
1042 const ubit16 maxtimes = 200;
1043 ubit16 IJ[maxtimes][4], channels[maxtimes][4][maxchan];
1044 float times[maxtimes] = {0};
1046 strcpy(plane[0],
"I0");
1047 strcpy(plane[1],
"I1");
1048 strcpy(plane[2],
"J0");
1049 strcpy(plane[3],
"J1");
1051 for (
ubit16 l = 0; l < maxtimes; l++) {
1052 for (
ubit16 i = 0; i < 4; i++) { IJ[l][i] = 0; }
1055 float timeover = 999999.;
1056 bool completed =
false;
1057 float timelast = -timeover;
1059 std::cout <<
this << std::endl;
1061 while (!completed) {
1062 float timemin = timeover;
1065 int ijk = MRS.
ijk();
1067 float time = ((float)(MRS.
bcid() * 8 + MRS.
time()) - 0.5) * 3.125;
1070 if (time > timelast && time < timemin) timemin = time;
1074 if (timemin == timeover) {
1077 ubit16 this_time_counter = 0;
1080 int ijk = MRS.
ijk();
1083 float time = ((float)(MRS.
bcid() * 8 + MRS.
time()) - 0.5) * 3.125;
1084 if (time == timemin && ntimes < maxtimes) {
1085 if (!this_time_counter) ntimes++;
1086 this_time_counter++;
1092 else if (ijk == 2 || ijk == 3)
1094 else if (ijk == 4 || ijk == 5)
1096 times[ntimes - 1] = time;
1097 if (IJ[ntimes - 1][ijk_index] < maxchan) {
1098 IJ[ntimes - 1][ijk_index]++;
1099 channels[ntimes - 1][ijk_index][IJ[ntimes - 1][ijk_index] - 1] = channel;
1112 vhdlinput <<
" RUN " <<
run <<
" EVENT " << eventNum <<
" CMID " << cmid <<
" WINDOW " << NBunch;
1113 vhdlinput <<
" LINES " << (ntimes + ktimes) <<
'\n';
1115 for (
ubit16 l = 0; l < ntimes; l++) {
1116 vhdlinput <<
" TIME " << times[l] <<
" ";
1117 for (
ubit16 i = 0; i < 4; i++) {
1118 vhdlinput << plane[i][0] << plane[i][1] <<
" " << IJ[l][i] <<
" ";
1119 for (
ubit16 j = 0; j < IJ[l][i]; j++) { vhdlinput << channels[l][i][j] <<
" "; }
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()
int run(int argc, char *argv[])