Skip to content

Commit

Permalink
The battle agains coverity
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusFrankATcernch committed May 21, 2024
1 parent 29c85be commit 169fc4f
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 71 deletions.
6 changes: 4 additions & 2 deletions DDCAD/src/plugins/CADPlugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ static dd4hep::Handle<TObject> create_CAD_Assembly(dd4hep::Detector& dsc, xml_h
"understandable tessellated volumes.", fname.c_str());
}
dd4hep::Assembly assembly("assembly");
for(std::size_t i=0; i < volumes.size(); ++i)
assembly.placeVolume(volumes[i].release());
for(std::size_t i=0; i < volumes.size(); ++i) {
dd4hep::Volume vol(volumes[i].release());
assembly.placeVolume(vol);
}

if ( elt.hasAttr(_U(name)) ) assembly->SetName(elt.attr<std::string>(_U(name)).c_str());
return assembly;
Expand Down
6 changes: 3 additions & 3 deletions DDCore/include/DD4hep/detail/AlignmentsInterna.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#define DD4HEP_DETAIL_ALIGNMENTSINTERNA_H

// Framework include files
#include "DD4hep/IOV.h"
#include "DD4hep/Alignments.h"
#include "DD4hep/detail/ConditionsInterna.h"
#include <DD4hep/IOV.h>
#include <DD4hep/Alignments.h>
#include <DD4hep/detail/ConditionsInterna.h>

// C/C++ include files
#include <map>
Expand Down
8 changes: 4 additions & 4 deletions DDCore/include/DD4hep/detail/ConditionsInterna.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#define DD4HEP_DETAIL_CONDITIONSINTERNA_H

// Framework include files
#include "DD4hep/DetElement.h"
#include "DD4hep/Conditions.h"
#include "DD4hep/Grammar.h"
#include "DD4hep/NamedObject.h"
#include <DD4hep/DetElement.h>
#include <DD4hep/Conditions.h>
#include <DD4hep/Grammar.h>
#include <DD4hep/NamedObject.h>

// C/C++ include files
#include <map>
Expand Down
2 changes: 1 addition & 1 deletion DDCore/include/DD4hep/detail/ContainerHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define DD4HEP_DETAIL_CONTAINERHELPERS_H

// Framework include files
#include "DD4hep/Primitives.h"
#include <DD4hep/Primitives.h>

// C/C++ include files
#include <map>
Expand Down
20 changes: 10 additions & 10 deletions DDCore/include/DD4hep/detail/DetectorInterna.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
#define DD4HEP_DETAIL_DETECTORINTERNA_H

// Framework include files
#include "DD4hep/Callback.h"
#include "DD4hep/NamedObject.h"
#include "DD4hep/World.h"
#include "DD4hep/Objects.h"
#include "DD4hep/DetElement.h"
#include "DD4hep/Alignments.h"
#include "DD4hep/Conditions.h"
#include "DD4hep/Segmentations.h"
#include "DD4hep/ObjectExtensions.h"
#include <DD4hep/Callback.h>
#include <DD4hep/NamedObject.h>
#include <DD4hep/World.h>
#include <DD4hep/Objects.h>
#include <DD4hep/DetElement.h>
#include <DD4hep/Alignments.h>
#include <DD4hep/Conditions.h>
#include <DD4hep/Segmentations.h>
#include <DD4hep/ObjectExtensions.h>

// ROOT include files
#include "TGeoMatrix.h"
#include <TGeoMatrix.h>

