Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-15 01:07:38

0001 /*
0002  *  friendlyname_t.cppunit.cc
0003  *  CMSSW
0004  *
0005  *  Created by Chris Jones on 8/8/05.
0006  *
0007  */
0008 
0009 #include <cppunit/extensions/HelperMacros.h>
0010 #include <iostream>
0011 #include "FWCore/Utilities/interface/FriendlyName.h"
0012 
0013 using namespace edm;
0014 
0015 class testfriendlyName : public CppUnit::TestFixture {
0016   CPPUNIT_TEST_SUITE(testfriendlyName);
0017 
0018   CPPUNIT_TEST(test);
0019 
0020   CPPUNIT_TEST_SUITE_END();
0021 
0022 public:
0023   void setUp() {}
0024   void tearDown() {}
0025 
0026   void test();
0027 };
0028 
0029 ///registration of the test so that the runner can find it
0030 CPPUNIT_TEST_SUITE_REGISTRATION(testfriendlyName);
0031 
0032 void testfriendlyName::test() {
0033   typedef std::pair<std::string, std::string> Values;
0034   std::map<std::string, std::string> classToFriendly;
0035   classToFriendly.insert(Values("Foo", "Foo"));
0036   classToFriendly.insert(Values("const Foo", "constFoo"));
0037   classToFriendly.insert(Values("bar::Foo", "barFoo"));
0038   classToFriendly.insert(Values("std::vector<Foo>", "Foos"));
0039   classToFriendly.insert(Values("std::vector<bar::Foo>", "barFoos"));
0040   classToFriendly.insert(Values("std::set<bar::Foo>", "barFoostdset"));
0041   classToFriendly.insert(Values("std::map<Foo, bar::Bar>", "FoobarBarstdmap"));
0042   classToFriendly.insert(Values("std::unordered_set<bar::Foo>", "barFoostduset"));
0043   classToFriendly.insert(Values("std::unordered_set<std::basic_string<char>>", "Stringstduset"));
0044   classToFriendly.insert(Values("std::unordered_set<bar::Foo, std::hash<bar::Foo>>", "barFoostduset"));
0045   classToFriendly.insert(
0046       Values("std::unordered_set<std::basic_string<char>, std::hash<std::basic_string<char>>>", "Stringstduset"));
0047   classToFriendly.insert(
0048       Values("std::unordered_set<bar::Foo, std::hash<bar::Foo>, std::equal_to<bar::Foo>>", "barFoostduset"));
0049   classToFriendly.insert(
0050       Values("std::unordered_set<std::basic_string<char>, std::hash<std::basic_string<char>>, "
0051              "std::equal_to<std::basic_string<char>>>",
0052              "Stringstduset"));
0053   classToFriendly.insert(
0054       Values("std::unordered_set<bar::Foo, CustomHash, std::equal_to<bar::Foo>>", "barFooCustomHashstduset"));
0055   classToFriendly.insert(
0056       Values("std::unordered_set<std::basic_string<char>, CustomHash, std::equal_to<std::basic_string<char>>>",
0057              "StringCustomHashstduset"));
0058   classToFriendly.insert(Values("std::unordered_set<bar::Foo, CustomHash>", "barFooCustomHashstduset"));
0059   classToFriendly.insert(Values("std::unordered_set<std::basic_string<char>, CustomHash>", "StringCustomHashstduset"));
0060   classToFriendly.insert(Values("std::unordered_map<Foo, bar::Bar>", "FoobarBarstdumap"));
0061   classToFriendly.insert(Values("std::unordered_map<std::basic_string<char>, bar::Bar>", "StringbarBarstdumap"));
0062   classToFriendly.insert(Values("std::unordered_map<Foo, std::basic_string<char>>", "FooStringstdumap"));
0063   classToFriendly.insert(Values("std::unordered_map<Foo, bar::Bar, std::hash<Foo>>", "FoobarBarstdumap"));
0064   classToFriendly.insert(
0065       Values("std::unordered_map<std::basic_string<char> , bar::Bar, std::hash<std::basic_string<char> > >",
0066              "StringbarBarstdumap"));
0067   classToFriendly.insert(
0068       Values("std::unordered_map<Foo, std::basic_string<char> , std::hash<Foo>>", "FooStringstdumap"));
0069   classToFriendly.insert(
0070       Values("std::unordered_map<Foo, bar::Bar, std::hash<Foo>, std::equal_to<Foo>>", "FoobarBarstdumap"));
0071   classToFriendly.insert(
0072       Values("std::unordered_map<std::basic_string<char>, bar::Bar, std::hash<std::basic_string<char>>, "
0073              "std::equal_to<std::basic_string<char>>>",
0074              "StringbarBarstdumap"));
0075   classToFriendly.insert(Values("std::unordered_map<Foo, std::basic_string<char>, std::hash<Foo>, std::equal_to<Foo>>",
0076                                 "FooStringstdumap"));
0077   classToFriendly.insert(
0078       Values("std::unordered_map<Foo, bar::Bar, CustomHash, std::equal_to<Foo>>", "FoobarBarCustomHashstdumap"));
0079   classToFriendly.insert(Values(
0080       "std::unordered_map<std::basic_string<char>, bar::Bar, CustomHash, std::equal_to<std::basic_string<char>>>",
0081       "StringbarBarCustomHashstdumap"));
0082   classToFriendly.insert(Values("std::unordered_map<Foo, std::basic_string<char>, CustomHash, std::equal_to<Foo>>",
0083                                 "FooStringCustomHashstdumap"));
0084   classToFriendly.insert(Values("std::unordered_map<Foo, bar::Bar, CustomHash>", "FoobarBarCustomHashstdumap"));
0085   classToFriendly.insert(
0086       Values("std::unordered_map<std::basic_string<char>, bar::Bar, CustomHash>", "StringbarBarCustomHashstdumap"));
0087   classToFriendly.insert(
0088       Values("std::unordered_map<Foo, std::basic_string<char>, CustomHash>", "FooStringCustomHashstdumap"));
0089   classToFriendly.insert(Values("std::shared_ptr<Foo>", "FooSharedPtr"));
0090   classToFriendly.insert(Values("std::shared_ptr<bar::Foo>", "barFooSharedPtr"));
0091   classToFriendly.insert(Values("std::basic_string<char>", "String"));
0092   classToFriendly.insert(Values("std::string", "String"));
0093   classToFriendly.insert(Values("std::__cxx11::basic_string<char>", "String"));
0094   classToFriendly.insert(Values("std::__cxx11::basic_string<char,std::char_traits<char> >", "String"));
0095   classToFriendly.insert(Values("std::list<int>", "intstdlist"));
0096   classToFriendly.insert(Values("std::__cxx11::list<int>", "intstdlist"));
0097   classToFriendly.insert(Values("std::vector<std::shared_ptr<bar::Foo>>", "barFooSharedPtrs"));
0098   classToFriendly.insert(Values("std::vector<std::basic_string<char>>", "Strings"));
0099   classToFriendly.insert(Values("std::__cxx11::vector<std::__cxx11::basic_string<char>>", "Strings"));
0100   classToFriendly.insert(Values("std::unique_ptr<Foo>", "FooUniquePtr"));
0101   classToFriendly.insert(Values("std::unique_ptr<bar::Foo>", "barFooUniquePtr"));
0102   classToFriendly.insert(Values("std::unique_ptr<const Foo>", "constFooUniquePtr"));
0103   classToFriendly.insert(Values("const std::unique_ptr<Foo>", "FooconstUniquePtr"));
0104   classToFriendly.insert(Values("std::unique_ptr<Foo,std::default_delete<Foo>>", "FooUniquePtr"));
0105   classToFriendly.insert(Values("std::unique_ptr<const Foo, std::default_delete<const Foo>>", "constFooUniquePtr"));
0106   classToFriendly.insert(
0107       Values("std::unique_ptr<std::unique_ptr<Bar,std::default_delete<Bar>>,std::default_delete<std::unique_ptr<Bar,"
0108              "std::default_delete<Bar>>>>",
0109              "BarUniquePtrUniquePtr"));
0110   classToFriendly.insert(Values("std::vector<std::unique_ptr<bar::Foo>>", "barFooUniquePtrs"));
0111   classToFriendly.insert(
0112       Values("std::vector<std::unique_ptr<bar::Foo, std::default_delete<bar::Foo>>>", "barFooUniquePtrs"));
0113   classToFriendly.insert(Values("std::vector<std::unique_ptr<const Foo>>", "constFooUniquePtrs"));
0114   classToFriendly.insert(
0115       Values("std::unique_ptr<std::vector<std::unique_ptr<bar::Foo>>>", "barFooUniquePtrsUniquePtr"));
0116   classToFriendly.insert(
0117       Values("std::unique_ptr<std::vector<std::unique_ptr<bar::Foo>>, "
0118              "std::default_delete<std::vector<std::unique_ptr<bar::Foo>>>>",
0119              "barFooUniquePtrsUniquePtr"));
0120   classToFriendly.insert(
0121       Values("std::unique_ptr<std::vector<std::unique_ptr<bar::Foo, std::default_delete<bar::Foo>>>>",
0122              "barFooUniquePtrsUniquePtr"));
0123   classToFriendly.insert(
0124       Values("std::unique_ptr<std::vector<std::unique_ptr<bar::Foo, std::default_delete<bar::Foo>>>, "
0125              "std::default_delete<std::vector<std::unique_ptr<bar::Foo, std::default_delete<bar::Foo>>>>>",
0126              "barFooUniquePtrsUniquePtr"));
0127   classToFriendly.insert(Values("V<A,B>", "ABV"));
0128   classToFriendly.insert(Values("edm::ExtCollection<std::vector<reco::SuperCluster>,reco::SuperClusterRefProds>",
0129                                 "recoSuperClustersrecoSuperClusterRefProdsedmExtCollection"));
0130   classToFriendly.insert(
0131       Values("edm::SortedCollection<EcalUncalibratedRecHit,edm::StrictWeakOrdering<EcalUncalibratedRecHit> >",
0132              "EcalUncalibratedRecHitsSorted"));
0133   classToFriendly.insert(
0134       Values("edm::OwnVector<aod::Candidate,edm::ClonePolicy<aod::Candidate> >", "aodCandidatesOwned"));
0135   classToFriendly.insert(Values("edm::OwnVector<Foo,edm::ClonePolicy<Foo> >", "FoosOwned"));
0136   classToFriendly.insert(Values("edm::OwnVector<My<int>, edm::ClonePolicy<My<int> > >", "intMysOwned"));
0137   classToFriendly.insert(Values("std::vector<edm::OwnVector<My<int>, edm::ClonePolicy<My<int> > > >", "intMysOwneds"));
0138   classToFriendly.insert(
0139       Values("edm::Wrapper<MuonDigiCollection<CSCDetId,CSCALCTDigi> >", "CSCDetIdCSCALCTDigiMuonDigiCollection"));
0140   classToFriendly.insert(
0141       Values("edm::AssociationMap<edm::OneToMany<std::vector<CaloJet>,std::vector<reco::Track>,unsigned int> >",
0142              "CaloJetsToManyrecoTracksAssociation"));
0143   classToFriendly.insert(
0144       Values("edm::AssociationMap<edm::OneToOne<std::vector<reco::Track>,std::vector<reco::TrackInfo>,unsigned int> >",
0145              "recoTracksToOnerecoTrackInfosAssociation"));
0146   classToFriendly.insert(Values("edm::AssociationMap<edm::OneToValue<std::vector<reco::Electron>,float,unsigned int> >",
0147                                 "recoElectronsToValuefloatAssociation"));
0148   classToFriendly.insert(
0149       Values("edm::AssociationMap<edm::OneToManyWithQuality<edm::OwnVector<reco::Candidate,edm::ClonePolicy<reco::"
0150              "Candidate> >,edm::OwnVector<reco::Candidate,edm::ClonePolicy<reco::Candidate> >,double,unsigned int> >",
0151              "recoCandidatesOwnedToManyrecoCandidatesOwnedWithQuantitydoubleAssociation"));
0152   classToFriendly.insert(
0153       Values("edm::AssociationVector<edm::RefProd<std::vector<reco::CaloJet> "
0154              ">,std::vector<int>,edm::Ref<std::vector<reco::CaloJet>,reco::CaloJet,edm::refhelper::FindUsingAdvance<"
0155              "std::vector<reco::CaloJet>,reco::CaloJet> >,unsigned int,edm::helper::AssociationIdenticalKeyReference>",
0156              "recoCaloJetsedmRefProdTointsAssociationVector"));
0157   classToFriendly.insert(
0158       Values("edm::AssociationVector<edm::RefProd<edm::OwnVector<reco::Candidate,edm::ClonePolicy<reco::Candidate> > "
0159              ">,std::vector<double>,edm::Ref<edm::OwnVector<reco::Candidate,edm::ClonePolicy<reco::Candidate> "
0160              ">,reco::Candidate,edm::refhelper::FindUsingAdvance<edm::OwnVector<reco::Candidate,edm::ClonePolicy<reco::"
0161              "Candidate> >,reco::Candidate> >,unsigned int,edm::helper::AssociationIdenticalKeyReference>",
0162              "recoCandidatesOwnededmRefProdTodoublesAssociationVector"));
0163   classToFriendly.insert(
0164       Values("edm::AssociationMap<edm::OneToOne<std::vector<reco::Track>,std::vector<std::pair<double,double> "
0165              ">,unsigned int> >",
0166              "recoTracksToOnedoubledoublestdpairsAssociation"));
0167   classToFriendly.insert(
0168       Values("edm::AssociationMap<edm::OneToOne<std::vector<reco::Track>,std::vector<std::pair<Point3DBase<float,"
0169              "GlobalTag>,GlobalErrorBase<double,ErrorMatrixTag> > >,unsigned int> >",
0170              "recoTracksToOnefloatGlobalTagPoint3DBasedoubleErrorMatrixTagGlobalErrorBasestdpairsAssociation"));
0171   classToFriendly.insert(Values("A<B<C>, D<E> >", "CBEDA"));
0172   classToFriendly.insert(Values("A<B<C<D> > >", "DCBA"));
0173   classToFriendly.insert(Values("A<B<C,D>, E<F> >", "CDBFEA"));
0174   classToFriendly.insert(Values("Aa<Bb<Cc>, Dd<Ee> >", "CcBbEeDdAa"));
0175   classToFriendly.insert(Values("Aa<Bb<Cc<Dd> > >", "DdCcBbAa"));
0176   classToFriendly.insert(Values("Aa<Bb<Cc,Dd>, Ee<Ff> >", "CcDdBbFfEeAa"));
0177   classToFriendly.insert(Values("Aa<Bb<Cc,Dd>, Ee<Ff,Gg> >", "CcDdBbFfGgEeAa"));
0178   classToFriendly.insert(
0179       Values("edm::RangeMap<DetId,edm::OwnVector<SiPixelRecHit,edm::ClonePolicy<SiPixelRecHit> "
0180              ">,edm::ClonePolicy<SiPixelRecHit> >",
0181              "DetIdSiPixelRecHitsOwnedRangeMap"));
0182   classToFriendly.insert(
0183       Values("std::vector<edm::RangeMap<DetId,edm::OwnVector<SiPixelRecHit,edm::ClonePolicy<SiPixelRecHit> "
0184              ">,edm::ClonePolicy<SiPixelRecHit> > >",
0185              "DetIdSiPixelRecHitsOwnedRangeMaps"));
0186   classToFriendly.insert(
0187       Values("edm::RefVector< edm::OwnVector<reco::Candidate,edm::ClonePolicy<reco::Candidate> >,reco::Candidate, "
0188              "edm::refhelper::FindUsingAdvance<edm::OwnVector<reco::Candidate,edm::ClonePolicy<reco::Candidate> >, "
0189              "reco::Candidate> >",
0190              "recoCandidatesOwnedRefs"));
0191   classToFriendly.insert(
0192       Values("edm::RefVector< std::vector<reco::Track>, reco::Track, "
0193              "edm::refhelper::FindUsingAdvance<std::vector<reco::Track>, reco::Track> >",
0194              "recoTracksRefs"));
0195   classToFriendly.insert(
0196       Values("edm::RefVector<Col, Type, edm::refhelper::FindUsingAdvance<Col, Type> >", "ColTypeRefs"));
0197   classToFriendly.insert(
0198       Values("edm::AssociationMap<edm::OneToMany<std::vector<reco::PixelMatchGsfElectron>,edm::SortedCollection<"
0199              "EcalRecHit,edm::StrictWeakOrdering<EcalRecHit> >,unsigned int> >",
0200              "recoPixelMatchGsfElectronsToManyEcalRecHitsSortedAssociation"));
0201   classToFriendly.insert(
0202       Values("edm::AssociationVector<edm::RefToBaseProd<reco::Candidate>,std::vector<double>,edm::RefToBase<reco::"
0203              "Candidate>,unsigned int,edm::helper::AssociationIdenticalKeyReference>",
0204              "recoCandidateedmRefToBaseProdTodoublesAssociationVector"));
0205   classToFriendly.insert(
0206       Values("edm::RefVector<edm::AssociationMap<edm::OneToOne<std::vector<reco::BasicCluster>,std::vector<reco::"
0207              "ClusterShape>,unsigned int> "
0208              ">,edm::helpers::KeyVal<edm::Ref<std::vector<reco::BasicCluster>,reco::BasicCluster,edm::refhelper::"
0209              "FindUsingAdvance<std::vector<reco::BasicCluster>,reco::BasicCluster> "
0210              ">,edm::Ref<std::vector<reco::ClusterShape>,reco::ClusterShape,edm::refhelper::FindUsingAdvance<std::"
0211              "vector<reco::ClusterShape>,reco::ClusterShape> > "
0212              ">,edm::AssociationMap<edm::OneToOne<std::vector<reco::BasicCluster>,std::vector<reco::ClusterShape>,"
0213              "unsigned int> >::Find>",
0214              "recoBasicClustersToOnerecoClusterShapesAssociationRefs"));
0215   classToFriendly.insert(
0216       Values("edmNew::DetSetVector<edm::Ref<edmNew::DetSetVector<SiPixelCluster>,SiPixelCluster,edmNew::DetSetVector<"
0217              "SiPixelCluster>::FindForDetSetVector> >",
0218              "SiPixelClusteredmNewDetSetVectorSiPixelClusterSiPixelClusteredmNewDetSetVectorFindForDetSetVectoredmRefed"
0219              "mNewDetSetVector"));
0220   classToFriendly.insert(
0221       Values("std::vector<std::pair<const pat::Muon *, TLorentzVector>>", "constpatMuonptrTLorentzVectorstdpairs"));
0222   classToFriendly.insert(Values("int[]", "intAs"));
0223   classToFriendly.insert(Values("foo<int[]>", "intAsfoo"));
0224   classToFriendly.insert(Values("bar<foo<int[]>>", "intAsfoobar"));
0225 
0226   // Alpaka types
0227   classToFriendly.insert(Values("alpaka::DevCpu", "alpakaDevCpu"));
0228   classToFriendly.insert(Values("alpaka::DevUniformCudaHipRt<alpaka::ApiCudaRt>", "alpakaDevCudaRt"));
0229   classToFriendly.insert(Values("alpaka::DevUniformCudaHipRt<alpaka::ApiHipRt>", "alpakaDevHipRt"));
0230   classToFriendly.insert(Values("alpaka::QueueGenericThreadsBlocking<alpaka::DevCpu>", "alpakaQueueCpuBlocking"));
0231   classToFriendly.insert(Values("alpaka::QueueGenericThreadsNonBlocking<alpaka::DevCpu>", "alpakaQueueCpuNonBlocking"));
0232   classToFriendly.insert(Values("alpaka::uniform_cuda_hip::detail::QueueUniformCudaHipRt<alpaka::ApiCudaRt,true>",
0233                                 "alpakaQueueCudaRtBlocking"));
0234   classToFriendly.insert(Values("alpaka::uniform_cuda_hip::detail::QueueUniformCudaHipRt<alpaka::ApiCudaRt,false>",
0235                                 "alpakaQueueCudaRtNonBlocking"));
0236   classToFriendly.insert(Values("alpaka::uniform_cuda_hip::detail::QueueUniformCudaHipRt<alpaka::ApiHipRt,true>",
0237                                 "alpakaQueueHipRtBlocking"));
0238   classToFriendly.insert(Values("alpaka::uniform_cuda_hip::detail::QueueUniformCudaHipRt<alpaka::ApiHipRt,false>",
0239                                 "alpakaQueueHipRtNonBlocking"));
0240 
0241   for (std::map<std::string, std::string>::iterator itInfo = classToFriendly.begin(), itInfoEnd = classToFriendly.end();
0242        itInfo != itInfoEnd;
0243        ++itInfo) {
0244     //std::cout <<itInfo->first<<std::endl;
0245     if (itInfo->second != edm::friendlyname::friendlyName(itInfo->first)) {
0246       std::cout << "class name: '" << itInfo->first << "' has wrong friendly name \n"
0247                 << "expect: '" << itInfo->second << "' got: '" << edm::friendlyname::friendlyName(itInfo->first) << "'"
0248                 << std::endl;
0249       CPPUNIT_ASSERT(0 && "expected friendly name does not match actual friendly name");
0250     }
0251   }
0252 }