Skip to content
Snippets Groups Projects
Commit 8bada8ff authored by Michael Duehrssen-Debling's avatar Michael Duehrssen-Debling
Browse files

Delete temporary objects only after the write operation has finished, as...

Delete temporary objects only after the write operation has finished, as TBuffer is otherwise identifying a 2nd temporary object at the same address with the 1st deleted object


Former-commit-id: eb2ac5b11fdd8aa523adc328f9c93c8bda8c5722
parent 7cb00bf5
No related branches found
No related tags found
No related merge requests found
......@@ -135,6 +135,10 @@ public:
///Print object information.
void Print(Option_t *option = "") const;
///Deletes all objects from the s_cleanup_list.
///This list can get filled during streaming operations, where an immediate delete is not possible
static void DoCleanup();
protected:
const double init_Ekin_nominal=0;
......@@ -144,6 +148,8 @@ protected:
const double init_eta_min=-100;
const double init_eta_max=100;
static std::vector< TFCSParametrizationBase* > s_cleanup_list;
#if defined(__FastCaloSimStandAlone__)
public:
/// Update outputlevel
......
......@@ -10,6 +10,7 @@
//=============================================
std::set< int > TFCSParametrizationBase::s_no_pdgid;
std::vector< TFCSParametrizationBase* > TFCSParametrizationBase::s_cleanup_list;
#ifndef __FastCaloSimStandAlone__
//Initialize only in constructor to make sure the needed services are ready
......@@ -75,3 +76,14 @@ void TFCSParametrizationBase::Print(Option_t *option) const
ATH_MSG_INFO(optprint<<GetTitle());
}
}
void TFCSParametrizationBase::DoCleanup()
{
//Do cleanup only at the end of read/write operations
for(auto ptr:s_cleanup_list) if(ptr) {
delete ptr;
}
s_cleanup_list.resize(0);
}
......@@ -169,13 +169,13 @@ void TFCSParametrizationChain::Streamer(TBuffer &R__b)
TFCSParametrization::Streamer(R__b);
TObject* parent=R__b.GetParent();
//cout<<" do split! parent="<<parent<<endl;
//cout<<GetName()<<": do split="<<SplitChainObjects()<<", parent="<<parent<<endl;
if(R__b.GetParent()) {
//cout<<" parent class="<<parent->ClassName()<<endl;
//cout<<" parent name="<<parent->GetName()<<endl;
//cout<<" parent title="<<parent->GetTitle()<<endl;
if(parent->InheritsFrom(TDirectory::Class())) {
//cout<<" parent inherits from TDirectory"<<endl;
//if(SplitChainObjects()) cout<<GetName()<<": parent inherits from TDirectory"<<endl;
dir=(TDirectory*)parent;
//dir->ls();
}
......@@ -194,13 +194,15 @@ void TFCSParametrizationChain::Streamer(TBuffer &R__b)
//cout<<"Streamer() "<<this<<" ("<<GetName()<<") read "<<R__n<<" elements"<<endl;
for (R__i = 0; R__i < R__n; R__i++) {
TFCSParametrizationBase* R__t;
//cout<<" "<<R__i<<": Streamer() "<<this<<" ("<<GetName()<<") read element"<<endl;
//if(SplitChainObjects()) cout<<" "<<R__i<<": Streamer() "<<this<<" ("<<GetName()<<") read element"<<endl;
R__t = (TFCSParametrizationBase*)R__b.ReadObjectAny(R__tcl1);
//if(R__t==nullptr) {
// cout<<" "<<R__i<<": Streamer() "<<this<<" ("<<GetName()<<") read nullptr"<<endl;
//} else {
// cout<<" "<<R__i<<": Streamer() "<<this<<" ("<<GetName()<<") read element done="<<R__t<<" ("<<R__t->GetName()<<") "<<endl;
//}
//if(SplitChainObjects()) {
// if(R__t==nullptr) {
// cout<<" "<<R__i<<": Streamer() "<<this<<" ("<<GetName()<<") read nullptr"<<endl;
// } else {
// cout<<" "<<R__i<<": Streamer() "<<this<<" ("<<GetName()<<") read element done="<<R__t<<" ("<<R__t->GetName()<<") "<<endl;
// }
//}
if(R__t!=nullptr) {
if(R__t->InheritsFrom(TFCSParametrizationPlaceholder::Class())) {
//cout<<" "<<R__i<<": Streamer() "<<this<<" ("<<GetName()<<") read element is placeholder="<<R__t<<" ("<<R__t->GetName()<<") "<<endl;
......@@ -254,7 +256,7 @@ void TFCSParametrizationChain::Streamer(TBuffer &R__b)
if(dir && R__t!=nullptr) {
//cout<<" "<<R__i<<": Streamer() "<<this<<" ("<<GetName()<<") write element as extra key to file"<<endl;
dir->WriteTObject(R__t);
//cout<<" "<<R__i<<": Streamer() "<<this<<" ("<<GetName()<<") write element as extra key to file done"<<endl;
//cout<<" "<<R__i<<": Streamer() "<<this<<" ("<<GetName()<<") write element as extra key to file done="<<R__t<<" ("<<R__t->GetName()<<") "<<endl;
new_R__t=new TFCSParametrizationPlaceholder(R__t->GetName(),TString("Placeholder for: ")+R__t->GetTitle());
R__t=new_R__t;
}
......@@ -265,7 +267,10 @@ void TFCSParametrizationChain::Streamer(TBuffer &R__b)
//}
R__b << R__t;
//cout<<" "<<R__i<<": Streamer() "<<this<<" ("<<GetName()<<") write element done"<<endl;
if(new_R__t) delete new_R__t;
//delete new_R__t only after the end of read/write operations by calling TFCSParametrizationBase::DoCleanup();
if(new_R__t) s_cleanup_list.push_back(new_R__t);
++R__i;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment