Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:13:29

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #pragma once
0012 
0013 #include <Gaudi/Accumulators/StaticHistogram.h>
0014 
0015 #include <Gaudi/Parsers/Factory.h>
0016 #include <GaudiKernel/ToStream.h>
0017 
0018 #if ( BOOST_VERSION >= 187000 ) && ( BOOST_VERSION < 188000 )
0019 #  define BOOST_ALLOW_DEPRECATED_HEADERS
0020 #endif
0021 #include <boost/spirit/include/qi.hpp>
0022 #undef BOOST_ALLOW_DEPRECATED_HEADERS
0023 
0024 /**
0025  * This file provides a Grammar for the type Gaudi::Accumulators::Axis
0026  * It allows to use that type from python with a format liks :
0027  *    ( nbins, min, max, title )
0028  * where title can be ommited.
0029  * note that for the parsing, min and max will be parsed as doubles before
0030  * being converted to the actual type used as Arithmetic for Axis, so an
0031  * automatic conversion between the 2 must be provided
0032  */
0033 namespace Gaudi {
0034   namespace Parsers {
0035 
0036     namespace qi = boost::spirit::qi;
0037 
0038     template <typename Iterator, typename Skipper, typename Arithmetic>
0039     struct AxisGrammar : qi::grammar<Iterator, Gaudi::Accumulators::Axis<Arithmetic>(), qi::locals<char>, Skipper> {
0040       using Axis = Gaudi::Accumulators::Axis<Arithmetic>;
0041       struct StoreNbinsOp {
0042         void operator()( Axis& res, unsigned int const& nBins ) const { res.setNumBins( nBins ); }
0043       };
0044       struct StoreMinValueOp {
0045         void operator()( Axis& res, Arithmetic const& minValue ) const { res.setMinValue( minValue ); }
0046       };
0047       struct StoreMaxValueOp {
0048         void operator()( Axis& res, Arithmetic const& maxValue ) const { res.setMaxValue( maxValue ); }
0049       };
0050       struct StoreTitleOp {
0051         void operator()( Axis& res, std::string const& title ) const { res.setTitle( title ); }
0052       };
0053       AxisGrammar() : AxisGrammar::base_type( axis ) {
0054         begin = enc::char_( '[' )[qi::_val = ']'] | enc::char_( '(' )[qi::_val = ')'];
0055         end   = enc::char_( qi::_r1 );
0056         core  = qi::int_[storeNbins( qi::_val, qi::_1 )] >> "," >> qi::double_[storeMinValue( qi::_val, qi::_1 )] >>
0057                "," >> qi::double_[storeMaxValue( qi::_val, qi::_1 )] >>
0058                -( "," >> title[storeTitle( qi::_val, qi::_1 )] );
0059         axis = begin[qi::_a = qi::_1] >> core[qi::_val = qi::_1] >> end( qi::_a );
0060       }
0061       qi::rule<Iterator, Axis(), qi::locals<char>, Skipper> axis;
0062       qi::rule<Iterator, Axis(), Skipper>                   core;
0063       qi::rule<Iterator, char()>                            begin;
0064       qi::rule<Iterator, void( char )>                      end;
0065       StringGrammar<Iterator, Skipper>                      title;
0066       ph::function<StoreNbinsOp>                            storeNbins;
0067       ph::function<StoreMinValueOp>                         storeMinValue;
0068       ph::function<StoreMaxValueOp>                         storeMaxValue;
0069       ph::function<StoreTitleOp>                            storeTitle;
0070     };
0071 
0072     template <typename Iterator, typename Skipper, typename Arithmetic>
0073     struct Grammar_<Iterator, Gaudi::Accumulators::Axis<Arithmetic>, Skipper> {
0074       using Grammar = AxisGrammar<Iterator, Skipper, Arithmetic>;
0075     };
0076 
0077     // Parse function... nothing special, but it must be done explicitely.
0078     template <typename Arithmetic>
0079     StatusCode parse( Gaudi::Accumulators::Axis<Arithmetic>& result, const std::string& input ) {
0080       return parse_( result, input );
0081     }
0082 
0083   } // namespace Parsers
0084 
0085 } // namespace Gaudi