All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
icarus::details::ROPnumberDispatcher Class Reference

Algorithm assigning IDs to readout planes. More...

Public Member Functions

 ROPnumberDispatcher (std::vector< PlaneColl_t > const &refROP, std::string const &logCategory)
 Constructor: uses refROP as reference to assign number ranges to views. More...
 
void setTPCset (readout::TPCsetID const &TPCset)
 Rests the object to work with the specified TPC set next. More...
 
readout::ROPID assignID (PlaneColl_t const &ROP)
 Returns the next available ID for the specified ROP. More...
 

Static Public Member Functions

static geo::View_t ROPview (PlaneColl_t const &planes)
 Returns the view of the planes (geo::kUnknown if mixed or none). More...
 

Private Types

template<typename T >
using DataByView_t = std::map< geo::View_t, T >
 Type of collection of T by view. More...
 

Private Member Functions

DataByView_t< unsigned int > ViewROPcounts (std::vector< PlaneColl_t > const &ROPplanes) const
 Returns the number of planes with each view. More...
 
DataByView_t
< readout::ROPID::ROPID_t
PreferredROPrangesByView (std::vector< PlaneColl_t > const &ROPs) const
 Returns the fist ROP number for each view in ROP. More...
 

Private Attributes

std::string const fLogCategory
 Log category name for messages. More...
 
DataByView_t
< readout::ROPID::ROPID_t >
const 
fFirstROPno
 The first ROP number for each view. More...
 
DataByView_t
< readout::ROPID::ROPID_t
fAvailableROPno
 The first available ROP number for each view. More...
 
readout::TPCsetID fTPCset
 The TPC set being served. More...
 

Detailed Description

Algorithm assigning IDs to readout planes.

The usage workflow is the following:

  1. the algorithm is initialized with a TPC set to be taken as model (constructor);
  2. a new TPC set is declared (setTPCset());
  3. for each readout plane, an ID is requested (assignID());
  4. if more TPC sets need to follow the same reference, repeat steps 2 and 3.

The assignment of the ROP number is in blocks according to the view. The distribution between different views is first come, first serve: the first ROP within a certain view conquers the lowest number still available for all the ROP's within that view.

