Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:10

0001 # This file is part of the ACTS project.
0002 #
0003 # Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 #
0005 # This Source Code Form is subject to the terms of the Mozilla Public
0006 # License, v. 2.0. If a copy of the MPL was not distributed with this
0007 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 import argparse
0010 import logging
0011 import os
0012 import sys
0013 from datetime import datetime
0014 
0015 # ------------------------------------------------------------------------------
0016 # Options parsing
0017 # ------------------------------------------------------------------------------
0018 
0019 """ Parent parser that contains logging options """
0020 
0021 
0022 def add_logging_options(parser):
0023 
0024     parser.add_argument(
0025         "-v",
0026         "--info",
0027         action="store_const",
0028         dest="loglevel",
0029         const=logging.INFO,
0030         help=("increase log level (INFO)"),
0031     )
0032     parser.add_argument(
0033         "-vv",
0034         "--debug",
0035         action="store_const",
0036         dest="loglevel",
0037         const=logging.DEBUG,
0038         help=("increase log level (DEBUG)"),
0039     )
0040 
0041     return parser
0042 
0043 
0044 """ Parse logging options from commandline and set up logging service"""
0045 
0046 
0047 def parse_logging_options(args, prog_name=sys.argv[0]):
0048     # Configure log level
0049     log_level = logging.WARNING
0050     if args.loglevel:
0051         log_level = args.loglevel
0052 
0053     # Write log to terminal
0054     logging.basicConfig(
0055         format=("%(levelname)s (%(module)s): %(message)s"), level=log_level
0056     )
0057 
0058     logging.info(
0059         "\ndetray - "
0060         + str(datetime.now().strftime("%d/%m/%Y %H:%M"))
0061         + ': Running detector type generator "'
0062         + os.path.basename(prog_name)
0063         + '"\n'
0064     )
0065 
0066 
0067 """ Parent parser that contains IO options """
0068 
0069 
0070 def add_io_options(parser):
0071 
0072     parser.add_argument(
0073         "-o",
0074         "--output",
0075         help=("Metadata output directory"),
0076         default="",
0077         type=str,
0078     )
0079 
0080     return parser
0081 
0082 
0083 """ Parse IO options from commandline"""
0084 
0085 
0086 def parse_io_options(args):
0087     # Check if the output directory exists
0088     if args.output and not os.path.isdir(args.output):
0089         print(f"Output directory does not exist! ({args.output})")
0090         sys.exit(1)