Bug Summary

File:generators/phokhara/phokhara/eemmg-lib/src/pointer.h
Warning:line 25, column 28
Use of memory after it is freed

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 cache.cpp -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_="generators" -D G4UI_USE_TCSH -D RaveDllExport= -D HAS_SQLITE -D HAS_CALLGRIND -D HAVE_CONFIG_H -I generators/phokhara/phokhara/eemmg-lib/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++ generators/phokhara/phokhara/eemmg-lib/src/cache.cpp

generators/phokhara/phokhara/eemmg-lib/src/cache.cpp

1/*
2 * cache.h - cache classes
3 *
4 * this file is part of PJFry library
5 * Copyright 2011 Valery Yundin
6 */
7
8#include "cache.h"
9#include "integral.h"
10
11/* ------------------------------------------------------------
12 * ------------------------------------------------------------
13 * ICache section
14 * ------------------------------------------------------------
15 * ------------------------------------------------------------
16*/
17
18double ICache::mu2=1;
19
20double ICache::getMu2()
21{
22 return mu2;
23}
24
25double ICache::setMu2(const double newmu2)
26{
27 if (newmu2 > 0 && newmu2 != mu2) {
28 MinorBase::Rescale(newmu2/mu2);
29 mu2=newmu2;
30#ifdef USE_ONELOOP
31 double mu=sqrt(mu2);
32 F77_FUNC_(avh_olo_mu_set,AVH_OLO_MU_SET)avh_olo_mu_set_(&mu);
33#endif
34 ICache::Clear();
35 MCache::Clear();
36 }
37 return mu2;
38}
39
40void ICache::Clear()
41{
42 ClearCC();
43 ClearIC();
44}
45
46/* clear coefficient cache */
47void ICache::ClearCC()
48{
49 ic5[0].reset();
50 ic5[1].reset();
51 ic4[0].reset();
52 ic4[1].reset();
53 ic3[0].reset();
54 ic3[1].reset();
55 ic2[0].reset();
56 ic2[1].reset();
57}
58
59/* clear scalar integral cache */
60void ICache::ClearIC()
61{
62 ics4.reset();
63 ics3.reset();
64 ics2.reset();
65 ics1.reset();
66}
67
68/* clear minor cache */
69void MCache::Clear()
70{
71 cm5.reset();
72 cm4.reset();
73 cm3.reset();
74 cm2.reset();
75}
76
77// const double ICache::sNan=std::numeric_limits<double>::signaling_NaN();
78// const int64_t ICache::sNAN=0x7ffc0000BA13BA13LL;
79// const double ICache::sNAN.d64=reinterpret_cast<const double&>(sNAN); // Bad because breaks strict aliasing
80// const double ICache::sNAN.d64=((const ICache::ID64&)sNAN).dbl;
81
82const ICache::ID64 ICache::sNAN={ 0x7ffc0000BA13BA13LL };
83
84ICache::Array5 ICache::ic5[3];
85ICache::Array4 ICache::ic4[3];
86ICache::Array3 ICache::ic3[3];
87ICache::Array2 ICache::ic2[3];
88
89ICache::ArrayS4 ICache::ics4;
90ICache::ArrayS3 ICache::ics3;
91ICache::ArrayS2 ICache::ics2;
92ICache::ArrayS1 ICache::ics1;
93
94/* ===========================================================
95 *
96 * PENTAGON: 5 point coefficients
97 *
98 * ===========================================================
99 */
100
101/* --------------------------------------------------------
102 Rank-5 PENTAGON
103 * --------------------------------------------------------
104 */
105ncomplex ICache::getE(int ep, int i, int j, int k, int l, int m, const Kinem5 &kin)
106{
107#ifdef USE_CACHE_HIGH"1"
108 assert( (i==0 && j==0 && ( (k==0 && l==0 && m!=0) || (k!=0 && l!=0 && m!=0) ))(static_cast <bool> ((i==0 && j==0 && (
(k==0 && l==0 && m!=0) || (k!=0 && l
!=0 && m!=0) )) || (i!=0 && j!=0 && k
!=0 && l!=0 && m!=0)) ? void (0) : __assert_fail
("(i==0 && j==0 && ( (k==0 && l==0 && m!=0) || (k!=0 && l!=0 && m!=0) )) || (i!=0 && j!=0 && k!=0 && l!=0 && m!=0)"
, "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp", 109
, __extension__ __PRETTY_FUNCTION__))
109 || (i!=0 && j!=0 && k!=0 && l!=0 && m!=0) )(static_cast <bool> ((i==0 && j==0 && (
(k==0 && l==0 && m!=0) || (k!=0 && l
!=0 && m!=0) )) || (i!=0 && j!=0 && k
!=0 && l!=0 && m!=0)) ? void (0) : __assert_fail
("(i==0 && j==0 && ( (k==0 && l==0 && m!=0) || (k!=0 && l!=0 && m!=0) )) || (i!=0 && j!=0 && k!=0 && l!=0 && m!=0)"
, "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp", 109
, __extension__ __PRETTY_FUNCTION__))
;
110 int coefn=0;
111 if (i==0 && j==0) {
112 if (k==0 && l==0)
113 coefn=(m-1)+ee00001;
114 else
115 coefn=Minor5::is(k-1,l-1,m-1)+ee00111;
116 }
117 else {
118 coefn=Minor5::iss(i-1,j-1,k-1,l-1,m-1)+ee11111;
119 }
120 Save5 *s5=getS5(ep, kin, coefn);
121
122 ncomplex ivalue=(*s5)[coefn];
123 if (ivalue.real() == sNAN) {
124 ivalue=MCache::getMinor5(kin)->evalE(ep, i, j, k, l, m);
125 (*s5)[coefn]=ivalue;
126 }
127#else
128 ncomplex ivalue=MCache::getMinor5(kin)->evalE(ep, i, j, k, l, m);
129#endif /* USE_CACHE_HIGH */
130 return ivalue;
131}
132
133/* --------------------------------------------------------
134 Rank-4 PENTAGON
135 * --------------------------------------------------------
136 */
137ncomplex ICache::getE(int ep, int i, int j, int k, int l, const Kinem5 &kin)
138{
139#ifdef USE_CACHE_HIGH"1"
140 assert( (i==0 && j==0 && ( (k==0 && l==0) || (k!=0 && l!=0) )) || (i!=0 && j!=0 && k!=0 && l!=0) )(static_cast <bool> ((i==0 && j==0 && (
(k==0 && l==0) || (k!=0 && l!=0) )) || (i!=0
&& j!=0 && k!=0 && l!=0)) ? void (0)
: __assert_fail ("(i==0 && j==0 && ( (k==0 && l==0) || (k!=0 && l!=0) )) || (i!=0 && j!=0 && k!=0 && l!=0)"
, "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp", 140
, __extension__ __PRETTY_FUNCTION__))
;
141 int coefn=0;
142 if (i==0 && j==0) {
143 if (k==0 && l==0)
144 coefn=ee0000;
145 else
146 coefn=Minor5::is(k-1,l-1)+ee0011;
147 }
148 else {
149 coefn=Minor5::is(i-1,j-1,k-1,l-1)+ee1111;
150 }
151 Save5 *s5=getS5(ep, kin, coefn);
152
153 ncomplex ivalue=(*s5)[coefn];
154 if (ivalue.real() == sNAN) {
155 ivalue=MCache::getMinor5(kin)->evalE(ep, i, j, k, l);
156 (*s5)[coefn]=ivalue;
157 }
158#else
159 ncomplex ivalue=MCache::getMinor5(kin)->evalE(ep, i, j, k, l);
160#endif /* USE_CACHE_HIGH */
161 return ivalue;
162}
163
164/* --------------------------------------------------------
165 Rank-3 PENTAGON
166 * --------------------------------------------------------
167 */
168ncomplex ICache::getE(int ep, int i, int j, int k, const Kinem5 &kin)
169{
170#ifdef USE_CACHE_HIGH"1"
171 assert( (i==0 && j==0 && k!=0) || (i!=0 && j!=0 && k!=0) )(static_cast <bool> ((i==0 && j==0 && k
!=0) || (i!=0 && j!=0 && k!=0)) ? void (0) : __assert_fail
("(i==0 && j==0 && k!=0) || (i!=0 && j!=0 && k!=0)"
, "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp", 171
, __extension__ __PRETTY_FUNCTION__))
;
172 int coefn=(i==0 && j==0) ? (k-1)+ee001 : Minor5::is(i-1,j-1,k-1)+ee111;
173 Save5 *s5=getS5(ep, kin, coefn);
174
175 ncomplex ivalue=(*s5)[coefn];
176 if (ivalue.real() == sNAN) {
177 ivalue=MCache::getMinor5(kin)->evalE(ep, i, j, k);
178 (*s5)[coefn]=ivalue;
179 }
180#else
181 ncomplex ivalue=MCache::getMinor5(kin)->evalE(ep, i, j, k);
182#endif /* USE_CACHE_HIGH */
183 return ivalue;
184}
185
186/* --------------------------------------------------------
187 Rank-2 PENTAGON
188 * --------------------------------------------------------
189 */
190ncomplex ICache::getE(int ep, int i, int j, const Kinem5 &kin)
191{
192#ifdef USE_CACHE_HIGH"1"
193 assert( (i==0 && j==0) || (i!=0 && j!=0) )(static_cast <bool> ((i==0 && j==0) || (i!=0 &&
j!=0)) ? void (0) : __assert_fail ("(i==0 && j==0) || (i!=0 && j!=0)"
, "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp", 193
, __extension__ __PRETTY_FUNCTION__))
;
194 int coefn=(i==0 && j==0) ? ee00 : Minor5::is(i-1,j-1)+ee11;
195 Save5 *s5=getS5(ep, kin, coefn);
196
197 ncomplex ivalue=(*s5)[coefn];
198 if (ivalue.real() == sNAN) {
199 ivalue=MCache::getMinor5(kin)->evalE(ep, i, j);
200 (*s5)[coefn]=ivalue;
201 }
202#else
203 ncomplex ivalue=MCache::getMinor5(kin)->evalE(ep, i, j);
204#endif /* USE_CACHE_HIGH */
205 return ivalue;
206}
207
208/* --------------------------------------------------------
209 Rank-1 PENTAGON
210 * --------------------------------------------------------
211 */
212ncomplex ICache::getE(int ep, int i, const Kinem5 &kin)
213{
214#ifdef USE_CACHE_HIGH"1"
215 int coefn=(i-1)+ee1;
216 Save5 *s5=getS5(ep, kin, coefn);
217
218 ncomplex ivalue=(*s5)[coefn];
219 if (ivalue.real() == sNAN) {
220 ivalue=MCache::getMinor5(kin)->evalE(ep, i);
221 (*s5)[coefn]=ivalue;
222 }
223#else
224 ncomplex ivalue=MCache::getMinor5(kin)->evalE(ep, i);
225#endif /* USE_CACHE_HIGH */
226 return ivalue;
227}
228
229/* --------------------------------------------------------
230 Rank-0 PENTAGON
231 * --------------------------------------------------------
232 */
233ncomplex ICache::getE(int ep, const Kinem5 &kin)
234{
235#ifdef USE_CACHE_HIGH"1"
236 int coefn=ee0;
237 Save5 *s5=getS5(ep, kin, coefn);
238
239 ncomplex ivalue=(*s5)[coefn];
240 if (ivalue.real() == sNAN) {
241 ivalue=MCache::getMinor5(kin)->evalE(ep);
242 (*s5)[coefn]=ivalue;
243 }
244#else
245 ncomplex ivalue=MCache::getMinor5(kin)->evalE(ep);
246#endif /* USE_CACHE_HIGH */
247 return ivalue;
248}
249
250/* ===========================================================
251 *
252 * BOX: 4 point coefficients
253 *
254 * ===========================================================
255 */
256
257/* --------------------------------------------------------
258 Rank-4 BOX
259 * --------------------------------------------------------
260 */
261ncomplex ICache::getD(int ep, int i, int j, int k, int l, const Kinem4 &kin)
262{
263#ifdef USE_CACHE_LOW
264 assert( (i==0 && j==0 && ( (k==0 && l==0) || (k!=0 && l!=0) )) || (i!=0 && j!=0 && k!=0 && l!=0) )(static_cast <bool> ((i==0 && j==0 && (
(k==0 && l==0) || (k!=0 && l!=0) )) || (i!=0
&& j!=0 && k!=0 && l!=0)) ? void (0)
: __assert_fail ("(i==0 && j==0 && ( (k==0 && l==0) || (k!=0 && l!=0) )) || (i!=0 && j!=0 && k!=0 && l!=0)"
, "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp", 264
, __extension__ __PRETTY_FUNCTION__))
;
265 int coefn=0;
266 if (i==0 && j==0) {
267 if (k==0 && l==0)
268 coefn=dd0000;
269 else
270 coefn=Minor4::is(k-1,l-1)+dd0011;
271 }
272 else {
273 coefn=Minor5::is(i-1,j-1,k-1,l-1)+dd1111;
274 }
275 Save4 *s4=getS4(ep, kin, coefn);
276
277 ncomplex ivalue=(*s4)[coefn];
278 if (ivalue.real() == sNAN) {
279 ivalue=MCache::getMinor4(kin)->evalD(ep, i, j, k, l);
280 (*s4)[coefn]=ivalue;
281 }
282#else
283 ncomplex ivalue=MCache::getMinor4(kin)->evalD(ep, i, j, k, l);
284#endif /* USE_CACHE_LOW */
285 return ivalue;
286}
287
288/* --------------------------------------------------------
289 Rank-3 BOX
290 * --------------------------------------------------------
291 */
292ncomplex ICache::getD(int ep, int i, int j, int k, const Kinem4 &kin)
293{
294#ifdef USE_CACHE_LOW
295 assert( (i==0 && j==0 && k!=0) || (i!=0 && j!=0 && k!=0) )(static_cast <bool> ((i==0 && j==0 && k
!=0) || (i!=0 && j!=0 && k!=0)) ? void (0) : __assert_fail
("(i==0 && j==0 && k!=0) || (i!=0 && j!=0 && k!=0)"
, "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp", 295
, __extension__ __PRETTY_FUNCTION__))
;
296 int coefn=(i==0 && j==0) ? (k-1)+dd001 : Minor4::is(i-1,j-1,k-1)+dd111;
297 Save4 *s4=getS4(ep, kin, coefn);
298
299 ncomplex ivalue=(*s4)[coefn];
300 if (ivalue.real() == sNAN) {
301 ivalue=MCache::getMinor4(kin)->evalD(ep, i, j, k);
302 (*s4)[coefn]=ivalue;
303 }
304#else
305 ncomplex ivalue=MCache::getMinor4(kin)->evalD(ep, i, j, k);
306#endif /* USE_CACHE_LOW */
307 return ivalue;
308}
309
310/* --------------------------------------------------------
311 Rank-2 BOX
312 * --------------------------------------------------------
313 */
314ncomplex ICache::getD(int ep, int i, int j, const Kinem4 &kin)
315{
316#ifdef USE_CACHE_LOW
317 assert( (i==0 && j==0) || (i!=0 && j!=0) )(static_cast <bool> ((i==0 && j==0) || (i!=0 &&
j!=0)) ? void (0) : __assert_fail ("(i==0 && j==0) || (i!=0 && j!=0)"
, "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp", 317
, __extension__ __PRETTY_FUNCTION__))
;
318 int coefn=(i==0 && j==0) ? dd00 : Minor4::is(i-1,j-1)+dd11;
319 Save4 *s4=getS4(ep, kin, coefn);
320
321 ncomplex ivalue=(*s4)[coefn];
322 if (ivalue.real() == sNAN) {
323 ivalue=MCache::getMinor4(kin)->evalD(ep, i, j);
324 (*s4)[coefn]=ivalue;
325 }
326#else
327 ncomplex ivalue=MCache::getMinor4(kin)->evalD(ep, i, j);
328#endif /* USE_CACHE_LOW */
329 return ivalue;
330}
331
332/* --------------------------------------------------------
333 Rank-1 BOX
334 * --------------------------------------------------------
335 */
336ncomplex ICache::getD(int ep, int i, const Kinem4 &kin)
337{
338#ifdef USE_CACHE_LOW
339 int coefn=(i-1)+dd1;
340 Save4 *s4=getS4(ep, kin, coefn);
341
342 ncomplex ivalue=(*s4)[coefn];
343 if (ivalue.real() == sNAN) {
344 ivalue=MCache::getMinor4(kin)->evalD(ep, i);
345 (*s4)[coefn]=ivalue;
346 }
347#else
348 ncomplex ivalue=MCache::getMinor4(kin)->evalD(ep, i);
1
Calling 'MCache::getMinor4'
17
Returning; memory was released
18
Calling 'SPtr::operator->'
349#endif /* USE_CACHE_LOW */
350 return ivalue;
351}
352
353/* ===========================================================
354 *
355 * TRIANGLE: 3 point coefficients
356 *
357 * ===========================================================
358 */
359
360
361/* --------------------------------------------------------
362 Rank-3 TRIANGLE
363 * --------------------------------------------------------
364 */
365ncomplex ICache::getC(int ep, int i, int j, int k, const Kinem3 &kin)
366{
367#ifdef USE_CACHE_LOW
368 assert( (i==0 && j==0 && k!=0) || (i!=0 && j!=0 && k!=0) )(static_cast <bool> ((i==0 && j==0 && k
!=0) || (i!=0 && j!=0 && k!=0)) ? void (0) : __assert_fail
("(i==0 && j==0 && k!=0) || (i!=0 && j!=0 && k!=0)"
, "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp", 368
, __extension__ __PRETTY_FUNCTION__))
;
369 int coefn=(i==0 && j==0) ? (k-1)+cc001 : Minor3::is(i-1,j-1,k-1)+cc111;
370 Save3 *s3=getS3(ep, kin, coefn);
371
372 ncomplex ivalue=(*s3)[coefn];
373 Minor3::Ptr pm3;
374 if (ivalue.real() == sNAN && (pm3=MCache::getMinor3(kin))!=0) {
375 ivalue=pm3->evalC(ep, i, j, k);
376 (*s3)[coefn]=ivalue;
377 }
378#else
379 Minor3::Ptr pm3=MCache::getMinor3(kin);
380 ncomplex ivalue= ( pm3!=0 ? pm3->evalC(ep, i, j, k) : sNAN.d64 );
381#endif /* USE_CACHE_LOW */
382#ifndef NDEBUG
383 if (pm3==0) printf("C%d%d%d(%.18e,%.18e,%.18e,%e,%e,%e)=%f\n",i,j,k,kin.p1(),kin.p2(),kin.p3(),kin.m1(),kin.m2(),kin.m3(),ivalue.real());
384#endif
385 return ivalue;
386}
387
388/* --------------------------------------------------------
389 Rank-2 TRIANGLE
390 * --------------------------------------------------------
391 */
392ncomplex ICache::getC(int ep, int i, int j, const Kinem3 &kin)
393{
394#ifdef USE_CACHE_LOW
395 assert( (i==0 && j==0) || (i!=0 && j!=0) )(static_cast <bool> ((i==0 && j==0) || (i!=0 &&
j!=0)) ? void (0) : __assert_fail ("(i==0 && j==0) || (i!=0 && j!=0)"
, "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp", 395
, __extension__ __PRETTY_FUNCTION__))
;
396 int coefn=(i==0 && j==0) ? cc00 : Minor3::is(i-1,j-1)+cc11;
397 Save3 *s3=getS3(ep, kin, coefn);
398
399 ncomplex ivalue=(*s3)[coefn];
400 Minor3::Ptr pm3;
401 if (ivalue.real() == sNAN && (pm3=MCache::getMinor3(kin))!=0) {
402 ivalue=pm3->evalC(ep, i, j);
403 (*s3)[coefn]=ivalue;
404 }
405#else
406 Minor3::Ptr pm3=MCache::getMinor3(kin);
407 ncomplex ivalue= ( pm3!=0 ? pm3->evalC(ep, i, j) : sNAN.d64 );
408#endif /* USE_CACHE_LOW */
409#ifndef NDEBUG
410 if (pm3==0) printf("C%d%d(%.18e,%.18e,%.18e,%e,%e,%e)=%f\n",i,j,kin.p1(),kin.p2(),kin.p3(),kin.m1(),kin.m2(),kin.m3(),ivalue.real());
411#endif
412 return ivalue;
413}
414
415/* --------------------------------------------------------
416 Rank-1 TRIANGLE
417 * --------------------------------------------------------
418 */
419ncomplex ICache::getC(int ep, int i, const Kinem3 &kin)
420{
421#ifdef USE_CACHE_LOW
422 int coefn=(i-1)+cc1;
423 Save3 *s3=getS3(ep, kin, coefn);
424
425 ncomplex ivalue=(*s3)[coefn];
426 Minor3::Ptr pm3;
427 if (ivalue.real() == sNAN && (pm3=MCache::getMinor3(kin))!=0) {
428 ivalue=pm3->evalC(ep, i);
429 (*s3)[coefn]=ivalue;
430 }
431#else
432 Minor3::Ptr pm3=MCache::getMinor3(kin);
433 ncomplex ivalue= ( pm3!=0 ? pm3->evalC(ep, i) : sNAN.d64 );
434#endif /* USE_CACHE_LOW */
435#ifndef NDEBUG
436 if (pm3==0) printf("C%d(%.18e,%.18e,%.18e,%e,%e,%e)=%f\n",i,kin.p1(),kin.p2(),kin.p3(),kin.m1(),kin.m2(),kin.m3(),ivalue.real());
437#endif
438 return ivalue;
439}
440
441/* ===========================================================
442 *
443 * BUBBLE: 2 point coefficients
444 *
445 * ===========================================================
446 */
447
448/* --------------------------------------------------------
449 Rank-2 BUBBLE
450 * --------------------------------------------------------
451 */
452ncomplex ICache::getB(int ep, int i, int j, const Kinem2 &kin)
453{
454#ifdef USE_CACHE_LOW
455 assert( (i==0 && j==0) || (i!=0 && j!=0) )(static_cast <bool> ((i==0 && j==0) || (i!=0 &&
j!=0)) ? void (0) : __assert_fail ("(i==0 && j==0) || (i!=0 && j!=0)"
, "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp", 455
, __extension__ __PRETTY_FUNCTION__))
;
456 int coefn=(i==0 && j==0) ? bb00 : Minor2::is(i-1,j-1)+bb11;
457 Save2 *s2=getS2(ep, kin, coefn);
458
459 ncomplex ivalue=(*s2)[coefn];
460 Minor2::Ptr pm2;
461 if (ivalue.real() == sNAN && (pm2=MCache::getMinor2(kin))!=0) {
462 ivalue=pm2->evalB(ep, i, j);
463 (*s2)[coefn]=ivalue;
464 }
465#else
466 Minor2::Ptr pm2=MCache::getMinor2(kin);
467 ncomplex ivalue= ( pm2!=0 ? pm2->evalB(ep, i, j) : sNAN.d64 );
468#endif /* USE_CACHE_LOW */
469#ifndef NDEBUG
470 if (pm2==0) printf("B%d%d(%.18e,%.18e,%.18e)=%f\n",i,j,kin.p1(),kin.m1(),kin.m2(),ivalue.real());
471#endif
472 return ivalue;
473}
474
475/* --------------------------------------------------------
476 Rank-1 BUBBLE
477 * --------------------------------------------------------
478 */
479ncomplex ICache::getB(int ep, int i, const Kinem2 &kin)
480{
481#ifdef USE_CACHE_LOW
482 int coefn=(i-1)+bb1;
483 Save2 *s2=getS2(ep, kin, coefn);
484
485 ncomplex ivalue=(*s2)[coefn];
486 Minor2::Ptr pm2;
487 if (ivalue.real() == sNAN && (pm2=MCache::getMinor2(kin))!=0) {
488 ivalue=pm2->evalB(ep, i);
489 (*s2)[coefn]=ivalue;
490 }
491#else
492 Minor2::Ptr pm2=MCache::getMinor2(kin);
493 ncomplex ivalue= ( pm2!=0 ? pm2->evalB(ep, i) : sNAN.d64 );
494#endif /* USE_CACHE_LOW */
495#ifndef NDEBUG
496 if (pm2==0) printf("B%d(%.18e,%.18e,%.18e)=%f\n",i,kin.p1(),kin.m1(),kin.m2(),ivalue.real());
497#endif
498 return ivalue;
499}
500
501/* ===========================================================
502 *
503 * Get saved value
504 *
505 * ===========================================================
506 */
507
508// ICache::Save5* ICache::getS5(int ep, const Kinem5 &kin, int coefn)
509// {
510// Save5 *s5=0;
511// for (Array5::iterator it5=ic5[ep].begin(); it5 != ic5[ep].end(); ++it5) {
512// if (it5->key == kin) {
513// s5=it5->val.get();
514// break;
515// }
516// }
517// if (s5 == 0) {
518// Save5::Ptr sptr(new Save5(ncomplex(sNAN.d64, 0)));
519// s5=sptr.get();
520// ic5[ep].insert(Entry5(kin, sptr));
521// }
522// return s5;
523// }
524
525#define getSave(n) \
526ICache::Save##n * ICache::getS##n(int ep, const Kinem##n &kin, int coefn) \
527{ \
528 Save##n *s##n=0; \
529 for (Array##n::iterator it##n=ic##n[ep].begin(); it##n != ic##n[ep].end(); ++it##n) { \
530 if (it##n->key == kin) { \
531 s##n=it##n->val.get(); \
532 break; \
533 } \
534 } \
535 if (s##n == 0) { \
536 Save##n::Ptr sptr(new Save##n(ncomplex(sNAN.d64, 0))); \
537 s##n=sptr.get(); \
538 ic##n[ep].insert(Entry##n(kin, sptr)); \
539 } \
540 return s##n; \
541} \
542
543getSave(5)
544getSave(4)
545getSave(3)
546getSave(2)
547
548#undef getSave
549
550// ncomplex ICache::getI2(int ep, const Kinem2 &k)
551// {
552// ncomplex ivalue(sNAN.d64, 0);
553// for (ArrayS2::iterator it2=ics2[ep].begin(); it2 != ics2[ep].end(); ++it2) {
554// if (it2->key == k) {
555// ivalue=it2->val;
556// break;
557// }
558// }
559// if (ivalue.real() == sNAN) {
560// ivalue=qlI2(k.p1(),
561// k.m1(), k.m2(),
562// -ep);
563// ics2[ep].insert(EntryS2(k,ivalue));
564// }
565// return ivalue;
566// }
567
568#define getIN(n) \
569ncomplex ICache::getI##n(int ep, const Kinem##n &k) \
570{ \
571 Ival ivalue; \
572 bool found=false; \
573 for (ArrayS##n::iterator it##n=ics##n.begin(); it##n != ics##n.end(); ++it##n) { \
574 if (it##n->key == k) { \
575 ivalue=it##n->val; \
576 found=true; \
577 break; \
578 } \
579 } \
580 if ( ! found ) { \
581 ivalue=qlI##n(k); \
582 ics##n.insert(EntryS##n(k,ivalue)); \
583 } \
584 return ivalue.val[ep]; \
585}
586
587getIN(1)
588getIN(2)
589getIN(3)
590getIN(4)
591
592#undef getIN
593
594/* ------------------------------------------------------------
595 * ------------------------------------------------------------
596 * MCache section
597 * ------------------------------------------------------------
598 * ------------------------------------------------------------
599*/
600
601MCache::Array5 MCache::cm5;
602MCache::Array4 MCache::cm4;
603MCache::Array3 MCache::cm3;
604MCache::Array2 MCache::cm2;
605
606// Minor5::Ptr MCache::getMinor5(const Kinem5 &k)
607// {
608// Minor5::Ptr minor;
609// for (Array5::iterator it5=cm5.begin(); it5!=cm5.end(); ++it5) {
610// if (it5->key == k) {
611// minor=it5->val;
612// break;
613// }
614// }
615// if (minor==0) {
616// minor=Minor5::create(k);
617// cm5.insert(Entry5(k,minor));
618// }
619// return minor;
620// }
621
622#define getMinorN(n) \
623Minor##n::Ptr MCache::getMinor##n(const Kinem##n &k) \
624{ \
625 Minor##n::Ptr minor; \
626 for (Array##n::iterator it##n=cm##n.begin(); it##n!=cm##n.end(); ++it##n) { \
627 if (it##n->key == k) { \
628 minor=it##n->val; \
629 break; \
630 } \
631 } \
632 /* if (minor==0) { \
633 minor=Minor##n::create(k); \
634 cm##n.insert(Entry##n(k,minor)); \
635 } \
636 assert(minor!=0); */ \
637 return minor; \
638}
639
640getMinorN(3)
641getMinorN(2)
642
643#undef getMinorN
644
645Minor5::Ptr MCache::getMinor5(const Kinem5 &k)
646{
647 Minor5::Ptr minor;
648 for (Array5::iterator it5=cm5.begin(); it5!=cm5.end(); ++it5) {
649 if (it5->key == k) {
650 minor=it5->val;
651 break;
652 }
653 }
654 if (minor==0) {
655 minor=Minor5::create(k);
656 cm5.insert(Entry5(k,minor));
657 }
658 assert(minor!=0)(static_cast <bool> (minor!=0) ? void (0) : __assert_fail
("minor!=0", "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp"
, 658, __extension__ __PRETTY_FUNCTION__))
;
659 return minor;
660}
661
662Minor4::Ptr MCache::getMinor4(const Kinem4 &k)
663{
664 Minor4::Ptr minor;
665 for (Array4::iterator it4=cm4.begin(); it4!=cm4.end(); ++it4) {
2
Loop condition is true. Entering loop body
666 if (it4->key == k) {
3
Assuming the condition is true
4
Taking true branch
667 minor=it4->val;
5
Calling copy assignment operator for 'SPtr<Minor4>'
8
Returning from copy assignment operator for 'SPtr<Minor4>'
668 break;
669 }
670 }
671 if (minor==0) {
9
Execution continues on line 671
10
Taking false branch
672 Minor5::create(k);
673 minor=cm4.begin()->val;
674 cm4.insert(Entry4(k,minor));
675 }
676 assert(minor!=0)(static_cast <bool> (minor!=0) ? void (0) : __assert_fail
("minor!=0", "generators/phokhara/phokhara/eemmg-lib/src/cache.cpp"
, 676, __extension__ __PRETTY_FUNCTION__))
;
11
'?' condition is true
677 return minor;
12
Calling '~SPtr'
16
Returning from '~SPtr'
678}
679
680
681#ifdef USE_SMART_INSERT"1"
682
683void MCache::smartinsertMinor3(const Kinem3 &k, Minor3::Ptr &m)
684{
685 for (Array3::iterator it3=cm3.begin(); it3!=cm3.end(); ++it3) {
686 if (it3->key == k) {
687 cm3.remove(it3);
688 break;
689 }
690 }
691 insertMinor3(k,m);
692}
693
694void MCache::smartinsertMinor2(const Kinem2 &k, Minor2::Ptr &m)
695{
696 for (Array2::iterator it2=cm2.begin(); it2!=cm2.end(); ++it2) {
697 if (it2->key == k) {
698 cm2.remove(it2);
699 break;
700 }
701 }
702 insertMinor2(k,m);
703}
704
705#endif
706
707// -------------------------------------------------------

