The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
THistSvc.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
19#include <GaudiKernel/Service.h>
20#include <GaudiKernel/System.h>
21#include <TEfficiency.h>
22#include <TFile.h>
23#include <TGraph.h>
24#include <TH1.h>
25#include <TH2.h>
26#include <TH3.h>
27#include <TList.h>
28#include <TObject.h>
29#include <TTree.h>
30#include <map>
31#include <string>
32
33class THistSvc : public extends<Service, ITHistSvc, IIncidentListener, IIoComponent> {
34public:
35 THistSvc( const std::string& name, ISvcLocator* svcloc );
36
37 StatusCode initialize() override;
38 StatusCode reinitialize() override;
39 StatusCode finalize() override;
40
41public:
42 // Methods from ITHistSvc
45
47 StatusCode regHist( const std::string& name ) override;
51 StatusCode regHist( const std::string& name, std::unique_ptr<TH1> hist ) override;
54 StatusCode regHist( const std::string& name, TH1* ) override;
55
57 StatusCode getHist( const std::string& name, TH1*&, size_t index = 0 ) const override;
59 StatusCode getHist( const std::string& name, TH2*&, size_t index = 0 ) const override;
61 StatusCode getHist( const std::string& name, TH3*&, size_t index = 0 ) const override;
62
64
67
69 StatusCode regTree( const std::string& name ) override;
71 StatusCode regTree( const std::string& name, std::unique_ptr<TTree> ) override;
74 StatusCode regTree( const std::string& name, TTree* ) override;
76 StatusCode getTree( const std::string& name, TTree*& ) const override;
77
79
82
84 StatusCode regGraph( const std::string& name ) override;
86 StatusCode regGraph( const std::string& name, std::unique_ptr<TGraph> ) override;
89 virtual StatusCode regGraph( const std::string& name, TGraph* ) override;
91 StatusCode getGraph( const std::string& name, TGraph*& ) const override;
92
94 StatusCode regEfficiency( const std::string& name ) override;
96 StatusCode regEfficiency( const std::string& name, std::unique_ptr<TEfficiency> ) override;
99 virtual StatusCode regEfficiency( const std::string& name, TEfficiency* ) override;
101 StatusCode getEfficiency( const std::string& name, TEfficiency*& ) const override;
102
104
107
109 StatusCode regShared( const std::string& name, std::unique_ptr<TH1>, LockedHandle<TH1>& ) override;
111 StatusCode regShared( const std::string& name, std::unique_ptr<TH2>, LockedHandle<TH2>& ) override;
113 StatusCode regShared( const std::string& name, std::unique_ptr<TH3>, LockedHandle<TH3>& ) override;
115 StatusCode regShared( const std::string& name, std::unique_ptr<TGraph>, LockedHandle<TGraph>& ) override;
117 StatusCode regShared( const std::string& name, std::unique_ptr<TEfficiency>, LockedHandle<TEfficiency>& ) override;
119 StatusCode getShared( const std::string& name, LockedHandle<TH1>& ) const override;
121 StatusCode getShared( const std::string& name, LockedHandle<TH2>& ) const override;
123 StatusCode getShared( const std::string& name, LockedHandle<TH3>& ) const override;
125 StatusCode getShared( const std::string& name, LockedHandle<TGraph>& ) const override;
127 StatusCode getShared( const std::string& name, LockedHandle<TEfficiency>& ) const override;
128
130
133
135 StatusCode deReg( const std::string& name ) override;
137 StatusCode deReg( TObject* obj ) override;
138
140 StatusCode merge( const std::string& id ) override;
142 StatusCode merge( TObject* ) override;
143
146 bool exists( const std::string& name ) const override;
148 bool existsHist( const std::string& name ) const override;
150 bool existsTree( const std::string& name ) const override;
152 bool existsGraph( const std::string& name ) const override;
154 bool existsEfficiency( const std::string& name ) const override;
155
157
160
161 std::vector<std::string> getHists() const override;
162 std::vector<std::string> getTrees() const override;
163 std::vector<std::string> getGraphs() const override;
164 std::vector<std::string> getEfficiencies() const override;
165
166 StatusCode getTHists( TDirectory* td, TList&, bool recurse = false ) const override;
167 StatusCode getTHists( const std::string& name, TList&, bool recurse = false ) const override;
168 StatusCode getTHists( TDirectory* td, TList& tl, bool recurse = false, bool reg = false ) override;
169 StatusCode getTHists( const std::string& name, TList& tl, bool recurse = false, bool reg = false ) override;
170
171 StatusCode getTTrees( TDirectory* td, TList&, bool recurse = false ) const override;
172 StatusCode getTTrees( const std::string& name, TList&, bool recurse = false ) const override;
173 StatusCode getTTrees( TDirectory* td, TList& tl, bool recurse = false, bool reg = false ) override;
174 StatusCode getTTrees( const std::string& name, TList& tl, bool recurse = false, bool reg = false ) override;
175
176 StatusCode getTEfficiencies( TDirectory* td, TList&, bool recurse = false ) const override;
177 StatusCode getTEfficiencies( const std::string& name, TList&, bool recurse = false ) const override;
178 StatusCode getTEfficiencies( TDirectory* td, TList& tl, bool recurse = false, bool reg = false ) override;
179 StatusCode getTEfficiencies( const std::string& name, TList& tl, bool recurse = false, bool reg = false ) override;
180
182
183public:
184 // Methods from other interfaces
185 // From IIncidentListener
186 void handle( const Incident& ) override;
187
188 // From IIoComponent
189 StatusCode io_reinit() override;
190
191private:
192 typedef std::recursive_mutex THistSvcMutex_t;
193 typedef std::mutex histMut_t;
194
197 public:
200
201 private:
202 TDirectory* m_gDirectory;
203 TFile* m_gFile;
205 std::lock_guard<THistSvcMutex_t> m_lock;
206 };
207
210
213
215 static Mode charToMode( const char typ ) {
216 switch ( typ ) {
217 case 'O':
218 return READ;
219 case 'A':
220 return APPEND;
221 case 'R':
222 return UPDATE;
223 case 'S':
224 return SHARE;
225 default:
226 return INVALID;
227 }
228 }
229
231 struct THistID {
232 std::string id{};
233 TObject* obj{ nullptr };
234 TFile* file{ nullptr };
235 histMut_t* mutex{ nullptr };
238 bool temp{ true };
239 bool shared{ false };
240
241 THistID() = default;
242 THistID( const THistID& rhs ) = default;
243 THistID& operator=( const THistID& rhs ) = default;
244 THistID( std::string& i, bool& t, TObject* o, TFile* f ) : id( i ), obj( o ), file( f ), temp( t ) {}
245 THistID( std::string& i, bool& t, TObject* o, TFile* f, Mode m )
246 : id( i ), obj( o ), file( f ), mode( m ), temp( t ) {}
247
248 bool operator<( THistID const& rhs ) const { return ( obj < rhs.obj ); }
249
250 friend std::ostream& operator<<( std::ostream& ost, const THistID& hid ) {
251 ost << "id: " << hid.id << " t: " << hid.temp << " s: " << hid.shared << " M: " << hid.mode << " m: " << hid.mutex
252 << " o: " << hid.obj << " T: " << static_cast<int>( hid.type ) << " " << hid.obj->IsA()->GetName();
253 return ost;
254 }
255 };
256
259
260 std::vector<std::string> m_Rstream, m_Wstream;
261
264 std::set<std::string> m_alreadyConnectedInFiles;
265
268 std::set<std::string> m_alreadyConnectedOutFiles;
269
270 // containers for fast lookups
271 // same uid for all elements in vec
272 typedef std::vector<THistID> vhid_t;
273 // all THistIDs
274 typedef std::list<vhid_t*> hlist_t;
275 // uid: /stream/name -> vhid
276 typedef std::unordered_map<std::string, vhid_t*> uidMap_t;
277 // name -> vhid
278 typedef std::unordered_multimap<std::string, vhid_t*> idMap_t;
279 typedef std::unordered_map<TObject*, std::pair<vhid_t*, size_t>> objMap_t;
280
284
285 // Container holding all TObjects and vhid*s
287
288 std::map<std::string, std::pair<TFile*, Mode>> m_files; // stream->file
289 typedef std::multimap<std::string, std::string> streamMap;
290 streamMap m_fileStreams; // fileName->streams
291
292 // stream->filename of shared files
293 std::map<std::string, std::string> m_sharedFiles;
294
296
299
300 template <typename T>
301 StatusCode regHist_i( std::unique_ptr<T> hist, const std::string& name, bool shared );
302 template <typename T>
303 StatusCode regHist_i( std::unique_ptr<T> hist, const std::string& name, bool shared, THistID*& hid );
304 template <typename T>
305 T* getHist_i( const std::string& name, const size_t& ind = 0, bool quiet = false ) const;
306 template <typename T>
307 T* readHist_i( const std::string& name ) const;
308
309 template <typename T>
310 LockedHandle<T> regShared_i( const std::string& id, std::unique_ptr<T> hist );
311 template <typename T>
312 LockedHandle<T> getShared_i( const std::string& name ) const;
313
315
318
319 template <typename T>
320 T* readHist( const std::string& name ) const;
321 TTree* readTree( const std::string& name ) const;
322
324 void updateFiles();
326 StatusCode connect( const std::string& );
327 TDirectory* changeDir( const THistSvc::THistID& hid ) const;
328 std::string stripDirectoryName( std::string& dir ) const;
329 void removeDoubleSlash( std::string& ) const;
330
331 void MergeRootFile( TDirectory*, TDirectory* );
332
333 bool findStream( const std::string& name, std::string& root, std::string& rem, TFile*& file ) const;
334 void parseString( const std::string& id, std::string& root, std::string& rem ) const;
335
337 void setupInputFile();
338
340 void setupOutputFile();
341
343 void copyFileLayout( TDirectory*, TDirectory* );
344
345 size_t findHistID( const std::string& id, const THistID*& hid, const size_t& index = 0 ) const;
346
347 void dump() const;
348
350 StatusCode merge( const THistID& );
353
356
358
361
362 Gaudi::Property<int> m_autoSave{ this, "AutoSave", 0 };
363 Gaudi::Property<int> m_autoFlush{ this, "AutoFlush", 0 };
364 Gaudi::Property<bool> m_print{ this, "PrintAll", false };
365 Gaudi::Property<int> m_maxFileSize{ this, "MaxFileSize", 10240,
366 "maximum file size in MB. if exceeded,"
367 " will cause an abort. -1 to never check." };
368 Gaudi::Property<int> m_compressionLevel{ this, "CompressionLevel", 1, [this]( auto& ) {
369 this->warning()
370 << "\"CompressionLevel\" Property has been deprecated. "
371 << "Set it via the \"CL=\" parameter in the \"Output\" Property"
372 << endmsg;
373 } };
375 this, "Output", {}, &THistSvc::setupOutputFile, "", "OrderedSet<std::string>" };
377 this, "Input", {}, &THistSvc::setupInputFile, "", "OrderedSet<std::string>" };
378
380
383
384 bool m_delayConnect = false;
385 bool m_okToConnect = false;
386 bool m_hasTTrees = false;
387
388 mutable std::string m_curstream;
389
391};
392
393template <typename T>
394StatusCode THistSvc::regHist_i( std::unique_ptr<T> hist, const std::string& id, bool shared ) {
395 THistID* hid = nullptr;
396 return regHist_i( std::move( hist ), id, shared, hid );
397}
398
399template <typename T>
400StatusCode THistSvc::regHist_i( std::unique_ptr<T> hist_unique, const std::string& id, bool shared, THistID*& phid ) {
402 phid = nullptr;
403
404 // It is sad that we lose propper memory management here
405 T* hist = nullptr;
406 if ( hist_unique.get() != nullptr ) { hist = hist_unique.release(); }
407 if ( msgLevel( MSG::DEBUG ) ) {
408 debug() << "regHist_i obj: " << hist << " id: " << id << " s: " << shared << endmsg;
409 }
410
411 std::string idr( id );
412 removeDoubleSlash( idr );
413
414 if ( idr.find( "/" ) == idr.length() ) {
415 error() << "Badly formed identifier \"" << idr << "\": "
416 << "Must not end with a /" << endmsg;
417 delete hist;
418 return StatusCode::FAILURE;
419 }
420
421 TFile* f = nullptr;
422 std::string stream, name;
423 if ( !findStream( idr, stream, name, f ) ) {
424 error() << "Could not register id: \"" << idr << "\"" << endmsg;
425 delete hist;
426 return StatusCode::FAILURE;
427 }
428
429 std::string uid = "/" + stream + "/" + name;
430
431 uidMap_t::iterator uitr = m_uids.find( uid );
432 bool exists( false );
433 if ( uitr != m_uids.end() ) {
434 exists = true;
435 TObject* t1 = uitr->second->at( 0 ).obj;
436 if ( hist->Compare( t1 ) != 0 ) {
437 error() << "previously registered object with identifier \"" << uid << "\" does not compare to this one"
438 << endmsg;
439 delete hist;
440 return StatusCode::FAILURE;
441 } else {
442 if ( msgLevel( MSG::DEBUG ) ) {
443 debug() << "previously registered id \"" << uid << "\": num " << uitr->second->size() << endmsg;
444 }
445 }
446 }
447
448 bool temp = false;
449 if ( !f ) {
450 temp = true;
451 if ( msgLevel( MSG::DEBUG ) ) { debug() << "Historgram with id \"" << idr << "\" is temporary" << endmsg; }
452 }
453
454 TObject* to = nullptr;
455 THistID hid;
456 // check to see if this hist is to be read in;
457 if ( !temp && m_files.find( stream )->second.second == READ ) {
458 if ( hist != 0 ) { warning() << "Registering id: \"" << idr << "\" with non zero pointer!" << endmsg; }
459
460 hist = readHist_i<T>( idr );
461 if ( hist == nullptr ) {
462 error() << "Unable to read in hist" << endmsg;
463 delete hist;
464 return StatusCode::FAILURE;
465 }
466 to = dynamic_cast<TObject*>( hist );
467 hid = THistID( uid, temp, to, f, m_files.find( stream )->second.second );
468 } else if ( !hist ) {
469 error() << "Unable to read in hist with id: \"" << idr << "\"" << endmsg;
470 delete hist;
471 return StatusCode::FAILURE;
472 } else {
473 to = dynamic_cast<TObject*>( hist );
474 if ( to == nullptr ) {
475 error() << "Could not dcast to TObject. id: \"" << idr << "\"" << endmsg;
476 delete hist;
477 return StatusCode::FAILURE;
478 }
479
480 auto oitr = m_tobjs.find( to );
481 if ( oitr != m_tobjs.end() ) {
482 error() << "already registered id: \"" << idr << "\" with identifier \""
483 << oitr->second.first->at( oitr->second.second ).id << "\"" << endmsg;
484 delete hist;
485 return StatusCode::FAILURE;
486 }
487 }
488
489 const auto findF = m_files.find( stream );
490 hid = ( findF != m_files.end() ? THistID( uid, temp, to, f, findF->second.second ) : THistID( uid, temp, to, f ) );
491
492 hid.shared = shared;
493 TDirectory* dir = changeDir( hid );
494
495 if ( TTree* tree = dynamic_cast<TTree*>( hist ) ) {
496 tree->SetDirectory( dir );
498 m_hasTTrees = true; // at least one TTree is registered
499 } else if ( TH1* th1 = dynamic_cast<TH1*>( hist ) ) {
500 th1->SetDirectory( dir );
501 hid.type = ObjectType::TH1;
502 } else if ( TEfficiency* teff = dynamic_cast<TEfficiency*>( hist ) ) {
503 teff->SetDirectory( dir );
505 } else if ( dynamic_cast<TGraph*>( hist ) ) {
506 dir->Append( hist );
508 } else {
509 error() << "id: \"" << idr << "\" is not a TH, TTree, TGraph, or TEfficiency. Attaching it to current dir."
510 << endmsg;
511 dir->Append( hist );
513 }
514
515 std::string fname;
516 if ( !f ) {
517 fname = "none";
518 } else {
519 fname = f->GetName();
520 }
521
522 if ( msgLevel( MSG::DEBUG ) ) {
523 debug() << "Registering" << ( shared ? " shared " : " " ) << System::typeinfoName( typeid( *hist ) ) << " title: \""
524 << hist->GetTitle() << "\" id: \"" << uid
525 << "\" dir: "
526 // << hist->GetDirectory()->GetPath() << " "
527 << changeDir( hid )->GetPath() << " file: " << fname << endmsg;
528 }
529
530 // create a mutex for all shared histograms
531 if ( shared ) { hid.mutex = new histMut_t; }
532
533 if ( exists ) {
534 vhid_t* vi = uitr->second;
535 vi->push_back( hid );
536 phid = &( vi->back() );
537
538 m_tobjs.emplace( to, std::pair<vhid_t*, size_t>( vi, vi->size() - 1 ) );
539 } else {
540 vhid_t* vi = new vhid_t{ hid };
541 m_hlist.emplace( m_hlist.end(), vi );
542
543 phid = &( vi->back() );
544 m_uids.emplace( uid, vi );
545 m_ids.emplace( name, vi );
546
547 m_tobjs.emplace( to, std::pair<vhid_t*, size_t>( vi, 0 ) );
548 }
549
550 if ( msgLevel( MSG::DEBUG ) ) { debug() << "regHist_i THistID: " << hid << endmsg; }
551
552 return StatusCode::SUCCESS;
553}
554
555template <typename T>
556T* THistSvc::getHist_i( const std::string& id, const size_t& ind, bool quiet ) const {
557 // id starts with "/": unique
558
560
561 T* hist = nullptr;
562 const THistID* hid = nullptr;
563 size_t num = findHistID( id, hid, ind );
564 if ( num == 0 ) {
565 // no matches found
566 if ( !quiet ) { error() << "could not locate Hist with id \"" << id << "\"" << endmsg; }
567 return nullptr;
568 } else if ( num > 1 ) {
569 if ( !quiet ) {
570 // return failure if trying to GET a single hist
571 error() << "Multiple matches with id \"" << id << "\"."
572 << " Further specifications required." << endmsg;
573 return nullptr;
574 } else {
575 info() << "Found multiple matches with id \"" << id << "\"" << endmsg;
576 // return first match if just INQUIRING (i.e. != nullptr)
577 hist = dynamic_cast<T*>( hid->obj );
578 if ( hist == nullptr ) {
579 error() << "dcast failed, Hist id: \"" << id << "\"" << endmsg;
580 return nullptr;
581 }
582 }
583 } else {
584 hist = dynamic_cast<T*>( hid->obj );
585 if ( hist == nullptr ) {
586 error() << "dcast failed, Hist id: \"" << id << "\"" << endmsg;
587 return nullptr;
588 }
589 if ( msgLevel( MSG::VERBOSE ) ) {
590 verbose() << "found unique Hist title: \"" << hist->GetTitle() << "\" id: \"" << id << "\"" << endmsg;
591 }
592 }
593
594 return hist;
595}
596
597template <typename T>
598T* THistSvc::readHist_i( const std::string& id ) const {
600
601 std::string idr( id );
602 removeDoubleSlash( idr );
603
604 std::string stream, rem, dir, fdir, bdir, fdir2;
605 TFile* file = nullptr;
606
607 if ( !findStream( idr, stream, rem, file ) ) { return nullptr; }
608
609 if ( !file ) {
610 error() << "no associated file found" << endmsg;
611 return nullptr;
612 }
613
614 file->cd( "/" );
615
616 fdir = idr;
617 bdir = stripDirectoryName( fdir );
618 fdir2 = fdir;
619 while ( ( dir = stripDirectoryName( fdir ) ) != "" ) {
620 if ( !gDirectory->GetKey( dir.c_str() ) ) {
621 error() << "Directory \"" << fdir2 << "\" doesnt exist in " << file->GetName() << endmsg;
622 return nullptr;
623 }
624 gDirectory->cd( dir.c_str() );
625 }
626
627 TObject* to = nullptr;
628 gDirectory->GetObject( fdir.c_str(), to );
629
630 if ( !to ) {
631 error() << "Could not get obj \"" << fdir << "\" in " << gDirectory->GetPath() << endmsg;
632 return nullptr;
633 }
634
635 T* hist = dynamic_cast<T*>( to );
636 if ( hist == nullptr ) {
637 error() << "Could not convert \"" << idr << "\" to a " << System::typeinfoName( typeid( *hist ) ) << " as is a "
638 << to->IsA()->GetName() << endmsg;
639 return nullptr;
640 }
641
642 if ( msgLevel( MSG::DEBUG ) ) {
643 debug() << "Read in " << hist->IsA()->GetName() << " \"" << hist->GetName() << "\" from file " << file->GetName()
644 << endmsg;
645 hist->Print();
646 }
647
648 return hist;
649}
650
651template <typename T>
652LockedHandle<T> THistSvc::regShared_i( const std::string& id, std::unique_ptr<T> hist ) {
653 LockedHandle<T> lh( nullptr, nullptr );
654 const THistID* hid = nullptr;
655 if ( findHistID( id, hid ) == 0 ) {
656 T* phist = hist.get();
657 THistID* phid = nullptr;
658 if ( regHist_i( std::move( hist ), id, true, phid ).isSuccess() ) {
659 lh.set( phist, phid->mutex );
660
661 } else {
662 error() << "regSharedHist: unable to register shared hist with id \"" << id << "\"" << endmsg;
663 }
664 } else {
665 if ( !hid->shared ) {
666 error() << "regSharedHist: previously register Hist with id \"" << id << "\" was not marked shared" << endmsg;
667 }
668
669 if ( hist->Compare( hid->obj ) != 0 ) {
670 error() << "regSharedHist: Histogram " << id << " does not compare with " << hid << endmsg;
671 } else {
672 T* phist = dynamic_cast<T*>( hid->obj );
673 if ( phist == 0 ) {
674 error() << "regSharedHist: unable to dcast retrieved shared hist \"" << id << "\" of type "
675 << hid->obj->IsA()->GetName() << " to requested type " << System::typeinfoName( typeid( T ) ) << endmsg;
676 } else {
677 lh.set( phist, hid->mutex );
678 delete hist.release();
679 }
680 }
681 }
682 return lh;
683}
684
685template <typename T>
686LockedHandle<T> THistSvc::getShared_i( const std::string& name ) const {
688
689 const THistID* hid = nullptr;
690 size_t i = findHistID( name, hid );
691
692 LockedHandle<T> hist( nullptr, nullptr );
693
694 if ( i == 1 ) {
695 if ( !hid->shared ) {
696 error() << "getSharedHist: found Hist with id \"" << name << "\", but it's not marked as shared" << endmsg;
697 return hist;
698 }
699 T* h1 = dynamic_cast<T*>( hid->obj );
700 hist = LockedHandle<T>( h1, hid->mutex );
701
702 if ( msgLevel( MSG::DEBUG ) ) { debug() << "getSharedHist: found THistID: " << *hid << endmsg; }
703 } else if ( i == 0 ) {
704 error() << "no histograms matching id \"" << name << "\" found" << endmsg;
705 } else {
706 info() << "multiple matches for id \"" << name << "\" found [" << i << "], probably from different streams"
707 << endmsg;
708 }
709 return hist;
710}
#define FILEMGR_CALLBACK_ARGS
Definition IFileMgr.h:272
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
TemplatedAlg< int, std::vector< std::string > > t1
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
Base class for all Incidents (computing events).
Definition Incident.h:24
Provides automatic lock/unlock access to a class upon deref of ptr.
void set(T *ptr, MutexType *mut)
Handle to be used in lieu of naked pointers to services.
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
Helper class that manages ROOts global directory and file.
Definition THistSvc.h:196
GlobalDirectoryRestore(THistSvcMutex_t &mut)
std::lock_guard< THistSvcMutex_t > m_lock
Definition THistSvc.h:205
StatusCode finalize() override
Definition THistSvc.cpp:193
std::recursive_mutex THistSvcMutex_t
Definition THistSvc.h:192
LockedHandle< T > regShared_i(const std::string &id, std::unique_ptr< T > hist)
Definition THistSvc.h:652
StatusCode io_reinit() override
callback method to reinitialize the internal state of the component for I/O purposes (e....
idMap_t m_ids
Definition THistSvc.h:283
StatusCode initialize() override
Definition THistSvc.cpp:82
bool existsHist(const std::string &name) const override
Check if histogram with given name is managed by THistSvcMT.
Definition THistSvc.cpp:669
T * getHist_i(const std::string &name, const size_t &ind=0, bool quiet=false) const
Definition THistSvc.h:556
T * readHist_i(const std::string &name) const
Definition THistSvc.h:598
Mode
Enumerating all possible file access modes.
Definition THistSvc.h:209
Gaudi::Property< int > m_maxFileSize
Definition THistSvc.h:365
StatusCode regShared(const std::string &name, std::unique_ptr< TH1 >, LockedHandle< TH1 > &) override
Register shared object of type TH1 and return LockedHandle for that object.
Definition THistSvc.cpp:470
ServiceHandle< IIncidentSvc > p_incSvc
Definition THistSvc.h:381
std::vector< std::string > m_Wstream
Definition THistSvc.h:260
size_t findHistID(const std::string &id, const THistID *&hid, const size_t &index=0) const
StatusCode getHist(const std::string &name, TH1 *&, size_t index=0) const override
Return histogram with given name as TH1*, THistSvcMT still owns object.
Definition THistSvc.cpp:344
T * readHist(const std::string &name) const
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
Definition THistSvc.cpp:912
void setupOutputFile()
call-back method to handle output stream property
Gaudi::Property< int > m_compressionLevel
Definition THistSvc.h:368
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition THistSvc.h:288
objMap_t m_tobjs
Definition THistSvc.h:286
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...
Definition THistSvc.cpp:667
void setupInputFile()
call-back method to handle input stream property
StatusCode connect(const std::string &)
std::unordered_multimap< std::string, vhid_t * > idMap_t
Definition THistSvc.h:278
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition THistSvc.h:394
Gaudi::Property< std::vector< std::string > > m_inputfile
Definition THistSvc.h:376
bool m_delayConnect
Definition THistSvc.h:384
std::unordered_map< std::string, vhid_t * > uidMap_t
Definition THistSvc.h:276
bool m_hasTTrees
Definition THistSvc.h:386
uidMap_t m_uids
Definition THistSvc.h:282
ObjectType
Possible TObject types.
Definition THistSvc.h:212
std::vector< THistID > vhid_t
Definition THistSvc.h:272
std::vector< std::string > getEfficiencies() const override
Definition THistSvc.cpp:705
std::vector< std::string > getHists() const override
Definition THistSvc.cpp:681
bool m_okToConnect
Definition THistSvc.h:385
StatusCode regTree(const std::string &name) override
Register a new TTree with a given name.
Definition THistSvc.cpp:371
ServiceHandle< IFileMgr > p_fileMgr
Definition THistSvc.h:382
bool existsEfficiency(const std::string &name) const override
Check if TEfficiency with given name is managed by THistSvcMT.
Definition THistSvc.cpp:671
TDirectory * changeDir(const THistSvc::THistID &hid) const
void MergeRootFile(TDirectory *, TDirectory *)
Gaudi::Property< std::vector< std::string > > m_outputfile
Definition THistSvc.h:374
std::list< vhid_t * > hlist_t
Definition THistSvc.h:274
void dump() const
std::string stripDirectoryName(std::string &dir) const
static Mode charToMode(const char typ)
Convert a char to a Mode enum.
Definition THistSvc.h:215
TTree * readTree(const std::string &name) const
StatusCode merge(const std::string &id) override
Merge all clones for object with a given id.
Definition THistSvc.cpp:647
Gaudi::Property< int > m_autoSave
Definition THistSvc.h:362
StatusCode deReg(const std::string &name) override
Deregister object with given name and give up ownership (without deletion!)
Definition THistSvc.cpp:561
void handle(const Incident &) override
void copyFileLayout(TDirectory *, TDirectory *)
helper function to recursively copy the layout of a TFile into a new TFile
StatusCode getShared(const std::string &name, LockedHandle< TH1 > &) const override
Retrieve shared object with given name as TH1 through LockedHandle.
Definition THistSvc.cpp:516
hlist_t m_hlist
Definition THistSvc.h:281
std::map< std::string, std::string > m_sharedFiles
Definition THistSvc.h:293
std::multimap< std::string, std::string > streamMap
Definition THistSvc.h:289
void parseString(const std::string &id, std::string &root, std::string &rem) const
std::vector< std::string > m_Rstream
Definition THistSvc.h:260
StatusCode writeObjectsToFile()
Gaudi::Property< int > m_autoFlush
Definition THistSvc.h:363
void removeDoubleSlash(std::string &) const
StatusCode rootOpenAction(FILEMGR_CALLBACK_ARGS)
std::string m_curstream
Definition THistSvc.h:388
Gaudi::Property< bool > m_print
Definition THistSvc.h:364
THistSvcMutex_t m_svcMut
Definition THistSvc.h:390
void updateFiles()
Handle case where TTree grows beyond TTree::fgMaxTreeSize.
LockedHandle< T > getShared_i(const std::string &name) const
Definition THistSvc.h:686
std::vector< std::string > getTrees() const override
Definition THistSvc.cpp:689
std::mutex histMut_t
Definition THistSvc.h:193
std::set< std::string > m_alreadyConnectedOutFiles
list of already connected files.
Definition THistSvc.h:268
StatusCode regEfficiency(const std::string &name) override
Register a new TEfficiency with a given name.
Definition THistSvc.cpp:447
StatusCode reinitialize() override
Definition THistSvc.cpp:187
std::vector< std::string > getGraphs() const override
Definition THistSvc.cpp:697
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
streamMap m_fileStreams
Definition THistSvc.h:290
std::unordered_map< TObject *, std::pair< vhid_t *, size_t > > objMap_t
Definition THistSvc.h:279
StatusCode getEfficiency(const std::string &name, TEfficiency *&) const override
Return TEfficiency with given name.
Definition THistSvc.cpp:461
bool existsGraph(const std::string &name) const override
Check if graph with given name is managed by THistSvcMT.
Definition THistSvc.cpp:675
bool existsTree(const std::string &name) const override
Check if tree with given name is managed by THistSvcMT.
Definition THistSvc.cpp:679
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
Definition THistSvc.h:264
StatusCode rootOpenErrAction(FILEMGR_CALLBACK_ARGS)
StatusCode getTree(const std::string &name, TTree *&) const override
Return TTree with given name.
Definition THistSvc.cpp:397
StatusCode regGraph(const std::string &name) override
Register a new TGraph with a given name.
Definition THistSvc.cpp:406
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
Definition THistSvc.cpp:713
StatusCode regHist(const std::string &name) override
Register a new ROOT histogram TH*X with a name.
Definition THistSvc.cpp:330
StatusCode getTEfficiencies(TDirectory *td, TList &, bool recurse=false) const override
StatusCode getGraph(const std::string &name, TGraph *&) const override
Return TGraph with given name.
Definition THistSvc.cpp:438
THistSvc(const std::string &name, ISvcLocator *svcloc)
Definition THistSvc.cpp:79
Base class used to extend a class implementing other interfaces.
Definition extends.h:19
@ DEBUG
Definition IMessageSvc.h:22
@ VERBOSE
Definition IMessageSvc.h:22
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition System.cpp:260
Helper struct that bundles the histogram ID with a mutex, TFile and TObject*.
Definition THistSvc.h:231
TObject * obj
Definition THistSvc.h:233
bool operator<(THistID const &rhs) const
Definition THistSvc.h:248
histMut_t * mutex
Definition THistSvc.h:235
THistID(const THistID &rhs)=default
THistID(std::string &i, bool &t, TObject *o, TFile *f)
Definition THistSvc.h:244
ObjectType type
Definition THistSvc.h:237
std::string id
Definition THistSvc.h:232
THistID & operator=(const THistID &rhs)=default
friend std::ostream & operator<<(std::ostream &ost, const THistID &hid)
Definition THistSvc.h:250
THistID(std::string &i, bool &t, TObject *o, TFile *f, Mode m)
Definition THistSvc.h:245