From 6b9c1cc9c3601e96d68b6ea6e471ee17d23676a2 Mon Sep 17 00:00:00 2001 From: scott snyder <sss@karma> Date: Wed, 7 Oct 2020 15:10:57 -0400 Subject: [PATCH] RootCollection: cppcheck fixes - Pass class instances by const reference, not by value. - Don't use string::find to test the start of a string. --- Database/APR/RootCollection/src/RootCollection.cpp | 14 ++++++++------ Database/APR/RootCollection/src/RootCollection.h | 4 ++-- .../APR/RootCollection/src/RootCollectionQuery.cpp | 6 ++---- .../src/RootCollectionSchemaEditor.cpp | 2 +- .../src/RootCollectionSchemaEditor.h | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Database/APR/RootCollection/src/RootCollection.cpp b/Database/APR/RootCollection/src/RootCollection.cpp index 837647462d4..0216037688d 100755 --- a/Database/APR/RootCollection/src/RootCollection.cpp +++ b/Database/APR/RootCollection/src/RootCollection.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "RootCollection.h" @@ -79,7 +79,7 @@ namespace pool { } - void RootCollection::delayedFileOpen( std::string method ) + void RootCollection::delayedFileOpen( const std::string& method ) { if( m_open && !m_file && m_session && m_mode != ICollection::READ ) { m_file = TFile::Open(m_fileName.c_str(), poolOptToRootOpt[m_mode] ); @@ -434,7 +434,7 @@ namespace pool { string RootCollection::retrievePFN() const { - if(m_name.find("PFN:")!=0) + if (m_name.substr (0, 4) != "PFN:") throw pool::Exception( "In CREATE mode a PFN has to be provided", "RootCollection::open", "RootCollection"); @@ -447,17 +447,19 @@ namespace pool { FileCatalog::FileID fid=""; string fileType=""; - if(m_name.find("PFN:")==0){ + if (m_name.substr (0, 4) == "PFN:") { string pfn = m_name.substr(4,string::npos); m_fileCatalog->start(); m_fileCatalog->lookupFileByPFN(pfn,fid,fileType); m_fileCatalog->commit(); - }else if(m_name.find("LFN:")==0){ + } + else if (m_name.substr (0, 4) == "LFN:") { string lfn = m_name.substr(4,string::npos); m_fileCatalog->start(); m_fileCatalog->lookupFileByLFN(lfn,fid); m_fileCatalog->commit(); - }else if(m_name.find("FID:")==0){ + } + else if (m_name.substr (0, 4) == "FID:") { fid = m_name.substr(4,string::npos); }else throw pool::Exception( "A FID, PFN or and LFN has to be provided", diff --git a/Database/APR/RootCollection/src/RootCollection.h b/Database/APR/RootCollection/src/RootCollection.h index b927679ff8b..e78822e3ece 100755 --- a/Database/APR/RootCollection/src/RootCollection.h +++ b/Database/APR/RootCollection/src/RootCollection.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef ROOTCOLLECTION_ROOTCOLLECTION_H @@ -188,7 +188,7 @@ namespace pool { /// copying unimplemented in this class. RootCollection & operator = (const RootCollection &); - void delayedFileOpen( std::string method ); + void delayedFileOpen( const std::string& method ); TTree* getCollectionTree(); void setupTree() const; void readAttributeListSpecification() const; diff --git a/Database/APR/RootCollection/src/RootCollectionQuery.cpp b/Database/APR/RootCollection/src/RootCollectionQuery.cpp index b224669ea3c..cf67393fd26 100644 --- a/Database/APR/RootCollection/src/RootCollectionQuery.cpp +++ b/Database/APR/RootCollection/src/RootCollectionQuery.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "RootCollectionQuery.h" @@ -113,9 +113,7 @@ pool::RootCollection::RootCollectionQuery::selectAll() void pool::RootCollection::RootCollectionQuery::addToCollectionFragmentList( const std::string& fragmentName ) { - if( m_collectionFragmentNames.find( fragmentName ) == m_collectionFragmentNames.end() ) { - m_collectionFragmentNames.insert( fragmentName ); - + if (m_collectionFragmentNames.insert (fragmentName).second) { /* // Add data table associated with collection fragment to query table list. std::string dataTableName = ( m_dataTableNameForCollectionFragmentName.find( fragmentName ) )->second; diff --git a/Database/APR/RootCollection/src/RootCollectionSchemaEditor.cpp b/Database/APR/RootCollection/src/RootCollectionSchemaEditor.cpp index 2b41f3e291d..29d40f3a34c 100644 --- a/Database/APR/RootCollection/src/RootCollectionSchemaEditor.cpp +++ b/Database/APR/RootCollection/src/RootCollectionSchemaEditor.cpp @@ -301,7 +301,7 @@ renameCollectionFragment( const std::string& /* oldName */, const std::string& / void pool::RootCollection::RootCollectionSchemaEditor:: -addTreeBranch( const std::string& name, const std::string type_name ) +addTreeBranch( const std::string& name, const std::string& type_name ) { static std::map< std::string, char > typeDict; if( !typeDict.size() ) { diff --git a/Database/APR/RootCollection/src/RootCollectionSchemaEditor.h b/Database/APR/RootCollection/src/RootCollectionSchemaEditor.h index edf8eb8eabc..473c5d967c1 100644 --- a/Database/APR/RootCollection/src/RootCollectionSchemaEditor.h +++ b/Database/APR/RootCollection/src/RootCollectionSchemaEditor.h @@ -256,7 +256,7 @@ namespace pool { virtual ~RootCollectionSchemaEditor(); protected: - void addTreeBranch( const std::string& name, const std::string type_name ); + void addTreeBranch( const std::string& name, const std::string& type_name ); void readSchema(); void createTreeBranches(); void writeSchema(); -- GitLab