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(); }
40 debug() <<
"regHist_i obj: " << hist <<
" id: " <<
id <<
" s: " << shared <<
endmsg;
46 error() <<
"Badly formed identifier \"" << idr <<
"\": "
47 <<
"Must not end with a /" <<
endmsg;
55 error() <<
"Could not register id: \"" << idr <<
"\"" <<
endmsg;
66 TObject*
t1 = uitr->second->at( 0 ).obj;
67 if ( hist->Compare(
t1 ) != 0 ) {
68 error() <<
"previously registered object with identifier \"" << uid <<
"\" does not compare to this one"
73 debug() <<
"previously registered id \"" << uid <<
"\": num " << uitr->second->
size() <<
endmsg;
83 TObject* to =
nullptr;
87 if ( hist != 0 ) { warning() <<
"Registering id: \"" << idr <<
"\" with non zero pointer!" <<
endmsg; }
89 hist = readHist_i<T>( idr );
90 if ( hist ==
nullptr ) {
91 error() <<
"Unable to read in hist" <<
endmsg;
95 to =
dynamic_cast<TObject*
>( hist );
98 error() <<
"Unable to read in hist with id: \"" << idr <<
"\"" <<
endmsg;
102 to =
dynamic_cast<TObject*
>( hist );
103 if ( to ==
nullptr ) {
104 error() <<
"Could not dcast to TObject. id: \"" << idr <<
"\"" <<
endmsg;
111 error() <<
"already registered id: \"" << idr <<
"\" with identifier \""
112 << oitr->second.first->
at( oitr->second.second ).id <<
"\"" <<
endmsg;
123 if ( TTree* tree =
dynamic_cast<TTree*
>( hist ) ) {
124 tree->SetDirectory( dir );
125 }
else if ( TH1* th1 =
dynamic_cast<TH1*
>( hist ) ) {
126 th1->SetDirectory( dir );
127 }
else if ( TEfficiency* teff =
dynamic_cast<TEfficiency*
>( hist ) ) {
128 teff->SetDirectory( dir );
129 }
else if (
dynamic_cast<TGraph*
>( hist ) ) {
132 error() <<
"id: \"" << idr <<
"\" is not a TH, TTree, TGraph, or TEfficiency. Attaching it to current dir."
142 fname = f->GetName();
145 debug() <<
"Registering" << ( shared ?
" shared " :
" " ) <<
System::typeinfoName(
typeid( *hist ) ) <<
" title: \""
146 << hist->GetTitle() <<
"\" id: \"" << uid
155 vhid_t* vi = uitr->second;
157 phid = &( vi->
back() );
164 phid = &( vi->
back() );
171 debug() <<
"regHist_i THistID: " << hid <<
endmsg;
176 template <
typename T>
187 if ( !quiet ) { error() <<
"could not locate Hist with id \"" <<
id <<
"\"" <<
endmsg; }
189 }
else if ( num > 1 ) {
192 error() <<
"Multiple matches with id \"" <<
id <<
"\"."
193 <<
" Further specifications required." <<
endmsg;
196 info() <<
"Found multiple matches with id \"" <<
id <<
"\"" <<
endmsg;
198 hist =
dynamic_cast<T*
>( hid->
obj );
199 if ( hist ==
nullptr ) {
200 error() <<
"dcast failed, Hist id: \"" <<
id <<
"\"" <<
endmsg;
205 hist =
dynamic_cast<T*
>( hid->
obj );
206 if ( hist ==
nullptr ) {
207 error() <<
"dcast failed, Hist id: \"" <<
id <<
"\"" <<
endmsg;
210 verbose() <<
"found unique Hist title: \"" << hist->GetTitle() <<
"\" id: \"" <<
id <<
"\"" <<
endmsg;
216 template <
typename T>
224 TFile* file =
nullptr;
229 error() <<
"no associated file found" <<
endmsg;
239 if ( !gDirectory->GetKey( dir.
c_str() ) ) {
240 error() <<
"Directory \"" << fdir2 <<
"\" doesnt exist in " << file->GetName() <<
endmsg;
243 gDirectory->cd( dir.
c_str() );
246 TObject* to =
nullptr;
247 gDirectory->GetObject( fdir.
c_str(), to );
250 error() <<
"Could not get obj \"" << fdir <<
"\" in " << gDirectory->GetPath() <<
endmsg;
254 T* hist =
dynamic_cast<T*
>( to );
255 if ( hist ==
nullptr ) {
256 error() <<
"Could not convert \"" << idr <<
"\" to a " <<
System::typeinfoName(
typeid( *hist ) ) <<
" as is a "
257 << to->IsA()->GetName() <<
endmsg;
262 debug() <<
"Read in " << hist->IsA()->GetName() <<
" \"" << hist->GetName() <<
"\" from file " << file->GetName()
270 template <
typename T>
275 T* phist = hist.
get();
281 error() <<
"regSharedHist: unable to register shared hist with id \"" <<
id <<
"\"" <<
endmsg;
285 error() <<
"regSharedHist: previously register Hist with id \"" <<
id <<
"\" was not marked shared" <<
endmsg;
288 if ( hist->Compare( hid->
obj ) != 0 ) {
289 error() <<
"regSharedHist: Histogram " <<
id <<
" does not compare with " << hid <<
endmsg;
291 T* phist =
dynamic_cast<T*
>( hid->
obj );
293 error() <<
"regSharedHist: unable to dcast retrieved shared hist \"" <<
id <<
"\" of type "
304 template <
typename T>
315 error() <<
"getSharedHist: found Hist with id \"" <<
name <<
"\", but it's not marked as shared" <<
endmsg;
318 T*
h1 =
dynamic_cast<T*
>( hid->
obj );
321 debug() <<
"getSharedHist: found THistID: " << *hid <<
endmsg;
322 }
else if ( i == 0 ) {
323 error() <<
"no histograms matching id \"" <<
name <<
"\" found" <<
endmsg;
325 info() <<
"multiple matches for id \"" <<
name <<
"\" found [" << i <<
"], probably from different streams"
331 #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*.