Skip to content
Snippets Groups Projects
Commit 616633d2 authored by Chao Peng's avatar Chao Peng
Browse files

implement destructors for EvChannel and EtChannel

parent 0915565a
Branches
No related tags found
1 merge request!2Revamp the code structure
......@@ -74,8 +74,19 @@ status EtChannel::Open(const std::string &station)
void EtChannel::Close()
{
if (IsETOpen() && (att_id != ID_NULL)) {
auto status = et_status(et_station_detach(et_id, att_id), true);
et_status(et_station_detach(et_id, att_id), true);
att_id = ID_NULL;
et_status(et_station_remove(et_id, stat_id), true);
stat_id = ID_NULL;
}
}
void EtChannel::Disconnect()
{
Close();
if (IsETOpen()) {
et_status(et_close(et_id), true);
et_id = nullptr;
}
}
......
......@@ -28,12 +28,17 @@ class EtChannel : public EvChannel
{
public:
EtChannel(size_t chunk_buf = 2000);
virtual ~EtChannel() { Disconnect(); }
EtChannel(const EtChannel &) = delete;
void operator =(const EtChannel &) = delete;
virtual status Open(const std::string &station);
virtual void Close();
virtual status Read();
status Connect(const std::string &ip, int port, const std::string &et_file);
void Disconnect();
bool IsETOpen() const { return (et_id != nullptr) && et_alive(et_id); }
void AddEvFilter(std::function<bool(const BankHeader &)> &&func) { filters.emplace_back(func); }
......
......@@ -56,6 +56,10 @@ class EvChannel
{
public:
EvChannel(size_t buflen = 1024*2000);
virtual ~EvChannel() { Close(); }
EvChannel(const EvChannel &) = delete;
void operator =(const EvChannel &) = delete;
virtual status Open(const std::string &path);
virtual void Close();
......
......@@ -49,8 +49,8 @@ int main(int argc, char* argv[])
}
// evio file reader
evc::EvChannel chan;
if (chan.Open(args["evio_file"].String()) != evc::status::success) {
evc::EvChannel ev_chan;
if (ev_chan.Open(args["evio_file"].String()) != evc::status::success) {
std::cerr << "Failed to open coda file \"" << args["evio_file"] << "\"." << std::endl;
return -1;
}
......@@ -75,7 +75,7 @@ int main(int argc, char* argv[])
loop = false;
continue;
}
chan.Read();
ev_chan.Read();
system_clock::time_point start(system_clock::now());
system_clock::time_point next(start + std::chrono::milliseconds(args["interval"].Int()));
......@@ -83,7 +83,7 @@ int main(int argc, char* argv[])
std::cout << "Received " << count << " events to ET.\r" << std::flush;
}
auto et_buf = et_chan.GetRawBufferVec();
auto ev_buf = chan.GetRawBuffer();
auto ev_buf = ev_chan.GetRawBuffer();
std::cout << "New Event: " << et_buf.size() << ", " << et_buf[0] + 1 << ", " << ev_buf[0] + 1 << std::endl;
std::cout << std::hex << std::setfill('0');
for (size_t i = 0; (i < ev_buf[0] + 1) || (i < et_buf[0] + 1); ++i) {
......@@ -98,6 +98,8 @@ int main(int argc, char* argv[])
std::cout << "Received " << count << " events to ET" << std::endl;
et_chan.Close();
et_chan.Disconnect();
ev_chan.Close();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment