Skip to content

Commit 2ea95a4

Browse files
committed
attempt to fix crash at the 1st event
1 parent bf6e277 commit 2ea95a4

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

SimG4CMS/Calo/src/CaloSD.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,9 @@ void CaloSD::DrawAll() {}
432432

433433
void CaloSD::PrintAll() {
434434
for (int k = 0; k < nHC_; ++k) {
435+
if (nullptr == theHC[k]) { continue; }
435436
#ifdef EDM_ML_DEBUG
436-
edm::LogVerbatim("CaloSim") << "CaloSD: Collection " << theHC[k]->GetName();
437+
edm::LogVerbatim("CaloSim") << "CaloSD: Collection " << k << " " << theHC[k]->GetName();
437438
#endif
438439
theHC[k]->PrintAllHits();
439440
}
@@ -783,6 +784,7 @@ void CaloSD::update(const EndOfTrack* trk) {
783784
void CaloSD::update(const ::EndOfEvent*) {
784785
endEvent();
785786
for (int k = 0; k < nHC_; ++k) {
787+
if (nullptr == slave[k].get()) { continue; }
786788
slave[k].get()->ReserveMemory(theHC[k]->entries());
787789

788790
int count(0);
@@ -1043,10 +1045,12 @@ void CaloSD::update(const BeginOfTrack* trk) {
10431045

10441046
void CaloSD::cleanHitCollection() {
10451047
for (int k = 0; k < nHC_; ++k) {
1048+
if (nullptr == theHC[k]) { continue; }
10461049
std::vector<CaloG4Hit*>* theCollection = theHC[k]->GetVector();
10471050

10481051
#ifdef EDM_ML_DEBUG
1049-
edm::LogVerbatim("CaloSim") << "CaloSD: collection before merging, size = " << theHC[k]->entries();
1052+
edm::LogVerbatim("CaloSim")
1053+
<< "CaloSD: collection " << k << " before merging, size = " << theHC[k]->entries();
10501054
#endif
10511055
if (reusehit[k].empty())
10521056
reusehit[k].reserve(theHC[k]->entries() - cleanIndex[k]);
@@ -1059,21 +1063,21 @@ void CaloSD::cleanHitCollection() {
10591063
sort((hitvec.begin() + cleanIndex[k]), hitvec.end(), CaloG4HitLess());
10601064
#ifdef EDM_ML_DEBUG
10611065
edm::LogVerbatim("CaloSim") << "CaloSD::cleanHitCollection: sort hits in buffer starting from "
1062-
<< "element = " << cleanIndex[k];
1066+
<< "element = " << cleanIndex[k];
10631067
for (unsigned int i = 0; i < hitvec.size(); ++i) {
1064-
if (hitvec[i] == nullptr)
1065-
edm::LogVerbatim("CaloSim") << i << " has a null pointer";
1066-
else
1067-
edm::LogVerbatim("CaloSim") << i << " " << *hitvec[i];
1068+
if (hitvec[i] == nullptr)
1069+
edm::LogVerbatim("CaloSim") << i << " has a null pointer";
1070+
else
1071+
edm::LogVerbatim("CaloSim") << i << " " << *hitvec[i];
10681072
}
10691073
#endif
10701074
CaloG4HitEqual equal;
10711075
for (unsigned int i = cleanIndex[k]; i < hitvec.size(); ++i) {
1072-
int jump = 0;
1073-
for (unsigned int j = i + 1; j < hitvec.size() && equal(hitvec[i], hitvec[j]); ++j) {
1074-
++jump;
1075-
// merge j to i
1076-
(*hitvec[i]).addEnergyDeposit(*hitvec[j]);
1076+
int jump = 0;
1077+
for (unsigned int j = i + 1; j < hitvec.size() && equal(hitvec[i], hitvec[j]); ++j) {
1078+
++jump;
1079+
// merge j to i
1080+
(*hitvec[i]).addEnergyDeposit(*hitvec[j]);
10771081
(*hitvec[j]).setEM(0.);
10781082
(*hitvec[j]).setHadr(0.);
10791083
reusehit[k].emplace_back(hitvec[j]);
@@ -1113,7 +1117,6 @@ void CaloSD::cleanHitCollection() {
11131117
CaloG4Hit* aHit((*theCollection)[i]);
11141118

11151119
// selection
1116-
11171120
double time = aHit->getTimeSlice();
11181121
if (corrTOFBeam)
11191122
time += correctT;
@@ -1122,9 +1125,7 @@ void CaloSD::cleanHitCollection() {
11221125
edm::LogVerbatim("CaloSim") << "CaloSD: dropped CaloG4Hit "
11231126
<< " " << *aHit;
11241127
#endif
1125-
11261128
// create the list of hits to be reused
1127-
11281129
reusehit[k].emplace_back((*theCollection)[i]);
11291130
(*theCollection)[i] = nullptr;
11301131
++addhit;

0 commit comments

Comments
 (0)