LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
geo_types_fhicl.h
Go to the documentation of this file.
1 
10 #ifndef LARCOREOBJ_SIMPLETYPESANDCONSTANTS_GEO_TYPES_FHICL_H
11 #define LARCOREOBJ_SIMPLETYPESANDCONSTANTS_GEO_TYPES_FHICL_H
12 
13 // LArSoft libraries
15 
16 // support libraries
17 #include "fhiclcpp/types/Atom.h"
22 #include "fhiclcpp/types/Table.h"
23 
24 // C/C++ standard libraries
25 #include <cstddef> // std::size_t
26 #include <optional>
27 #include <vector>
28 
30 namespace geo::fhicl {
31 
32  // --- BEGIN -- Validated configuration parameters for geometry ID objects ---
194 
197 
210  template <typename IDparam>
213 
215  template <typename IDparam>
219 
220  // --- BEGIN -- Generic ID infrastructure ------------------------------------
222  struct ValidIDConfig {
223 
225  ::fhicl::Comment("whether the ID is valid"),
226  true};
227 
228  bool valid() const { return isValid(); }
229 
230  }; // struct ValidIDConfig
231 
233  template <typename IDtype>
234  struct IDConfig;
235 
237  template <typename IDtype>
239 
241  template <typename IDtype>
243 
245  template <typename IDtype>
247 
249  template <typename IDtype>
251 
252  // --- END -- Generic ID infrastructure --------------------------------------
253 
254  // --- BEGIN -- Cryostat ID --------------------------------------------------
256  template <>
257  struct IDConfig<geo::CryostatID> : public ValidIDConfig {
259 
261  ::fhicl::Comment("cryostat number"),
262  [this]() { return valid(); }};
263 
264  ID_t ID() const { return !valid() ? ID_t{} : ID_t{C()}; }
265  operator ID_t() const { return ID(); }
266 
267  }; // struct IDConfig<geo::CryostatID>
268 
271 
274 
277 
280 
281  // --- END -- Cryostat ID ----------------------------------------------------
282 
283  // --- BEGIN -- TPC ID -------------------------------------------------------
285  template <>
286  struct IDConfig<geo::TPCID> : public IDConfig<geo::CryostatID> {
287  using ID_t = geo::TPCID;
288 
290  ::fhicl::Comment("TPC number within the cryostat"),
291  [this]() { return valid(); }};
292 
293  ID_t ID() const { return !valid() ? ID_t{} : ID_t{IDConfig<geo::CryostatID>::ID(), T()}; }
294  operator ID_t() const { return ID(); }
295  }; // struct IDConfig<geo::TPCID>
296 
299 
302 
305 
308 
309  // --- END -- TPC ID ---------------------------------------------------------
310 
311  // --- BEGIN -- Optical detector ID ------------------------------------------
313  template <>
314  struct IDConfig<geo::OpDetID> : public IDConfig<geo::CryostatID> {
315  using ID_t = geo::OpDetID;
316 
318  ::fhicl::Name("O"),
319  ::fhicl::Comment("Optical detector number within the cryostat"),
320  [this]() { return valid(); }};
321 
322  ID_t ID() const { return !valid() ? ID_t{} : ID_t{IDConfig<geo::CryostatID>::ID(), O()}; }
323  operator ID_t() const { return ID(); }
324  }; // struct IDConfig<geo::OpDetID>
325 
328 
331 
334 
337 
338  // --- END -- Optical detector ID --------------------------------------------
339 
340  // --- BEGIN -- Plane ID -----------------------------------------------------
342  template <>
343  struct IDConfig<geo::PlaneID> : public IDConfig<geo::TPCID> {
344  using ID_t = geo::PlaneID;
345 
347  ::fhicl::Comment("Plane number within the TPC"),
348  [this]() { return valid(); }};
349 
350  ID_t ID() const { return !valid() ? ID_t{} : ID_t{IDConfig<geo::TPCID>::ID(), P()}; }
351  operator ID_t() const { return ID(); }
352  }; // struct IDConfig<geo::PlaneID>
353 
356 
359 
362 
365 
366  // --- END -- Plane ID -------------------------------------------------------
367 
368  // --- BEGIN -- Wire ID ------------------------------------------------------
370  template <>
371  struct IDConfig<geo::WireID> : public IDConfig<geo::PlaneID> {
372  using ID_t = geo::WireID;
373 
375  ::fhicl::Comment("Wire number within the plane"),
376  [this]() { return valid(); }};
377 
378  ID_t ID() const { return !valid() ? ID_t{} : ID_t{IDConfig<geo::PlaneID>::ID(), W()}; }
379  operator ID_t() const { return ID(); }
380  }; // struct IDConfig<geo::WireID>
381 
384 
387 
390 
393 
394  // --- END -- Wire ID --------------------------------------------------------
395 
396  // --- BEGIN -- ID parsing ---------------------------------------------------
397 
399 
444  template <typename SrcID, typename ID = SrcID>
445  ID readID(IDparameter<SrcID> const& atom);
446 
447  template <typename SrcID, typename ID = SrcID>
449  {
450  return readID<SrcID, ID>(atom);
451  }
453 
455 
491  template <typename SrcID, typename ID = SrcID>
492  std::optional<ID> readOptionalID(OptionalID<SrcID> const& atom);
493 
494  template <typename SrcID, typename ID = SrcID>
495  std::optional<ID> readParameter(OptionalID<SrcID> const& atom)
496  {
497  return readOptionalID<SrcID, ID>(atom);
498  }
500 
502 
539  template <typename SrcID, typename ID = SrcID>
540  ID readOptionalID(OptionalID<SrcID> const& atom, ID const& defValue);
541 
542  template <typename SrcID, typename ID = SrcID>
543  ID readOptionalID(OptionalID<SrcID> const& atom, ID&& defValue);
544 
545  template <typename SrcID, typename ID = SrcID>
546  ID readParameter(OptionalID<SrcID> const& atom, ID const& defValue)
547  {
548  return readOptionalID<SrcID, ID>(atom, defValue);
549  }
550 
551  template <typename SrcID, typename ID = SrcID>
552  ID readParameter(OptionalID<SrcID> const& atom, ID&& defValue)
553  {
554  return readOptionalID<SrcID, ID>(atom, std::move(defValue));
555  }
557 
559 
593  template <typename SrcID, typename ID = SrcID>
594  std::vector<ID> readIDsequence(IDsequence<SrcID> const& seq);
595 
596  template <typename SrcID, typename ID = SrcID>
597  std::vector<ID> readParameter(IDsequence<SrcID> const& seq)
598  {
599  return readIDsequence<SrcID, ID>(seq);
600  }
602 
604 
657  template <typename SrcID, typename ID = SrcID>
658  std::optional<std::vector<ID>> readOptionalIDsequence(OptionalIDsequence<SrcID> const& seq);
659 
660  template <typename SrcID, typename ID = SrcID>
661  std::optional<std::vector<ID>> readParameter(OptionalIDsequence<SrcID> const& seq)
662  {
663  return readOptionalIDsequence<SrcID, ID>(seq);
664  }
666 
668 
683  template <typename SrcID, typename ID = SrcID>
684  std::vector<ID> readOptionalIDsequence(OptionalIDsequence<SrcID> const& seq,
685  std::vector<ID> const& defValue);
686 
687  template <typename SrcID, typename ID = SrcID>
688  std::vector<ID> readOptionalIDsequence(OptionalIDsequence<SrcID> const& seq,
689  std::vector<ID>&& defValue);
690 
691  template <typename SrcID, typename ID = SrcID>
692  std::vector<ID> readParameter(OptionalIDsequence<SrcID> const& seq,
693  std::vector<ID> const& defValue)
694  {
695  return readOptionalIDsequence<SrcID, ID>(seq, defValue);
696  }
697 
698  template <typename SrcID, typename ID = SrcID>
699  std::vector<ID> readParameter(OptionalIDsequence<SrcID> const& seq, std::vector<ID>&& defValue)
700  {
701  return readOptionalIDsequence<SrcID, ID>(seq, std::move(defValue));
702  }
703 
705 
706  // --- END -- ID parsing -----------------------------------------------------
707 
709  // --- END -- Validated configuration parameters for geometry ID objects -----
710 
711 } // namespace geo::fhicl
712 
713 // -----------------------------------------------------------------------------
714 // --- template implementation
715 // -----------------------------------------------------------------------------
716 // --- definition of the traits
717 // ---
718 template <typename ID>
720 
722 
723  using ID_t = typename type::ID_t;
724 
725  static constexpr bool isOptional = false;
726 
727  static constexpr bool isAtom = true;
728 
729  static constexpr bool isSequence = false;
730 
731 }; // geo::fhicl::IDparameterTraits<geo::fhicl::IDparameter<ID>>
732 
733 template <typename ID>
735  : geo::fhicl::IDparameterTraits<geo::fhicl::IDparameter<ID>> {
736  // override:
737  static constexpr bool isOptional = true;
738 }; // geo::fhicl::IDparameterTraits<geo::fhicl::OptionalID<ID>>
739 
740 template <typename ID>
742  : geo::fhicl::IDparameterTraits<geo::fhicl::IDparameter<ID>> {
743  // override:
744  static constexpr bool isAtom = false;
745  static constexpr bool isSequence = true;
746 }; // geo::fhicl::IDparameterTraits<geo::fhicl::IDsequence<ID>>
747 
748 template <typename ID>
750  : geo::fhicl::IDparameterTraits<geo::fhicl::IDsequence<ID>> {
751  // override:
752  static constexpr bool isOptional = true;
753 }; // geo::fhicl::IDparameterTraits<geo::fhicl::OptionalIDsequence<ID>>
754 
755 // -----------------------------------------------------------------------------
756 template <typename SrcID, typename ID /* = SrcID */>
758 {
759  return atom(); // conversions happen as needed (if possible)
760 } // geo::fhicl::readID()
761 
762 // -----------------------------------------------------------------------------
763 template <typename SrcID, typename ID /* = SrcID */>
764 std::optional<ID> geo::fhicl::readOptionalID(OptionalID<SrcID> const& atom)
765 {
766  using ID_t = ID;
767 
768  typename OptionalID<SrcID>::value_type cs;
769  return atom(cs) ? std::make_optional<ID_t>(cs.ID()) : std::nullopt;
770 } // geo::fhicl::readOptionalID()
771 
772 // -----------------------------------------------------------------------------
773 template <typename SrcID, typename ID /* = SrcID */>
774 ID geo::fhicl::readOptionalID(OptionalID<SrcID> const& atom, ID const& defValue)
775 {
776  return readOptionalID(atom).value_or(defValue);
777 }
778 
779 // -----------------------------------------------------------------------------
780 template <typename SrcID, typename ID /* = SrcID */>
781 ID geo::fhicl::readOptionalID(OptionalID<SrcID> const& atom, ID&& defValue)
782 {
783  return readOptionalID(atom).value_or(std::move(defValue));
784 }
785 
786 // -----------------------------------------------------------------------------
787 template <typename SrcID, typename ID /* = SrcID */>
789 {
790  using ID_t = ID;
791 
792  std::vector<ID_t> IDs;
793  std::size_t const n = seq.size();
794  IDs.reserve(n);
795  for (std::size_t i = 0; i < n; ++i)
796  IDs.push_back(seq(i)); // seq(i) is TPCIDConfig
797  return IDs;
798 } // geo::fhicl::readIDsequence()
799 
800 // -----------------------------------------------------------------------------
801 template <typename SrcID, typename ID /* = SrcID */>
802 std::optional<std::vector<ID>> geo::fhicl::readOptionalIDsequence(
803  OptionalIDsequence<SrcID> const& seq)
804 {
805  using values_t = std::vector<ID>;
806 
808  if (!seq(values)) return std::nullopt;
809 
810  values_t IDs;
811  IDs.reserve(values.size());
812  std::copy(values.begin(), values.end(), std::back_inserter(IDs));
813  return {std::move(IDs)};
814 
815 } // geo::fhicl::readOptionalIDsequence()
816 
817 // -----------------------------------------------------------------------------
818 template <typename SrcID, typename ID /* = SrcID */>
820  std::vector<ID> const& defValue)
821 {
822  // making sure `paramValue` is not a r-value; not sure whether it is necessary
823  auto paramValue = readOptionalIDsequence(seq);
824  return paramValue.value_or(defValue);
825 } // geo::fhicl::readOptionalIDsequence(std::vector const&)
826 
827 // -----------------------------------------------------------------------------
828 template <typename SrcID, typename ID /* = SrcID */>
830  std::vector<ID>&& defValue)
831 {
832  return readOptionalIDsequence(seq).value_or(std::move(defValue));
833 } // geo::fhicl::readOptionalIDsequence(std::vector const&)
834 
835 // -----------------------------------------------------------------------------
836 
837 #endif // LARCOREOBJ_SIMPLETYPESANDCONSTANTS_GEO_TYPES_FHICL_H
IDparameter< geo::OpDetID > OpDetID
Member type of validated geo::OpDetID parameter.
IDparameter< geo::CryostatID > CryostatID
Member type of validated geo::CryostatID parameter.
std::size_t size() const noexcept
Definition: SequenceBase.h:33
std::vector< ID > readIDsequence(IDsequence< SrcID > const &seq)
Returns a vector of IDs extracted from the specified ID sequence.
std::array< tt::return_type< T >, N > value_type
Traits for ID parameter objects.
Helper class holding the ID validity flag.
ID readID(IDparameter< SrcID > const &atom)
Returns an ID extracted from the specified ID atom.
IDparameter< geo::PlaneID > PlaneID
Member type of validated geo::PlaneID parameter.
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::optional< ID > readOptionalID(OptionalID< SrcID > const &atom)
Returns an ID extracted from the specified optional ID atom.
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
std::optional< std::vector< ID > > readOptionalIDsequence(OptionalIDsequence< SrcID > const &seq)
Returns a vector of IDs extracted from the specified optional ID sequence.
Type of ID configuration structure (requires specialization)
Definition of data types for geometry description.
FHiCL objects representing geometry classes as configuration parameters.
::fhicl::Atom< bool > isValid
Char_t n[5]
IDparameter< geo::TPCID > TPCID
Member type of validated geo::TPCID parameter.
Namespace collecting geometry-related classes utilities.
ID readParameter(IDparameter< SrcID > const &atom)
Returns an ID extracted from the specified ID atom.
typename IDparameterTraits< IDparam >::ID_t IDof
Type of ID of the specified ID FHiCL parameter object/.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:192