/// Namespace for the AIDA detector description toolkit
namespace dd4hep {
Expand Down
10 changes: 5 additions & 5 deletions DDCore/include/DD4hep/detail/ObjectsInterna.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#define DD4HEP_DETAIL_OBJECTSINTERNA_H

// Framework include files
#include "DD4hep/Volumes.h"
#include "DD4hep/NamedObject.h"
#include "DD4hep/IDDescriptor.h"
#include "DD4hep/Segmentations.h"
#include "DD4hep/BitFieldCoder.h"
#include <DD4hep/Volumes.h>
#include <DD4hep/NamedObject.h>
#include <DD4hep/IDDescriptor.h>
#include <DD4hep/Segmentations.h>
#include <DD4hep/BitFieldCoder.h>

// C/C++ include files
#include <set>
Expand Down
8 changes: 4 additions & 4 deletions DDCore/include/DD4hep/detail/Plugins.inl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
#define Reflex_CollectionProxy 1
#endif

#include "DD4hep/Printout.h"
#include "Reflex/PluginService.h"
#include "Reflex/Reflex.h"
#include "Reflex/Builder/ReflexBuilder.h"
#include <DD4hep/Printout.h>
#include <Reflex/PluginService.h>
#include <Reflex/Reflex.h>
#include <Reflex/Builder/ReflexBuilder.h>

/// The dd4hep namespace declaration
namespace dd4hep {
Expand Down
6 changes: 3 additions & 3 deletions DDCore/include/DD4hep/detail/SegmentationsInterna.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#define DD4HEP_DETAIL_SEGMENTATIONSINTERNA_H

// Framework include files
#include "DD4hep/Handle.h"
#include "DD4hep/Objects.h"
#include "DD4hep/BitFieldCoder.h"
#include <DD4hep/Handle.h>
#include <DD4hep/Objects.h>
#include <DD4hep/BitFieldCoder.h>

// C/C++ include files

Expand Down
2 changes: 1 addition & 1 deletion DDCore/include/DD4hep/detail/ShapesInterna.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define DD4HEP_DETAIL_SHAPESINTERNA_H

// Framework include files
#include "DD4hep/Shapes.h"
#include <DD4hep/Shapes.h>

/// Namespace for the AIDA detector description toolkit
namespace dd4hep {
Expand Down
10 changes: 5 additions & 5 deletions DDCore/include/DD4hep/detail/VolumeManagerInterna.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
#define DD4HEP_DETAIL_VOLUMEMANAGERINTERNA_H

// Framework include files
#include "DD4hep/Volumes.h"
#include "DD4hep/DetElement.h"
#include "DD4hep/IDDescriptor.h"
#include "DD4hep/VolumeManager.h"
#include <DD4hep/Volumes.h>
#include <DD4hep/DetElement.h>
#include <DD4hep/IDDescriptor.h>
#include <DD4hep/VolumeManager.h>

// ROOT include files
#include "TGeoMatrix.h"
#include <TGeoMatrix.h>

/// Namespace for the AIDA detector description toolkit
namespace dd4hep {
Expand Down
3 changes: 2 additions & 1 deletion DDCore/src/DetElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <DD4hep/AlignmentTools.h>
#include <DD4hep/DetectorTools.h>
#include <DD4hep/Printout.h>
#include <DD4hep/World.h>
#include <DD4hep/Detector.h>
#include <DD4hep/World.h>

using namespace dd4hep;

Expand Down Expand Up @@ -104,6 +104,7 @@ DetElement& DetElement::setType(const std::string& typ) {
return *this;
}

/// Access the type of the sensitive detector
unsigned int DetElement::typeFlag() const {
return m_element ? m_element->typeFlag : 0 ;
}
Expand Down
4 changes: 2 additions & 2 deletions DDCore/src/XML/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ dd4hep::Solid dd4hep::xml::createShape(Detector& description,
/// Create a volume using the plugin mechanism from the attributes of the XML element
dd4hep::Volume dd4hep::xml::createStdVolume(Detector& description, xml::Element element) {
Volume vol;
int dbg = 1;
xml_dim_t elt(element);
std::string typ, tag = elt.tag();
PrintLevel lvl = dbg ? ALWAYS : DEBUG;
PrintLevel lvl = ALWAYS;
//PrintLevel lvl = DEBUG;

printout(lvl, "xml::createStdVolume", "++ Processing tag: %-12s", tag.c_str());
if ( elt.hasAttr(_U(material)) ) {
Expand Down
56 changes: 52 additions & 4 deletions DDDigi/include/DDDigi/DigiAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@

// Framework include files
#include <DD4hep/Printout.h>
#include <DD4hep/ObjectExtensions.h>
#include <DD4hep/ComponentProperties.h>
#include <DDDigi/DigiContext.h>

// C/C++ include files
#include <string>
#include <memory>
#include <cstdarg>
#include <cstdint>

#if defined(G__ROOT) || defined(__CLING__) || defined(__ROOTCLING__)
#define DDDIGI_DEFINE_ACTION_DEFAULT_CTOR(action) public: action() = default;
Expand All @@ -44,6 +47,9 @@
/// Namespace for the AIDA detector description toolkit
namespace dd4hep {

/// Forward declarations
class ExtensionEntry;

/// Namespace for the Digitization part of the AIDA detector description toolkit
namespace digi {

Expand Down Expand Up @@ -89,10 +95,38 @@ namespace dd4hep {
friend class DigiKernel;

public:
using context_t = DigiContext;
using kernel_t = DigiKernel;
using context_t = DigiContext;
using kernel_t = DigiKernel;
using extensions_t = std::map<uint64_t, std::unique_ptr<ExtensionEntry> >;

protected:
template <typename T> struct Extension : public ExtensionEntry {
T* ptr = 0;

/// Inhibit default constructor
Extension() = delete;
/// Typed objects constructor
Extension(T* p) : ptr(p) { }
/// Copy constructor
Extension(const Extension& copy) = delete;
/// Assignment operator
Extension& operator=(const Extension& copy) = delete;
/// Copy constructor
Extension(Extension&& copy) = delete;
/// Assignment operator
Extension& operator=(Extension&& copy) = delete;
/// Default destructor
virtual ~Extension() = default;
/// Wrapper for the object destruction
virtual void* object() const override { return ptr; }
/// Wrapper for the object destruction
virtual void destruct() const override { delete ptr; }
virtual void* copy(void*) const override { return nullptr; }
virtual ExtensionEntry* clone(void*) const override { return nullptr; }
virtual unsigned long long int hash64() const override { return uint64_t(ptr); }
};


/// Reference to the Digi context
#if defined(G__ROOT) || defined(__CLING__) || defined(__ROOTCLING__)
const kernel_t* m_kernel;
Expand All @@ -110,12 +144,14 @@ namespace dd4hep {
std::string m_name;
/// Property pool
PropertyManager m_properties;
///
std::vector<void*> m_opt_properties;
/// Object extensions if used
extensions_t m_extensions;
/// Reference count. Initial value: 1
long m_refCount = 1;
/// Default property: Output level
int m_outputLevel = 3;
///
std::vector<void*> m_opt_properties;

protected:
/// Define standard assignments and constructors
Expand Down Expand Up @@ -182,6 +218,18 @@ namespace dd4hep {
/// Adopt named tool to delegate actions
virtual void adopt_tool(DigiAction* action, const std::string& typ);

/// Add an extension object to the detector element
uint64_t addExtension(uint64_t key, std::unique_ptr<ExtensionEntry>&& e);

/// Access an existing extension object from the detector element
void* extension(uint64_t key);

/// Extend the detector element with an arbitrary structure accessible by the type
template <typename T> uint64_t addExtension(T* c) {
std::unique_ptr<ExtensionEntry> e = std::make_unique<Extension<T> >(c);
return this->addExtension(uint64_t(c), std::move(e));
}

/** Support for output messages */
/// Support for messages with variable output level using output level
void print(const char* fmt, ...) const;
Expand Down
1 change: 1 addition & 0 deletions DDDigi/plugins/DigiDepositDropKilled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace dd4hep {
m->remove(iter);
iter = (last_cell != ~0x0ULL) ? m->data.find(last_cell) : m->begin();
if ( iter == m->end() ) iter = m->begin();
if ( iter == m->end() ) break;
continue;
}
last_cell = iter->first;
Expand Down
33 changes: 25 additions & 8 deletions DDDigi/src/DigiAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ DigiAction::DigiAction(const DigiKernel& krnl, const std::string& nam)

/// Default destructor
DigiAction::~DigiAction() {
for(auto* ptr : m_opt_properties)
::operator delete(ptr);
for( auto& ptr : m_extensions )
ptr.second->destruct();
m_extensions.clear();
m_opt_properties.clear();
InstanceCount::decrement(this);
}
Expand Down Expand Up @@ -116,6 +117,21 @@ const dd4hep::Property& DigiAction::property(const std::string& nam) const {
return properties()[nam];
}

/// Add an extension object to the detector element
uint64_t DigiAction::addExtension(uint64_t key, std::unique_ptr<ExtensionEntry>&& e) {
if ( m_extensions.emplace(key, std::move(e)).second )
return key;
return 0UL;
}

/// Access an existing extension object from the detector element
void* DigiAction::extension(uint64_t key) {
auto iter = m_extensions.find(key);
if ( iter != m_extensions.end() )
return iter->second.get();
return nullptr;
}

/// Support of debug messages.
std::string DigiAction::format(const char* fmt, ...) const {
va_list args;
Expand Down Expand Up @@ -227,21 +243,22 @@ namespace dd4hep {
int add_action_property(DigiAction* action, const std::string& name, VAL value) {
VAL* new_val = new VAL(value);
action->addProperty(name, *(new_val));
action->addExtension(new_val);
printout(INFO, "addProperty", "+++ Added property %s of type %s",
name.c_str(), typeName(typeid(VAL)).c_str());
return 1;
}

#define ADD_SINGLE_PROPERTY(X) \
#define ADD_SINGLE_PROPERTY(X) \
template int add_action_property<X>(DigiAction* action, const std::string& name, X value);

#define ADD_MAPPED_PROPERTY(K,X) \
#define ADD_MAPPED_PROPERTY(K,X) \
template int add_action_property<std::map<std::string,X> >(DigiAction* action, const std::string& name, std::map<K,X> value);

#define ADD_PROPERTY(X) \
ADD_SINGLE_PROPERTY(X) \
ADD_SINGLE_PROPERTY(std::set<X>) \
ADD_SINGLE_PROPERTY(std::list<X>) \
#define ADD_PROPERTY(X) \
ADD_SINGLE_PROPERTY(X) \
ADD_SINGLE_PROPERTY(std::set<X>) \
ADD_SINGLE_PROPERTY(std::list<X>) \
ADD_SINGLE_PROPERTY(std::vector<X>) \
ADD_MAPPED_PROPERTY(std::string,X)

Expand Down
2 changes: 1 addition & 1 deletion DDDigi/src/DigiStoreDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ DigiStoreDump::dump_history(DigiContext& context,
std::vector<std::string> records;

str << Key::key_name(container_key) << "[" << seq_no << "]:";
line = format("+----- %-30s Container: Segment:%04X Mask:%04X Item:%08X Cell:%016X Hist: Hits:%ld Parts:%ld",
line = format("+----- %-30s Container: Segment:%04X Mask:%04X Item:%08X Cell:%016lX History: Hits:%ld Parts:%ld",
str.str().c_str(), container_key.segment(), container_key.mask(), container_key.item(),
cell, item.history.hits.size(), item.history.particles.size());
records.emplace_back(line);
Expand Down
12 changes: 6 additions & 6 deletions DDG4/plugins/Geant4GDMLWriteAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ void Geant4GDMLWriteAction::writeGDML() {
error("+++ No GDML file name given. Please set the output file (property Output)");
return;
}
if ( 0 == ::stat(fname.c_str(), &buff) ) {
if ( !m_overWrite ) {
error("+++ GDML file %s elready exists. Please set another output file (property Output)",
fname.c_str());
return;
}
if ( (0 == ::stat(fname.c_str(), &buff)) && !m_overWrite ) {
error("+++ GDML file %s elready exists. Please set another output file (property Output)",
fname.c_str());
return;
}
else if ( 0 == ::stat(fname.c_str(), &buff) ) {
warning("+++ GDML file %s already exists. Overwriting existing file.", fname.c_str());
::unlink(fname.c_str());
}
Expand Down
Loading

0 comments on commit 169fc4f

Please sign in to comment.