CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/SimCalorimetry/EcalElectronicsEmulation/bin/recycleTccEmu.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <sstream>
00004 #include <inttypes.h>
00005 #include <iomanip>
00006 #include <cstdlib>
00007 #include <stdio.h>
00008 #include <string.h>
00009 using namespace std;
00010 
00011 const int nChs = 68;
00012 const int nEvts = 2048;
00013 uint16_t mem[nChs][nEvts];
00014 
00023 int main(int argc, char* argv[]){
00024   if((argc>=2 && ( (strcmp(argv[1],"-h")==0) || (strcmp(argv[1],"--help")==0) ))
00025       || argc!=3){
00026     cout << "Usage: recycleTccEmu infile outfile\n";
00027     return 1;
00028   }
00029   
00030   string ifilename = argv[1];
00031   string ofilename = argv[2];
00032   
00033   for(int iCh=0; iCh<nChs; ++iCh){
00034     for(int iEvts = 0; iEvts<nEvts; ++iEvts){
00035       mem[iCh][iEvts] = 0xFFFF;
00036     }
00037   }
00038   
00039   ifstream in(ifilename.c_str());
00040   int chnb;
00041   int bcnb;
00042   int val ;
00043   int dummy ;
00044   int oldLineCnt = 0;  
00045   
00046   //reads input file:
00047   if(in){
00048     while(!in.eof()) {
00049       in >>dec>> chnb >> bcnb >>hex>> val >> dummy ;
00050       mem[chnb-1][bcnb] = val&0x7FF;
00051       if(mem[chnb-1][bcnb]!=val){
00052         cout << "Invalid Et value at line " << oldLineCnt+1 << ".\n";
00053         exit(1);
00054       }
00055       // cout<<"Channel: "<< dec <<chnb <<", BX: "
00056       // << dec << bcnb << " filled with val:"<< hex<< mem[chnb-1][bcnb]
00057       // << dec << endl;
00058       ++oldLineCnt;
00059     }
00060   } else{
00061     cout << "Failed to open file " << ifilename << "\n";
00062   }
00063 
00064   in.close();
00065   ofstream out(ofilename.c_str());
00066   
00067   if(!out){
00068     cout << "Failed to open file '" << ofilename
00069          << "' in write mode.\n";
00070     return 1;
00071   }
00072   
00073   
00074   bool singleOldEventCnt = true;
00075   int oldEventCnt[nChs];
00076   //fills output file:
00077   for(int iCh = 0; iCh<nChs; ++iCh){
00078     int evtcnt = 0;
00079     //find first not initialized events:
00080     while(evtcnt<nEvts && mem[iCh][evtcnt]!=0xFFFF){++evtcnt;}
00081     //cout << "ch " << iCh << " event count: " << evtcnt << "\n";
00082     oldEventCnt[iCh] = evtcnt;
00083     if(oldEventCnt[0]!=oldEventCnt[iCh]) singleOldEventCnt = false;
00084     if(evtcnt==0){
00085       cout << "Error: no data found for channel "<< iCh << "\n";
00086     }
00087     //clones data of channel iCh
00088     for(int ievt = evtcnt; ievt<nEvts; ++ievt){
00089       if(mem[iCh][ievt]!=0xFFFF){
00090         cout << "Error: memory offset of channel " << iCh
00091              << " events are not contiguous.\n";
00092         exit(1);
00093       }
00094       mem[iCh][ievt] = mem[iCh][ievt%evtcnt];
00095     }
00096     
00097     for(int ievt=0; ievt<nEvts; ++ievt){
00098       out << iCh+1 << "\t" << ievt
00099           << "\t" << hex << "0x" << setfill('0') << setw(4)
00100           << mem[iCh][ievt]
00101           << setfill(' ') << dec << "\t0"
00102           << "\n";
00103     }
00104   }
00105 
00106   //warning for aperiodic case:
00107   if(singleOldEventCnt && (nEvts%oldEventCnt[0]!=0)){
00108     cout << "Warning: ouput event count (2048) is not a mulitple of input "
00109       "event counts\n" ;
00110   }
00111   if(!singleOldEventCnt){
00112     stringstream s;
00113     for(int iCh=0; iCh<nChs; ++iCh){
00114       if(nEvts%oldEventCnt[iCh]){
00115         s << (s.str().size()==0?"":", ") << iCh;
00116       }
00117     }
00118     if(s.str().size()!=0)
00119       cout << "Warning: ouput event count (2048) for channel"
00120            << (s.str().size()>1?"s":"") << " "
00121            << s.str()
00122            << " is not a mulitple of input event counts\n" ;
00123   }
00124   
00125   if(!singleOldEventCnt){
00126     cout << "Info: in the input file the event count depends on the channel";
00127   }
00128 }
00129