Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • Allpix Squared Allpix Squared
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 18
    • Issues 18
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 14
    • Merge requests 14
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Issue
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Allpix Squared
  • Allpix SquaredAllpix Squared
  • Merge requests
  • !483

Merged
Created May 07, 2021 by Simon Spannagel@simonspaOwner

Introduce Enum Reflection

  • Overview 7
  • Commits 17
  • Pipelines 7
  • Changes 23

This MR adds the Magic Enum class to allow for enum reflection. An overload of allpix::to_string_impl() and allpix::from_string_impl() for enum types enable parsing configuration keys directly into enums:

enum class FileType {
    ROOT,
    TXT,
    CSV,
};

auto model = config.get<FileType>("file_type");
if(model == FileType::ROOT) {
    // do sth
}

without odd string comparisons. If the requested key does not exist in the enum, an error message with all available options is printed, emulating the behavior of the manual else printouts used in string comparisons so far:

|23:08:27.240|   (FATAL) [C:DepositionPointCharge:dut] Error in the configuration:
                                                       Could not convert value '"spock"' from key 'model' in section 'DepositionPointCharge' to type DepositionPointChargeModule::DepositionModel: invalid value, possible values are: fixed, scan, spot
                                                       The configuration needs to be updated. Cannot continue.

Many modules have already been ported to this, the last missing part is Mobility where I'm not sure whether I want to pass an enum value to the constructor or rather the full Configuration object such that further keys could be queried (such as model parameters).

The "default" handling of non-implemented types had to go, I couldn't figure out how to re-implement it. But I'm not entirely sure it ever worked properly, at least it didn't for is_enum-like objects. 🙂

This MR is based on top of !482 (merged) which should be reviewed and merged first.

(cc) @kwolters

Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: magic_enum