// EventListProc.cc // Contact person: A. Mastbaum // See EventListProc.hh for more details. //—————————————————————---------------------------------------------——// #include #include #include #include #include #include #include #include #include #include #include #include namespace RAT { void EventListProc::SetS(const std::string& param, const std::string& value) { if (param == "file") { if (!LoadFile(value)) { throw ParamInvalid(param, dformat("EventListProc::SetS: Could not load file %s.", value.c_str())); } Log::Assert(!fEventIDList.empty(), dformat("EventListProc::SetS: List file %s is empty.", value.c_str())); fFileSet = true; } else { throw ParamUnknown(param); } } bool EventListProc::LoadFile(const std::string filename) { std::ifstream infile; infile.open(filename.c_str(), std::ios::in); if (!infile.is_open()) { return false; } std::string line; while (getline(infile >> std::ws, line)) { std::replace(line.begin(), line.end(), ',', ' '); std::istringstream iss(line); std::string token; while (iss >> token) { std::istringstream isu(token); unsigned gtid; if (token.compare(0, 2, "0x") == 0) { isu >> std::hex >> gtid; } else if (token.compare(0, 1, "0") == 0) { isu >> std::oct >> gtid; } else { isu >> gtid; } fEventIDList.push_back(gtid); } } std::sort(fEventIDList.begin(), fEventIDList.end()); return true; } Processor::Result EventListProc::DSEvent(DS::Run&, DS::Entry& ds) { for( size_t iEV = 0; iEV < ds.GetEVCount(); iEV++ ) { DS::EV& ev = ds.GetEV(iEV); Log::Assert(fFileSet, "EventListProc::Event: No event list file set. Try /rat/procset file \"list.txt\"."); if (std::binary_search(fEventIDList.begin(), fEventIDList.end(), ev.GetGTID())) { debug << "EventListProc::Event: Processing event ID " << ev.GetGTID() << newline; continue; } else { // stop processing of this event debug << "EventListProc::Event: Skipping event ID " << ev.GetGTID() << newline; return Processor::OKFALSE; } } return Processor::OKTRUE; } } // namespace RAT