LDMX Software
Public Member Functions | Private Attributes | List of all members
packing::rawdatafile::File Class Reference

The raw data file object. More...

#include <File.h>

Public Member Functions

 File (const framework::config::Parameters &params)
 General file constructor.
 
bool connect (framework::Event &event)
 Connect the passed event bus to this event file.
 
bool nextEvent ()
 Load the next event into our connected event bus.
 
void writeRunHeader (ldmx::RunHeader &header)
 Write the run header.
 
void close ()
 close this file
 

Private Attributes

bool is_output_
 are we reading or writing?
 
std::string ecal_object_name_
 the event bus object name of the ECal encoded data
 
std::string hcal_object_name_
 the event bus object name of the HCal encoded data
 
std::string tracker_object_name_
 the event bus object name of the Tracker encoded data
 
std::string triggerpad_object_name_
 the event bus object name of the Trigger Pad encoded data
 
std::string pass_name_
 for writing, we also should be able to specify a pass name
 
bool skip_unavailable_
 for writing, do we skip subsystems if their raw object is unavailable
 
uint32_t entries_ {0}
 number of entries in the file
 
uint32_t i_entry_ {0}
 current entry index (may not be same as event number)
 
framework::Eventevent_ {nullptr}
 handle to the event bus we are reading from or writing to
 
uint32_t run_
 run number corresponding to this file of raw data
 
utility::Reader reader_
 utility class for reading binary data files
 
utility::Writer writer_
 utility class for writing binary data files
 
utility::CRC crc_
 crc calculator for output mode
 

Detailed Description

The raw data file object.

Definition at line 17 of file File.h.

Constructor & Destructor Documentation

◆ File()

packing::rawdatafile::File::File ( const framework::config::Parameters params)

General file constructor.

Parameters
[in]paramsparameters use to configure this file
[in]filenamename of the file to read/write

Definition at line 11 of file File.cxx.

11 {
12 is_output_ = ps.getParameter<bool>("is_output");
13 skip_unavailable_ = ps.getParameter<bool>("skip_unavailable");
14
15 std::string fn = ps.getParameter<std::string>("filename");
16
17 ecal_object_name_ = ps.getParameter<std::string>("ecal_object_name");
18 hcal_object_name_ = ps.getParameter<std::string>("hcal_object_name");
19 tracker_object_name_ = ps.getParameter<std::string>("tracker_object_name");
21 ps.getParameter<std::string>("triggerpad_object_name");
22 pass_name_ = ps.getParameter<std::string>("pass_name");
23
24 std::cerr << "creating file" << std::endl;
25 if (is_output_) {
26 writer_.open(fn);
27 // leave entry count undefined
28 entries_ = 0;
29 i_entry_ = 0;
30 } else {
31 reader_.open(fn);
32 // get entry count from file
33 // get run id number from file
34 uint32_t word;
35 reader_ >> word;
36
37 uint8_t version = word & utility::mask<4>;
38 if (version != 0) {
39 EXCEPTION_RAISE("RawFileVers", "Unable to handle raw file version " +
40 std::to_string(version));
41 }
42
43 run_ = ((word >> 4) & utility::mask<28>);
44
45 reader_.seek<uint32_t>(-2, std::ios::end);
46 // save EOF in number of 32-bit-width words
47 auto eof{reader_.tell<uint32_t>()};
48 uint32_t crc_read_in;
49 reader_ >> entries_ >> crc_read_in;
50 i_entry_ = 0;
51
52 reader_.seek<uint32_t>(1, std::ios::beg);
53
54 if (ps.getParameter<bool>("verify_checksum")) {
55 utility::CRC crc;
56 for (auto ifile{reader_.tell<uint32_t>()}; ifile < eof; ifile++) {
57 reader_ >> word;
58 crc << word;
59 }
60
61 if (crc.get() != crc_read_in) {
62 EXCEPTION_RAISE("CRCNotOk",
63 "Failure to verify CRC checksum of entire input file.");
64 }
65
66 reader_.seek<uint32_t>(1, std::ios::beg);
67 } // verify checksum of input file
68 } // input or output file
69}
bool skip_unavailable_
for writing, do we skip subsystems if their raw object is unavailable
Definition File.h:59
uint32_t run_
run number corresponding to this file of raw data
Definition File.h:69
std::string tracker_object_name_
the event bus object name of the Tracker encoded data
Definition File.h:53
uint32_t i_entry_
current entry index (may not be same as event number)
Definition File.h:65
std::string triggerpad_object_name_
the event bus object name of the Trigger Pad encoded data
Definition File.h:55
uint32_t entries_
number of entries in the file
Definition File.h:63
std::string ecal_object_name_
the event bus object name of the ECal encoded data
Definition File.h:49
utility::Reader reader_
utility class for reading binary data files
Definition File.h:71
utility::Writer writer_
utility class for writing binary data files
Definition File.h:73
std::string hcal_object_name_
the event bus object name of the HCal encoded data
Definition File.h:51
bool is_output_
are we reading or writing?
Definition File.h:47
std::string pass_name_
for writing, we also should be able to specify a pass name
Definition File.h:57
void open(const std::string &file_name)
Open a file with this reader.
Definition Reader.h:35
int tell()
Tell us where the reader is.
Definition Reader.h:87
void seek(int off, std::ios_base::seekdir dir=std::ios::beg)
Go ("seek") a specific position in the file.
Definition Reader.h:61
void open(const std::string &file_name)
Open a file with this writer.
Definition Writer.h:35

