The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
CC.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#include <Gaudi/Decays/CC.h>
12
13namespace Decays = Gaudi::Decays;
14
20namespace {
28 inline std::string cc_( const std::string& decay, const Decays::CC::MapCC& map_,
29 const std::string::size_type pos = 0 ) {
30 // check the validity of position
31 if ( pos >= decay.size() ) { return decay; }
32 // find the match:
33 auto _p = std::string::npos;
34 Decays::CC::MapCC::const_iterator _i = map_.end();
35 // look for the "nearest" and "longest" match
36 for ( auto ic = map_.begin(); map_.end() != ic; ++ic ) {
37 // find the particle
38 std::string::size_type p = decay.find( ic->first, pos );
39 // match?
40 if ( std::string::npos == p ) { continue; }
41 // find the nearest match
42 if ( p < _p ) {
43 _p = p;
44 _i = ic;
45 }
46 }
47 // no match at all.
48 if ( std::string::npos == _p || map_.end() == _i ) { return decay; }
49
50 // replace
51 std::string aux = decay;
52 aux.replace( _p, _i->first.size(), _i->second );
53
54 // advance the position
55 _p += _i->second.size();
56 // ... and start the recursion here
57 return _p < aux.size() ? cc_( aux, map_, _p ) : aux;
58 }
59} // namespace
60/* simple function to make charge conjugated inside the original string.
61 * All substrings are substituted by their charge conjugates
62 * @param decay the original string
63 * @param map_ the full map of substitutions
64 * @return charge-conjugated string
65 */
66
67std::string Decays::CC::cc( const std::string& decay, const Decays::CC::MapCC& map_ ) { return cc_( decay, map_ ); }
68
69std::string Decays::CC::cc( const std::string& decay, const std::map<std::string, std::string>& map_ ) {
70 return cc_( decay, { map_.begin(), map_.end() } );
71}
std::map< std::string, std::string, CmpCC > MapCC
the actual type of CC-map
Definition CC.h:36
std::string cc(const std::string &decay, const MapCC &map_)
simple function to make charge conjugated inside the original string.
Definition CC.cpp:67