From b538089246f21c28a138aa3a6b8e5d8edb439f39 Mon Sep 17 00:00:00 2001
From: Frank Winklmeier <fwinkl@cern>
Date: Thu, 16 Jul 2020 15:42:13 +0200
Subject: [PATCH] Code cleanup IOVDbFolder and some cppcheck fixes

Use default member initializers in IOVDbFolder and some cppcheck fixes
throughout the code.
---
 Database/IOVDbSvc/src/IOVDbFolder.cxx     | 42 +-----------
 Database/IOVDbSvc/src/IOVDbFolder.h       | 82 +++++++++++------------
 Database/IOVDbSvc/src/IOVDbResolveTag.cxx |  6 +-
 Database/IOVDbSvc/src/IOVDbResolveTag.h   |  6 +-
 Database/IOVDbSvc/src/Json2Cool.cxx       |  4 +-
 5 files changed, 52 insertions(+), 88 deletions(-)

diff --git a/Database/IOVDbSvc/src/IOVDbFolder.cxx b/Database/IOVDbSvc/src/IOVDbFolder.cxx
index b08813053c7..fa3bfb3c335 100644
--- a/Database/IOVDbSvc/src/IOVDbFolder.cxx
+++ b/Database/IOVDbSvc/src/IOVDbFolder.cxx
@@ -78,47 +78,11 @@ IOVDbFolder::IOVDbFolder(IOVDbConn* conn,
                          IClassIDSvc* clidsvc, const bool checklock, const bool outputToFile,
                          const std::string & source):
   AthMessaging(Athena::getMessageSvc(), "IOVDbFolder"),
-  p_detStore(0),
   p_clidSvc(clidsvc),
-  p_metaDataTool(0),
   m_conn(conn),
-  m_foldername(""),
-  m_key(""),
-  m_multiversion(false),
-  m_timestamp(false),
-  m_tagoverride(false),
-  m_notagoverride(false),
-  m_writemeta(false),
-  m_fromMetaDataOnly(false),
-  m_extensible(false),
-  m_named(false),
-  m_iovoverridden(false),
-  m_jokey(false),
-  m_dropped(false),
-  m_autocache(true),
   m_checklock(checklock),
-  m_iovoverride(0),
   m_foldertype(AttrList),
-  m_metacon(0),
-  m_cachelength(0),
-  m_cachehint(0),
-  m_cacheinc(0),
   m_chansel(cool::ChannelSelection::all()),