References ecal_object_name_, entries_, packing::utility::CRC::get(), framework::config::Parameters::getParameter(), hcal_object_name_, i_entry_, is_output_, packing::utility::Reader::open(), packing::utility::Writer::open(), pass_name_, reader_, run_, packing::utility::Reader::seek(), skip_unavailable_, packing::utility::Reader::tell(), tracker_object_name_, triggerpad_object_name_, and writer_.

Member Function Documentation

◆ close()

void packing::rawdatafile::File::close ( )

close this file

Definition at line 144 of file File.cxx.

144 {
145 event_ = nullptr;
146 if (is_output_) {
147 writer_ << entries_;
148 crc_ << entries_;
149 writer_ << crc_.get();
150 }
151}
framework::Event * event_
handle to the event bus we are reading from or writing to
Definition File.h:67
utility::CRC crc_
crc calculator for output mode
Definition File.h:75
uint32_t get()
Get the calculate checksum from the calculator.
Definition CRC.h:110

References crc_, entries_, event_, packing::utility::CRC::get(), is_output_, and writer_.

◆ connect()

bool packing::rawdatafile::File::connect ( framework::Event event)

Connect the passed event bus to this event file.

Definition at line 71 of file File.cxx.

71 {
72 event_ = &event;
73 return true;
74}

References event_.

◆ nextEvent()

bool packing::rawdatafile::File::nextEvent ( )

Load the next event into our connected event bus.

Definition at line 76 of file File.cxx.

76 {
77 static std::map<uint16_t, std::string> eid_to_name = {
78 {ldmx::SubdetectorIDType::EID_TRACKER, tracker_object_name_},
79 {ldmx::SubdetectorIDType::EID_TRIGGER_SCINT, triggerpad_object_name_},
80 {ldmx::SubdetectorIDType::EID_ECAL, ecal_object_name_},
81 {ldmx::SubdetectorIDType::EID_HCAL, hcal_object_name_},
82 };
83
84 if (is_output_) {
85 // dump buffers into event packet and write out
86 std::map<uint16_t, std::vector<uint32_t>> the_subsys_data;
87 for (auto const &[id, name] : eid_to_name) {
88 if (skip_unavailable_ and not event_->exists(name, pass_name_)) continue;
89 the_subsys_data[id] = event_->getCollection<uint32_t>(name, pass_name_);
90 }
91
92 EventPacket write_event(event_->getEventNumber(), the_subsys_data);
93 writer_ << write_event;
94 crc_ << write_event;
95 if (!writer_) return false;
96
97 entries_++;
98 i_entry_++;
99 } else {
100 // check for EoF
101 if (i_entry_ + 1 > entries_) return false;
102
103 i_entry_++;
104
105 // read buffers from event packet and add to event bus
106 static EventPacket read_event;
107 reader_ >> read_event;
108 if (!reader_) {
109 // ERROR
110 return false;
111 }
112
113 event_->getEventHeader().setEventNumber(read_event.id());
114
115 for (auto &subsys : read_event.data()) {
116 // construct name if not provided by default EID mappings
117 if (eid_to_name.find(subsys.id()) == eid_to_name.end()) {
118 std::cerr << subsys.id() << " unrecognized electronics ID."
119 << std::endl;
120 eid_to_name[subsys.id()] = "EID" + std::to_string(subsys.id());
121 }
122
123 event_->add(eid_to_name.at(subsys.id()), subsys.data());
124 } // loop over subsystems
125 } // input or output
126 return true;
127}
const std::vector< ContentType > & getCollection(const std::string &collectionName, const std::string &passName="") const
Get a collection (std::vector) of objects from the event bus.
Definition Event.h:386
int getEventNumber() const
Get the event number.
Definition Event.h:70
ldmx::EventHeader & getEventHeader()
Get the event header.
Definition Event.h:58
void add(const std::string &collectionName, T &obj)
Adds an object to the event bus.
Definition Event.h:173
bool exists(const std::string &name, const std::string &passName="", bool unique=true) const
Check for the existence of an object or collection with the given name and pass name in the event.
Definition Event.cxx:92
void setEventNumber(int eventNumber)
Set the event number.

