46 DetectorEvent::group_type
group{0};
48 DetectorEvent::coord_type
coord{0};
64 void add( uint16_t ch ) {
65 _channels.push_back(ch);
66 std::sort( _channels.begin(), _channels.end() );
74 auto it = std::find( _channels.begin(), _channels.end(), ch );
75 if( it != _channels.end() )
76 _channels.erase( it );
83 const std::string &
getName() const noexcept {
return _name; }
90 const std::vector<uint16_t> &
getChannels() const noexcept {
return _channels; }
97 std::vector<uint16_t> _channels;
106 : _ctxh(
ContextBase::getActive().createHandle(
"DAQChannels") ),
116 void addGroup( DetectorEvent::group_type group,
const std::string &name ) {
119 throw std::runtime_error(
"DAQChannels::addGroup(): group must be >= 1!" );
120 if( _groups.find( group ) != _groups.end() )
121 throw std::runtime_error(
"DAQChannels::addGroup(): group exists already" );
124 _groups[ group ] = std::move(g);
140 void setChannel( uint16_t channel, DetectorEvent::group_type group,
141 DetectorEvent::coord_type coord,
const std::string &name ) {
144 if( _chInfos[channel].group != 0 )
145 _groups[_chInfos[channel].group].remove( channel );
147 auto it = _groups.find( group );
148 if( it == _groups.end() )
149 throw std::runtime_error( fmt::format(
"DAQChannels::setChannel(): group {} doesnt exist", group ) );
150 it->second.add( channel );
162 uint16_t
getCh(
const std::string &name )
const {
163 for( uint16_t ch = 0; ch < _chInfos.size(); ++ch ) {
164 if( _chInfos[ch].name == name )
167 throw std::runtime_error(
"Channel with given name not found" );
175 uint16_t
getCh( DetectorEvent::group_type group, DetectorEvent::coord_type coord )
const {
176 for( uint16_t ch = 0; ch < _chInfos.size(); ++ch ) {
177 if( _chInfos[ch].group == group &&
178 _chInfos[ch].coord == coord )
181 throw std::runtime_error(
"Channel with given group and coord not found" );
189 const std::map<DetectorEvent::group_type, DetectorGroup> &
getGroups() const noexcept {
199 auto it = _groups.find( group );
200 if( it == _groups.end() )
201 throw std::runtime_error( fmt::format(
"DAQChannels::getChannel(): group {} doesnt exist", group ) );
212 const std::vector<channel_info_t> &
getChInfos() const noexcept {
return _chInfos; }
222 virtual void process( std::vector<DetectorEvent> &data ) noexcept {
223 auto proci = _ctxh->processInstance();
225 for(
auto &event : data ) {
226 event.group = _chInfos[
event.ch].group;
227 event.coord = _chInfos[
event.ch].coord;
234 std::vector<channel_info_t> _chInfos;
235 std::map<DetectorEvent::group_type, DetectorGroup> _groups;
Handle to context used by specific class.
Definition: ContextBase.hpp:188
Simple class to store name and included channels for this group.
Definition: DAQChannels.hpp:57
const std::string & getName() const noexcept
Returns the name of the group.
Definition: DAQChannels.hpp:83
void add(uint16_t ch)
Adds channel to this group.
Definition: DAQChannels.hpp:64
const std::vector< uint16_t > & getChannels() const noexcept
Returns the vector of channel numbers assigned to this group.
Definition: DAQChannels.hpp:90
void remove(uint16_t ch)
Removes channel from this group.
Definition: DAQChannels.hpp:73
A pipeline stage which sets the group and coord for the detector events.
Definition: DAQChannels.hpp:37
void setChannel(uint16_t channel, DetectorEvent::group_type group, DetectorEvent::coord_type coord, const std::string &name)
Assigns a DAQ channel to a detector group and coordinate.
Definition: DAQChannels.hpp:140
const DetectorGroup & getGroup(DetectorEvent::group_type group) const
Returns registered group by its index.
Definition: DAQChannels.hpp:198
uint16_t getCh(const std::string &name) const
Returns channel info for given name
Definition: DAQChannels.hpp:162
virtual void process(std::vector< DetectorEvent > &data) noexcept
Fills detector group index and coord index to the events.
Definition: DAQChannels.hpp:222
const std::vector< channel_info_t > & getChInfos() const noexcept
Returns vector containing group, channel and name of all channels.
Definition: DAQChannels.hpp:212
uint16_t getCh(DetectorEvent::group_type group, DetectorEvent::coord_type coord) const
Returns channel info for given (group, coord) combination.
Definition: DAQChannels.hpp:175
const std::map< DetectorEvent::group_type, DetectorGroup > & getGroups() const noexcept
Returns all registered groups.
Definition: DAQChannels.hpp:189
void addGroup(DetectorEvent::group_type group, const std::string &name)
Adds a new detector group.
Definition: DAQChannels.hpp:116
DAQChannels()
Constructor.
Definition: DAQChannels.hpp:105
Abstract baseclass for all stages which uses or modifies detector events.
Definition: StageDetectorEvent.hpp:20
Definition: mainpage.dox:6
static void throwIfNotValidName(const std::string &name)
Checks that the given string can be used as a filename.
Definition: result_collection_support.hpp:216
Default context for printing and collecting statistics.
Definition: ContextBase.hpp:41
Group, coordinate and name information for a daq channel.
Definition: DAQChannels.hpp:44
std::string name
Name of the channel.
Definition: DAQChannels.hpp:50
DetectorEvent::coord_type coord
Coordinate of the channel in the group.
Definition: DAQChannels.hpp:48
DetectorEvent::group_type group
Group index of the channel.
Definition: DAQChannels.hpp:46