-  m_jotag(""),
-  m_tag(""),
-  m_typename(""),
-  m_eventstore(""),
-  m_cachepar(""),
-  m_addrheader(""),
-  m_clid(0),
-  m_ndbread(0),
-  m_ncacheread(0),
-  m_nobjread(0),
-  m_nbytesread(0),
-  m_readtime(0.),
-  m_nchan(0),
-  m_retrieved(false),
-  m_cachespec(0),
   m_outputToFile{outputToFile},
   m_source{source}
 {
@@ -145,13 +109,13 @@ IOVDbFolder::IOVDbFolder(IOVDbConn* conn,
   // channel selection from 'channelSelection' property
   // syntax is A:B,C:D,E:F
   // :B implies zero lower limit, A: implies zero upper limit
-  std::string chanspec,rangespec;
+  std::string chanspec;
   if (folderprop.getKey("channelSelection","",chanspec) && chanspec!="") {
     m_chanrange=IOVDbNamespace::parseChannelSpec<cool::ChannelId>(chanspec);
     // explicit setting of channel selection
-    bool first(true);
-    //push to the channel selection
+    // push to the channel selection
     try{
+      bool first(true);
       for(const auto & i:m_chanrange){
         if (first){
           first = false;
diff --git a/Database/IOVDbSvc/src/IOVDbFolder.h b/Database/IOVDbSvc/src/IOVDbFolder.h
index 5ad35bea15a..987b1a763e9 100644
--- a/Database/IOVDbSvc/src/IOVDbFolder.h
+++ b/Database/IOVDbSvc/src/IOVDbFolder.h
@@ -40,7 +40,7 @@ class CondAttrListCollection;
 class IOVDbFolder : public AthMessaging {
 public:
   IOVDbFolder(IOVDbConn* conn, const IOVDbParser& folderprop, MsgStream& msg,
-              IClassIDSvc* clidsvc,const bool checkglock, const bool outputToFile=false,
+              IClassIDSvc* clidsvc,const bool checklock, const bool outputToFile=false,
               const std::string & source="COOL_DATABASE");
   ~IOVDbFolder();
   
@@ -214,69 +214,69 @@ private:
   specialCacheUpdate(const cool::IObject& obj,const ServiceHandle<IIOVSvc>& iovSvc);
  
   
-  StoreGateSvc*        p_detStore;     // pointer to detector store
-  IClassIDSvc*         p_clidSvc;      // pointer to CLID service
-  IIOVDbMetaDataTool*  p_metaDataTool; // pointer to metadata tool (writing)
-  IOVDbConn*           m_conn;         // pointer to corresponding IOVDbConn object (=0 FLMD)
-  std::string m_foldername; // COOL foldername
-  std::string m_key;   // SG key where data is loaded (unique)
-  bool m_multiversion; // is folder multiversion
-  bool m_timestamp;    // is folder indexed by timestamp (else runLB)
-  bool m_tagoverride;  // is tag reset from override (needed for FLMD)
-  bool m_notagoverride;// tag must not be overridden from input file
-  bool m_writemeta;    // is writing to metadata
-  bool m_fromMetaDataOnly; // to be read from metadata only
-  bool m_extensible;   // is this an extensible folder?
-  bool m_named;        // folder has named channels
-  bool m_iovoverridden;// folder has IOV override
-  bool m_jokey;        // folder has non-default key from joboptions
-  bool m_dropped;      // data object was dropped from SG
-  bool m_autocache;    // indicates if cache length was automatically set
-  bool m_checklock;    // indicates if global tags should be checked locked
-  cool::ValidityKey m_iovoverride; // validity key to use
-  IOVDbNamespace::FolderType        m_foldertype; // type of data in folder (enum)
-  const IOVMetaDataContainer* m_metacon; // metadata container (=0 if not FLMD)
-
-  cool::ValidityKey m_cachelength; // length of cache
-  int m_cachehint; // cachehint value (set initial size to Nxchan)
-  int m_cacheinc;  // number of cache increments performed
+  StoreGateSvc*        p_detStore{nullptr};     // pointer to detector store
+  IClassIDSvc*         p_clidSvc{nullptr};      // pointer to CLID service
+  IIOVDbMetaDataTool*  p_metaDataTool{nullptr}; // pointer to metadata tool (writing)
+  IOVDbConn*           m_conn{nullptr};         // pointer to corresponding IOVDbConn object (=0 FLMD)
+  std::string m_foldername;       // COOL foldername
+  std::string m_key;              // SG key where data is loaded (unique)
+  bool m_multiversion{false};     // is folder multiversion
+  bool m_timestamp{false};        // is folder indexed by timestamp (else runLB)
+  bool m_tagoverride{false};      // is tag reset from override (needed for FLMD)
+  bool m_notagoverride{false};    // tag must not be overridden from input file
+  bool m_writemeta{false};        // is writing to metadata
+  bool m_fromMetaDataOnly{false}; // to be read from metadata only
+  bool m_extensible{false};       // is this an extensible folder?
+  bool m_named{false};            // folder has named channels
+  bool m_iovoverridden{false};    // folder has IOV override
+  bool m_jokey{false};            // folder has non-default key from joboptions
+  bool m_dropped{false};          // data object was dropped from SG
+  bool m_autocache{true};         // indicates if cache length was automatically set
+  bool m_checklock{true};         // indicates if global tags should be checked locked
+  cool::ValidityKey m_iovoverride{0};             // validity key to use
+  IOVDbNamespace::FolderType m_foldertype;        // type of data in folder (enum)
+  const IOVMetaDataContainer* m_metacon{nullptr}; // metadata container (=0 if not FLMD)
+
+  cool::ValidityKey m_cachelength{0}; // length of cache
+  int m_cachehint{0};                 // cachehint value (set initial size to Nxchan)
+  int m_cacheinc{0};                  // number of cache increments performed
 
   cool::ChannelSelection m_chansel; // COOL channel selection
   typedef std::pair<cool::ChannelId,cool::ChannelId> ChanRange;
   std::vector<ChanRange> m_chanrange; // explicit list of channel ranges
   // channel range list needed to work around COOL bug 42708 which does not
   // properly select channels in non-contiguous ranges
-  std::string m_jotag; // raw tag found on job options
-  std::string m_tag;   // resolved tag actually used for lookup
-  std::string m_typename; // typename, read from folder description
+  std::string m_jotag;      // raw tag found on job options
+  std::string m_tag;        // resolved tag actually used for lookup
+  std::string m_typename;   // typename, read from folder description
   std::string m_eventstore; // associated event store name
-  std::string m_cachepar; // folder cache parameter read from jobopt/desc
+  std::string m_cachepar;   // folder cache parameter read from jobopt/desc
   std::string m_addrheader; // address header string from folder description
-  CLID m_clid;         // CLID, read from folder description or ClassIDSvc
+  CLID m_clid{0};           // CLID, read from folder description or ClassIDSvc
 
-  unsigned int m_ndbread; // number of times data read from DB
-  unsigned int m_ncacheread; // number of times data read from cache
-  unsigned int m_nobjread; // number of objects read from DB
-  unsigned long long m_nbytesread; // number of bytes read from DB
-  float m_readtime; // time spent reading data from COOL (in loadcache)
+  unsigned int m_ndbread{0};          // number of times data read from DB
+  unsigned int m_ncacheread{0};       // number of times data read from cache
+  unsigned int m_nobjread{0};         // number of objects read from DB
+  unsigned long long m_nbytesread{0}; // number of bytes read from DB
+  float m_readtime{0};                // time spent reading data from COOL (in loadcache)
 
   // channel number and names (latter only filled for 'named' folders)
-  unsigned int m_nchan;
+  unsigned int m_nchan{0};
   std::vector<cool::ChannelId> m_channums;
   std::vector<std::string> m_channames;
 
   // current range and validity flag
-  bool m_retrieved;
+  bool m_retrieved{false};
   IOVRange m_currange;
 
   // COOL data cache and limits
-  coral::AttributeListSpecification* m_cachespec;
+  coral::AttributeListSpecification* m_cachespec{nullptr};
   std::vector<cool::ChannelId> m_cachechan;
   std::vector<coral::AttributeList> m_cacheattr;
   std::vector<unsigned int> m_cacheccstart;
   std::vector<unsigned int> m_cacheccend;
   IOVDbNamespace::IovStore m_iovs;
-  const bool m_outputToFile;
+  const bool m_outputToFile{false};
   const std::string m_source;
 };
 
diff --git a/Database/IOVDbSvc/src/IOVDbResolveTag.cxx b/Database/IOVDbSvc/src/IOVDbResolveTag.cxx
index f0a52397870..a7ffd962cd4 100644
--- a/Database/IOVDbSvc/src/IOVDbResolveTag.cxx
+++ b/Database/IOVDbSvc/src/IOVDbResolveTag.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 // @file IOVDbResolveTag.cxx
 // Implementation for tag resolving function, associating global tag to local folder
@@ -16,7 +16,7 @@ using json = nlohmann::json;
 
 namespace IOVDbNamespace{
   std::string
-  resolveCrestTag(const std::string & globalTagName, const std::string & folderName, const std::string forceTag){
+  resolveCrestTag(const std::string & globalTagName, const std::string & folderName, const std::string & forceTag){
     std::string result{};
     static std::string curlReply{};//preserves state, not very threadsafe
     if (not forceTag.empty()) return forceTag;
@@ -41,4 +41,4 @@ namespace IOVDbNamespace{
   }
 
 
-}
\ No newline at end of file
+}
diff --git a/Database/IOVDbSvc/src/IOVDbResolveTag.h b/Database/IOVDbSvc/src/IOVDbResolveTag.h
index cc4239e3080..1ee4a95ebd8 100644
--- a/Database/IOVDbSvc/src/IOVDbResolveTag.h
+++ b/Database/IOVDbSvc/src/IOVDbResolveTag.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 #ifndef IOVDbSvc_IOVDbResolveTag_h
 #define IOVDbSvc_IOVDbResolveTag_h
@@ -12,7 +12,7 @@
 
 	namespace IOVDbNamespace{
 	std::string
-	resolveCrestTag(const std::string & globalTagName, const std::string & folderName, const std::string forceTag="");
+	resolveCrestTag(const std::string & globalTagName, const std::string & folderName, const std::string & forceTag="");
 	
 	}
-	#endif
\ No newline at end of file
+	#endif
diff --git a/Database/IOVDbSvc/src/Json2Cool.cxx b/Database/IOVDbSvc/src/Json2Cool.cxx
index 259cf80805b..1aa0f0d7076 100644
--- a/Database/IOVDbSvc/src/Json2Cool.cxx
+++ b/Database/IOVDbSvc/src/Json2Cool.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "Json2Cool.h"
@@ -139,7 +139,7 @@ Json2Cool::Json2Cool(std::istream & stream, BasicFolder & b):m_basicFolder(b){
     for (unsigned int i(0);i!=s;++i){
       auto & f=a[i];
       const auto & v = it.value();
-      it++;
+      ++it;
       try{
         auto & att=const_cast<coral::Attribute&>(a.attributeList()[i]);
         if (v.is_null()){
-- 
GitLab