Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:28

0001 #include <stdio.h>
0002 #include <errno.h>
0003 #include "EventFilter/CSCRawToDigi/interface/CSCDCCExaminer.h"
0004 // To compile: g++ -o examiner examiner.cc -I../../../
0005 
0006 int main(int argc, char *argv[]) {
0007   CSCDCCExaminer examiner;
0008   examiner.modeDDU(true);
0009   examiner.crcCFEB(0);
0010   examiner.crcTMB(0);
0011   examiner.crcALCT(0);
0012   examiner.output1().show();
0013   examiner.output2().show();
0014 
0015   if (argc != 2) {
0016     printf("Usage: ./examiner INPUT_FILENAME\n");
0017     return 0;
0018   }
0019   FILE *input;
0020   if ((input = fopen(argv[1], "rt")) == NULL) {
0021     printf("Cannot open input file: %s (errno=%d)\n", argv[2], errno);
0022     return 1;
0023   }
0024 
0025   // Arbitrary size chunk of data to be read from file
0026   const int bufferSize = 116384;
0027   unsigned short buffer[bufferSize];
0028   int length = 0;
0029   bzero(buffer, sizeof(buffer));
0030 
0031   // Read entire data block from file;
0032   //  don't bother about DDU/DCC headers and traiers, as they are going to found by the examiner
0033   while (!feof(input) && (length = fread((char *)(buffer), sizeof(short), bufferSize, input)) != 0) {
0034     std::cout << "Read " << length << " words" << std::endl;
0035     // Sliding buffer to be offset by the examiner after if swallows next DDU/DCC event from the block
0036     const unsigned short *buffer_end = buffer;
0037     // Beginning of the block, which processed by the examiner (DDU/DCC/unidentified)
0038     const unsigned short *buffer_start = buffer;
0039 
0040     while ((length = examiner.check(buffer_end, length)) >= 0) {
0041       std::cout << "Event size=" << length << std::endl;
0042       // If examiner is in DCC mode, several DDUs may be found in event
0043       //  (for DDU mode event always consists from one DDU)
0044       std::vector<int> sourceIDs = examiner.listOfDDUs();
0045       // Iterate over all DDUs from the event
0046       for (unsigned int ddu = 0; ddu < sourceIDs.size(); ddu++) {
0047         // Obtain pointer to the DDU data block
0048         const unsigned short *block = examiner.DDU_block()[sourceIDs[ddu]];
0049         // Obtain offset relative to 'buffer_start', which identifies DDU data block
0050         unsigned long offset = examiner.DDU_ptrOffsets()[sourceIDs[ddu]];
0051         // Example of accessing DDU data:
0052         std::cout << "DDU " << sourceIDs[ddu] << std::hex << " 0x" << *(block + 0) << " 0x" << *(block + 1) << " 0x"
0053                   << *(block + 2) << " 0x" << *(block + 3) << " size=" << std::dec
0054                   << examiner.DDU_size()[sourceIDs[ddu]] << std::endl
0055                   << " method2" << std::hex << " 0x" << *(buffer_start + offset + 0) << " 0x"
0056                   << *(buffer_start + offset + 1) << " 0x" << *(buffer_start + offset + 2) << " 0x"
0057                   << *(buffer_start + offset + 3) << std::dec << std::endl;
0058         // Any errors for the DDU?
0059         if (examiner.errorsForDDU(sourceIDs[ddu]))
0060           std::cout << std::hex << "Errors for ddu=0x" << sourceIDs[ddu] << " : 0x"
0061                     << examiner.errorsForDDU(sourceIDs[ddu]) << std::dec << std::endl;
0062         // Obtain pointer to a certain DMB data block
0063         std::map<short, const unsigned short *> DMBs = examiner.DMB_block()[sourceIDs[ddu]];
0064         // Obtain offset relative to 'buffer_start', which identifies certain DMB data block
0065         std::map<short, unsigned long> _DMBs = examiner.DMB_ptrOffsets()[sourceIDs[ddu]];
0066         // Example of accessing DMB data:
0067         for (std::map<short, const unsigned short *>::const_iterator dmb = DMBs.begin(); dmb != DMBs.end(); dmb++)
0068           std::cout << "  DMB " << dmb->first << std::hex << " 0x" << *(dmb->second + 0) << " 0x" << *(dmb->second + 1)
0069                     << " 0x" << *(dmb->second + 2) << " 0x" << *(dmb->second + 3) << " size=" << std::dec
0070                     << examiner.DMB_size()[sourceIDs[ddu]][dmb->first] << std::endl;
0071         for (std::map<short, unsigned long>::const_iterator dmb = _DMBs.begin(); dmb != _DMBs.end(); dmb++)
0072           std::cout << " method2" << std::hex << " 0x" << *(buffer_start + dmb->second + 0) << " 0x"
0073                     << *(buffer_start + dmb->second + 1) << " 0x" << *(buffer_start + dmb->second + 2) << " 0x"
0074                     << *(buffer_start + dmb->second + 3) << std::dec << std::endl;
0075       }
0076       buffer_start = buffer_end;
0077     }
0078   }
0079 
0080   return 0;
0081 }