CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
recycleTccEmu.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <sstream>
4 #include <inttypes.h>
5 #include <iomanip>
6 #include <cstdlib>
7 #include <stdio.h>
8 #include <string.h>
9 using namespace std;
10 
11 const int nChs = 68;
12 const int nEvts = 2048;
13 uint16_t mem[nChs][nEvts];
14 
23 int main(int argc, char* argv[]){
24  if((argc>=2 && ( (strcmp(argv[1],"-h")==0) || (strcmp(argv[1],"--help")==0) ))
25  || argc!=3){
26  cout << "Usage: recycleTccEmu infile outfile\n";
27  return 1;
28  }
29 
30  string ifilename = argv[1];
31  string ofilename = argv[2];
32 
33  for(int iCh=0; iCh<nChs; ++iCh){
34  for(int iEvts = 0; iEvts<nEvts; ++iEvts){
35  mem[iCh][iEvts] = 0xFFFF;
36  }
37  }
38 
39  ifstream in(ifilename.c_str());
40  int chnb;
41  int bcnb;
42  int val ;
43  int dummy ;
44  int oldLineCnt = 0;
45 
46  //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);
54  }
55  // cout<<"Channel: "<< dec <<chnb <<", BX: "
56  // << dec << bcnb << " filled with val:"<< hex<< mem[chnb-1][bcnb]
57  // << dec << endl;
58  ++oldLineCnt;
59  }
60  } else{
61  cout << "Failed to open file " << ifilename << "\n";
62  }
63 
64  in.close();
65  ofstream out(ofilename.c_str());
66 
67  if(!out){
68  cout << "Failed to open file '" << ofilename
69  << "' in write mode.\n";
70  return 1;
71  }
72 
73 
74  bool singleOldEventCnt = true;
75  int oldEventCnt[nChs];
76  //fills output file:
77  for(int iCh = 0; iCh<nChs; ++iCh){
78  int evtcnt = 0;
79  //find first not initialized events:
80  while(evtcnt<nEvts && mem[iCh][evtcnt]!=0xFFFF){++evtcnt;}
81  //cout << "ch " << iCh << " event count: " << evtcnt << "\n";
82  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";
86  }
87  //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);
93  }
94  mem[iCh][ievt] = mem[iCh][ievt%evtcnt];
95  }
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 << "\t0"
102  << "\n";
103  }
104  }
105 
106  //warning for aperiodic case:
107  if(singleOldEventCnt && (nEvts%oldEventCnt[0]!=0)){
108  cout << "Warning: ouput event count (2048) is not a mulitple of input "
109  "event counts\n" ;
110  }
111  if(!singleOldEventCnt){
112  stringstream s;
113  for(int iCh=0; iCh<nChs; ++iCh){
114  if(nEvts%oldEventCnt[iCh]){
115  s << (s.str().size()==0?"":", ") << iCh;
116  }
117  }
118  if(s.str().size()!=0)
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" ;
123  }
124 
125  if(!singleOldEventCnt){
126  cout << "Info: in the input file the event count depends on the channel";
127  }
128 }
129 
const int nChs
uint16_t mem[nChs][nEvts]
tuple out
Definition: dbtoconf.py:99
const int nEvts
tuple argc
Definition: dir2webdir.py:38
tuple cout
Definition: gather_cfg.py:121