Bug Summary

File:beast/csi/geometry/src/CsiGeometryPar.cc
Warning:line 42, column 5
Attempt to free released memory

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name CsiGeometryPar.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/data/b2soft/buildbot/development/build -fcoverage-compilation-dir=/data/b2soft/buildbot/development/build -resource-dir /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++ -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/x86_64-redhat-linux -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/backward -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/python3.12 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/CLHEP -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/Geant4 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/root -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/belle_legacy -I include/ -D _PACKAGE_="beast" -D G4UI_USE_TCSH -D RaveDllExport= -D HAS_SQLITE -D HAS_CALLGRIND -I include -I /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/libxml2 -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++ -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/x86_64-redhat-linux -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/backward -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-missing-braces -Wno-unused-command-line-argument -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /scan_build/2026-05-31-004316-385593-1 -x c++ beast/csi/geometry/src/CsiGeometryPar.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <geometry/Materials.h>
9#include <framework/gearbox/GearDir.h>
10#include <framework/logging/Logger.h>
11#include <boost/format.hpp>
12#include <boost/lexical_cast.hpp>
13#include <boost/algorithm/string.hpp>
14#include <beast/csi/geometry/CsiGeometryPar.h>
15#include <cmath>
16#include <fstream>
17
18
19using namespace std;
20using namespace Belle2;
21using namespace csi;
22
23CsiGeometryPar* CsiGeometryPar::m_B4CsiGeometryParDB = 0;
24
25CsiGeometryPar* CsiGeometryPar::Instance()
26{
27 if (!m_B4CsiGeometryParDB) m_B4CsiGeometryParDB = new CsiGeometryPar();
28 return m_B4CsiGeometryParDB;
29}
30
31CsiGeometryPar::CsiGeometryPar()
32{
33 clear();
34 read();
35
36 PrintAll();
37}
38
39CsiGeometryPar::~CsiGeometryPar()
40{
41 if (m_B4CsiGeometryParDB
3.1
'm_B4CsiGeometryParDB' is non-null
5.1
'm_B4CsiGeometryParDB' is non-null
7.1
'm_B4CsiGeometryParDB' is non-null
9.1
'm_B4CsiGeometryParDB' is non-null
) {
1
Assuming 'm_B4CsiGeometryParDB' is non-null
2
Taking true branch
4
Taking true branch
6
Taking true branch
8
Taking true branch
10
Taking true branch
42 delete m_B4CsiGeometryParDB;
3
Calling '~CsiGeometryPar'
5
Calling '~CsiGeometryPar'
7
Calling '~CsiGeometryPar'
9
Calling '~CsiGeometryPar'
11
Memory is released
15
Returning from '~CsiGeometryPar'
16
Attempt to free released memory
43 B2INFO("m_B4CsiGeometryParDB deleted ")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "beast")) { { LogVariableStream varStream
; varStream << "m_B4CsiGeometryParDB deleted "; Belle2::
LogSystem::Instance().sendMessage(Belle2::LogMessage(Belle2::
LogConfig::c_Info, std::move(varStream), "beast", __PRETTY_FUNCTION__
, "beast/csi/geometry/src/CsiGeometryPar.cc", 43, 0)); }; } }
while(false)
;
12
Assuming the condition is false
13
Taking false branch
14
Loop condition is false. Exiting loop
44 }
45}
46
47void CsiGeometryPar::clear()
48{
49 m_cellID = 0;
50
51 m_Position.clear();
52 m_Orientation.clear();
53 m_BoxID.clear();
54 m_SlotID.clear();
55 m_thetaID.clear();
56 m_phiID.clear();
57
58}
59
60void CsiGeometryPar::read()
61{
62
63 GearDir content = GearDir("/Detector/DetectorComponent[@name=\"CSI\"]/Content/");
64 string gearPath = "Enclosures/Enclosure";
65 int nEnc = content.getNumberNodes(gearPath);
66
67 int iCell = 0;
68
69 for (int iEnc = 1; iEnc <= nEnc; iEnc++) {
70 // Build the box (same for all)
71 //double length = content.getLength("Enclosures/Length") * CLHEP::cm;
72 //double thk = content.getLength("Enclosures/Thickness") * CLHEP::cm;
73 //double halflength = 15.0 * CLHEP::cm;
74 //double zshift = 0.5 * length - thk - halflength; /*< Shift of the box along z-axis (cry touches panel) **/
75
76 string enclosurePath = (boost::format("/%1%[%2%]") % gearPath % iEnc).str();
77
78 // Connect the appropriate Gearbox path
79 GearDir enclosureContent(content);
80 enclosureContent.append(enclosurePath);
81
82 // Read position
83 double PosZ = enclosureContent.getLength("PosZ") * CLHEP::cm;
84 double PosR = enclosureContent.getLength("PosR") * CLHEP::cm;
85 double PosT = enclosureContent.getAngle("PosT") ;
86
87 // Read Orientation
88 double Phi1 = enclosureContent.getAngle("AngPhi1") ;
89 double Theta = enclosureContent.getAngle("AngTheta") ;
90 double Phi2 = enclosureContent.getAngle("AngPhi2") ;
91
92 //Transform3D zsh = Translate3D(0, 0, zshift);
93 Transform3D m1 = RotateZ3D(Phi1);
94 Transform3D m2 = RotateY3D(Theta);
95 Transform3D m3 = RotateZ3D(Phi2);
96 Transform3D position = Translate3D(PosR * cos(PosT), PosR * sin(PosT), PosZ);
97
98 /** Position of the nominal centre of crystals in the box **/
99 Transform3D Tr = position * m3 * m2 * m1;
100
101 int nSlots = enclosureContent.getNumberNodes("CrystalInSlot");
102 for (int iSlot = 1; iSlot <= nSlots; iSlot++) {
103 iCell++;
104
105 //Thread the strings
106 string slotPath = (boost::format("/Enclosures/Slot[%1%]") % iSlot).str();
107
108 GearDir slotContent(content);
109 slotContent.append(slotPath);
110
111 double SlotX = slotContent.getLength("PosX") * CLHEP::cm;
112 double SlotY = slotContent.getLength("PosY") * CLHEP::cm;
113 double SlotZ = slotContent.getLength("PosZ") * CLHEP::cm;
114 Transform3D Pos = Translate3D(SlotX, SlotY, SlotZ);
115
116 Transform3D CrystalPos = Tr * Pos;
117 RotationMatrix CrystalRot = CrystalPos.getRotation();
118
119 m_Position.push_back(ROOT::Math::XYZVector(CrystalPos.getTranslation()) * 1.0 / CLHEP::cm);
120 m_Orientation.push_back(ROOT::Math::XYZVector(CrystalRot.colZ()));
121
122 m_thetaID.push_back(CrystalPos.getTranslation().z() > 0 ? 0 : 1);
123 m_phiID.push_back(iCell - 9 * m_thetaID.back());
124
125 m_BoxID.push_back(iEnc - 1);
126 m_SlotID.push_back(iSlot - 1);
127 }
128 //
129 }
130}
131
132
133int CsiGeometryPar::CsiVolNameToCellID(const G4String VolumeName)
134{
135 int cellID = 0;
136
137 vector< string > partName;
138 boost::split(partName, VolumeName, boost::is_any_of("_"));
139
140 int iEnclosure = -1;
141 int iCrystal = -1;
142 for (std::vector<string>::iterator it = partName.begin() ; it != partName.end(); ++it) {
143 if (boost::equals(*it, "Enclosure")) iEnclosure = boost::lexical_cast<int>(*(it + 1)) - 1;
144 else if (boost::equals(*it, "Crystal")) iCrystal = boost::lexical_cast<int>(*(it + 1)) - 1;
145 }
146
147 cellID = 3 * iEnclosure + iCrystal;
148
149 if (cellID < 0) B2WARNING("CsiGeometryPar: volume " << VolumeName << " is not a crystal")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Warning, 0, "beast")) { { LogVariableStream varStream
; varStream << "CsiGeometryPar: volume " << VolumeName
<< " is not a crystal"; Belle2::LogSystem::Instance().
sendMessage(Belle2::LogMessage(Belle2::LogConfig::c_Warning, std
::move(varStream), "beast", __PRETTY_FUNCTION__, "beast/csi/geometry/src/CsiGeometryPar.cc"
, 149, 0)); }; } } while(false)
;
150
151 return cellID;
152}
153
154
155G4Material* CsiGeometryPar::GetMaterial(int cid)
156{
157 int iEnclosure = GetEnclosureID(cid) + 1;
158 int iSlot = GetSlotID(cid) + 1;
159
160 GearDir content = GearDir("/Detector/DetectorComponent[@name=\"CSI\"]/Content/");
161
162 GearDir enclosureContent(content);
163 string gearPath = "Enclosures/Enclosure";
164 string enclosurePath = (boost::format("/%1%[%2%]") % gearPath % iEnclosure).str();
165 enclosureContent.append(enclosurePath);
166
167 string slotName = (boost::format("CrystalInSlot[%1%]") % iSlot).str();
168 int iCry = enclosureContent.getInt(slotName);
169
170
171 GearDir crystalContent(content);
172 crystalContent.append((boost::format("/EndCapCrystals/EndCapCrystal[%1%]/") % (iCry)).str());
173 string strMatCrystal = crystalContent.getString("Material", "Air");
174
175 return geometry::Materials::get(strMatCrystal);
176
177}
178
179
180double CsiGeometryPar::GetMaterialProperty(int cid, const char* propertyname)
181{
182 G4Material* mat = GetMaterial(cid);
183 G4MaterialPropertiesTable* properties = mat->GetMaterialPropertiesTable();
184 G4MaterialPropertyVector* property = properties->GetProperty(propertyname);
185
186 return property->Value(0);
187}
188
189void CsiGeometryPar::Print(int cid, int debuglevel)
190{
191 B2DEBUG(debuglevel, "Cell ID : " << cid)do { if (Belle2::LogSystem::debugEnabled()) do { if (Belle2::
LogSystem::Instance().isLevelEnabled(Belle2::LogConfig::c_Debug
, debuglevel, "beast")) { { LogVariableStream varStream; varStream
<< "Cell ID : " << cid; Belle2::LogSystem::Instance
().sendMessage(Belle2::LogMessage(Belle2::LogConfig::c_Debug,
std::move(varStream), "beast", __PRETTY_FUNCTION__, "beast/csi/geometry/src/CsiGeometryPar.cc"
, 191, debuglevel)); }; } } while(false); } while(false)
;
192
193 B2DEBUG(debuglevel, " Position x : " << GetPosition(cid).x())do { if (Belle2::LogSystem::debugEnabled()) do { if (Belle2::
LogSystem::Instance().isLevelEnabled(Belle2::LogConfig::c_Debug
, debuglevel, "beast")) { { LogVariableStream varStream; varStream
<< " Position x : " << GetPosition(cid).x(); Belle2
::LogSystem::Instance().sendMessage(Belle2::LogMessage(Belle2
::LogConfig::c_Debug, std::move(varStream), "beast", __PRETTY_FUNCTION__
, "beast/csi/geometry/src/CsiGeometryPar.cc", 193, debuglevel
)); }; } } while(false); } while(false)
;
194 B2DEBUG(debuglevel, " Position y : " << GetPosition(cid).y())do { if (Belle2::LogSystem::debugEnabled()) do { if (Belle2::
LogSystem::Instance().isLevelEnabled(Belle2::LogConfig::c_Debug
, debuglevel, "beast")) { { LogVariableStream varStream; varStream
<< " Position y : " << GetPosition(cid).y(); Belle2
::LogSystem::Instance().sendMessage(Belle2::LogMessage(Belle2
::LogConfig::c_Debug, std::move(varStream), "beast", __PRETTY_FUNCTION__
, "beast/csi/geometry/src/CsiGeometryPar.cc", 194, debuglevel
)); }; } } while(false); } while(false)
;
195 B2DEBUG(debuglevel, " Position z : " << GetPosition(cid).z())do { if (Belle2::LogSystem::debugEnabled()) do { if (Belle2::
LogSystem::Instance().isLevelEnabled(Belle2::LogConfig::c_Debug
, debuglevel, "beast")) { { LogVariableStream varStream; varStream
<< " Position z : " << GetPosition(cid).z(); Belle2
::LogSystem::Instance().sendMessage(Belle2::LogMessage(Belle2
::LogConfig::c_Debug, std::move(varStream), "beast", __PRETTY_FUNCTION__
, "beast/csi/geometry/src/CsiGeometryPar.cc", 195, debuglevel
)); }; } } while(false); } while(false)
;
196
197 B2DEBUG(debuglevel, " Orientation x : " << GetOrientation(cid).x())do { if (Belle2::LogSystem::debugEnabled()) do { if (Belle2::
LogSystem::Instance().isLevelEnabled(Belle2::LogConfig::c_Debug
, debuglevel, "beast")) { { LogVariableStream varStream; varStream
<< " Orientation x : " << GetOrientation(cid)
.x(); Belle2::LogSystem::Instance().sendMessage(Belle2::LogMessage
(Belle2::LogConfig::c_Debug, std::move(varStream), "beast", __PRETTY_FUNCTION__
, "beast/csi/geometry/src/CsiGeometryPar.cc", 197, debuglevel
)); }; } } while(false); } while(false)
;
198 B2DEBUG(debuglevel, " Orientation y : " << GetOrientation(cid).y())do { if (Belle2::LogSystem::debugEnabled()) do { if (Belle2::
LogSystem::Instance().isLevelEnabled(Belle2::LogConfig::c_Debug
, debuglevel, "beast")) { { LogVariableStream varStream; varStream
<< " Orientation y : " << GetOrientation(cid)
.y(); Belle2::LogSystem::Instance().sendMessage(Belle2::LogMessage
(Belle2::LogConfig::c_Debug, std::move(varStream), "beast", __PRETTY_FUNCTION__
, "beast/csi/geometry/src/CsiGeometryPar.cc", 198, debuglevel
)); }; } } while(false); } while(false)
;
199 B2DEBUG(debuglevel, " Orientation z : " << GetOrientation(cid).z())do { if (Belle2::LogSystem::debugEnabled()) do { if (Belle2::
LogSystem::Instance().isLevelEnabled(Belle2::LogConfig::c_Debug
, debuglevel, "beast")) { { LogVariableStream varStream; varStream
<< " Orientation z : " << GetOrientation(cid)
.z(); Belle2::LogSystem::Instance().sendMessage(Belle2::LogMessage
(Belle2::LogConfig::c_Debug, std::move(varStream), "beast", __PRETTY_FUNCTION__
, "beast/csi/geometry/src/CsiGeometryPar.cc", 199, debuglevel
)); }; } } while(false); } while(false)
;
200
201 B2DEBUG(debuglevel, " Material : " << GetMaterial(cid)->GetName())do { if (Belle2::LogSystem::debugEnabled()) do { if (Belle2::
LogSystem::Instance().isLevelEnabled(Belle2::LogConfig::c_Debug
, debuglevel, "beast")) { { LogVariableStream varStream; varStream
<< " Material : " << GetMaterial(cid)->GetName
(); Belle2::LogSystem::Instance().sendMessage(Belle2::LogMessage
(Belle2::LogConfig::c_Debug, std::move(varStream), "beast", __PRETTY_FUNCTION__
, "beast/csi/geometry/src/CsiGeometryPar.cc", 201, debuglevel
)); }; } } while(false); } while(false)
;
202
203 B2DEBUG(debuglevel, " Slow time constant : " << GetMaterialProperty(cid, "SLOWTIMECONSTANT"))do { if (Belle2::LogSystem::debugEnabled()) do { if (Belle2::
LogSystem::Instance().isLevelEnabled(Belle2::LogConfig::c_Debug
, debuglevel, "beast")) { { LogVariableStream varStream; varStream
<< " Slow time constant : " << GetMaterialProperty
(cid, "SLOWTIMECONSTANT"); Belle2::LogSystem::Instance().sendMessage
(Belle2::LogMessage(Belle2::LogConfig::c_Debug, std::move(varStream
), "beast", __PRETTY_FUNCTION__, "beast/csi/geometry/src/CsiGeometryPar.cc"
, 203, debuglevel)); }; } } while(false); } while(false)
;
204 B2DEBUG(debuglevel, " Fast time constant : " << GetMaterialProperty(cid, "FASTTIMECONSTANT"))do { if (Belle2::LogSystem::debugEnabled()) do { if (Belle2::
LogSystem::Instance().isLevelEnabled(Belle2::LogConfig::c_Debug
, debuglevel, "beast")) { { LogVariableStream varStream; varStream
<< " Fast time constant : " << GetMaterialProperty
(cid, "FASTTIMECONSTANT"); Belle2::LogSystem::Instance().sendMessage
(Belle2::LogMessage(Belle2::LogConfig::c_Debug, std::move(varStream
), "beast", __PRETTY_FUNCTION__, "beast/csi/geometry/src/CsiGeometryPar.cc"
, 204, debuglevel)); }; } } while(false); } while(false)
;
205 B2DEBUG(debuglevel, " Light yield : " << GetMaterialProperty(cid, "SCINTILLATIONYIELD"))do { if (Belle2::LogSystem::debugEnabled()) do { if (Belle2::
LogSystem::Instance().isLevelEnabled(Belle2::LogConfig::c_Debug
, debuglevel, "beast")) { { LogVariableStream varStream; varStream
<< " Light yield : " << GetMaterialProperty(cid
, "SCINTILLATIONYIELD"); Belle2::LogSystem::Instance().sendMessage
(Belle2::LogMessage(Belle2::LogConfig::c_Debug, std::move(varStream
), "beast", __PRETTY_FUNCTION__, "beast/csi/geometry/src/CsiGeometryPar.cc"
, 205, debuglevel)); }; } } while(false); } while(false)
;
206
207 //GetMaterial(cid)->GetMaterialPropertiesTable()->DumpTable();
208}
209
210void CsiGeometryPar::PrintAll(int debuglevel)
211{
212 for (uint i = 0; i < m_thetaID.size(); i++)
213 Print(i, debuglevel);
214}