References framework::Event::add(), crc_, ecal_object_name_, entries_, event_, framework::Event::exists(), framework::Event::getCollection(), framework::Event::getEventHeader(), framework::Event::getEventNumber(), hcal_object_name_, i_entry_, is_output_, pass_name_, reader_, ldmx::EventHeader::setEventNumber(), skip_unavailable_, tracker_object_name_, triggerpad_object_name_, and writer_.

◆ writeRunHeader()

void packing::rawdatafile::File::writeRunHeader ( ldmx::RunHeader header)

Write the run header.

Definition at line 129 of file File.cxx.

129 {
130 if (is_output_) {
131 // use passed run number
132 run_ = header.getRunNumber();
133 // Why cant we just take the header from above?
134 uint32_t tempHeader =
135 (0 & utility::mask<4>)+((run_ & utility::mask<28>) << 4);
136 writer_ << tempHeader;
137 crc_ << tempHeader;
138 } else {
139 // put our read-in run number here
140 header.setIntParameter("raw_run", run_);
141 }
142}
void setIntParameter(const std::string &name, int value)
Set an int parameter value.
Definition RunHeader.h:164
int getRunNumber() const
Definition RunHeader.h:74

References crc_, ldmx::RunHeader::getRunNumber(), is_output_, run_, ldmx::RunHeader::setIntParameter(), and writer_.

Member Data Documentation

◆ crc_

utility::CRC packing::rawdatafile::File::crc_
private

crc calculator for output mode

Definition at line 75 of file File.h.

Referenced by close(), nextEvent(), and writeRunHeader().

◆ ecal_object_name_

std::string packing::rawdatafile::File::ecal_object_name_
private

the event bus object name of the ECal encoded data

Definition at line 49 of file File.h.

Referenced by File(), and nextEvent().

◆ entries_

uint32_t packing::rawdatafile::File::entries_ {0}
private

number of entries in the file

Definition at line 63 of file File.h.

63{0};

Referenced by close(), File(), and nextEvent().

◆ event_

framework::Event* packing::rawdatafile::File::event_ {nullptr}
private

handle to the event bus we are reading from or writing to

Definition at line 67 of file File.h.

67{nullptr};

Referenced by close(), connect(), and nextEvent().

◆ hcal_object_name_

std::string packing::rawdatafile::File::hcal_object_name_
private

the event bus object name of the HCal encoded data

Definition at line 51 of file File.h.

Referenced by File(), and nextEvent().

◆ i_entry_

uint32_t packing::rawdatafile::File::i_entry_ {0}
private

current entry index (may not be same as event number)

Definition at line 65 of file File.h.

65{0};

Referenced by File(), and nextEvent().

◆ is_output_

bool packing::rawdatafile::File::is_output_
private

are we reading or writing?

Definition at line 47 of file File.h.

Referenced by close(), File(), nextEvent(), and writeRunHeader().

◆ pass_name_

std::string packing::rawdatafile::File::pass_name_
private

for writing, we also should be able to specify a pass name

Definition at line 57 of file File.h.

Referenced by File(), and nextEvent().

◆ reader_

utility::Reader packing::rawdatafile::File::reader_
private

utility class for reading binary data files

Definition at line 71 of file File.h.

Referenced by File(), and nextEvent().

◆ run_

uint32_t packing::rawdatafile::File::run_
private

run number corresponding to this file of raw data

Definition at line 69 of file File.h.

Referenced by File(), and writeRunHeader().

◆ skip_unavailable_

bool packing::rawdatafile::File::skip_unavailable_
private

for writing, do we skip subsystems if their raw object is unavailable

Definition at line 59 of file File.h.

Referenced by File(), and nextEvent().

◆ tracker_object_name_

std::string packing::rawdatafile::File::tracker_object_name_
private

the event bus object name of the Tracker encoded data

Definition at line 53 of file File.h.

Referenced by File(), and nextEvent().

◆ triggerpad_object_name_

std::string packing::rawdatafile::File::triggerpad_object_name_
private

the event bus object name of the Trigger Pad encoded data

Definition at line 55 of file File.h.

Referenced by File(), and nextEvent().

◆ writer_

utility::Writer packing::rawdatafile::File::writer_
private

utility class for writing binary data files

Definition at line 73 of file File.h.

Referenced by close(), File(), nextEvent(), and writeRunHeader().


The documentation for this class was generated from the following files: