LDMX Software
DiscreteInputs_IO.h
1#ifndef DISCRETEINPUTS_IO
2#define DISCRETEINPUTS_IO
3
4#include <vector>
5
6#include "../../../Algo_HLS/Ecal/src/data.h"
7#include "DiscreteInputs.h"
8
9namespace trigger {
10
11struct EventDump {
12 uint64_t event;
13 std::vector<ldmx_int::EcalTP> EcalTPs;
14
15 EventDump() : event(0), EcalTPs() {}
16 bool readFromFile(FILE *file) {
17 if (!fread(&event, sizeof(uint64_t), 1, file)) return false;
18 ldmx_int::readManyFromFile(EcalTPs, file);
19 return true;
20 }
21 bool writeToFile(FILE *file) {
22 fwrite(&event, sizeof(uint64_t), 1, file);
23 ldmx_int::writeManyToFile(EcalTPs, file);
24 return true;
25 }
26};
27
29 public:
30 DiscreteInputs(const char *fileName) : file_(fopen(fileName, "rb")) {
31 if (!file_) {
32 std::cout << "ERROR: cannot read '" << fileName << "'" << std::endl;
33 }
34 assert(file_);
35 }
36 ~DiscreteInputs() { fclose(file_); }
37
38 bool nextEvent() {
39 if (feof(file_)) return false;
40 if (!event_.readFromFile(file_)) return false;
41 printf("Beginning of event %lu (%lu TPs) \n", event_.event,
42 event_.EcalTPs.size());
43 return true;
44 }
45 const EventDump &event() { return event_; }
46
47 private:
48 FILE *file_;
49 EventDump event_;
50};
51
52} // namespace trigger
53
54#endif /* DISCRETEINPUTS_IO */