Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CEPCSW
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
maxt@ihep.ac.cn
CEPCSW
Commits
9e9f7e1b
Commit
9e9f7e1b
authored
4 months ago
by
lintao@ihep.ac.cn
Browse files
Options
Downloads
Patches
Plain Diff
HepevtRdr: add StartIndex and fix potential memory leakage.
parent
d315d643
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Generator/src/HepevtRdr.cpp
+31
-12
31 additions, 12 deletions
Generator/src/HepevtRdr.cpp
Generator/src/HepevtRdr.h
+3
-0
3 additions, 0 deletions
Generator/src/HepevtRdr.h
with
34 additions
and
12 deletions
Generator/src/HepevtRdr.cpp
+
31
−
12
View file @
9e9f7e1b
...
@@ -22,7 +22,6 @@
...
@@ -22,7 +22,6 @@
using
namespace
lcio
;
using
namespace
lcio
;
using
namespace
IMPL
;
using
namespace
IMPL
;
using
namespace
edm4hep
;
using
namespace
edm4hep
;
using
namespace
std
;
typedef
enum
HEPFILEFORMATS
typedef
enum
HEPFILEFORMATS
{
{
...
@@ -46,6 +45,19 @@ StatusCode HepevtRdr::initialize() {
...
@@ -46,6 +45,19 @@ StatusCode HepevtRdr::initialize() {
return
StatusCode
::
FAILURE
;
return
StatusCode
::
FAILURE
;
}
}
// skip the first n events if startIndex is not 0.
if
(
startIndex
()
>
0
)
{
for
(
int
i
=
0
;
i
<
startIndex
();
++
i
)
{
++
m_processed_event
;
LCCollectionVec
*
mc_vec
=
m_hepevt_rdr
->
readEvent
();
if
(
mc_vec
==
nullptr
)
{
break
;
}
delete
mc_vec
;
}
info
()
<<
"Skip the first "
<<
startIndex
()
<<
" events."
<<
endmsg
;
}
return
sc
;
return
sc
;
}
}
...
@@ -68,17 +80,17 @@ bool HepevtRdr::configure_gentool(){
...
@@ -68,17 +80,17 @@ bool HepevtRdr::configure_gentool(){
}
}
m_hepevt_rdr
=
new
UTIL
::
LCAscHepRdr
(
m_filename
.
value
().
c_str
(),
format
);
m_hepevt_rdr
=
new
UTIL
::
LCAscHepRdr
(
m_filename
.
value
().
c_str
(),
format
);
m_processed_event
=
0
;
m_processed_event
=
-
1
;
std
::
cout
<<
"initial hepevt_rdr"
<<
std
::
endl
;
std
::
cout
<<
"initial hepevt_rdr"
<<
std
::
endl
;
return
true
;
return
true
;
}
}
bool
HepevtRdr
::
mutate
(
MyHepMC
::
GenEvent
&
event
){
bool
HepevtRdr
::
mutate
(
MyHepMC
::
GenEvent
&
event
){
++
m_processed_event
;
LCCollectionVec
*
mc_vec
=
m_hepevt_rdr
->
readEvent
();
LCCollectionVec
*
mc_vec
=
m_hepevt_rdr
->
readEvent
();
if
(
mc_vec
==
nullptr
)
return
false
;
if
(
mc_vec
==
nullptr
)
return
false
;
m_processed_event
++
;
int
n_mc
=
mc_vec
->
size
();
int
n_mc
=
mc_vec
->
size
();
std
::
cout
<<
"Read event :"
<<
m_processed_event
<<
", mc size :"
<<
n_mc
<<
std
::
endl
;
info
()
<<
"Read event :"
<<
m_processed_event
<<
", mc size :"
<<
n_mc
<<
endmsg
;
std
::
map
<
int
,
int
>
pmcid_lmcid
;
std
::
map
<
int
,
int
>
pmcid_lmcid
;
for
(
int
i
=
0
;
i
<
n_mc
;
i
++
){
for
(
int
i
=
0
;
i
<
n_mc
;
i
++
){
MCParticleImpl
*
mc
=
(
MCParticleImpl
*
)
mc_vec
->
getElementAt
(
i
);
MCParticleImpl
*
mc
=
(
MCParticleImpl
*
)
mc_vec
->
getElementAt
(
i
);
...
@@ -108,19 +120,22 @@ bool HepevtRdr::mutate(MyHepMC::GenEvent& event){
...
@@ -108,19 +120,22 @@ bool HepevtRdr::mutate(MyHepMC::GenEvent& event){
const
MCParticleVec
&
mc_daughters
=
mc
->
getDaughters
();
const
MCParticleVec
&
mc_daughters
=
mc
->
getDaughters
();
auto
pmc
=
event
.
m_mc_vec
.
at
(
i
);
auto
pmc
=
event
.
m_mc_vec
.
at
(
i
);
//std::cout<<"mc at "<< i<<", parent size "<<mc_parents.size() <<std::endl;
//std::cout<<"mc at "<< i<<", parent size "<<mc_parents.size() <<std::endl;
for
(
unsigned
int
j
=
0
;
j
<
mc_parents
.
size
();
j
++
){
int
p_id
=
mc_parents
.
at
(
j
)
->
id
();
for
(
unsigned
int
j
=
0
;
j
<
mc_parents
.
size
();
j
++
){
//std::cout<<"parent id "<<p_id<<std::endl;
int
p_id
=
mc_parents
.
at
(
j
)
->
id
();
pmc
.
addToParents
(
event
.
m_mc_vec
.
at
(
pmcid_lmcid
.
at
(
p_id
)
)
);
//std::cout<<"parent id "<<p_id<<std::endl;
}
pmc
.
addToParents
(
event
.
m_mc_vec
.
at
(
pmcid_lmcid
.
at
(
p_id
)
)
);
}
//std::cout<<"mc at "<< i<<", daughter size "<<mc_daughters.size() <<std::endl;
//std::cout<<"mc at "<< i<<", daughter size "<<mc_daughters.size() <<std::endl;
for
(
unsigned
int
j
=
0
;
j
<
mc_daughters
.
size
();
j
++
){
int
d_id
=
mc_daughters
.
at
(
j
)
->
id
();
for
(
unsigned
int
j
=
0
;
j
<
mc_daughters
.
size
();
j
++
){
//std::cout<<"daughter id "<<d_id<<std::endl;
int
d_id
=
mc_daughters
.
at
(
j
)
->
id
();
pmc
.
addToDaughters
(
event
.
m_mc_vec
.
at
(
pmcid_lmcid
.
at
(
d_id
)
)
);
//std::cout<<"daughter id "<<d_id<<std::endl;
}
pmc
.
addToDaughters
(
event
.
m_mc_vec
.
at
(
pmcid_lmcid
.
at
(
d_id
)
)
);
}
}
}
event
.
SetEventHeader
(
m_processed_event
,
-
99
,
9999
,
"Generator"
);
event
.
SetEventHeader
(
m_processed_event
,
-
99
,
9999
,
"Generator"
);
//std::cout<<"end event :"<< m_processed_event <<std::endl;
//std::cout<<"end event :"<< m_processed_event <<std::endl;
delete
mc_vec
;
return
true
;
return
true
;
}
}
...
@@ -131,3 +146,7 @@ bool HepevtRdr::isEnd(){
...
@@ -131,3 +146,7 @@ bool HepevtRdr::isEnd(){
bool
HepevtRdr
::
finish
(){
bool
HepevtRdr
::
finish
(){
return
true
;
return
true
;
}
}
int
HepevtRdr
::
startIndex
(){
return
m_startIndex
.
value
();
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Generator/src/HepevtRdr.h
+
3
−
0
View file @
9e9f7e1b
...
@@ -23,6 +23,8 @@ class HepevtRdr: public extends<AlgTool, GenReader> {
...
@@ -23,6 +23,8 @@ class HepevtRdr: public extends<AlgTool, GenReader> {
bool
mutate
(
MyHepMC
::
GenEvent
&
event
);
bool
mutate
(
MyHepMC
::
GenEvent
&
event
);
bool
finish
();
bool
finish
();
bool
isEnd
();
bool
isEnd
();
int
startIndex
()
override
;
private:
private:
UTIL
::
LCAscHepRdr
*
m_hepevt_rdr
=
nullptr
;
UTIL
::
LCAscHepRdr
*
m_hepevt_rdr
=
nullptr
;
long
m_total_event
=
-
1
;
long
m_total_event
=
-
1
;
...
@@ -31,6 +33,7 @@ class HepevtRdr: public extends<AlgTool, GenReader> {
...
@@ -31,6 +33,7 @@ class HepevtRdr: public extends<AlgTool, GenReader> {
// input file name
// input file name
Gaudi
::
Property
<
std
::
string
>
m_filename
{
this
,
"Input"
};
Gaudi
::
Property
<
std
::
string
>
m_filename
{
this
,
"Input"
};
Gaudi
::
Property
<
std
::
string
>
m_format
{
this
,
"Format"
};
Gaudi
::
Property
<
std
::
string
>
m_format
{
this
,
"Format"
};
Gaudi
::
Property
<
int
>
m_startIndex
{
this
,
"StartIndex"
,
0
,
"Default start index"
};
};
};
#endif
#endif
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment