Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:45

0001 #include <string.h>
0002 #include <iostream>
0003 #include <iomanip>
0004 #include <stdio.h>
0005 #include <set>
0006 #include "EventFilter/CSCTFRawToDigi/src/CSCTFEvent.cc"
0007 #include "EventFilter/CSCTFRawToDigi/src/CSCSPEvent.cc"
0008 #include "EventFilter/CSCTFRawToDigi/src/CSCSPRecord.cc"
0009 #include "IORawData/CSCCommissioning/src/FileReaderDDU.cc"
0010 //g++ -o test test.cc -I../../../
0011 
0012 int main(int argc, char *argv[]){
0013     using namespace std;
0014 
0015     FILE *out;
0016     if( (out=fopen("dump2.raw","wt"))==NULL ){
0017         printf("Cannot open output file: %s (errno=%d)\n","dump2.raw",errno);
0018         return 1;
0019     }
0020 
0021     // DDU File Reader
0022     FileReaderDDU reader;
0023     reader.open(argv[1]);
0024 
0025     // Event buffer
0026     size_t size, nevents=0;
0027     const unsigned short *buf=0;
0028 
0029     // Main cycle
0030     while( (size = reader.read(buf)) /*&& nevents<100*/ ){
0031         unsigned short event[size];
0032 
0033         // Swep out C-words
0034         unsigned int index1=12, index2=12;
0035         memcpy(event,buf,12*sizeof(unsigned short));
0036         while( index1 < size ){
0037             if( (buf[index1]&0xF000)!=0xC000 ){
0038                 event[index2] = buf[index1];
0039                 index1++;
0040                 index2++;
0041             } else {
0042                 index1++;
0043             }
0044         }
0045 
0046         CSCTFEvent tfEvent, qwe;
0047         if(nevents%1000==0) cout<<"Event: "<<nevents<<endl;
0048 ///     cout<<" Unpack: "<<
0049         tfEvent.unpack(event,index2);
0050 ///     <<endl;
0051 
0052         bool log_event = false;
0053 
0054         vector<CSCSPEvent> SPs = tfEvent.SPs();
0055         for(int sp=0; sp<SPs.size(); sp++){
0056 ///         cout<<" L1A="<<SPs[0].header().L1A()<<endl;
0057             for(unsigned int tbin=0; tbin<SPs[sp].header().nTBINs(); tbin++){
0058                 bool mismatch = false;
0059                 vector<CSCSP_SPblock> tracks = SPs[sp].record(tbin).tracks();
0060                 for(vector<CSCSP_SPblock>::const_iterator track=tracks.begin(); track!=tracks.end(); track++){
0061                     unsigned int nStations=0;
0062                     if( track->ME1_id() ) nStations++;
0063                     if( track->ME2_id() ) nStations++;
0064                     if( track->ME3_id() ) nStations++;
0065                     if( track->ME4_id() ) nStations++;
0066                     if( track->LCTs().size() != nStations ){
0067                         mismatch = true;
0068                         cout<<" mismatch found in tbin="<<tbin<<": ("<<track->LCTs().size()<<"!="<<nStations<<")";
0069                     }
0070 
0071                     if( mismatch ){
0072                         cout<<hex<<" ME1: 0x"<<track->ME1_id()<<" tbin: "<<track->ME1_tbin()<<", "<<dec;
0073                         cout<<hex<<" ME2: 0x"<<track->ME2_id()<<" tbin: "<<track->ME2_tbin()<<", "<<dec;
0074                         cout<<hex<<" ME3: 0x"<<track->ME3_id()<<" tbin: "<<track->ME3_tbin()<<", "<<dec;
0075                         cout<<hex<<" ME4: 0x"<<track->ME4_id()<<" tbin: "<<track->ME4_tbin()<<" "<<dec;
0076                     }
0077                 }
0078                 vector<CSCSP_MEblock> lct = SPs[sp].record(tbin).LCTs();
0079                 if( lct.size() ){
0080                     cout<<"Event: "<<nevents<<" SP"<<sp<<" L1A="<<SPs[sp].header().L1A()<<" BXN="<<SPs[sp].header().BXN()<<" Orbit counter="<<SPs[sp].counters().orbit_counter()<<endl;
0081                     cout<<" Endcap: "<<(SPs[sp].header().endcap()?2:1)<<" sector: "<<SPs[sp].header().sector();
0082                     cout<<"  tbin: "<<tbin<<"  nLCTs: "<<SPs[sp].record(tbin).LCTs().size()<<" (";//<<endl;
0083                 }
0084                 for(std::vector<CSCSP_MEblock>::const_iterator i=lct.begin(); i!=lct.end(); i++){
0085                     cout<<" F"<<((i->spInput()-1)/3+1)<<"/CSC"<<i->csc()<<":{w="<<i->wireGroup()<<",s="<<i->strip()<<"} ";
0086                 }
0087                 if( lct.size() ) cout<<" )"<<endl;
0088                 std::vector<CSCSP_SPblock> trks = SPs[sp].record(tbin).tracks();
0089                 if( trks.size() ){ cout<<"  Track(s) at BX=: "<<SPs[sp].header().BXN(); }
0090 for(std::vector<CSCSP_SPblock>::const_iterator trk=trks.begin(); trk<trks.end(); trk++){ cout<<" mode="<<trk->mode(); if(trk->mode()==15 && SPs[sp].header().BXN()==380) log_event=true; }
0091 
0092                 if( trks.size() ){ cout<<endl; }
0093             }
0094         }
0095         if(log_event) fwrite(event,2,index2,out); 
0096         nevents++;
0097     }
0098     fclose(out);
0099 
0100     return 0;
0101 }