23 return regHist_i( std::move( hist ),
id, shared, hid );
33 if ( hist_unique.get() !=
nullptr ) { hist = hist_unique.release(); }
35 debug() <<
"regHist_i obj: " << hist <<
" id: " <<
id <<
" s: " << shared <<
endmsg;
38 std::string idr(
id );
41 if ( idr.find(
"/" ) == idr.length() ) {
42 error() <<
"Badly formed identifier \"" << idr <<
"\": "
43 <<
"Must not end with a /" <<
endmsg;
51 error() <<
"Could not register id: \"" << idr <<
"\"" <<
endmsg;
58 uidMap_t::iterator uitr =
m_uids.find( uid );
60 if ( uitr !=
m_uids.end() ) {
62 TObject*
t1 = uitr->second->at( 0 ).obj;
63 if ( hist->Compare(
t1 ) != 0 ) {
64 error() <<
"previously registered object with identifier \"" << uid <<
"\" does not compare to this one"
70 debug() <<
"previously registered id \"" << uid <<
"\": num " << uitr->second->size() <<
endmsg;
81 TObject* to =
nullptr;
85 if ( hist != 0 ) { warning() <<
"Registering id: \"" << idr <<
"\" with non zero pointer!" <<
endmsg; }
87 hist = readHist_i<T>( idr );
88 if ( hist ==
nullptr ) {
89 error() <<
"Unable to read in hist" <<
endmsg;
93 to =
dynamic_cast<TObject*
>( hist );
96 error() <<
"Unable to read in hist with id: \"" << idr <<
"\"" <<
endmsg;
100 to =
dynamic_cast<TObject*
>( hist );
101 if ( to ==
nullptr ) {
102 error() <<
"Could not dcast to TObject. id: \"" << idr <<
"\"" <<
endmsg;
107 auto oitr =
m_tobjs.find( to );
109 error() <<
"already registered id: \"" << idr <<
"\" with identifier \""
110 << oitr->second.first->at( oitr->second.second ).id <<
"\"" <<
endmsg;
117 hid = ( findF !=
m_files.end() ?
THistID( uid, temp, to, f, findF->second.second ) :
THistID( uid, temp, to, f ) );
122 if ( TTree* tree =
dynamic_cast<TTree*
>( hist ) ) {
123 tree->SetDirectory( dir );
126 }
else if ( TH1* th1 =
dynamic_cast<TH1*
>( hist ) ) {
127 th1->SetDirectory( dir );
129 }
else if ( TEfficiency* teff =
dynamic_cast<TEfficiency*
>( hist ) ) {
130 teff->SetDirectory( dir );
132 }
else if (
dynamic_cast<TGraph*
>( hist ) ) {
136 error() <<
"id: \"" << idr <<
"\" is not a TH, TTree, TGraph, or TEfficiency. Attaching it to current dir."
146 fname = f->GetName();
150 debug() <<
"Registering" << ( shared ?
" shared " :
" " ) <<
System::typeinfoName(
typeid( *hist ) ) <<
" title: \""
151 << hist->GetTitle() <<
"\" id: \"" << uid
161 vhid_t* vi = uitr->second;
162 vi->push_back( hid );
163 phid = &( vi->back() );
165 m_tobjs.emplace( to, std::pair<vhid_t*, size_t>( vi, vi->size() - 1 ) );
170 phid = &( vi->back() );
171 m_uids.emplace( uid, vi );
174 m_tobjs.emplace( to, std::pair<vhid_t*, size_t>( vi, 0 ) );
182 template <
typename T>
193 if ( !quiet ) { error() <<
"could not locate Hist with id \"" <<
id <<
"\"" <<
endmsg; }
195 }
else if ( num > 1 ) {
198 error() <<
"Multiple matches with id \"" <<
id <<
"\"."
199 <<
" Further specifications required." <<
endmsg;
202 info() <<
"Found multiple matches with id \"" <<
id <<
"\"" <<
endmsg;
204 hist =
dynamic_cast<T*
>( hid->
obj );
205 if ( hist ==
nullptr ) {
206 error() <<
"dcast failed, Hist id: \"" <<
id <<
"\"" <<
endmsg;
211 hist =
dynamic_cast<T*
>( hid->
obj );
212 if ( hist ==
nullptr ) {
213 error() <<
"dcast failed, Hist id: \"" <<
id <<
"\"" <<
endmsg;
217 verbose() <<
"found unique Hist title: \"" << hist->GetTitle() <<
"\" id: \"" <<
id <<
"\"" <<
endmsg;
224 template <
typename T>
228 std::string idr(
id );
231 std::string
stream, rem, dir, fdir, bdir, fdir2;
232 TFile* file =
nullptr;
237 error() <<
"no associated file found" <<
endmsg;
247 if ( !gDirectory->GetKey( dir.c_str() ) ) {
248 error() <<
"Directory \"" << fdir2 <<
"\" doesnt exist in " << file->GetName() <<
endmsg;
251 gDirectory->cd( dir.c_str() );
254 TObject* to =
nullptr;
255 gDirectory->GetObject( fdir.c_str(), to );
258 error() <<
"Could not get obj \"" << fdir <<
"\" in " << gDirectory->GetPath() <<
endmsg;
262 T* hist =
dynamic_cast<T*
>( to );
263 if ( hist ==
nullptr ) {
264 error() <<
"Could not convert \"" << idr <<
"\" to a " <<
System::typeinfoName(
typeid( *hist ) ) <<
" as is a "
265 << to->IsA()->GetName() <<
endmsg;
270 debug() <<
"Read in " << hist->IsA()->GetName() <<
" \"" << hist->GetName() <<
"\" from file " << file->GetName()
278 template <
typename T>
283 T* phist = hist.get();
285 if (
regHist_i( std::move( hist ),
id,
true, phid ).isSuccess() ) {
289 error() <<
"regSharedHist: unable to register shared hist with id \"" <<
id <<
"\"" <<
endmsg;
293 error() <<
"regSharedHist: previously register Hist with id \"" <<
id <<
"\" was not marked shared" <<
endmsg;
296 if ( hist->Compare( hid->
obj ) != 0 ) {
297 error() <<
"regSharedHist: Histogram " <<
id <<
" does not compare with " << hid <<
endmsg;
299 T* phist =
dynamic_cast<T*
>( hid->
obj );
301 error() <<
"regSharedHist: unable to dcast retrieved shared hist \"" <<
id <<
"\" of type "
305 delete hist.release();
312 template <
typename T>
323 error() <<
"getSharedHist: found Hist with id \"" <<
name <<
"\", but it's not marked as shared" <<
endmsg;
326 T* h1 =
dynamic_cast<T*
>( hid->
obj );
330 }
else if ( i == 0 ) {
331 error() <<
"no histograms matching id \"" <<
name <<
"\" found" <<
endmsg;
333 info() <<
"multiple matches for id \"" <<
name <<
"\" found [" << i <<
"], probably from different streams"