11 #ifndef GAUDISVC_THISTSVC_ICC
12 #define GAUDISVC_THISTSVC_ICC
20 #ifndef GAUDIKERNEL_MSGSTREAM_H
29 return regHist_i( std::move( hist ),
id, shared, hid );
39 if ( hist_unique.get() !=
nullptr ) { hist = hist_unique.release(); }
41 debug() <<
"regHist_i obj: " << hist <<
" id: " <<
id <<
" s: " << shared <<
endmsg;
44 std::string idr(
id );
47 if ( idr.find(
"/" ) == idr.length() ) {
48 error() <<
"Badly formed identifier \"" << idr <<
"\": "
49 <<
"Must not end with a /" <<
endmsg;
57 error() <<
"Could not register id: \"" << idr <<
"\"" <<
endmsg;
64 uidMap_t::iterator uitr =
m_uids.find( uid );
66 if ( uitr !=
m_uids.end() ) {
68 TObject*
t1 = uitr->second->at( 0 ).obj;
69 if ( hist->Compare(
t1 ) != 0 ) {
70 error() <<
"previously registered object with identifier \"" << uid <<
"\" does not compare to this one"
76 debug() <<
"previously registered id \"" << uid <<
"\": num " << uitr->second->size() <<
endmsg;
87 TObject* to =
nullptr;
91 if ( hist != 0 ) { warning() <<
"Registering id: \"" << idr <<
"\" with non zero pointer!" <<
endmsg; }
93 hist = readHist_i<T>( idr );
94 if ( hist ==
nullptr ) {
95 error() <<
"Unable to read in hist" <<
endmsg;
99 to =
dynamic_cast<TObject*
>( hist );
101 }
else if ( !hist ) {
102 error() <<
"Unable to read in hist with id: \"" << idr <<
"\"" <<
endmsg;
106 to =
dynamic_cast<TObject*
>( hist );
107 if ( to ==
nullptr ) {
108 error() <<
"Could not dcast to TObject. id: \"" << idr <<
"\"" <<
endmsg;
113 auto oitr =
m_tobjs.find( to );
115 error() <<
"already registered id: \"" << idr <<
"\" with identifier \""
116 << oitr->second.first->at( oitr->second.second ).id <<
"\"" <<
endmsg;
123 hid = ( findF !=
m_files.end() ?
THistID( uid, temp, to, f, findF->second.second ) :
THistID( uid, temp, to, f ) );
128 if ( TTree* tree =
dynamic_cast<TTree*
>( hist ) ) {
129 tree->SetDirectory( dir );
132 }
else if ( TH1* th1 =
dynamic_cast<TH1*
>( hist ) ) {
133 th1->SetDirectory( dir );
135 }
else if ( TEfficiency* teff =
dynamic_cast<TEfficiency*
>( hist ) ) {
136 teff->SetDirectory( dir );
138 }
else if (
dynamic_cast<TGraph*
>( hist ) ) {
142 error() <<
"id: \"" << idr <<
"\" is not a TH, TTree, TGraph, or TEfficiency. Attaching it to current dir."
152 fname = f->GetName();
156 debug() <<
"Registering" << ( shared ?
" shared " :
" " ) <<
System::typeinfoName(
typeid( *hist ) ) <<
" title: \""
157 << hist->GetTitle() <<
"\" id: \"" << uid
167 vhid_t* vi = uitr->second;
168 vi->push_back( hid );
169 phid = &( vi->back() );
171 m_tobjs.emplace( to, std::pair<vhid_t*, size_t>( vi, vi->size() - 1 ) );
176 phid = &( vi->back() );
177 m_uids.emplace( uid, vi );
180 m_tobjs.emplace( to, std::pair<vhid_t*, size_t>( vi, 0 ) );
188 template <
typename T>
199 if ( !quiet ) { error() <<
"could not locate Hist with id \"" <<
id <<
"\"" <<
endmsg; }
201 }
else if ( num > 1 ) {
204 error() <<
"Multiple matches with id \"" <<
id <<
"\"."
205 <<
" Further specifications required." <<
endmsg;
208 info() <<
"Found multiple matches with id \"" <<
id <<
"\"" <<
endmsg;
210 hist =
dynamic_cast<T*
>( hid->
obj );
211 if ( hist ==
nullptr ) {
212 error() <<
"dcast failed, Hist id: \"" <<
id <<
"\"" <<
endmsg;
217 hist =
dynamic_cast<T*
>( hid->
obj );
218 if ( hist ==
nullptr ) {
219 error() <<
"dcast failed, Hist id: \"" <<
id <<
"\"" <<
endmsg;
223 verbose() <<
"found unique Hist title: \"" << hist->GetTitle() <<
"\" id: \"" <<
id <<
"\"" <<
endmsg;
230 template <
typename T>
234 std::string idr(
id );
237 std::string
stream, rem, dir, fdir, bdir, fdir2;
238 TFile* file =
nullptr;
243 error() <<
"no associated file found" <<
endmsg;
253 if ( !gDirectory->GetKey( dir.c_str() ) ) {
254 error() <<
"Directory \"" << fdir2 <<
"\" doesnt exist in " << file->GetName() <<
endmsg;
257 gDirectory->cd( dir.c_str() );
260 TObject* to =
nullptr;
261 gDirectory->GetObject( fdir.c_str(), to );
264 error() <<
"Could not get obj \"" << fdir <<
"\" in " << gDirectory->GetPath() <<
endmsg;
268 T* hist =
dynamic_cast<T*
>( to );
269 if ( hist ==
nullptr ) {
270 error() <<
"Could not convert \"" << idr <<
"\" to a " <<
System::typeinfoName(
typeid( *hist ) ) <<
" as is a "
271 << to->IsA()->GetName() <<
endmsg;
276 debug() <<
"Read in " << hist->IsA()->GetName() <<
" \"" << hist->GetName() <<
"\" from file " << file->GetName()
284 template <
typename T>
289 T* phist = hist.get();
291 if (
regHist_i( std::move( hist ),
id,
true, phid ).isSuccess() ) {
295 error() <<
"regSharedHist: unable to register shared hist with id \"" <<
id <<
"\"" <<
endmsg;
299 error() <<
"regSharedHist: previously register Hist with id \"" <<
id <<
"\" was not marked shared" <<
endmsg;
302 if ( hist->Compare( hid->
obj ) != 0 ) {
303 error() <<
"regSharedHist: Histogram " <<
id <<
" does not compare with " << hid <<
endmsg;
305 T* phist =
dynamic_cast<T*
>( hid->
obj );
307 error() <<
"regSharedHist: unable to dcast retrieved shared hist \"" <<
id <<
"\" of type "
311 delete hist.release();
318 template <
typename T>
329 error() <<
"getSharedHist: found Hist with id \"" <<
name <<
"\", but it's not marked as shared" <<
endmsg;
332 T* h1 =
dynamic_cast<T*
>( hid->
obj );
336 }
else if ( i == 0 ) {
337 error() <<
"no histograms matching id \"" <<
name <<
"\" found" <<
endmsg;
339 info() <<
"multiple matches for id \"" <<
name <<
"\" found [" << i <<
"], probably from different streams"
345 #endif // GAUDISVC_THISTSVC_ICC