24 if ((
argc >= 2 && ((strcmp(
argv[1],
"-h") == 0) || (strcmp(
argv[1],
"--help") == 0))) ||
argc != 3) {
25 cout <<
"Usage: recycleTccEmu infile outfile\n";
29 string ifilename =
argv[1];
30 string ofilename =
argv[2];
32 for (
int iCh = 0; iCh <
nChs; ++iCh) {
33 for (
int iEvts = 0; iEvts <
nEvts; ++iEvts) {
34 mem[iCh][iEvts] = 0xFFFF;
38 ifstream
in(ifilename.c_str());
49 mem[chnb - 1][bcnb] =
val & 0x7FF;
50 if (
mem[chnb - 1][bcnb] !=
val) {
51 cout <<
"Invalid Et value at line " << oldLineCnt + 1 <<
".\n";
60 cout <<
"Failed to open file " << ifilename <<
"\n";
64 ofstream
out(ofilename.c_str());
67 cout <<
"Failed to open file '" << ofilename <<
"' in write mode.\n";
71 bool singleOldEventCnt =
true;
72 int oldEventCnt[
nChs];
74 for (
int iCh = 0; iCh <
nChs; ++iCh) {
77 while (evtcnt <
nEvts &&
mem[iCh][evtcnt] != 0xFFFF) {
81 oldEventCnt[iCh] = evtcnt;
82 if (oldEventCnt[0] != oldEventCnt[iCh])
83 singleOldEventCnt =
false;
85 cout <<
"Error: no data found for channel " << iCh <<
"\n";
88 for (
int ievt = evtcnt; ievt <
nEvts; ++ievt) {
89 if (
mem[iCh][ievt] != 0xFFFF) {
90 cout <<
"Error: memory offset of channel " << iCh <<
" events are not contiguous.\n";
93 mem[iCh][ievt] =
mem[iCh][ievt % evtcnt];
96 for (
int ievt = 0; ievt <
nEvts; ++ievt) {
97 out << iCh + 1 <<
"\t" << ievt <<
"\t" << hex <<
"0x" << setfill(
'0') << setw(4) <<
mem[iCh][ievt] << setfill(
' ')
104 if (singleOldEventCnt && (
nEvts % oldEventCnt[0] != 0)) {
105 cout <<
"Warning: ouput event count (2048) is not a mulitple of input " 108 if (!singleOldEventCnt) {
110 for (
int iCh = 0; iCh <
nChs; ++iCh) {
111 if (
nEvts % oldEventCnt[iCh]) {
112 s << (
s.str().empty() ?
"" :
", ") << iCh;
115 if (!
s.str().empty())
116 cout <<
"Warning: ouput event count (2048) for channel" << (
s.str().size() > 1 ?
"s" :
"") <<
" " <<
s.str()
117 <<
" is not a mulitple of input event counts\n";
120 if (!singleOldEventCnt) {
121 cout <<
"Info: in the input file the event count depends on the channel";
int main(int argc, char *argv[])
uint16_t mem[nChs][nEvts]