1 #ifndef GAUDISVC_THISTSVC_ICC 2 #define GAUDISVC_THISTSVC_ICC 10 #ifndef GAUDIKERNEL_MSGSTREAM_H 29 if ( hist_unique.
get() != nullptr ) { hist = hist_unique.
release(); }
30 debug() <<
"regHist_i obj: " << hist <<
" id: " <<
id <<
" s: " << shared <<
endmsg;
36 error() <<
"Badly formed identifier \"" << idr <<
"\": " 37 <<
"Must not end with a /" <<
endmsg;
45 error() <<
"Could not register id: \"" << idr <<
"\"" <<
endmsg;
56 TObject* t1 = uitr->second->at( 0 ).obj;
57 if ( hist->Compare( t1 ) != 0 ) {
58 error() <<
"previously registered object with identifier \"" << uid <<
"\" does not compare to this one" 63 debug() <<
"previously registered id \"" << uid <<
"\": num " << uitr->second->
size() <<
endmsg;
73 TObject* to =
nullptr;
77 if ( hist != 0 ) {
warning() <<
"Registering id: \"" << idr <<
"\" with non zero pointer!" <<
endmsg; }
79 hist = readHist_i<T>( idr );
80 if ( hist ==
nullptr ) {
85 to =
dynamic_cast<TObject*
>( hist );
88 error() <<
"Unable to read in hist with id: \"" << idr <<
"\"" <<
endmsg;
92 to =
dynamic_cast<TObject*
>( hist );
93 if ( to ==
nullptr ) {
94 error() <<
"Could not dcast to TObject. id: \"" << idr <<
"\"" <<
endmsg;
101 error() <<
"already registered id: \"" << idr <<
"\" with identifier \"" 102 << oitr->second.first->
at( oitr->second.second ).id <<
"\"" <<
endmsg;
113 if ( dynamic_cast<TTree*>( hist ) ) {
114 dynamic_cast<TTree*
>( hist )->SetDirectory( dir );
115 }
else if ( dynamic_cast<TH1*>( hist ) ) {
116 dynamic_cast<TH1*
>( hist )->SetDirectory( dir );
117 }
else if ( dynamic_cast<TGraph*>( hist ) ) {
120 error() <<
"id: \"" << idr <<
"\" is not a TH, TTree, or TGraph. Attaching it to current dir." <<
endmsg;
129 fname = f->GetName();
133 << hist->GetTitle() <<
"\" id: \"" << uid
142 vhid_t* vi = uitr->second;
144 phid = &( vi->
back() );
151 phid = &( vi->
back() );
163 template <
typename T>
174 if ( !quiet ) {
error() <<
"could not locate Hist with id \"" <<
id <<
"\"" <<
endmsg; }
176 }
else if ( num > 1 ) {
179 error() <<
"Multiple matches with id \"" <<
id <<
"\"." 180 <<
" Further specifications required." <<
endmsg;
183 info() <<
"Found multiple matches with id \"" <<
id <<
"\"" <<
endmsg;
185 hist =
dynamic_cast<T*
>( hid->
obj );
186 if ( hist ==
nullptr ) {
187 error() <<
"dcast failed, Hist id: \"" <<
id <<
"\"" <<
endmsg;
192 hist =
dynamic_cast<T*
>( hid->
obj );
193 if ( hist ==
nullptr ) {
194 error() <<
"dcast failed, Hist id: \"" <<
id <<
"\"" <<
endmsg;
197 verbose() <<
"found unique Hist title: \"" << hist->GetTitle() <<
"\" id: \"" <<
id <<
"\"" <<
endmsg;
203 template <
typename T>
211 TFile* file =
nullptr;
213 if ( !
findStream( idr, stream, rem, file ) ) {
return nullptr; }
226 if ( !gDirectory->GetKey( dir.
c_str() ) ) {
227 error() <<
"Directory \"" << fdir2 <<
"\" doesnt exist in " << file->GetName() <<
endmsg;
230 gDirectory->cd( dir.
c_str() );
233 TObject* to =
nullptr;
234 gDirectory->GetObject( fdir.
c_str(), to );
237 error() <<
"Could not get obj \"" << fdir <<
"\" in " << gDirectory->GetPath() <<
endmsg;
241 T* hist =
dynamic_cast<T*
>( to );
242 if ( hist ==
nullptr ) {
244 << to->IsA()->GetName() <<
endmsg;
249 debug() <<
"Read in " << hist->IsA()->GetName() <<
" \"" << hist->GetName() <<
"\" from file " << file->GetName()
257 template <
typename T>
262 T* phist = hist.
get();
268 error() <<
"regSharedHist: unable to register shared hist with id \"" <<
id <<
"\"" <<
endmsg;
272 error() <<
"regSharedHist: previously register Hist with id \"" <<
id <<
"\" was not marked shared" <<
endmsg;
275 if ( hist->Compare( hid->
obj ) != 0 ) {
276 error() <<
"regSharedHist: Histogram " <<
id <<
" does not compare with " << hid <<
endmsg;
278 T* phist =
dynamic_cast<T*
>( hid->
obj );
280 error() <<
"regSharedHist: unable to dcast retrieved shared hist \"" <<
id <<
"\" of type " 291 template <
typename T>
302 error() <<
"getSharedHist: found Hist with id \"" << name <<
"\", but it's not marked as shared" <<
endmsg;
305 T* h1 =
dynamic_cast<T*
>( hid->
obj );
308 debug() <<
"getSharedHist: found THistID: " << *hid <<
endmsg;
309 }
else if ( i == 0 ) {
310 error() <<
"no histograms matching id \"" << name <<
"\" found" <<
endmsg;
312 info() <<
"multiple matches for id \"" << name <<
"\" found [" << i <<
"], probably from different streams" 318 #endif // GAUDISVC_THISTSVC_ICC
Helper struct that bundles the histogram ID with a mutex, TFile and TObject*.
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
constexpr static const auto SUCCESS
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)
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
constexpr static const auto FAILURE
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)