Commit d9a07c28 authored by Martin Errenst's avatar Martin Errenst
Browse files

Fix bug in deReg and add test

The lambda in deReg( TObject* ) tried to access vhid->at(0) after a
check for vhid->size() == 0. This resulted in a certain crash.

I've reorganized the function to delete the vector of THistIDs when
vhid->size() is 1 (not 0).
There is also a new test case that registers and deregisters a single
histogram.

Apply formatting
parent 21264e1f
......@@ -87,6 +87,14 @@ StatusCode THistWrite::initialize()
error() << "Couldn't use TempHist6 afterwards. getName = " << h6->GetName() << endmsg;
}
TH1D* h7 = new TH1D( "TempHist7", "Temporary Tree 7", 100, 0., 100. );
if ( m_ths->regHist( "TempHist7", h7 ).isFailure() ) {
error() << "Couldn't register TempHist6" << endmsg;
}
if ( strcmp( h7->GetName(), "TempHist7" ) ) {
error() << "Couldn't use TempHist7 afterwards. getName = " << h7->GetName() << endmsg;
}
// Profile in "/"
std::unique_ptr<TH1> tp = std::make_unique<TProfile>( "profile", "profile", 100, -50., -50. );
if ( m_ths->regHist( "/rec/prof", std::move( tp ) ).isFailure() ) {
......@@ -269,5 +277,13 @@ StatusCode THistWrite::finalize()
{
info() << "Finalizing..." << endmsg;
TH1* h7 = nullptr;
if ( m_ths->getHist( "TempHist7", h7 ).isFailure() ) {
error() << "Couldn't retrieve TempHist7" << endmsg;
}
if ( m_ths->deReg( h7 ).isFailure() ) {
error() << "Failed to deregister histogram TempHist7" << endmsg;
}
return StatusCode::SUCCESS;
}
......@@ -17,7 +17,8 @@ preprocessor = normalizeExamples + \
RegexpReplacer(when = "^ - 0x########.*id: ",
orig = r"(.+id: )(\/.*\/.*)( t: )([0,1])( s: )([0,1])( M: )([0-9]+)(.*o: 0x######## )(.*)",
repl = r"\1\2\3\4\5\6\7########\9\10") + \
SortGroupOfLines(r"^ -")
SortGroupOfLines(r"^ -") + \
SortGroupOfLines(r"^THistSvc\s+DEBUG finalize")
validateWithReference(preproc = preprocessor)
</text></argument>
......
......@@ -68,6 +68,10 @@ THistSvc DEBUG regHist_i obj: 0x31d9a70 id: TempHist6 s: 0
THistSvc DEBUG Historgram with id "TempHist6" is temporary
THistSvc DEBUG Registering TH1D title: "Temporary Tree 6" id: "/temp/TempHist6" dir: root:/ file: none
THistSvc DEBUG regHist_i THistID: id: /temp/TempHist6 t: 1 s: 0 M: 52216688 m: 0 o: 0x31d9a70 TH1D
THistSvc DEBUG regHist_i obj: 0x1aeb690 id: TempHist7 s: 0
THistSvc DEBUG Historgram with id "TempHist7" is temporary
THistSvc DEBUG Registering TH1D title: "Temporary Tree 7" id: "/temp/TempHist7" dir: root:/ file: none
THistSvc DEBUG regHist_i THistID: id: /temp/TempHist7 t: 1 s: 0 M: 27169504 m: 0 o: 0x1aeb690 TH1D
THistSvc DEBUG regHist_i obj: 0x31da3c0 id: /rec/prof s: 0
THistSvc DEBUG Registering TProfile title: "profile" id: "/rec/prof" dir: tuple3.rt:/ file: tuple3.rt
THistSvc DEBUG regHist_i THistID: id: /rec/prof t: 0 s: 0 M: 2 m: 0 o: 0x31da3c0 TProfile
......@@ -173,6 +177,7 @@ THistSvc DEBUG getSharedHist: found THistID: id: /rec/gauss3d_shared
THistSvc DEBUG updateFiles()
ApplicationMgr INFO Application Manager Stopped successfully
THistWrite INFO Finalizing...
THistSvc DEBUG vhid for /temp/TempHist7 is empty. deleting
EventLoopMgr INFO Histograms converted successfully according to request.
THistSvc DEBUG dumping THistSvc contents
m_hlist: size: 13
......
......@@ -68,6 +68,10 @@ THistSvc DEBUG regHist_i obj: 0x2d9a400 id: TempHist6 s: 0
THistSvc DEBUG Historgram with id "TempHist6" is temporary
THistSvc DEBUG Registering TH1D title: "Temporary Tree 6" id: "/temp/TempHist6" dir: root:/ file: none
THistSvc DEBUG regHist_i THistID: id: /temp/TempHist6 t: 1 s: 0 M: 47762608 m: 0 o: 0x2d9a400 TH1D
THistSvc DEBUG regHist_i obj: 0x203a910 id: TempHist7 s: 0
THistSvc DEBUG Historgram with id "TempHist7" is temporary
THistSvc DEBUG Registering TH1D title: "Temporary Tree 7" id: "/temp/TempHist7" dir: root:/ file: none
THistSvc DEBUG regHist_i THistID: id: /temp/TempHist7 t: 1 s: 0 M: 32781792 m: 0 o: 0x203a910 TH1D
THistSvc DEBUG regHist_i obj: 0x2d9b130 id: /rec/prof s: 0
THistSvc DEBUG Registering TProfile title: "profile" id: "/rec/prof" dir: tuple3.rt:/ file: tuple3.rt
THistSvc DEBUG regHist_i THistID: id: /rec/prof t: 0 s: 0 M: 2 m: 0 o: 0x2d9b130 TProfile
......@@ -213,6 +217,7 @@ THistSvc DEBUG stream: rec name: tuple3.rt size: 432
THistSvc DEBUG stream: upd name: tuple2.rt size: 4732
ApplicationMgr INFO Application Manager Stopped successfully
THistWrite INFO Finalizing...
THistSvc DEBUG vhid for /temp/TempHist7 is empty. deleting
EventLoopMgr INFO Histograms converted successfully according to request.
THistSvc DEBUG dumping THistSvc contents
m_hlist: size: 13
......
......@@ -604,43 +604,48 @@ StatusCode THistSvc::deReg( TObject* obj )
return StatusCode::FAILURE;
}
delete obj_itr->first;
m_tobjs.erase( obj_itr );
vhid->erase( vhid->begin() + obj_itr->second.second );
if ( vhid->size() != 0 ) {
// vector of THistIT is still not empty (i.e. other instances with same name registered)
return StatusCode::SUCCESS;
}
// In this case we have to delete vhid properly!
debug() << "vhid for " << hid.id << " is empty. deleting" << endmsg;
if ( vhid->size() == 1 ) {
// We are the last object, so we have to delete vhid properly
debug() << "vhid for " << hid.id << " is empty. deleting" << endmsg;
std::string root, rem;
parseString( hid.id, root, rem );
auto mitr = m_ids.equal_range( rem );
auto id_itr = std::find_if( mitr.first, mitr.second,
[&]( idMap_t::const_reference i ) { return i.second->at( 0 ).obj == obj; } );
if ( id_itr == mitr.second ) {
error() << "Problems deregistering TObject \"" << obj->GetName() << "\" with id \"" << hid.id
<< "\": not in idMap" << endmsg;
return StatusCode::FAILURE;
}
std::string id, root, rem;
parseString( hid.id, root, rem );
auto hlist_itr = std::find( m_hlist.begin(), m_hlist.end(), vhid );
if ( hlist_itr == m_hlist.end() ) {
error() << "Problems deregistering TObject \"" << obj->GetName() << "\" with id \"" << hid.id
<< "\": not in hlist" << endmsg;
return StatusCode::FAILURE;
}
auto mitr = m_ids.equal_range( rem );
auto id_itr = std::find_if( mitr.first, mitr.second,
[&]( idMap_t::const_reference i ) { return i.second->at( 0 ).obj == obj; } );
if ( id_itr == mitr.second ) {
error() << "Problems deregistering TObject \"" << obj->GetName() << "\" with id \"" << hid.id
<< "\": not in idMap" << endmsg;
return StatusCode::FAILURE;
}
delete obj_itr->first;
m_tobjs.erase( obj_itr );
vhid->erase( vhid->begin() + obj_itr->second.second );
auto hlist_itr = std::find( m_hlist.begin(), m_hlist.end(), vhid );
if ( hlist_itr == m_hlist.end() ) {
error() << "Problems deregistering TObject \"" << obj->GetName() << "\" with id \"" << hid.id
<< "\": not in hlist" << endmsg;
return StatusCode::FAILURE;
}
m_uids.erase( uid_itr );
m_ids.erase( id_itr );
m_hlist.erase( hlist_itr );
m_uids.erase( uid_itr );
m_ids.erase( id_itr );
m_hlist.erase( hlist_itr );
delete vhid;
delete vhid;
} else if ( vhid->size() > 1 ) {
delete obj_itr->first;
m_tobjs.erase( obj_itr );
vhid->erase( vhid->begin() + obj_itr->second.second );
// vector of THistID is still not empty (i.e. other instances with same name registered)
} else {
error() << "Deregistration failed unexpectedly. (bug in THistSvc?)" << endmsg;
}
return StatusCode::SUCCESS;
} else {
error() << "Cannot unregister TObject \"" << obj->GetName() << "\": not known to THistSvc" << endmsg;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment