Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:23

0001 #include <iostream>
0002 #include <fstream>
0003 #include <sstream>
0004 #include <cinttypes>
0005 #include <iomanip>
0006 #include <cstdlib>
0007 #include <cstdio>
0008 #include <cstring>
0009 using namespace std;
0010 
0011 const int nChs = 68;
0012 const int nEvts = 2048;
0013 uint16_t mem[nChs][nEvts];
0014 
0015 /** \file
0016  * The TCC memory for FE data emulation takes a fixed number, 2048, of events.
0017  * This standalone application completes a FE emulation data file with an
0018  * arbitrary number of events (<=2048) in order to have the required 2048
0019  * events. The N initial events are repeated till having 2048 events. In
0020  * general the number of initial events is choosen as a divider of 2048.
0021  */
0022 
0023 int main(int argc, char* argv[]){
0024   if((argc>=2 && ( (strcmp(argv[1],"-h")==0) || (strcmp(argv[1],"--help")==0) ))
0025       || argc!=3){
0026     cout << "Usage: recycleTccEmu infile outfile\n";
0027     return 1;
0028   }
0029   
0030   string ifilename = argv[1];
0031   string ofilename = argv[2];
0032   
0033   for(int iCh=0; iCh<nChs; ++iCh){
0034     for(int iEvts = 0; iEvts<nEvts; ++iEvts){
0035       mem[iCh][iEvts] = 0xFFFF;
0036     }
0037   }
0038   
0039   ifstream in(ifilename.c_str());
0040   int chnb;
0041   int bcnb;
0042   int val ;
0043   int dummy ;
0044   int oldLineCnt = 0;  
0045   
0046   //reads input file:
0047   if(in){
0048     while(!in.eof()) {
0049       in >>dec>> chnb >> bcnb >>hex>> val >> dummy ;
0050       mem[chnb-1][bcnb] = val&0x7FF;
0051       if(mem[chnb-1][bcnb]!=val){
0052     cout << "Invalid Et value at line " << oldLineCnt+1 << ".\n";
0053     exit(1);
0054       }
0055       // cout<<"Channel: "<< dec <<chnb <<", BX: "
0056       // << dec << bcnb << " filled with val:"<< hex<< mem[chnb-1][bcnb]
0057       // << dec << endl;
0058       ++oldLineCnt;
0059     }
0060   } else{
0061     cout << "Failed to open file " << ifilename << "\n";
0062   }
0063 
0064   in.close();
0065   ofstream out(ofilename.c_str());
0066   
0067   if(!out){
0068     cout << "Failed to open file '" << ofilename
0069      << "' in write mode.\n";
0070     return 1;
0071   }
0072   
0073   
0074   bool singleOldEventCnt = true;
0075   int oldEventCnt[nChs];
0076   //fills output file:
0077   for(int iCh = 0; iCh<nChs; ++iCh){
0078     int evtcnt = 0;
0079     //find first not initialized events:
0080     while(evtcnt<nEvts && mem[iCh][evtcnt]!=0xFFFF){++evtcnt;}
0081     //cout << "ch " << iCh << " event count: " << evtcnt << "\n";
0082     oldEventCnt[iCh] = evtcnt;
0083     if(oldEventCnt[0]!=oldEventCnt[iCh]) singleOldEventCnt = false;
0084     if(evtcnt==0){
0085       cout << "Error: no data found for channel "<< iCh << "\n";
0086     }
0087     //clones data of channel iCh
0088     for(int ievt = evtcnt; ievt<nEvts; ++ievt){
0089       if(mem[iCh][ievt]!=0xFFFF){
0090     cout << "Error: memory offset of channel " << iCh
0091          << " events are not contiguous.\n";
0092     exit(1);
0093       }
0094       mem[iCh][ievt] = mem[iCh][ievt%evtcnt];
0095     }
0096     
0097     for(int ievt=0; ievt<nEvts; ++ievt){
0098       out << iCh+1 << "\t" << ievt
0099       << "\t" << hex << "0x" << setfill('0') << setw(4)
0100       << mem[iCh][ievt]
0101       << setfill(' ') << dec << "\t0"
0102       << "\n";
0103     }
0104   }
0105 
0106   //warning for aperiodic case:
0107   if(singleOldEventCnt && (nEvts%oldEventCnt[0]!=0)){
0108     cout << "Warning: ouput event count (2048) is not a mulitple of input "
0109       "event counts\n" ;
0110   }
0111   if(!singleOldEventCnt){
0112     stringstream s;
0113     for(int iCh=0; iCh<nChs; ++iCh){
0114       if(nEvts%oldEventCnt[iCh]){
0115     s << (s.str().empty()?"":", ") << iCh;
0116       }
0117     }
0118     if(!s.str().empty())
0119       cout << "Warning: ouput event count (2048) for channel"
0120        << (s.str().size()>1?"s":"") << " "
0121        << s.str()
0122        << " is not a mulitple of input event counts\n" ;
0123   }
0124   
0125   if(!singleOldEventCnt){
0126     cout << "Info: in the input file the event count depends on the channel";
0127   }
0128 }
0129