Skip to content
Snippets Groups Projects
Commit 275d1813 authored by Vakhtang Tsulaia's avatar Vakhtang Tsulaia
Browse files

Merge branch 'cppcheck.CaloIdentifier-20190316' into 'master'

CaloIdentifier: Fix cppcheck warnings.

See merge request atlas/athena!21969
parents 6c4ba0f3 4dec34b7
No related branches found
No related tags found
No related merge requests found
Showing
with 96 additions and 146 deletions
......@@ -71,7 +71,7 @@ public:
~CaloCell_Base_ID();
int GetSubCaloName( const std::string SubCaloName ) const;
int GetSubCaloName( const std::string& SubCaloName ) const;
/// Initialization from the identifier dictionary
virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr) override;
......
......@@ -980,7 +980,7 @@ inline float CaloCell_Base_ID::phi0(const Identifier regId) const
}
//---------------------------------------------------------------------------
inline int CaloCell_Base_ID::GetSubCaloName(const std::string SubCaloName )const
inline int CaloCell_Base_ID::GetSubCaloName(const std::string& SubCaloName )const
{
if(SubCaloName=="LAREM"){
return(LAREM);
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
/* date of creation : 10/X/2002 */
......@@ -28,12 +28,12 @@ public:
/**
* constructor to be used
*/
CaloID_Exception(std::string lMessage , int lCode) ;
CaloID_Exception(const std::string& lMessage , int lCode);
/**
* set error message
*/
void message(std::string lMessage) ;
void message(const std::string& lMessage);
/**
* return error message <br>
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef CALOIDENTIFIER_CALONEIGHBOURS_H
......@@ -43,7 +43,7 @@ class CaloNeighbourRegion {
enum {SIDE = 2, SAMPL = 3, REGION = 4, ETA = 5, PHI = 6, TILESECTION = 1, TILEPHI = 3, TILEETA = 4, TILESAMPL = 5, FCALETA = 4, FCALPHI = 5};
CaloNeighbourRegion(const std::string name,
CaloNeighbourRegion(const std::string& name,
const CaloCell_Base_ID * theCaloId);
virtual ~CaloNeighbourRegion();
......@@ -86,8 +86,8 @@ class CaloNeighbourRegion {
bool m_isValidMinus,m_isValidPlus;
IdentifierHash m_minHashMinus,m_maxHashMinus,m_minHashPlus,m_maxHashPlus;
std::vector< std::vector<IdentifierHash>* > m_neighbours_plus;
std::vector< std::vector<IdentifierHash>* > m_neighbours_minus;
std::vector< std::unique_ptr<std::vector<IdentifierHash> > > m_neighbours_plus;
std::vector< std::unique_ptr<std::vector<IdentifierHash> > > m_neighbours_minus;
};
class CaloNeighbours {
......@@ -106,12 +106,14 @@ public:
int get_prevInCalo(const IdentifierHash &id,std::vector<IdentifierHash>& neighbourList) const;
int get_neighbours(const IdentifierHash &id, const std::vector<CaloNeighbourRegion*> &regions, std::vector<IdentifierHash>& neighbourList) const;
int get_neighbours(const IdentifierHash &id,
const std::vector<std::unique_ptr<CaloNeighbourRegion> > &regions,
std::vector<IdentifierHash>& neighbourList) const;
private:
const CaloCell_Base_ID * m_calo_id;
std::vector<CaloNeighbourRegion*> m_next_regions;
std::vector<CaloNeighbourRegion*> m_prev_regions;
std::vector<std::unique_ptr<CaloNeighbourRegion> > m_next_regions;
std::vector<std::unique_ptr<CaloNeighbourRegion> > m_prev_regions;
};
#endif // CALOIDENTIFIER_CALONEIGHBOURS_H
......@@ -176,19 +176,19 @@ private:
int initLevelsFromDict(const std::string& group_name) ;
int init_hashes(void) ;
int init_neighbours_from_file(std::string filename, std::vector<std::set<IdentifierHash> > &vec);
int init_neighbours_from_file(const std::string& filename, std::vector<std::set<IdentifierHash> > &vec);
int init_neighbours_2d(std::string filename)
int init_neighbours_2d(const std::string& filename)
{
return init_neighbours_from_file(filename, m_neighbours_2d_vec);
}
int init_neighbours_3d_next(std::string filename)
int init_neighbours_3d_next(const std::string& filename)
{
return init_neighbours_from_file(filename, m_neighbours_3d_next_vec);
}
int init_neighbours_3d_prev(std::string filename)
int init_neighbours_3d_prev(const std::string& filename)
{
return init_neighbours_from_file(filename, m_neighbours_3d_prev_vec);
}
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
/* Generated by Together */
......@@ -28,12 +28,12 @@ public:
/**
* constructor to be used
*/
LArID_Exception(std::string l_message , int l_code) : m_message ( l_message ) , m_code ( l_code ) { }
LArID_Exception(const std::string& l_message , int l_code) : m_message ( l_message ) , m_code ( l_code ) { }
/**
* set error message
*/
void message(std::string l_message) { m_message = l_message ;}
void message(const std::string& l_message) { m_message = l_message ;}
/**
* return error message <br>
......
......@@ -222,19 +222,19 @@ private:
int init_hashes(void) ;
int init_neighbors_from_file(std::string filename, std::vector<std::set<IdentifierHash> > &vec);
int init_neighbors_from_file(const std::string& filename, std::vector<std::set<IdentifierHash> > &vec);
int init_neighbors_2d(std::string filename)
int init_neighbors_2d(const std::string& filename)
{
return init_neighbors_from_file(filename, m_neighbors_2d_vec);
}
int init_neighbors_3d_next(std::string filename)
int init_neighbors_3d_next(const std::string& filename)
{
return init_neighbors_from_file(filename, m_neighbors_3d_next_vec);
}
int init_neighbors_3d_prev(std::string filename)
int init_neighbors_3d_prev(const std::string& filename)
{
return init_neighbors_from_file(filename, m_neighbors_3d_prev_vec);
}
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TILEID_EXCEPTION_H
......@@ -24,12 +24,12 @@ public:
/**
* constructor to be used
*/
TileID_Exception(std::string l_message , int l_code) : m_message ( l_message ) , m_code ( l_code ) { }
TileID_Exception(const std::string& l_message , int l_code) : m_message ( l_message ) , m_code ( l_code ) { }
/**
* set error message
*/
void message(std::string l_message) { m_message = l_message ;}
void message(const std::string& l_message) { m_message = l_message ;}
/**
* return error message
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include "CaloIdentifier/CaloCellGroup.h"
......@@ -289,10 +289,7 @@ void CaloCellGroupList::dump(const CaloCell_ID* caloCellId) {
m_groups[i].printDef();
}
std::cout << "Results: "<< std::endl;
std::vector<Identifier>::const_iterator it=caloCellId->cell_begin();
std::vector<Identifier>::const_iterator it_e=caloCellId->cell_end();
for(;it!=it_e;it++) {
const Identifier id=(*it);
for (const Identifier& id : caloCellId->cell_range()) {
std::cout << "Values for " << caloCellId->show_to_string(id);
const std::vector<float>& x=this->valuesForCell(id);
std::cout << " [";
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
/*
*/
......@@ -16,8 +16,8 @@
CaloHelpersTest::CaloHelpersTest()
: m_parser (std::make_unique<IdDictParser>())
{
m_parser = std::make_unique<IdDictParser>();
m_parser->register_external_entity("LArCalorimeter", "IdDictLArCalorimeter.xml");
IdDictMgr& idd = m_parser->parse("IdDictParser/ATLAS_IDS.xml");
m_em_idHelper.set_quiet (true);
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
// $Id$
......@@ -268,6 +268,7 @@ CaloIDHelper::fill_vec_of_dict_regions (const std::string& group_name /*= ""*/)
m_vecOfDictRegions.push_back (m_dict->find_region(expRegId,group_name));
}
}
// cppcheck-suppress assertWithSideEffect
assert (m_vecOfDictRegions.size() == regions().hash_max());
return 0;
}
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include "CaloIdentifier/CaloID_Exception.h"
......@@ -12,11 +12,11 @@ CaloID_Exception::CaloID_Exception() :
m_message("No error message") , m_code( 999 )
{ }
CaloID_Exception::CaloID_Exception(std::string lMessage , int lCode) :
CaloID_Exception::CaloID_Exception(const std::string& lMessage , int lCode) :
m_message ( lMessage ) , m_code ( lCode )
{ }
void CaloID_Exception::message(std::string lMessage)
void CaloID_Exception::message(const std::string& lMessage)
{ m_message = lMessage ;}
std::string CaloID_Exception::message() const
......
......@@ -39,10 +39,11 @@
//###############################################################################
CaloNeighbourRegion::CaloNeighbourRegion(const std::string name,
CaloNeighbourRegion::CaloNeighbourRegion(const std::string& name,
const CaloCell_Base_ID *theCaloId) :
m_name(name),
m_type(nextInCalo),
m_calo_id(0),
m_calo_id(theCaloId),
m_hasPhi(false),
m_iPhiSource(0),
m_iPhiTarget(0),
......@@ -52,30 +53,12 @@ CaloNeighbourRegion::CaloNeighbourRegion(const std::string name,
m_isValidMinus(false),
m_isValidPlus(false)
{
m_name = name;
m_calo_id = theCaloId;
}
//###############################################################################
CaloNeighbourRegion::~CaloNeighbourRegion()
{
std::vector< std::vector<IdentifierHash>* >::iterator nIter = m_neighbours_plus.begin();
std::vector< std::vector<IdentifierHash>* >::iterator nIterEnd = m_neighbours_plus.end();
for(; nIter != nIterEnd; nIter++ ) {
if ( (*nIter) ) {
delete (*nIter);
(*nIter) = 0;
}
}
nIter = m_neighbours_minus.begin();
nIterEnd = m_neighbours_minus.end();
for(; nIter != nIterEnd; nIter++ ) {
if ( (*nIter) ) {
delete (*nIter);
(*nIter) = 0;
}
}
}
//###############################################################################
......@@ -231,12 +214,10 @@ int CaloNeighbourRegion::setNeighbours(ExpandedIdentifier& id1,
// get hash ID's for the source
IdentifierHash myHash = m_calo_id->calo_cell_hash (myId);
// get ID's and hash ID's for the target
std::vector<ExpandedIdentifier>::const_iterator idIter = id2.begin();
std::vector<ExpandedIdentifier>::const_iterator idIterEnd = id2.end();
std::vector<IdentifierHash> theTargetHashIDs;
for ( ; idIter != idIterEnd; idIter++ ) {
for (const ExpandedIdentifier& eid : id2) {
Identifier myTargetId;
ExpandedIdentifier myNExpID(*idIter);
ExpandedIdentifier myNExpID(eid);
if ( getId(myNExpID,myTargetId,m_targetRange,side,dphi2) ) {
return 1;
}
......@@ -260,25 +241,19 @@ int CaloNeighbourRegion::setNeighbours(ExpandedIdentifier& id1,
void CaloNeighbourRegion::initializeVectors(std::map<IdentifierHash, std::vector<IdentifierHash>, ltIdHash>& neighbourMapPlus, std::map<IdentifierHash, std::vector<IdentifierHash>, ltIdHash>& neighbourMapMinus)
{
if ( m_isValidMinus ) {
std::map<IdentifierHash, std::vector<IdentifierHash>, ltIdHash>::const_iterator first = neighbourMapMinus.begin();
std::map<IdentifierHash, std::vector<IdentifierHash>, ltIdHash>::const_iterator end = neighbourMapMinus.end();
std::map<IdentifierHash, std::vector<IdentifierHash>, ltIdHash>::const_reverse_iterator last = neighbourMapMinus.rbegin();
m_minHashMinus = (*first).first;
m_maxHashMinus = (*last).first;
m_neighbours_minus.resize((unsigned int)(m_maxHashMinus-m_minHashMinus+1),0);
for(;first != end;first++) {
m_neighbours_minus[(unsigned int)((*first).first-m_minHashMinus)] = new std::vector<IdentifierHash>((*first).second);
m_minHashMinus = neighbourMapMinus.begin()->first;
m_maxHashMinus = neighbourMapMinus.rbegin()->first;
m_neighbours_minus.resize((unsigned int)(m_maxHashMinus-m_minHashMinus+1));
for (const auto& p : neighbourMapMinus) {
m_neighbours_minus[(unsigned int)(p.first-m_minHashMinus)] = std::make_unique<std::vector<IdentifierHash> >(p.second);
}
}
if ( m_isValidPlus ) {
std::map<IdentifierHash, std::vector<IdentifierHash>, ltIdHash>::const_iterator first = neighbourMapPlus.begin();
std::map<IdentifierHash, std::vector<IdentifierHash>, ltIdHash>::const_iterator end = neighbourMapPlus.end();
std::map<IdentifierHash, std::vector<IdentifierHash>, ltIdHash>::const_reverse_iterator last = neighbourMapPlus.rbegin();
m_minHashPlus = (*first).first;
m_maxHashPlus = (*last).first;
m_neighbours_plus.resize((unsigned int)(m_maxHashPlus-m_minHashPlus+1),0);
for(;first != end;first++) {
m_neighbours_plus[(unsigned int)((*first).first-m_minHashPlus)] = new std::vector<IdentifierHash>((*first).second);
m_minHashPlus = neighbourMapPlus.begin()->first;
m_maxHashPlus = neighbourMapPlus.rbegin()->first;
m_neighbours_plus.resize((unsigned int)(m_maxHashPlus-m_minHashPlus+1));
for (const auto& p : neighbourMapPlus) {
m_neighbours_plus[(unsigned int)(p.first-m_minHashPlus)] = std::make_unique<std::vector<IdentifierHash> >(p.second);
}
}
......@@ -315,23 +290,6 @@ CaloNeighbours::CaloNeighbours() :
CaloNeighbours::~CaloNeighbours()
{
std::vector<CaloNeighbourRegion*>::iterator rIter = m_next_regions.begin();
std::vector<CaloNeighbourRegion*>::iterator rIterEnd = m_next_regions.end();
for(; rIter != rIterEnd; rIter++ ) {
if ((*rIter)) {
delete (*rIter);
(*rIter) = 0;
}
}
rIter = m_prev_regions.begin();
rIterEnd = m_prev_regions.end();
for(; rIter != rIterEnd; rIter++ ) {
if ((*rIter)) {
delete (*rIter);
(*rIter) = 0;
}
}
}
//###############################################################################
......@@ -430,7 +388,7 @@ int CaloNeighbours::initialize(const CaloCell_Base_ID* caloID,
// }
// std::cout << std::endl;
// create new CaloNeighbourRegion
CaloNeighbourRegion * myRegion = new CaloNeighbourRegion(cName,m_calo_id);
auto myRegion = std::make_unique<CaloNeighbourRegion>(cName,m_calo_id);
if ( isNext )
myRegion->setType(nextInCalo);
else
......@@ -473,9 +431,9 @@ int CaloNeighbours::initialize(const CaloCell_Base_ID* caloID,
} while (!fin.eof() && !endOfBlock);
myRegion->initializeVectors(neighbourMapPlus,neighbourMapMinus);
if (isNext)
m_next_regions.push_back(myRegion);
m_next_regions.push_back(std::move(myRegion));
else
m_prev_regions.push_back(myRegion);
m_prev_regions.push_back(std::move(myRegion));
}
else {
std::cout << "CaloNeighbours::initialize ERROR Invalid neighbour dat file, exiting ... " << std::endl;
......@@ -504,13 +462,13 @@ int CaloNeighbours::get_prevInCalo(const IdentifierHash &id,std::vector<Identifi
//###############################################################################
int CaloNeighbours::get_neighbours(const IdentifierHash &id, const std::vector<CaloNeighbourRegion*> &regions, std::vector<IdentifierHash>& neighbourList) const
int CaloNeighbours::get_neighbours(const IdentifierHash &id,
const std::vector<std::unique_ptr<CaloNeighbourRegion> > &regions,
std::vector<IdentifierHash>& neighbourList) const
{
int result = 0;
std::vector<CaloNeighbourRegion*>::const_iterator rIter = regions.begin();
std::vector<CaloNeighbourRegion*>::const_iterator rIterEnd = regions.end();
for(; rIter != rIterEnd; rIter++ ) {
result = (*rIter)->getNeighbours(id,neighbourList);
for (const std::unique_ptr<CaloNeighbourRegion>& p : regions) {
result = p->getNeighbours(id,neighbourList);
if ( result != 0 )
return result;
}
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include "LArEM_region.h"
......@@ -28,24 +28,24 @@ LArEM_region::LArEM_region(unsigned int& minHash, short int& nbEtaBins, short in
float minEta, float granulEta, float minPhi, float granulPhi, bool fullSym, bool isBarrelMiddle,
short int& prevEtaReg, short int& nextEtaReg,
std::vector<short int>& prevSampReg, std::vector<short int>& nextSampReg,
std::vector<short int>& prevSubdetReg, std::vector<short int>& nextSubdetReg)
std::vector<short int>& prevSubdetReg, std::vector<short int>& nextSubdetReg)
: m_hashMin (minHash),
m_nbEtaBins (nbEtaBins),
m_nPhi (nPhi),
m_minEta (minEta),
m_granulEta (granulEta),
m_minPhi (minPhi),
m_granulPhi (granulPhi),
m_fullSym (fullSym),
m_isFirstBarrelRegion (isBarrelMiddle),
m_prevEtaReg (prevEtaReg),
m_nextEtaReg (nextEtaReg),
m_prevSampReg (prevSampReg),
m_nextSampReg (nextSampReg),
m_prevSubdetReg (prevSubdetReg),
m_nextSubdetReg (nextSubdetReg)
{
m_hashMin = minHash;
m_nbEtaBins = nbEtaBins;
m_minEta = minEta;
m_granulEta = granulEta;
m_minPhi = minPhi;
m_granulPhi = granulPhi;
m_nPhi = nPhi;
m_fullSym = fullSym;
m_isFirstBarrelRegion = isBarrelMiddle;
m_prevEtaReg = prevEtaReg;
m_nextEtaReg = nextEtaReg;
m_prevSampReg = prevSampReg;
m_nextSampReg = nextSampReg;
m_prevSubdetReg = prevSubdetReg;
m_nextSubdetReg = nextSubdetReg;
}
......
......@@ -604,7 +604,7 @@ int LArFCAL_Base_ID::get_neighbours(const IdentifierHash id, const LArNeighbou
return result;
}
int LArFCAL_Base_ID::init_neighbours_from_file(std::string filename, std::vector<std::set<IdentifierHash> > & vec)
int LArFCAL_Base_ID::init_neighbours_from_file(const std::string& filename, std::vector<std::set<IdentifierHash> > & vec)
{
MsgStream log(m_msgSvc, "LArFCAL_Base_ID" );
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include "LArHEC_region.h"
......@@ -26,20 +26,20 @@ LArHEC_region::LArHEC_region(unsigned int& minHash, short int& nbEtaBins, short
float minEta, float granulEta, float minPhi, float granulPhi, bool fullSym,
short int& prevEtaReg, short int& nextEtaReg,
std::vector<short int>& prevSampReg, std::vector<short int>& nextSampReg)
: m_hashMin (minHash),
m_nbEtaBins (nbEtaBins),
m_nPhi (nPhi),
m_minEta (minEta),
m_granulEta (granulEta),
m_minPhi (minPhi),
m_granulPhi (granulPhi),
m_fullSym (fullSym),
m_prevEtaReg (prevEtaReg),
m_nextEtaReg (nextEtaReg),
m_prevSampReg(prevSampReg),
m_nextSampReg(nextSampReg)
{
m_hashMin = minHash;
m_nbEtaBins = nbEtaBins;
m_minEta = minEta;
m_granulEta = granulEta;
m_minPhi = minPhi;
m_granulPhi = granulPhi;
m_nPhi = nPhi;
m_fullSym = fullSym;
m_prevEtaReg = prevEtaReg;
m_nextEtaReg = nextEtaReg;
m_prevSampReg = prevSampReg;
m_nextSampReg = nextSampReg;
}
......
......@@ -650,7 +650,7 @@ int LArMiniFCAL_ID::init_hashes(void)
}
int LArMiniFCAL_ID::init_neighbors_from_file(std::string filename, std::vector<std::set<IdentifierHash> > & vec)
int LArMiniFCAL_ID::init_neighbors_from_file(const std::string& filename, std::vector<std::set<IdentifierHash> > & vec)
{
MsgStream log(m_msgSvc, "LArMiniFCAL_ID" );
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
/***************************************************************************
......@@ -40,7 +40,7 @@ typedef struct
{
Identifier id;
IdentifierHash hash_id;
short int index;
short int index = 0;
std::string name;
std::vector<std::string> neighbours[4];
......
......@@ -41,11 +41,7 @@ void test_neighbours (const CaloCell_ID& calo_id)
std::vector<IdentifierHash> neighbourList;
assert (calo_id.get_neighbours(iCell, LArNeighbours::all3D, neighbourList)
== 0);
std::vector<IdentifierHash>::iterator first=neighbourList.begin();
std::vector<IdentifierHash>::iterator last=neighbourList.end();
for (;last!=first; first++){
IdentifierHash neighbourHash=(*first);
for (IdentifierHash neighbourHash : neighbourList) {
assert (hash_min <= neighbourHash && neighbourHash <= hash_max);
}
}
......
......@@ -55,11 +55,7 @@ void test4 (const LArEM_ID& em_id)
for (unsigned int iCell = 0 ; iCell < em_id.channel_hash_max(); ++iCell){
em_id.get_neighbours(iCell, LArNeighbours::all3D, neighbourList);
std::vector<IdentifierHash>::iterator first=neighbourList.begin();
std::vector<IdentifierHash>::iterator last=neighbourList.end();
for (;last!=first; first++){
IdentifierHash neighbourHash=(*first);
for (IdentifierHash neighbourHash : neighbourList) {
if(neighbourHash < hash_min ) {
hash_min = neighbourHash;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment