@@ -20,110 +20,104 @@ uint16_t mem[nChs][nEvts];
2020 * general the number of initial events is choosen as a divider of 2048.
2121 */
2222
23- int main (int argc, char * argv[]){
24- if ((argc>=2 && ( (strcmp (argv[1 ]," -h" )==0 ) || (strcmp (argv[1 ]," --help" )==0 ) ))
25- || argc!=3 ){
23+ int main (int argc, char * argv[]) {
24+ if ((argc >= 2 && ((strcmp (argv[1 ], " -h" ) == 0 ) || (strcmp (argv[1 ], " --help" ) == 0 ))) || argc != 3 ) {
2625 cout << " Usage: recycleTccEmu infile outfile\n " ;
2726 return 1 ;
2827 }
29-
28+
3029 string ifilename = argv[1 ];
3130 string ofilename = argv[2 ];
32-
33- for (int iCh= 0 ; iCh< nChs; ++iCh){
34- for (int iEvts = 0 ; iEvts< nEvts; ++iEvts){
31+
32+ for (int iCh = 0 ; iCh < nChs; ++iCh) {
33+ for (int iEvts = 0 ; iEvts < nEvts; ++iEvts) {
3534 mem[iCh][iEvts] = 0xFFFF ;
3635 }
3736 }
38-
37+
3938 ifstream in (ifilename.c_str ());
4039 int chnb;
4140 int bcnb;
42- int val ;
43- int dummy ;
44- int oldLineCnt = 0 ;
45-
41+ int val;
42+ int dummy;
43+ int oldLineCnt = 0 ;
44+
4645 // reads input file:
47- if (in){
48- while (!in.eof ()) {
49- in >>dec>> chnb >> bcnb >>hex>> val >> dummy ;
50- mem[chnb- 1 ][bcnb] = val& 0x7FF ;
51- if (mem[chnb- 1 ][bcnb]!= val){
52- cout << " Invalid Et value at line " << oldLineCnt+ 1 << " .\n " ;
53- exit (1 );
46+ if (in) {
47+ while (!in.eof ()) {
48+ in >> dec >> chnb >> bcnb >> hex >> val >> dummy;
49+ mem[chnb - 1 ][bcnb] = val & 0x7FF ;
50+ if (mem[chnb - 1 ][bcnb] != val) {
51+ cout << " Invalid Et value at line " << oldLineCnt + 1 << " .\n " ;
52+ exit (1 );
5453 }
5554 // cout<<"Channel: "<< dec <<chnb <<", BX: "
5655 // << dec << bcnb << " filled with val:"<< hex<< mem[chnb-1][bcnb]
5756 // << dec << endl;
5857 ++oldLineCnt;
5958 }
60- } else {
59+ } else {
6160 cout << " Failed to open file " << ifilename << " \n " ;
6261 }
6362
6463 in.close ();
6564 ofstream out (ofilename.c_str ());
66-
67- if (!out){
68- cout << " Failed to open file '" << ofilename
69- << " ' in write mode.\n " ;
65+
66+ if (!out) {
67+ cout << " Failed to open file '" << ofilename << " ' in write mode.\n " ;
7068 return 1 ;
7169 }
72-
73-
70+
7471 bool singleOldEventCnt = true ;
7572 int oldEventCnt[nChs];
7673 // fills output file:
77- for (int iCh = 0 ; iCh< nChs; ++iCh){
74+ for (int iCh = 0 ; iCh < nChs; ++iCh) {
7875 int evtcnt = 0 ;
7976 // find first not initialized events:
80- while (evtcnt<nEvts && mem[iCh][evtcnt]!=0xFFFF ){++evtcnt;}
77+ while (evtcnt < nEvts && mem[iCh][evtcnt] != 0xFFFF ) {
78+ ++evtcnt;
79+ }
8180 // cout << "ch " << iCh << " event count: " << evtcnt << "\n";
8281 oldEventCnt[iCh] = evtcnt;
83- if (oldEventCnt[0 ]!=oldEventCnt[iCh]) singleOldEventCnt = false ;
84- if (evtcnt==0 ){
85- cout << " Error: no data found for channel " << iCh << " \n " ;
82+ if (oldEventCnt[0 ] != oldEventCnt[iCh])
83+ singleOldEventCnt = false ;
84+ if (evtcnt == 0 ) {
85+ cout << " Error: no data found for channel " << iCh << " \n " ;
8686 }
8787 // clones data of channel iCh
88- for (int ievt = evtcnt; ievt<nEvts; ++ievt){
89- if (mem[iCh][ievt]!=0xFFFF ){
90- cout << " Error: memory offset of channel " << iCh
91- << " events are not contiguous.\n " ;
92- exit (1 );
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 " ;
91+ exit (1 );
9392 }
94- mem[iCh][ievt] = mem[iCh][ievt% evtcnt];
93+ mem[iCh][ievt] = mem[iCh][ievt % evtcnt];
9594 }
96-
97- for (int ievt=0 ; ievt<nEvts; ++ievt){
98- out << iCh+1 << " \t " << ievt
99- << " \t " << hex << " 0x" << setfill (' 0' ) << setw (4 )
100- << mem[iCh][ievt]
101- << setfill (' ' ) << dec << " \t 0"
102- << " \n " ;
95+
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 (' ' )
98+ << dec << " \t 0"
99+ << " \n " ;
103100 }
104101 }
105102
106103 // warning for aperiodic case:
107- if (singleOldEventCnt && (nEvts% oldEventCnt[0 ]!= 0 )){
104+ if (singleOldEventCnt && (nEvts % oldEventCnt[0 ] != 0 )) {
108105 cout << " Warning: ouput event count (2048) is not a mulitple of input "
109- " event counts\n " ;
106+ " event counts\n " ;
110107 }
111- if (!singleOldEventCnt){
108+ if (!singleOldEventCnt) {
112109 stringstream s;
113- for (int iCh= 0 ; iCh< nChs; ++iCh){
114- if (nEvts% oldEventCnt[iCh]){
115- s << (s.str ().empty ()? " " : " , " ) << iCh;
110+ for (int iCh = 0 ; iCh < nChs; ++iCh) {
111+ if (nEvts % oldEventCnt[iCh]) {
112+ s << (s.str ().empty () ? " " : " , " ) << iCh;
116113 }
117114 }
118- if (!s.str ().empty ())
119- cout << " Warning: ouput event count (2048) for channel"
120- << (s.str ().size ()>1 ?" s" :" " ) << " "
121- << s.str ()
122- << " is not a mulitple of input event counts\n " ;
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 " ;
123118 }
124-
125- if (!singleOldEventCnt){
119+
120+ if (!singleOldEventCnt) {
126121 cout << " Info: in the input file the event count depends on the channel" ;
127122 }
128123}
129-
0 commit comments