generators/phokhara/phokhara/eemmg-lib/src/pointer.h

1/*
2 * pointer.h - smart pointer and array classes
3 *
4 * this file is part of PJFry library
5 * Copyright 2011 Valery Yundin
6 */
7
8#ifndef QUL_POINTER_H
9#define QUL_POINTER_H
10
11#include <memory>
12#include <cstring>
13
14class SRefCnt {
15public:
16 SRefCnt() : count(0) { }
17
18protected:
19 int count;
20};
21
22template <typename T>
23class SPtr {
24public:
25 T* operator-> () const { return pObj; }
19
Use of memory after it is freed
26 bool operator== (const T* pobj) const { return pobj == pObj; }
27 bool operator!= (const T* pobj) const { return pobj != pObj; }
28
29 bool operator== (const SPtr<T>& spobj) const { return spobj.pObj == pObj; }
30 bool operator!= (const SPtr<T>& spobj) const { return spobj.pObj != pObj; }
31
32 SPtr(T* pobj = 0) : pObj(pobj)
33 {
34 if (pObj) { pObj->count++; }
35 }
36 SPtr(const SPtr& ptr) : pObj(ptr.pObj)
37 {
38 if (pObj) { pObj->count++; }
39 }
40
41 SPtr& operator= (const SPtr& ptr)
42 {
43 if (this == &ptr) { return *this; }
44 if (pObj
5.1
Field 'pObj' is null
5.1
Field 'pObj' is null
&& --(pObj->count) == 0) { delete pObj; }
45 if ((pObj = ptr.pObj)) { pObj->count++; }
6
Assuming 'pObj' is non-null
7
Taking true branch
46 return *this;
47 }
48
49 ~SPtr()
50 {
51 if (pObj
12.1
Field 'pObj' is non-null
12.1
Field 'pObj' is non-null
&& --(pObj->count) == 0) { delete pObj; }
13
Assuming the condition is true
14
Taking true branch
15
Memory is released
52 }
53
54private:
55 T* pObj;
56};
57
58template <typename T, int N> class DArray;
59// Iterator for DArray class
60template <typename T, int N>
61class NIter {
62 friend class DArray<T, N>;
63public:
64 inline T& operator* () { return ptr[idx % N]; }
65 inline T* operator-> () { return &ptr[idx % N]; }
66 inline NIter& operator++ () { idx++; return *this;}
67 inline NIter& operator+= (int n) { idx += n; return *this;}
68
69 inline bool operator== (const NIter& iter) { return idx == iter.idx && ptr == iter.ptr; }
70 inline bool operator!= (const NIter& iter) { return idx != iter.idx || ptr != iter.ptr; }
71
72 NIter(T* begin, int last) : ptr(begin), idx(last) {}
73private:
74 T* ptr;
75 int idx;
76};
77
78// DArray - static array with stack-like iterator
79template <typename T, int N>
80class DArray {
81public:
82 DArray() : last(N), len(0) {}
83
84 typedef NIter<T, N> iterator;
85 iterator begin() { return iterator(elems, last); }
86 iterator end() { return iterator(elems, last + len); }
87
88 T& insert(const T& el)
89 {
90 len = (len == N ? len : len + 1);
91 last = ((last - 1) + N) % N;
92 elems[last] = el;
93 return elems[last];
94 }
95
96#ifdef USE_SMART_INSERT"1"
97 void remove(iterator& it)
98 {
99// assert(it.ptr==elems);
100 int i = it.idx % N;
101 elems[i] = T();
102 if (i >= last) {
103 memmove(&elems[last + 1], &elems[last], (i - last)*sizeof(T));
104 memset(&elems[last], 0, sizeof(T));
105 last = (last + 1) % N;
106 } else {
107 memmove(&elems[i], &elems[i + 1], (last - i - 1)*sizeof(T));
108 memset(&elems[last - 1], 0, sizeof(T));
109 }
110 len = len - 1;
111 }
112#endif
113
114 void reset()
115 {
116#ifndef USE_DIRTY_RESET"1"
117 for (int i = 0; i < len; i++) {
118 elems[i] = T();
119 }
120#endif
121 last = N;
122 len = 0;
123 }
124
125 static const int size = N;
126 const T& operator [](const int idx) const { return elems[idx]; }
127 T& operator [](const int idx) { return elems[idx]; }
128
129private:
130 T elems[N];
131 int last;
132 int len;
133};
134
135// CArray - simple array with trivial iterator
136template <typename T, int N>
137class CArray {
138public:
139 typedef std::auto_ptr<CArray> Ptr;
140
141 CArray(T dval = T())
142 {
143 for (iterator i = begin(); i != end(); ++i) {
144 *i = dval;
145 }
146 }
147
148 typedef T* iterator;
149 iterator begin() { return &elems[0]; }
150 iterator end() { return &elems[N]; }
151
152
153 static const int size = N;
154
155 const T& operator [](const int idx) const { return elems[idx]; }
156 T& operator [](const int idx) { return elems[idx]; }
157
158private:
159 T elems[N];
160};
161
162#endif /* QUL_POINTER_H */
163
164/*
165class Test: public SRefCnt
166{
167 public:
168 friend class SPtr<Test>;
169 typedef SPtr<Test> Ptr;
170
171 static Ptr create(int x) { return Ptr(new Test(x)); };
172
173 ~Test() { };
174
175 private:
176 Test() { };
177};
178
179*/