The algorithm assumes that all TPC sets have the same view composition as the model one used in the constructor. If this requirement is violated, the behavior is undefined (but it's likely that a ROP ID will be assigned multiple times).

Definition at line 216 of file ROPandTPCsetBuildingAlg.cxx.

Member Typedef Documentation

template<typename T >
using icarus::details::ROPnumberDispatcher::DataByView_t = std::map<geo::View_t, T>
private

Type of collection of T by view.

Definition at line 220 of file ROPandTPCsetBuildingAlg.cxx.

Constructor & Destructor Documentation

icarus::details::ROPnumberDispatcher::ROPnumberDispatcher ( std::vector< PlaneColl_t > const &  refROP,
std::string const &  logCategory 
)
inline

Constructor: uses refROP as reference to assign number ranges to views.

Definition at line 244 of file ROPandTPCsetBuildingAlg.cxx.

245  : fLogCategory(logCategory)
248  {}
DataByView_t< readout::ROPID::ROPID_t > fAvailableROPno
The first available ROP number for each view.
std::string const fLogCategory
Log category name for messages.
DataByView_t< readout::ROPID::ROPID_t > const fFirstROPno
The first ROP number for each view.
DataByView_t< readout::ROPID::ROPID_t > PreferredROPrangesByView(std::vector< PlaneColl_t > const &ROPs) const
Returns the fist ROP number for each view in ROP.

Member Function Documentation

readout::ROPID icarus::details::ROPnumberDispatcher::assignID ( PlaneColl_t const &  ROP)
inline

Returns the next available ID for the specified ROP.

Definition at line 255 of file ROPandTPCsetBuildingAlg.cxx.

256  { return { fTPCset, fAvailableROPno.at(ROPview(ROP))++ }; }
DataByView_t< readout::ROPID::ROPID_t > fAvailableROPno
The first available ROP number for each view.
readout::TPCsetID fTPCset
The TPC set being served.
static geo::View_t ROPview(PlaneColl_t const &planes)
Returns the view of the planes (geo::kUnknown if mixed or none).
auto icarus::details::ROPnumberDispatcher::PreferredROPrangesByView ( std::vector< PlaneColl_t > const &  ROPs) const
private

Returns the fist ROP number for each view in ROP.

Definition at line 266 of file ROPandTPCsetBuildingAlg.cxx.

268 {
269  /*
270  * ROP numbers are assigned in blocks of views, on a first come, first serve
271  * basis.
272  * This, the first ROP on a view books as many ROP numbers as there are ROPs
273  * with that view.
274  */
275  DataByView_t<unsigned int> const viewROPcounts = ViewROPcounts(ROPs);
276 
277  DataByView_t<readout::ROPID::ROPID_t> FirstROPno;
278  readout::ROPID::ROPID_t nextAvailable { 0 };
279 
280  for (PlaneColl_t const& planes: ROPs) {
281 
282  geo::View_t const view = ROPview(planes);
283 
284  //
285  // using the facts that:
286  // * std::map::emplace() does not insert anything if the key already exists
287  // * std::map::emplace() returns as `second` whether it insert or not
288  //
289  if (!FirstROPno.emplace(view, nextAvailable).second) continue;
290 
291  mf::LogTrace(fLogCategory)
292  << "ROPs on view " << geo::PlaneGeo::ViewName(view)
293  << " preferring numbers from " << nextAvailable
294  << " (" << viewROPcounts.at(view) << " numbers reserved)";
295 
296  // so, insertion happened; let's reserve numbers
297  nextAvailable += viewROPcounts.at(view);
298 
299  } // for ROPs
300 
301  return FirstROPno;
302 
303 } // icarus::details::ROPnumberDispatcher::PreferredROPrangesByView()
static std::string ViewName(geo::View_t view)
Returns the name of the specified view.
Definition: PlaneGeo.cxx:763
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
unsigned int ROPID_t
Type for the ID number.
std::string const fLogCategory
Log category name for messages.
DataByView_t< unsigned int > ViewROPcounts(std::vector< PlaneColl_t > const &ROPplanes) const
Returns the number of planes with each view.
std::vector< geo::PlaneGeo const * > PlaneColl_t
Type of collection of planes (pointers to geo::PlaneGeo).
static geo::View_t ROPview(PlaneColl_t const &planes)
Returns the view of the planes (geo::kUnknown if mixed or none).
BEGIN_PROLOG Z planes
geo::View_t icarus::details::ROPnumberDispatcher::ROPview ( PlaneColl_t const &  planes)
static

Returns the view of the planes (geo::kUnknown if mixed or none).

Definition at line 336 of file ROPandTPCsetBuildingAlg.cxx.

337 {
338  auto iPlane = planes.begin();
339  auto const pend = planes.end();
340  if (iPlane == pend) return geo::kUnknown;
341  geo::View_t const view = (*iPlane)->View();
342  while (++iPlane != pend) {
343  if ((*iPlane)->View() !=view) return geo::kUnknown;
344  } // while
345  return view;
346 } // icarus::details::ROPnumberDispatcher::ROPview()
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Unknown view.
Definition: geo_types.h:136
BEGIN_PROLOG Z planes
void icarus::details::ROPnumberDispatcher::setTPCset ( readout::TPCsetID const &  TPCset)
inline

Rests the object to work with the specified TPC set next.

Definition at line 251 of file ROPandTPCsetBuildingAlg.cxx.

252  { fTPCset = TPCset; fAvailableROPno = fFirstROPno; }
DataByView_t< readout::ROPID::ROPID_t > fAvailableROPno
The first available ROP number for each view.
DataByView_t< readout::ROPID::ROPID_t > const fFirstROPno
The first ROP number for each view.
readout::TPCsetID fTPCset
The TPC set being served.
auto icarus::details::ROPnumberDispatcher::ViewROPcounts ( std::vector< PlaneColl_t > const &  ROPplanes) const
private

Returns the number of planes with each view.

Definition at line 308 of file ROPandTPCsetBuildingAlg.cxx.

310 {
311  DataByView_t<unsigned int> viewROPcounts;
312 
313  for (PlaneColl_t const& planes: ROPplanes) {
314  if (planes.empty()) continue;
315 
316  geo::View_t const view = ROPview(planes);
317  if (view == geo::kUnknown) {
318  mf::LogWarning log(fLogCategory);
319  log << "A ROP spans multiple views:";
320  for (geo::PlaneGeo const* plane: planes) {
321  log << " " << geo::PlaneGeo::ViewName(plane->View())
322  << " (" << plane->ID() << ")";
323  }
324  } // if unknown
325 
326  ++(viewROPcounts[view]);
327 
328  } // for ROPs
329 
330  return viewROPcounts;
331 } // icarus::details::ROPnumberDispatcher::ViewROPcounts()
static std::string ViewName(geo::View_t view)
Returns the name of the specified view.
Definition: PlaneGeo.cxx:763
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::string const fLogCategory
Log category name for messages.
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:82
std::vector< geo::PlaneGeo const * > PlaneColl_t
Type of collection of planes (pointers to geo::PlaneGeo).
static geo::View_t ROPview(PlaneColl_t const &planes)
Returns the view of the planes (geo::kUnknown if mixed or none).
BEGIN_PROLOG Z planes

Member Data Documentation

DataByView_t<readout::ROPID::ROPID_t> icarus::details::ROPnumberDispatcher::fAvailableROPno
private

The first available ROP number for each view.

Definition at line 228 of file ROPandTPCsetBuildingAlg.cxx.

DataByView_t<readout::ROPID::ROPID_t> const icarus::details::ROPnumberDispatcher::fFirstROPno
private

The first ROP number for each view.

Definition at line 225 of file ROPandTPCsetBuildingAlg.cxx.

std::string const icarus::details::ROPnumberDispatcher::fLogCategory
private

Log category name for messages.

Definition at line 222 of file ROPandTPCsetBuildingAlg.cxx.

readout::TPCsetID icarus::details::ROPnumberDispatcher::fTPCset
private

The TPC set being served.

Definition at line 231 of file ROPandTPCsetBuildingAlg.cxx.


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