The Gaudi Framework  master (ba5b4fb7)
Loading...
Searching...
No Matches
THistSvc.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 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 <memory>
32#include <string>
33
34class THistSvc : public extends<Service, ITHistSvc, IIncidentListener, IIoComponent> {
35public:
36 THistSvc( const std::string& name, ISvcLocator* svcloc );
37
38 StatusCode initialize() override;
39 StatusCode reinitialize() override;
40 StatusCode finalize() override;
41
42public:
43 // Methods from ITHistSvc
46
48 StatusCode regHist( const std::string& name ) override;
52 StatusCode regHist( const std::string& name, std::unique_ptr<TH1> hist ) override;
55 StatusCode regHist( const std::string& name, TH1* ) override;
56
58 StatusCode getHist( const std::string& name, TH1*&, size_t index = 0 ) const override;
60 StatusCode getHist( const std::string& name, TH2*&, size_t index = 0 ) const override;
62 StatusCode getHist( const std::string& name, TH3*&, size_t index = 0 ) const override;
63
65
68
70 StatusCode regTree( const std::string& name ) override;
72 StatusCode regTree( const std::string& name, std::unique_ptr<TTree> ) override;
75 StatusCode regTree( const std::string& name, TTree* ) override;
77 StatusCode getTree( const std::string& name, TTree*& ) const override;
78
80
83
85 StatusCode regGraph( const std::string& name ) override;
87 StatusCode regGraph( const std::string& name, std::unique_ptr<TGraph> ) override;
90 virtual StatusCode regGraph( const std::string& name, TGraph* ) override;
92 StatusCode getGraph( const std::string& name, TGraph*& ) const override;
93
95 StatusCode regEfficiency( const std::string& name ) override;
97 StatusCode regEfficiency( const std::string& name, std::unique_ptr<TEfficiency> ) override;
100 virtual StatusCode regEfficiency( const std::string& name, TEfficiency* ) override;
102 StatusCode getEfficiency( const std::string& name, TEfficiency*& ) const override;
103
105
108
110 StatusCode regShared( const std::string& name, std::unique_ptr<TH1>, LockedHandle<TH1>& ) override;
112 StatusCode regShared( const std::string& name, std::unique_ptr<TH2>, LockedHandle<TH2>& ) override;
114 StatusCode regShared( const std::string& name, std::unique_ptr<TH3>, LockedHandle<TH3>& ) override;
116 StatusCode regShared( const std::string& name, std::unique_ptr<TGraph>, LockedHandle<TGraph>& ) override;
118 StatusCode regShared( const std::string& name, std::unique_ptr<TEfficiency>, LockedHandle<TEfficiency>& ) override;
120 StatusCode getShared( const std::string& name, LockedHandle<TH1>& ) const override;
122 StatusCode getShared( const std::string& name, LockedHandle<TH2>& ) const override;
124 StatusCode getShared( const std::string& name, LockedHandle<TH3>& ) const override;
126 StatusCode getShared( const std::string& name, LockedHandle<TGraph>& ) const override;
128 StatusCode getShared( const std::string& name, LockedHandle<TEfficiency>& ) const override;
129
131
134
136 StatusCode deReg( const std::string& name ) override;
138 StatusCode deReg( TObject* obj ) override;
139
141 StatusCode merge( const std::string& id ) override;
143 StatusCode merge( TObject* ) override;
144
147 bool exists( const std::string& name ) const override;
149 bool existsHist( const std::string& name ) const override;
151 bool existsTree( const std::string& name ) const override;
153 bool existsGraph( const std::string& name ) const override;
155 bool existsEfficiency( const std::string& name ) const override;
156
158
161
162 std::vector<std::string> getHists() const override;
163 std::vector<std::string> getTrees() const override;
164 std::vector<std::string> getGraphs() const override;
165 std::vector<std::string> getEfficiencies() const override;
166
167 StatusCode getTHists( TDirectory* td, TList&, bool recurse = false ) const override;
168 StatusCode getTHists( const std::string& name, TList&, bool recurse = false ) const override;
169 StatusCode getTHists( TDirectory* td, TList& tl, bool recurse = false, bool reg = false ) override;
170 StatusCode getTHists( const std::string& name, TList& tl, bool recurse = false, bool reg = false ) override;
171
172 StatusCode getTTrees( TDirectory* td, TList&, bool recurse = false ) const override;
173 StatusCode getTTrees( const std::string& name, TList&, bool recurse = false ) const override;
174 StatusCode getTTrees( TDirectory* td, TList& tl, bool recurse = false, bool reg = false ) override;
175 StatusCode getTTrees( const std::string& name, TList& tl, bool recurse = false, bool reg = false ) override;
176
177 StatusCode getTEfficiencies( TDirectory* td, TList&, bool recurse = false ) const override;
178 StatusCode getTEfficiencies( const std::string& name, TList&, bool recurse = false ) const override;
179 StatusCode getTEfficiencies( TDirectory* td, TList& tl, bool recurse = false, bool reg = false ) override;
180 StatusCode getTEfficiencies( const std::string& name, TList& tl, bool recurse = false, bool reg = false ) override;
181
183
184public:
185 // Methods from other interfaces
186 // From IIncidentListener
187 void handle( const Incident& ) override;
188
189 // From IIoComponent
190 StatusCode io_reinit() override;
191
192private:
193 typedef std::recursive_mutex THistSvcMutex_t;
194 typedef std::mutex histMut_t;
195
198 public:
201
202 private:
203 TDirectory* m_gDirectory;
204 TFile* m_gFile;
206 std::lock_guard<THistSvcMutex_t> m_lock;
207 };
208
211
214
216 static Mode charToMode( const char typ ) {
217 switch ( typ ) {
218 case 'O':
219 return READ;
220 case 'A':
221 return APPEND;
222 case 'R':
223 return UPDATE;
224 case 'S':
225 return SHARE;
226 default:
227 return INVALID;
228 }
229 }
230
232 struct THistID {
233 std::string id{};
234 TObject* obj{ nullptr };
235 TFile* file{ nullptr };
236 std::unique_ptr<histMut_t> mutex;
239 bool temp{ true };
240 bool shared{ false };
241
242 THistID() = default;
243 ~THistID() = default;
244 THistID( const THistID& rhs ) = delete;
245 THistID& operator=( const THistID& rhs ) = delete;
246 THistID( THistID&& rhs ) = default;
247 THistID& operator=( THistID&& rhs ) = default;
248 THistID( std::string& i, bool& t, TObject* o, TFile* f ) : id( i ), obj( o ), file( f ), temp( t ) {}
249 THistID( std::string& i, bool& t, TObject* o, TFile* f, Mode m )
250 : id( i ), obj( o ), file( f ), mode( m ), temp( t ) {}
251
252 bool operator<( THistID const& rhs ) const { return ( obj < rhs.obj ); }
253
254 friend std::ostream& operator<<( std::ostream& ost, const THistID& hid ) {
255 ost << "id: " << hid.id << " t: " << hid.temp << " s: " << hid.shared << " M: " << hid.mode
256 << " m: " << hid.mutex.get() << " o: " << hid.obj << " T: " << static_cast<int>( hid.type ) << " "
257 << hid.obj->IsA()->GetName();
258 return ost;
259 }
260 };
261
264
265 std::vector<std::string> m_Rstream, m_Wstream;
266
269 std::set<std::string> m_alreadyConnectedInFiles;
270
273 std::set<std::string> m_alreadyConnectedOutFiles;
274
275 // containers for fast lookups
276 // same uid for all elements in vec
277 typedef std::vector<THistID> vhid_t;
278 // all THistIDs
279 typedef std::list<vhid_t*> hlist_t;
280 // uid: /stream/name -> vhid
281 typedef std::unordered_map<std::string, vhid_t*> uidMap_t;
282 // name -> vhid
283 typedef std::unordered_multimap<std::string, vhid_t*> idMap_t;
284 typedef std::unordered_map<TObject*, std::pair<vhid_t*, size_t>> objMap_t;
285
289
290 // Container holding all TObjects and vhid*s
292
293 std::map<std::string, std::pair<TFile*, Mode>> m_files; // stream->file
294 typedef std::multimap<std::string, std::string> streamMap;
295 streamMap m_fileStreams; // fileName->streams
296
297 // stream->filename of shared files
298 std::map<std::string, std::string> m_sharedFiles;
299
301
304
305 template <typename T>
306 StatusCode regHist_i( std::unique_ptr<T> hist, const std::string& name, bool shared );
307 template <typename T>
308 StatusCode regHist_i( std::unique_ptr<T> hist, const std::string& name, bool shared, THistID*& hid );
309 template <typename T>
310 T* getHist_i( const std::string& name, const size_t& ind = 0, bool quiet = false ) const;
311 template <typename T>
312 T* readHist_i( const std::string& name ) const;
313
314 template <typename T>
315 LockedHandle<T> regShared_i( const std::string& id, std::unique_ptr<T> hist );
316 template <typename T>
317 LockedHandle<T> getShared_i( const std::string& name ) const;
318
320
323
324 template <typename T>
325 T* readHist( const std::string& name ) const;
326 TTree* readTree( const std::string& name ) const;
327
329 void updateFiles();
331 StatusCode connect( const std::string& );
332 TDirectory* changeDir( const THistSvc::THistID& hid ) const;
333 std::string stripDirectoryName( std::string& dir ) const;
334 void removeDoubleSlash( std::string& ) const;
335
336 void MergeRootFile( TDirectory*, TDirectory* );
337
338 bool findStream( const std::string& name, std::string& root, std::string& rem, TFile*& file ) const;
339 void parseString( const std::string& id, std::string& root, std::string& rem ) const;
340
342 void setupInputFile();
343
345 void setupOutputFile();
346
348 void copyFileLayout( TDirectory*, TDirectory* );
349
350 size_t findHistID( const std::string& id, const THistID*& hid, const size_t& index = 0 ) const;
351
352 void dump() const;
353
355 StatusCode merge( const THistID& );
358
361
363
366
367 Gaudi::Property<int> m_autoSave{ this, "AutoSave", 0 };
368 Gaudi::Property<int> m_autoFlush{ this, "AutoFlush", 0 };
369 Gaudi::Property<bool> m_print{ this, "PrintAll", false };
370 Gaudi::Property<int> m_maxFileSize{ this, "MaxFileSize", 10240,
371 "maximum file size in MB. if exceeded,"
372 " will cause an abort. -1 to never check." };
373 Gaudi::Property<int> m_compressionLevel{ this, "CompressionLevel", 1, [this]( auto& ) {
374 this->warning()
375 << "\"CompressionLevel\" Property has been deprecated. "
376 << "Set it via the \"CL=\" parameter in the \"Output\" Property"
377 << endmsg;
378 } };
380 this, "Output", {}, &THistSvc::setupOutputFile, "", "OrderedSet<std::string>" };
382 this, "Input", {}, &THistSvc::setupInputFile, "", "OrderedSet<std::string>" };
383
385
388
389 bool m_delayConnect = false;
390 bool m_okToConnect = false;
391 bool m_hasTTrees = false;
392
393 mutable std::string m_curstream;
394
396};
397
398template <typename T>
399StatusCode THistSvc::regHist_i( std::unique_ptr<T> hist, const std::string& id, bool shared ) {
400 THistID* hid = nullptr;
401 return regHist_i( std::move( hist ), id, shared, hid );
402}
403
404template <typename T>
405StatusCode THistSvc::regHist_i( std::unique_ptr<T> hist_unique, const std::string& id, bool shared, THistID*& phid ) {
407 phid = nullptr;
408
409 // It is sad that we lose propper memory management here
410 T* hist = nullptr;
411 if ( hist_unique.get() != nullptr ) { hist = hist_unique.release(); }
412 if ( msgLevel( MSG::DEBUG ) ) {
413 debug() << "regHist_i obj: " << hist << " id: " << id << " s: " << shared << endmsg;
414 }
415
416 std::string idr( id );
417 removeDoubleSlash( idr );
418
419 if ( idr.find( "/" ) == idr.length() ) {
420 error() << "Badly formed identifier \"" << idr << "\": "
421 << "Must not end with a /" << endmsg;
422 delete hist;
423 return StatusCode::FAILURE;
424 }
425
426 TFile* f = nullptr;
427 std::string stream, name;
428 if ( !findStream( idr, stream, name, f ) ) {
429 error() << "Could not register id: \"" << idr << "\"" << endmsg;
430 delete hist;
431 return StatusCode::FAILURE;
432 }
433
434 std::string uid = "/" + stream + "/" + name;
435
436 uidMap_t::iterator uitr = m_uids.find( uid );
437 bool exists( false );
438 if ( uitr != m_uids.end() ) {
439 exists = true;
440 TObject* t1 = uitr->second->at( 0 ).obj;
441 if ( hist->Compare( t1 ) != 0 ) {
442 error() << "previously registered object with identifier \"" << uid << "\" does not compare to this one"
443 << endmsg;
444 delete hist;
445 return StatusCode::FAILURE;
446 } else {
447 if ( msgLevel( MSG::DEBUG ) ) {
448 debug() << "previously registered id \"" << uid << "\": num " << uitr->second->size() << endmsg;
449 }
450 }
451 }
452
453 bool temp = false;
454 if ( !f ) {
455 temp = true;
456 if ( msgLevel( MSG::DEBUG ) ) { debug() << "Historgram with id \"" << idr << "\" is temporary" << endmsg; }
457 }
458
459 TObject* to = nullptr;
460 THistID hid;
461 // check to see if this hist is to be read in;
462 if ( !temp && m_files.find( stream )->second.second == READ ) {
463 if ( hist != 0 ) { warning() << "Registering id: \"" << idr << "\" with non zero pointer!" << endmsg; }
464
465 hist = readHist_i<T>( idr );
466 if ( hist == nullptr ) {
467 error() << "Unable to read in hist" << endmsg;
468 delete hist;
469 return StatusCode::FAILURE;
470 }
471 to = dynamic_cast<TObject*>( hist );
472 hid = THistID( uid, temp, to, f, m_files.find( stream )->second.second );
473 } else if ( !hist ) {
474 error() << "Unable to read in hist with id: \"" << idr << "\"" << endmsg;
475 delete hist;
476 return StatusCode::FAILURE;
477 } else {
478 to = dynamic_cast<TObject*>( hist );
479 if ( to == nullptr ) {
480 error() << "Could not dcast to TObject. id: \"" << idr << "\"" << endmsg;
481 delete hist;
482 return StatusCode::FAILURE;
483 }
484
485 auto oitr = m_tobjs.find( to );
486 if ( oitr != m_tobjs.end() ) {
487 error() << "already registered id: \"" << idr << "\" with identifier \""
488 << oitr->second.first->at( oitr->second.second ).id << "\"" << endmsg;
489 delete hist;
490 return StatusCode::FAILURE;
491 }
492 }
493
494 const auto findF = m_files.find( stream );
495 hid = ( findF != m_files.end() ? THistID( uid, temp, to, f, findF->second.second ) : THistID( uid, temp, to, f ) );
496
497 hid.shared = shared;
498 TDirectory* dir = changeDir( hid );
499
500 if ( TTree* tree = dynamic_cast<TTree*>( hist ) ) {
501 tree->SetDirectory( dir );
503 m_hasTTrees = true; // at least one TTree is registered
504 } else if ( TH1* th1 = dynamic_cast<TH1*>( hist ) ) {
505 th1->SetDirectory( dir );
506 hid.type = ObjectType::TH1;
507 } else if ( TEfficiency* teff = dynamic_cast<TEfficiency*>( hist ) ) {
508 teff->SetDirectory( dir );
510 } else if ( dynamic_cast<TGraph*>( hist ) ) {
511 dir->Append( hist );
513 } else {
514 error() << "id: \"" << idr << "\" is not a TH, TTree, TGraph, or TEfficiency. Attaching it to current dir."
515 << endmsg;
516 dir->Append( hist );
518 }
519
520 std::string fname;
521 if ( !f ) {
522 fname = "none";
523 } else {
524 fname = f->GetName();
525 }
526
527 if ( msgLevel( MSG::DEBUG ) ) {
528 debug() << "Registering" << ( shared ? " shared " : " " ) << System::typeinfoName( typeid( *hist ) ) << " title: \""
529 << hist->GetTitle() << "\" id: \"" << uid
530 << "\" dir: "
531 // << hist->GetDirectory()->GetPath() << " "
532 << changeDir( hid )->GetPath() << " file: " << fname << endmsg;
533 }
534
535 // create a mutex for all shared histograms
536 if ( shared ) { hid.mutex = std::make_unique<histMut_t>(); }
537
538 if ( exists ) {
539 vhid_t* vi = uitr->second;
540 vi->push_back( std::move( hid ) );
541 phid = &( vi->back() );
542
543 m_tobjs.emplace( to, std::pair<vhid_t*, size_t>( vi, vi->size() - 1 ) );
544 } else {
545 vhid_t* vi = new vhid_t;
546 vi->push_back( std::move( hid ) );
547 m_hlist.emplace( m_hlist.end(), vi );
548
549 phid = &( vi->back() );
550 m_uids.emplace( uid, vi );
551 m_ids.emplace( name, vi );
552
553 m_tobjs.emplace( to, std::pair<vhid_t*, size_t>( vi, 0 ) );
554 }
555
556 if ( msgLevel( MSG::DEBUG ) ) { debug() << "regHist_i THistID: " << *phid << endmsg; }
557
558 return StatusCode::SUCCESS;
559}
560
561template <typename T>
562T* THistSvc::getHist_i( const std::string& id, const size_t& ind, bool quiet ) const {
563 // id starts with "/": unique
564
566
567 T* hist = nullptr;
568 const THistID* hid = nullptr;
569 size_t num = findHistID( id, hid, ind );
570 if ( num == 0 ) {
571 // no matches found
572 if ( !quiet ) { error() << "could not locate Hist with id \"" << id << "\"" << endmsg; }
573 return nullptr;
574 } else if ( num > 1 ) {
575 if ( !quiet ) {
576 // return failure if trying to GET a single hist
577 error() << "Multiple matches with id \"" << id << "\"."
578 << " Further specifications required." << endmsg;
579 return nullptr;
580 } else {
581 info() << "Found multiple matches with id \"" << id << "\"" << endmsg;
582 // return first match if just INQUIRING (i.e. != nullptr)
583 hist = dynamic_cast<T*>( hid->obj );
584 if ( hist == nullptr ) {
585 error() << "dcast failed, Hist id: \"" << id << "\"" << endmsg;
586 return nullptr;
587 }
588 }
589 } else {
590 hist = dynamic_cast<T*>( hid->obj );
591 if ( hist == nullptr ) {
592 error() << "dcast failed, Hist id: \"" << id << "\"" << endmsg;
593 return nullptr;
594 }
595 if ( msgLevel( MSG::VERBOSE ) ) {
596 verbose() << "found unique Hist title: \"" << hist->GetTitle() << "\" id: \"" << id << "\"" << endmsg;
597 }
598 }
599
600 return hist;
601}
602
603template <typename T>
604T* THistSvc::readHist_i( const std::string& id ) const {
606
607 std::string idr( id );
608 removeDoubleSlash( idr );
609
610 std::string stream, rem, dir, fdir, bdir, fdir2;
611 TFile* file = nullptr;
612
613 if ( !findStream( idr, stream, rem, file ) ) { return nullptr; }
614
615 if ( !file ) {
616 error() << "no associated file found" << endmsg;
617 return nullptr;
618 }
619
620 file->cd( "/" );
621
622 fdir = idr;
623 bdir = stripDirectoryName( fdir );
624 fdir2 = fdir;
625 while ( ( dir = stripDirectoryName( fdir ) ) != "" ) {
626 if ( !gDirectory->GetKey( dir.c_str() ) ) {
627 error() << "Directory \"" << fdir2 << "\" doesnt exist in " << file->GetName() << endmsg;
628 return nullptr;
629 }
630 gDirectory->cd( dir.c_str() );
631 }
632
633 TObject* to = nullptr;
634 gDirectory->GetObject( fdir.c_str(), to );
635
636 if ( !to ) {
637 error() << "Could not get obj \"" << fdir << "\" in " << gDirectory->GetPath() << endmsg;
638 return nullptr;
639 }
640
641 T* hist = dynamic_cast<T*>( to );
642 if ( hist == nullptr ) {
643 error() << "Could not convert \"" << idr << "\" to a " << System::typeinfoName( typeid( *hist ) ) << " as is a "
644 << to->IsA()->GetName() << endmsg;
645 return nullptr;
646 }
647
648 if ( msgLevel( MSG::DEBUG ) ) {
649 debug() << "Read in " << hist->IsA()->GetName() << " \"" << hist->GetName() << "\" from file " << file->GetName()
650 << endmsg;
651 hist->Print();
652 }
653
654 return hist;
655}
656
657template <typename T>
658LockedHandle<T> THistSvc::regShared_i( const std::string& id, std::unique_ptr<T> hist ) {
659 LockedHandle<T> lh( nullptr, nullptr );
660 const THistID* hid = nullptr;
661 if ( findHistID( id, hid ) == 0 ) {
662 T* phist = hist.get();
663 THistID* phid = nullptr;
664 if ( regHist_i( std::move( hist ), id, true, phid ).isSuccess() ) {
665 lh.set( phist, phid->mutex.get() );
666
667 } else {
668 error() << "regSharedHist: unable to register shared hist with id \"" << id << "\"" << endmsg;
669 }
670 } else {
671 if ( !hid->shared ) {
672 error() << "regSharedHist: previously register Hist with id \"" << id << "\" was not marked shared" << endmsg;
673 }
674
675 if ( hist->Compare( hid->obj ) != 0 ) {
676 error() << "regSharedHist: Histogram " << id << " does not compare with " << hid << endmsg;
677 } else {
678 T* phist = dynamic_cast<T*>( hid->obj );
679 if ( phist == 0 ) {
680 error() << "regSharedHist: unable to dcast retrieved shared hist \"" << id << "\" of type "
681 << hid->obj->IsA()->GetName() << " to requested type " << System::typeinfoName( typeid( T ) ) << endmsg;
682 } else {
683 lh.set( phist, hid->mutex.get() );
684 delete hist.release();
685 }
686 }
687 }
688 return lh;
689}
690
691template <typename T>
692LockedHandle<T> THistSvc::getShared_i( const std::string& name ) const {
694
695 const THistID* hid = nullptr;
696 size_t i = findHistID( name, hid );
697
698 LockedHandle<T> hist( nullptr, nullptr );
699
700 if ( i == 1 ) {
701 if ( !hid->shared ) {
702 error() << "getSharedHist: found Hist with id \"" << name << "\", but it's not marked as shared" << endmsg;
703 return hist;
704 }
705 T* h1 = dynamic_cast<T*>( hid->obj );
706 hist = LockedHandle<T>( h1, hid->mutex.get() );
707
708 if ( msgLevel( MSG::DEBUG ) ) { debug() << "getSharedHist: found THistID: " << *hid << endmsg; }
709 } else if ( i == 0 ) {
710 error() << "no histograms matching id \"" << name << "\" found" << endmsg;
711 } else {
712 info() << "multiple matches for id \"" << name << "\" found [" << i << "], probably from different streams"
713 << endmsg;
714 }
715 return hist;
716}
#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:197
GlobalDirectoryRestore(THistSvcMutex_t &mut)
std::lock_guard< THistSvcMutex_t > m_lock
Definition THistSvc.h:206
StatusCode finalize() override
Definition THistSvc.cpp:180
std::recursive_mutex THistSvcMutex_t
Definition THistSvc.h:193
LockedHandle< T > regShared_i(const std::string &id, std::unique_ptr< T > hist)
Definition THistSvc.h:658
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:288
StatusCode initialize() override
Definition THistSvc.cpp:69
bool existsHist(const std::string &name) const override
Check if histogram with given name is managed by THistSvcMT.
Definition THistSvc.cpp:660
T * getHist_i(const std::string &name, const size_t &ind=0, bool quiet=false) const
Definition THistSvc.h:562
T * readHist_i(const std::string &name) const
Definition THistSvc.h:604
Mode
Enumerating all possible file access modes.
Definition THistSvc.h:210
Gaudi::Property< int > m_maxFileSize
Definition THistSvc.h:370
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:461
ServiceHandle< IIncidentSvc > p_incSvc
Definition THistSvc.h:386
std::vector< std::string > m_Wstream
Definition THistSvc.h:265
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:335
T * readHist(const std::string &name) const
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
Definition THistSvc.cpp:903
void setupOutputFile()
call-back method to handle output stream property
Gaudi::Property< int > m_compressionLevel
Definition THistSvc.h:373
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition THistSvc.h:293
objMap_t m_tobjs
Definition THistSvc.h:291
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:658
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:283
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition THistSvc.h:399
Gaudi::Property< std::vector< std::string > > m_inputfile
Definition THistSvc.h:381
bool m_delayConnect
Definition THistSvc.h:389
std::unordered_map< std::string, vhid_t * > uidMap_t
Definition THistSvc.h:281
bool m_hasTTrees
Definition THistSvc.h:391
uidMap_t m_uids
Definition THistSvc.h:287
ObjectType
Possible TObject types.
Definition THistSvc.h:213
std::vector< THistID > vhid_t
Definition THistSvc.h:277
std::vector< std::string > getEfficiencies() const override
Definition THistSvc.cpp:696
std::vector< std::string > getHists() const override
Definition THistSvc.cpp:672
bool m_okToConnect
Definition THistSvc.h:390
StatusCode regTree(const std::string &name) override
Register a new TTree with a given name.
Definition THistSvc.cpp:362
ServiceHandle< IFileMgr > p_fileMgr
Definition THistSvc.h:387
bool existsEfficiency(const std::string &name) const override
Check if TEfficiency with given name is managed by THistSvcMT.
Definition THistSvc.cpp:662
TDirectory * changeDir(const THistSvc::THistID &hid) const
void MergeRootFile(TDirectory *, TDirectory *)
Gaudi::Property< std::vector< std::string > > m_outputfile
Definition THistSvc.h:379
std::list< vhid_t * > hlist_t
Definition THistSvc.h:279
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:216
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:638
Gaudi::Property< int > m_autoSave
Definition THistSvc.h:367
StatusCode deReg(const std::string &name) override
Deregister object with given name and give up ownership (without deletion!)
Definition THistSvc.cpp:552
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:507
hlist_t m_hlist
Definition THistSvc.h:286
std::map< std::string, std::string > m_sharedFiles
Definition THistSvc.h:298
std::multimap< std::string, std::string > streamMap
Definition THistSvc.h:294
void parseString(const std::string &id, std::string &root, std::string &rem) const
std::vector< std::string > m_Rstream
Definition THistSvc.h:265
StatusCode writeObjectsToFile()
Gaudi::Property< int > m_autoFlush
Definition THistSvc.h:368
void removeDoubleSlash(std::string &) const
StatusCode rootOpenAction(FILEMGR_CALLBACK_ARGS)
std::string m_curstream
Definition THistSvc.h:393
Gaudi::Property< bool > m_print
Definition THistSvc.h:369
THistSvcMutex_t m_svcMut
Definition THistSvc.h:395
void updateFiles()
Handle case where TTree grows beyond TTree::fgMaxTreeSize.
LockedHandle< T > getShared_i(const std::string &name) const
Definition THistSvc.h:692
std::vector< std::string > getTrees() const override
Definition THistSvc.cpp:680
std::mutex histMut_t
Definition THistSvc.h:194
std::set< std::string > m_alreadyConnectedOutFiles
list of already connected files.
Definition THistSvc.h:273
StatusCode regEfficiency(const std::string &name) override
Register a new TEfficiency with a given name.
Definition THistSvc.cpp:438
StatusCode reinitialize() override
Definition THistSvc.cpp:174
std::vector< std::string > getGraphs() const override
Definition THistSvc.cpp:688
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
streamMap m_fileStreams
Definition THistSvc.h:295
std::unordered_map< TObject *, std::pair< vhid_t *, size_t > > objMap_t
Definition THistSvc.h:284
StatusCode getEfficiency(const std::string &name, TEfficiency *&) const override
Return TEfficiency with given name.
Definition THistSvc.cpp:452
bool existsGraph(const std::string &name) const override
Check if graph with given name is managed by THistSvcMT.
Definition THistSvc.cpp:666
bool existsTree(const std::string &name) const override
Check if tree with given name is managed by THistSvcMT.
Definition THistSvc.cpp:670
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
Definition THistSvc.h:269
StatusCode rootOpenErrAction(FILEMGR_CALLBACK_ARGS)
StatusCode getTree(const std::string &name, TTree *&) const override
Return TTree with given name.
Definition THistSvc.cpp:388
StatusCode regGraph(const std::string &name) override
Register a new TGraph with a given name.
Definition THistSvc.cpp:397
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
Definition THistSvc.cpp:704
StatusCode regHist(const std::string &name) override
Register a new ROOT histogram TH*X with a name.
Definition THistSvc.cpp:321
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:429
THistSvc(const std::string &name, ISvcLocator *svcloc)
Definition THistSvc.cpp:66
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:232
THistID(const THistID &rhs)=delete
THistID & operator=(const THistID &rhs)=delete
~THistID()=default
std::unique_ptr< histMut_t > mutex
Definition THistSvc.h:236
TObject * obj
Definition THistSvc.h:234
bool operator<(THistID const &rhs) const
Definition THistSvc.h:252
THistID(THistID &&rhs)=default
THistID(std::string &i, bool &t, TObject *o, TFile *f)
Definition THistSvc.h:248
ObjectType type
Definition THistSvc.h:238
THistID & operator=(THistID &&rhs)=default
std::string id
Definition THistSvc.h:233
friend std::ostream & operator<<(std::ostream &ost, const THistID &hid)
Definition THistSvc.h:254
THistID(std::string &i, bool &t, TObject *o, TFile *f, Mode m)
Definition THistSvc.h:249