Go to the documentation of this file.
11 #ifndef GAUDISVC_THISTSVC_ICC
12 #define GAUDISVC_THISTSVC_ICC
20 #ifndef GAUDIKERNEL_MSGSTREAM_H
39 if ( hist_unique.
get() !=
nullptr ) { hist = hist_unique.
release(); }
41 debug() <<
"regHist_i obj: " << hist <<
" id: " <<
id <<
" s: " << shared <<
endmsg;
48 error() <<
"Badly formed identifier \"" << idr <<
"\": "
49 <<
"Must not end with a /" <<
endmsg;
57 error() <<
"Could not register id: \"" << idr <<
"\"" <<
endmsg;
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;
115 error() <<
"already registered id: \"" << idr <<
"\" with identifier \""
116 << oitr->second.first->
at( oitr->second.second ).id <<
"\"" <<
endmsg;
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;
169 phid = &( vi->
back() );
176 phid = &( vi->
back() );
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>
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();
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 "
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
T * readHist_i(const std::string &name) const
LockedHandle< T > regShared_i(const std::string &id, std::unique_ptr< T > hist)
void set(T *ptr, MutexType *mut)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
std::string stripDirectoryName(std::string &dir) const
LockedHandle< T > getShared_i(const std::string &name) const
const std::string & name() const override
Retrieve name of the service
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
TDirectory * changeDir(const THistSvc::THistID &hid) const
void removeDoubleSlash(std::string &) const
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Helper class that manages ROOts global directory and file.
T * getHist_i(const std::string &name, const size_t &ind=0, bool quiet=false) const
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
constexpr static const auto SUCCESS
std::map< std::string, std::pair< TFile *, Mode > > m_files
bool exists(const std::string &name) const override
Check if object with given name is managed by THistSvcMT exists calls existsHist and only works for T...
constexpr static const auto FAILURE
size_t findHistID(const std::string &id, const THistID *&hid, const size_t &index=0) const
Helper struct that bundles the histogram ID with a mutex, TFile and TObject*.