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