Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:39

0001 //
0002 // File: ScalersTest.cpp         (W.Badgett)
0003 //
0004 // Program to test Scalers RawToDigi conversion from binary raw
0005 // data file
0006 //
0007 
0008 #include "DataFormats/Scalers/interface/L1TriggerScalers.h"
0009 #include "DataFormats/Scalers/interface/L1TriggerRates.h"
0010 #include "DataFormats/Scalers/interface/LumiScalers.h"
0011 #include "DataFormats/Scalers/interface/ScalersRaw.h"
0012 
0013 #include <iostream>
0014 #include <math.h>
0015 #include <errno.h>
0016 #include <stdio.h>
0017 #include <stdlib.h>
0018 #include <fcntl.h>
0019 #include <cstring>
0020 #include <unistd.h>
0021 
0022 const char *fileName = "scalers.dat";
0023 
0024 int main(int argc, char **argv) {
0025   unsigned char buffer[sizeof(struct ScalersEventRecordRaw_v1)];
0026   int ctr = 0;
0027   int retcod;
0028   int bytes = 1;
0029   const L1TriggerScalers *previousTrig = NULL;
0030   int fd = open(fileName, O_RDONLY);
0031 
0032   if (fd > 0) {
0033     while (bytes > 0) {
0034       bytes = read(fd, buffer, sizeof(struct ScalersEventRecordRaw_v1));
0035       if (bytes <= 0) {
0036         retcod = errno;
0037         if (retcod == 0) {
0038           printf("Finished reading file %s with %d events\n", fileName, ctr);
0039         } else {
0040           printf("Error %s reading file %s\n", fileName, strerror(errno));
0041         }
0042       } else {
0043         ctr++;
0044         printf("\n******* Event %d Read %d bytes from %s *******\n", ctr, bytes, fileName);
0045         const L1TriggerScalers *trig = new L1TriggerScalers(buffer);
0046         std::cout << *trig;
0047 
0048         if (ctr > 1) {
0049           const L1TriggerScalers *previousTrigSave = previousTrig;
0050           if (previousTrig->orbitNumber() < trig->orbitNumber()) {
0051             L1TriggerRates rates(*previousTrig, *trig);
0052             std::cout << std::endl;
0053             std::cout << rates;
0054             previousTrig = trig;
0055           }
0056           delete (previousTrigSave);
0057         } else {
0058           previousTrig = trig;
0059         }
0060         std::cout << std::endl;
0061         LumiScalers lumi(buffer);
0062         std::cout << lumi;
0063       }
0064     }
0065     close(fd);
0066   } else {
0067     printf("Error %s opening file %s\n", fileName, strerror(errno));
0068   }
0069   return 0;
0070 }