Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:24

0001 //
0002 // Hex ascii reading works only with compiled code 
0003 // call by .L dumpBinaryFile.C+
0004 // and then   
0005 // dumpBinaryFiles("PhysicsData1_366.dmp")
0006 // Corrected for SLC4 7/07
0007 
0008 #ifndef __CINT__
0009 #include <iostream>
0010 #include <fstream>
0011 using namespace std;
0012 #endif
0013 
0014 // Include the helper decoding class 
0015 /////////////////////////////////////////////////////////////////////////////
0016 class MyDecode {
0017  public:
0018   MyDecode() {}
0019   ~MyDecode() {}
0020   static int error(int error);
0021   static int data(int error);
0022  private:
0023 };
0024 /////////////////////////////////////////////////////////////////////////////
0025 // Decode error FIFO
0026 // Works for both, the error FIFO and the SLink error words. d.k. 25/04/07
0027 int MyDecode::error(int word) {
0028   int status = -1;
0029   const unsigned int  errorMask      = 0x3e00000;
0030   const unsigned int  dummyMask      = 0x03600000;
0031   const unsigned int  gapMask        = 0x03400000;
0032   const unsigned int  timeOut        = 0x3a00000;
0033   const unsigned int  eventNumError  = 0x3e00000;
0034   const unsigned int  trailError     = 0x3c00000;
0035   const unsigned int  fifoError      = 0x3800000;
0036  
0037 //  const unsigned int  timeOutChannelMask = 0x1f;  // channel mask for timeouts
0038   const unsigned int  eventNumMask = 0x1fe000; // event number mask
0039   const unsigned int  channelMask = 0xfc000000; // channel num mask
0040   const unsigned int  tbmEventMask = 0xff;    // tbm event num mask
0041   const unsigned int  overflowMask = 0x100;   // data overflow
0042   const unsigned int  tbmStatusMask = 0xff;   //TBM trailer info
0043   const unsigned int  BlkNumMask = 0x700;   //pointer to error fifo #
0044   const unsigned int  FsmErrMask = 0x600;   //pointer to FSM errors
0045   const unsigned int  RocErrMask = 0x800;   //pointer to #Roc errors
0046   const unsigned int  ChnFifMask = 0x1f;   //channel mask for fifo error
0047   const unsigned int  Fif2NFMask = 0x40;   //mask for fifo2 NF
0048   const unsigned int  TrigNFMask = 0x80;   //mask for trigger fifo NF
0049  
0050  const int offsets[8] = {0,4,9,13,18,22,27,31};
0051  
0052  //cout<<"error word "<<hex<<word<<dec<<endl;                                                                                  
0053   if( (word&errorMask) == dummyMask ) { // DUMMY WORD
0054     //cout<<" Dummy word";
0055     return 0;
0056   } else if( (word&errorMask) == gapMask ) { // GAP WORD
0057     //cout<<" Gap word";
0058     return 0;
0059   } else if( (word&errorMask)==timeOut ) { // TIMEOUT
0060      // More than 1 channel within a group can have a timeout error
0061      unsigned int index = (word & 0x1F);  // index within a group of 4/5
0062      unsigned int chip = (word& BlkNumMask)>>8;
0063      int offset = offsets[chip];
0064      cout<<"Timeout Error- channels: ";
0065      for(int i=0;i<5;i++) {
0066        if( (index & 0x1) != 0) {
0067          int chan = offset + i + 1;
0068          cout<<chan<<" ";
0069        }
0070        index = index >> 1;
0071      }
0072      //end of timeout  chip and channel decoding
0073       
0074    } else if( (word&errorMask) == eventNumError ) { // EVENT NUMBER ERROR
0075      unsigned int channel =  (word & channelMask) >>26;
0076      unsigned int tbm_event   =  (word & tbmEventMask);
0077       
0078      cout<<"Event Number Error- channel: "<<channel<<" tbm event nr. "
0079          <<tbm_event;
0080                                                                                             
0081    } else if( ((word&errorMask) == trailError)) {
0082      unsigned int channel =  (word & channelMask) >>26;
0083      unsigned int tbm_status   =  (word & tbmStatusMask);
0084      if(word & RocErrMask)
0085        cout<<"Number of Rocs Error- "<<"channel: "<<channel<<" ";
0086      if(word & FsmErrMask)
0087        cout<<"Finite State Machine Error- "<<"channel: "<<channel
0088            <<" Error status:0x"<<hex<< ((word & FsmErrMask)>>9)<<dec<<" ";;
0089      if(word & overflowMask)
0090        cout<<"Overflow Error- "<<"channel: "<<channel<<" ";
0091      if(!((word & RocErrMask)|(word & FsmErrMask)|(word & overflowMask)))
0092        cout<<"Trailer Error- ";
0093   
0094      cout<<"channel: "<<channel<<" TBM status:0x"<<hex<<tbm_status<<dec<<" ";
0095       
0096    } else if((word&errorMask)==fifoError) {
0097      if(word & Fif2NFMask) cout<<"A fifo 2 is Nearly full- ";
0098      if(word & TrigNFMask) cout<<"The trigger fifo is nearly Full - ";
0099      if(word & ChnFifMask) cout<<"fifo-1 is nearly full for channel"<<(word & ChnFifMask);
0100       
0101    } else {
0102      cout<<" Unknown error?";
0103    }
0104  
0105    unsigned int event   =  (word & eventNumMask) >>13;
0106    //unsigned int tbm_status   =  (word & tbmStatusMask);
0107     
0108    if(event>0) cout<<":event: "<<event;
0109    cout<<endl;
0110 
0111   return status;
0112 }
0113 ///////////////////////////////////////////////////////////////////////////
0114 int MyDecode::data(int word) {
0115   const unsigned int plsmsk = 0xff;   // pulse height
0116   const unsigned int pxlmsk = 0xff00; // pixel index
0117   const unsigned int dclmsk = 0x1f0000;
0118   const unsigned int rocmsk = 0x3e00000;
0119   const unsigned int chnlmsk = 0xfc000000;
0120   int status = -1;
0121 
0122   int roc = ((word&rocmsk)>>21);
0123   // Check for embeded special words
0124   if(roc>0 && roc<25) {  // valid ROCs go from 1-24
0125     cout<<"data "<<hex<<word<<dec;
0126     unsigned int channel = ((word&chnlmsk)>>26);
0127     if(channel>0 && channel<37) {  // valid channels 1-36
0128       //cout<<hex<<word<<dec;
0129       int dcol=(word&dclmsk)>>16;
0130       int pix=(word&pxlmsk)>>8;
0131       int adc=(word&plsmsk);
0132       cout<<" Channel- "<<channel<<" ROC- "<<roc<<" DCOL- "<<dcol<<" Pixel- "
0133       <<pix<<" ADC- "<<adc<<endl;
0134       status=0;
0135     } else {
0136       cout<<"Wrong channel "<<channel<<endl;
0137       return -2;
0138     }
0139   } else {  // error word
0140     //cout<<"error word "<<hex<<word<<dec;
0141     status=error(word);
0142   }
0143 
0144   return status;
0145 }
0146 ////////////////////////////////////////////////////////////////////////////
0147 int dumpBinaryFiles(char * filename) {    
0148   //char filename[80] = "../../../SCRATCH/PhysicsData1_366.dmp";  
0149   ifstream in_file;  // data file pointer
0150   in_file.open(filename, ios::binary|ios::in ); // 
0151   //cout<<in_file.bad()<<" "<<in_file.good()<<" "<<in_file<<endl;
0152   if (!in_file) {
0153     cout << " File not found " << endl;
0154     return(1); // signal error
0155   }
0156 
0157 
0158   const int numMax=1000000;
0159   int numEvent=0; 
0160   int status=0;
0161   unsigned long long word64=0;
0162 
0163   // Event loop 
0164   while (numEvent < numMax) {  // 
0165 
0166     in_file.read((char*)&word64,8);
0167     if (in_file.eof()) {
0168       std::cout << "End of input file" <<  std::endl;
0169       return false;
0170     }
0171    
0172     cout<<hex<<word64<<dec<<endl;
0173 
0174     if ((word64 >> 60) != 0x5){
0175       std::cout << "DATA CORRUPTION!" <<  std::endl;
0176       std::cout << "Expected to find header, but read: 0x"
0177         <<std::hex<<word64<<std::dec <<  std::endl;
0178       return false;
0179     }
0180  
0181     unsigned int fed_id=(word64>>8)&0xfff;
0182     unsigned int event_id=(word64>>32)&0xffffff;
0183     unsigned int bx_id=(word64>>20)&0xfff;
0184     cout<<" Header "<<hex<<word64<<dec<<" for FED "
0185     <<fed_id<<" "<<event_id<<" "<<bx_id<<endl;
0186     if(event_id==1) cout<<" EVENT 1"<<endl;
0187 
0188     numEvent++;
0189     int i=0;
0190     do {
0191       in_file.read((char*)&word64,8);
0192       //buffer.push_back(data);
0193       if( (word64 >> 60) != 0xa ) {
0194     int data1 = int(  word64     &0x00000000ffffffffL );
0195     int data2 = int( (word64>>32)&0x00000000ffffffffL );
0196     //cout<<i<<" "<<hex<<word64<<" "<<data1<<" "<<data2<<dec<<endl;
0197     status = MyDecode::data(data1);
0198     status = MyDecode::data(data2); 
0199     i++;
0200       }
0201     } while((word64 >> 60) != 0xa);
0202 
0203     // Slink Trailer
0204     int slinkLength = int( (word64>>32) & 0xffffff );
0205     int tts         = int( (word64&0xf0)>>4);
0206     int slinkError  = int( (word64&0xf00)>>8);
0207     cout<<" Trailer "<<hex<<word64<<dec<<" "<<slinkLength<<"/"<<(i+2)<<" "<<tts<<" "
0208     <<slinkError<<endl;
0209     if(slinkLength != (i+2) ) cout <<"Error in the event length = slink = "<<slinkLength
0210                    <<" count = "<<(i+2)<<endl; 
0211     // 
0212     //if(event_id==1) {
0213     int dummy=0;
0214     cout<<" Enter 0 to continue, -1 to stop "; 
0215     cin>>dummy;
0216     if(dummy==-1) break;
0217     //}
0218 
0219   } // end event loop
0220 
0221   in_file.close();
0222   //cout << " Close input file " << endl;
0223   return(0);
0224 }
0225 
0226 
0227 
0228