1 #ifndef GAUDISVC_THISTSVC_ICC 2 #define GAUDISVC_THISTSVC_ICC 10 #ifndef GAUDIKERNEL_MSGSTREAM_H 31 if( hist_unique.
get() != nullptr ) {
34 debug() <<
"regHist_i obj: " << hist <<
" id: " <<
id <<
" s: " << shared <<
endmsg;
40 error() <<
"Badly formed identifier \"" << idr <<
"\": " 41 <<
"Must not end with a /" <<
endmsg;
49 error() <<
"Could not register id: \"" << idr <<
"\"" <<
endmsg;
60 TObject* t1 = uitr->second->at( 0 ).obj;
61 if ( hist->Compare( t1 ) != 0 ) {
62 error() <<
"previously registered object with identifier \"" << uid <<
"\" does not compare to this one" 67 debug() <<
"previously registered id \"" << uid <<
"\": num " << uitr->second->
size() <<
endmsg;
75 debug() <<
"Historgram with id \"" << idr <<
"\" is temporary" <<
endmsg;
79 TObject* to =
nullptr;
84 warning() <<
"Registering id: \"" << idr <<
"\" with non zero pointer!" <<
endmsg;
87 hist = readHist_i<T>( idr );
88 if ( hist ==
nullptr ) {
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;
109 error() <<
"already registered id: \"" << idr <<
"\" with identifier \"" 110 << oitr->second.first->
at( oitr->second.second ).id <<
"\"" <<
endmsg;
119 if ( dynamic_cast<TTree*>( hist ) ) {
120 dynamic_cast<TTree*
>( hist )->SetDirectory( dir );
121 }
else if ( dynamic_cast<TH1*>( hist) ) {
122 dynamic_cast<TH1*
>( hist )->SetDirectory( dir );
123 }
else if ( dynamic_cast<TGraph*>( hist ) ) {
126 error() <<
"id: \"" << idr <<
"\" is not a TH, TTree, or TGraph. Attaching it to current dir." <<
endmsg;
135 fname = f->GetName();
139 << hist->GetTitle() <<
"\" id: \"" << uid
150 vhid_t* vi = uitr->second;
152 phid = &( vi->
back() );
159 phid = &( vi->
back() );
171 template <
typename T>
184 error() <<
"could not locate Hist with id \"" <<
id <<
"\"" <<
endmsg;
187 }
else if ( num > 1 ) {
190 error() <<
"Multiple matches with id \"" <<
id <<
"\"." 191 <<
" Further specifications required." <<
endmsg;
194 info() <<
"Found multiple matches with id \"" <<
id <<
"\"" <<
endmsg;
196 hist =
dynamic_cast<T*
>( hid->
obj );
197 if ( hist ==
nullptr ) {
198 error() <<
"dcast failed, Hist id: \"" <<
id <<
"\"" <<
endmsg;
203 hist =
dynamic_cast<T*
>( hid->
obj );
204 if ( hist ==
nullptr ) {
205 error() <<
"dcast failed, Hist id: \"" <<
id <<
"\"" <<
endmsg;
208 verbose() <<
"found unique Hist title: \"" << hist->GetTitle() <<
"\" id: \"" <<
id <<
"\"" <<
endmsg;
214 template <
typename T>
223 TFile* file =
nullptr;
225 if ( !
findStream( idr, stream, rem, file ) ) {
240 if ( !gDirectory->GetKey( dir.
c_str() ) ) {
241 error() <<
"Directory \"" << fdir2 <<
"\" doesnt exist in " << file->GetName() <<
endmsg;
244 gDirectory->cd( dir.
c_str() );
247 TObject* to =
nullptr;
248 gDirectory->GetObject( fdir.
c_str(), to );
251 error() <<
"Could not get obj \"" << fdir <<
"\" in " << gDirectory->GetPath() <<
endmsg;
255 T* hist =
dynamic_cast<T*
>( to );
256 if ( hist ==
nullptr ) {
258 << to->IsA()->GetName() <<
endmsg;
263 debug() <<
"Read in " << hist->IsA()->GetName() <<
" \"" << hist->GetName() <<
"\" from file " << file->GetName()
271 template <
typename T>
277 T* phist = hist.
get();
283 error() <<
"regSharedHist: unable to register shared hist with id \"" <<
id <<
"\"" <<
endmsg;
287 error() <<
"regSharedHist: previously register Hist with id \"" <<
id <<
"\" was not marked shared" <<
endmsg;
290 if ( hist->Compare( hid->
obj ) != 0 ) {
291 error() <<
"regSharedHist: Histogram " <<
id <<
" does not compare with " << hid <<
endmsg;
293 T* phist =
dynamic_cast<T*
>( hid->
obj );
295 error() <<
"regSharedHist: unable to dcast retrieved shared hist \"" <<
id <<
"\" of type " 306 template <
typename T>
318 error() <<
"getSharedHist: found Hist with id \"" << name <<
"\", but it's not marked as shared" <<
endmsg;
321 T* h1 =
dynamic_cast<T*
>( hid->
obj );
324 debug() <<
"getSharedHist: found THistID: " << *hid <<
endmsg;
325 }
else if ( i == 0 ) {
326 error() <<
"no histograms matching id \"" << name <<
"\" found" <<
endmsg;
328 info() <<
"multiple matches for id \"" << name <<
"\" found [" << i <<
"], probably from different streams" 334 #endif // GAUDISVC_THISTSVC_ICC
Helper struct that bundles the histogram ID with a mutex, TFile and TObject*.
constexpr static const auto FAILURE
const std::string & name() const override
Retrieve name of the service.
LockedHandle< T > regShared_i(const std::string &id, std::unique_ptr< T > hist)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
bool exists(const std::string &name) const override
Check if object with given name is managed by THistSvcMT.
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
LockedHandle< T > getShared_i(const std::string &name) const
T * readHist_i(const std::string &name) const
TDirectory * changeDir(const THistSvc::THistID &hid) const
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
std::string stripDirectoryName(std::string &dir) const
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
void set(T *ptr, MutexType *mut)
This class is used for returning status codes from appropriate routines.
Provides automatic lock/unlock access to a class upon deref of ptr.
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
constexpr static const auto SUCCESS
T * getHist_i(const std::string &name, const size_t &ind=0, bool quiet=false) const
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
std::map< std::string, std::pair< TFile *, Mode > > m_files
size_t findHistID(const std::string &id, const THistID *&hid, const size_t &index=0) const
Helper class that manages ROOts global directory and file.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
void removeDoubleSlash(std::string &) const
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)