Gaudi Framework, version v23r9

Home   Generated: Thu Jul 18 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
THistSvc Class Reference

#include <THistSvc.h>

Inheritance diagram for THistSvc:
Inheritance graph
[legend]
Collaboration diagram for THistSvc:
Collaboration graph
[legend]

Classes

class  GlobalDirectoryRestore
 
struct  THistID
 

Public Member Functions

virtual StatusCode initialize ()
 
virtual StatusCode reinitialize ()
 
virtual StatusCode finalize ()
 
virtual StatusCode regHist (const std::string &name)
 
virtual StatusCode regHist (const std::string &name, TH1 *)
 
virtual StatusCode regHist (const std::string &name, TH2 *)
 
virtual StatusCode regHist (const std::string &name, TH3 *)
 
virtual StatusCode getHist (const std::string &name, TH1 *&) const
 
virtual StatusCode getHist (const std::string &name, TH2 *&) const
 
virtual StatusCode getHist (const std::string &name, TH3 *&) const
 
virtual StatusCode regTree (const std::string &name)
 
virtual StatusCode regTree (const std::string &name, TTree *)
 
virtual StatusCode getTree (const std::string &name, TTree *&) const
 
virtual StatusCode regGraph (const std::string &name)
 
virtual StatusCode regGraph (const std::string &name, TGraph *)
 
virtual StatusCode getGraph (const std::string &name, TGraph *&) const
 
virtual StatusCode deReg (TObject *obj)
 
virtual StatusCode deReg (const std::string &name)
 
virtual std::vector< std::stringgetHists () const
 
virtual std::vector< std::stringgetTrees () const
 
virtual std::vector< std::stringgetGraphs () const
 
virtual StatusCode getTHists (TDirectory *td, TList &, bool recurse=false) const
 
virtual StatusCode getTHists (const std::string &name, TList &, bool recurse=false) const
 
virtual StatusCode getTHists (TDirectory *td, TList &tl, bool recurse=false, bool reg=false)
 
virtual StatusCode getTHists (const std::string &name, TList &tl, bool recurse=false, bool reg=false)
 
virtual StatusCode getTTrees (TDirectory *td, TList &, bool recurse=false) const
 
virtual StatusCode getTTrees (const std::string &name, TList &, bool recurse=false) const
 
virtual StatusCode getTTrees (TDirectory *td, TList &tl, bool recurse=false, bool reg=false)
 
virtual StatusCode getTTrees (const std::string &name, TList &tl, bool recurse=false, bool reg=false)
 
virtual bool exists (const std::string &name) const
 
 THistSvc (const std::string &name, ISvcLocator *svc)
 
void handle (const Incident &)
 
virtual StatusCode io_reinit ()
 callback method to reinitialize the internal state of the component for I/O purposes (e.g.
 
- Public Member Functions inherited from extends3< Service, ITHistSvc, IIncidentListener, IIoComponent >
 extends3 (A1 a1, A2 a2, A3 a3)
 Templated constructor with 3 arguments.
 
 extends3 (A1 a1, A2 a2)
 Templated constructor with 2 arguments.
 
 extends3 (A1 a1)
 Templated constructor with 1 argument.
 
 extends3 ()
 Default constructor.
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast.
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface.
 
virtual std::vector< std::stringgetInterfaceNames () const
 Implementation of IInterface::getInterfaceNames.
 
virtual ~extends3 ()
 Virtual destructor.
 
- Public Member Functions inherited from Service
virtual unsigned long release ()
 Release Interface instance.
 
virtual const std::stringname () const
 Retrieve name of the service.
 
virtual StatusCode configure ()
 
virtual StatusCode start ()
 
virtual StatusCode stop ()
 
virtual StatusCode terminate ()
 
virtual Gaudi::StateMachine::State FSMState () const
 
virtual Gaudi::StateMachine::State targetFSMState () const
 
virtual StatusCode restart ()
 
virtual StatusCode sysInitialize ()
 Initialize Service.
 
virtual StatusCode sysStart ()
 Initialize Service.
 
virtual StatusCode sysStop ()
 Initialize Service.
 
virtual StatusCode sysFinalize ()
 Finalize Service.
 
virtual StatusCode sysReinitialize ()
 Re-initialize the Service.
 
virtual StatusCode sysRestart ()
 Re-initialize the Service.
 
virtual StatusCode setProperty (const Property &p)
 
virtual StatusCode setProperty (const std::string &s)
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 
virtual StatusCode getProperty (Property *p) const
 
virtual const PropertygetProperty (const std::string &name) const
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 
virtual const std::vector
< Property * > & 
getProperties () const
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 Service (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator.
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job.
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist.
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist.
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property.
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties.
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
- Public Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
 CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
 Templated constructor with 3 arguments.
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments.
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument.
 
 CommonMessaging ()
 Default constructor.
 
virtual ~CommonMessaging ()
 Virtual destructor.
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from extend_interfaces3< I1, I2, I3 >
virtual ~extend_interfaces3 ()
 Virtual destructor.
 

Protected Member Functions

virtual ~THistSvc ()
 

Private Types

enum  Mode {
  READ, WRITE, UPDATE, APPEND,
  SHARE
}
 
typedef std::map< std::string,
THistID
uidMap
 
typedef std::multimap
< std::string, THistID
idMap
 
typedef std::map< TObject
*, THistID
objMap
 
typedef std::multimap
< std::string, std::string
streamMap
 

Private Member Functions

template<typename T >
StatusCode regHist_i (T *hist, const std::string &name)
 
template<typename T >
StatusCode getHist_i (const std::string &name, T *&hist, bool quiet=false) const
 
template<typename T >
StatusCode readHist_i (const std::string &name, T *&hist) const
 
StatusCode readHist (const std::string &name, TH1 *&) const
 
StatusCode readHist (const std::string &name, TH2 *&) const
 
StatusCode readHist (const std::string &name, TH3 *&) const
 
StatusCode readTree (const std::string &name, TTree *&) const
 
void updateFiles ()
 
StatusCode write ()
 
StatusCode connect (const std::string &)
 
TDirectory * changeDir (const THistSvc::THistID &hid) const
 
std::string dirname (std::string &dir) const
 
void removeDoubleSlash (std::string &) const
 
bool browseTDir (TDirectory *dir) const
 
bool findStream (const std::string &name, std::string &root, std::string &rem, TFile *&file) const
 
void parseString (const std::string &id, std::string &root, std::string &rem) const
 
void setupInputFile (Property &inputfile)
 call-back method to handle input stream property
 
void setupOutputFile (Property &outputfile)
 call-back method to handle output stream property
 
void setupCompressionLevel (Property &cmp)
 
void copyFileLayout (TDirectory *, TDirectory *)
 helper function to recursively copy the layout of a TFile into a new TFile
 
void MergeRootFile (TDirectory *target, TDirectory *source)
 

Private Attributes

MsgStream m_log
 
StringArrayProperty m_inputfile
 
StringArrayProperty m_outputfile
 
std::vector< std::stringm_Rstream
 
std::vector< std::stringm_Wstream
 
IntegerProperty m_autoSave
 
IntegerProperty m_autoFlush
 
IntegerProperty m_compressionLevel
 
IntegerProperty m_maxFileSize
 
BooleanProperty m_print
 
std::set< std::stringm_alreadyConnectedInFiles
 list of already connected files.
 
std::set< std::stringm_alreadyConnectedOutFiles
 list of already connected files.
 
uidMap m_uids
 
idMap m_ids
 
objMap m_tobjs
 
std::map< std::string,
std::pair< TFile *, Mode > > 
m_files
 
streamMap m_fileStreams
 
std::map< std::string,
std::string
m_sharedFiles
 
bool signaledStop
 
std::string m_curstream
 

Additional Inherited Members

- Public Types inherited from extends3< Service, ITHistSvc, IIncidentListener, IIoComponent >
typedef extends3 base_class
 Typedef to this class.
 
typedef extend_interfaces3
< ITHistSvc, IIncidentListener,
IIoComponent
extend_interfaces_base
 Typedef to the base of this class.
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces.
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel
 Service output level.
 
Gaudi::StateMachine::State m_state
 Service state.
 
Gaudi::StateMachine::State m_targetState
 Service state.
 

Detailed Description

Definition at line 27 of file THistSvc.h.

Member Typedef Documentation

Definition at line 135 of file THistSvc.h.

typedef std::map<TObject*, THistID> THistSvc::objMap
private

Definition at line 136 of file THistSvc.h.

Definition at line 137 of file THistSvc.h.

Definition at line 134 of file THistSvc.h.

Member Enumeration Documentation

enum THistSvc::Mode
private
Enumerator:
READ 
WRITE 
UPDATE 
APPEND 
SHARE 

Definition at line 124 of file THistSvc.h.

Constructor & Destructor Documentation

THistSvc::THistSvc ( const std::string name,
ISvcLocator svc 
)

Definition at line 46 of file THistSvc.cpp.

: base_class(name, svc), m_log(msgSvc(), name ), signaledStop(false) {
declareProperty ("AutoSave", m_autoSave=0 );
declareProperty ("AutoFlush", m_autoFlush=0 );
declareProperty ("PrintAll", m_print=false);
declareProperty ("MaxFileSize", m_maxFileSize=10240,
"maximum file size in MB. if exceeded, will cause an abort");
}
THistSvc::~THistSvc ( )
protectedvirtual

Definition at line 63 of file THistSvc.cpp.

{
}

Member Function Documentation

bool THistSvc::browseTDir ( TDirectory *  dir) const
private

Definition at line 393 of file THistSvc.cpp.

{
if (dir == 0) {
std::cerr << "TDirectory == 0" << std::endl;
return false;
}
dir->cd();
cout << "-> " << dir->GetPath() << " "
<< dir->GetListOfKeys()->GetSize() << endl;
// TIter nextkey(dir->GetListOfKeys());
TIter nextkey(dir->GetList());
while (TKey *key = (TKey*)nextkey()) {
TObject *obj = key->ReadObj();
if (obj == 0) { cout << key->GetName() << " obj==0"<< endl; continue; }
// if (obj->IsA()->InheritsFrom("TDirectory")) {
cout << " Key: " << key->GetName() << " "
<< " tit: " << obj->GetTitle() << " "
<< " (" << key->GetClassName() << ")" << endl;
// }
}
nextkey = dir->GetListOfKeys();
while (TKey *key = (TKey*)nextkey()) {
TObject *obj = key->ReadObj();
if (obj == 0) { cout << key->GetName() << " obj==0"<< endl; continue; }
if (obj->IsA()->InheritsFrom("TDirectory")) {
TDirectory *tt = dynamic_cast<TDirectory*>(obj);
}
}
return true;
}
TDirectory * THistSvc::changeDir ( const THistSvc::THistID hid) const
private

Definition at line 1755 of file THistSvc.cpp.

{
string uid = hid.id;
TFile* file = hid.file;
string stream, fdir, bdir, dir, id;
if (file != 0) {
file->cd("/");
} else {
gROOT->cd();
}
fdir = uid;
bdir = dirname(fdir);
while ( (dir = dirname(fdir)) != "") {
if (! gDirectory->GetKey(dir.c_str())) {
gDirectory->mkdir(dir.c_str());
}
gDirectory->cd(dir.c_str());
}
return gDirectory;
}
StatusCode THistSvc::connect ( const std::string ident)
private

Definition at line 1460 of file THistSvc.cpp.

{
Tokenizer tok(true);
string::size_type loc = ident.find(" ");
string stream = ident.substr(0,loc);
char typ(0);
string val,VAL,TAG,filename,db_typ("ROOT");
int cl(1);
tok.analyse(ident.substr(loc+1,ident.length()), " ", "", "", "=", "'", "'");
for ( Tokenizer::Items::iterator i = tok.items().begin(); i != tok.items().end(); i++) {
const std::string& tag = (*i).tag();
TAG = tag;
toupper(TAG);
val = (*i).value();
VAL = val;
toupper(VAL);
if (TAG == "FILE" || TAG == "DATAFILE") {
filename = val;
removeDoubleSlash( filename );
} else if ( TAG == "OPT" ) {
if ( VAL == "APPEND" || VAL == "UPDATE" ) {
typ = 'A';
} else if ( VAL == "CREATE" || VAL == "NEW" || VAL == "WRITE" ) {
typ = 'N';
} else if ( VAL == "RECREATE" ) {
typ = 'R';
} else if (VAL == "SHARE") {
typ = 'S';
} else if ( VAL == "OLD" || VAL == "READ" ) {
typ = 'O';
} else {
m_log << MSG::ERROR << "Unknown OPT: \"" << (*i).value() << "\""
<< endmsg;
typ = 0;
}
} else if (TAG == "TYP") {
db_typ = (*i).value();
} else if (TAG == "CL") {
cl = atoi(val.c_str());
} else {
props.push_back( Prop((*i).tag(), (*i).value()));
}
}
if (stream == "temp") {
m_log << MSG::ERROR << "in JobOption \"" << ident
<< "\": stream name \"temp\" reserved."
<< endmsg;
}
if (db_typ != "ROOT") {
m_log << MSG::ERROR << "in JobOption \"" << ident
<< "\": technology type \"" << db_typ << "\" not supported."
<< endmsg;
}
if (m_files.find(stream) != m_files.end()) {
m_log << MSG::ERROR << "in JobOption \"" << ident
<< "\":\n stream \"" << stream << "\" already connected to file: \""
<< m_files[stream].first->GetName() << "\""
<< endmsg;
}
Mode newMode;
if (typ == 'O') {
newMode = THistSvc::READ;
} else if (typ == 'N') {
newMode = THistSvc::WRITE;
} else if (typ == 'A') {
newMode = THistSvc::APPEND;
} else if (typ == 'R') {
newMode = THistSvc::UPDATE;
} else if (typ == 'S') {
newMode = THistSvc::SHARE;
} else {
// something else?
m_log << MSG::ERROR << "No OPT= specified or unknown access mode in: "
<< ident << endmsg;
}
// Is this file already connected to another stream?
if (m_fileStreams.find(filename) != m_fileStreams.end()) {
std::string oldstream = (fitr.first)->second;
std::pair<TFile*,Mode> f_info = m_files[oldstream];
if (newMode != f_info.second) {
m_log << MSG::ERROR << "in JobOption \"" << ident
<< "\":\n file \"" << filename << "\" already opened by stream: \""
<< oldstream << "\" with different access mode."
<< endmsg;
} else {
TFile *f2 = f_info.first;
m_files[stream] = make_pair(f2, newMode);
m_log << MSG::DEBUG << "Connecting stream: \"" << stream
<< "\" to previously opened TFile: \"" << filename << "\""
<< endmsg;
}
}
if (service("IncidentSvc",pi).isFailure()) {
m_log << MSG::ERROR << "Unable to get the IncidentSvc" << endmsg;
}
TFile *f(0) ;
if (newMode == THistSvc::READ) {
// old file
try {
f = TFile::Open(filename.c_str(),"READ");
} catch (const std::exception& Exception) {
m_log << MSG::ERROR << "exception caught while trying to open root"
<< " file for reading: " << Exception.what() << std::endl
<< " -> file probably corrupt." << endmsg;
filename));
} catch (...) {
m_log << MSG::ERROR << "Problems opening input file \"" << filename
<< "\": probably corrupt" << endmsg;
filename));
}
if (!f->IsOpen()) {
m_log << MSG::ERROR << "Unable to open input file \"" << filename
<< "\": file does not exist" << endmsg;
filename));
}
// FIX ME!
pi->fireIncident(FileIncident(name(), "BeginHistFile",
filename));
} else if (newMode == THistSvc::WRITE) {
// new file
f = TFile::Open(filename.c_str(),"NEW",stream.c_str(),cl);
if (!f->IsOpen()) {
m_log << MSG::ERROR << "Unable to create new output file \"" << filename
<< "\" for writing: file already exists" << endmsg;
filename));
}
// FIX ME!
pi->fireIncident(FileIncident(name(), "BeginHistFile",
filename));
} else if (newMode == THistSvc::APPEND) {
// update file
try {
f = TFile::Open(filename.c_str(),"UPDATE",stream.c_str(),cl);
} catch (const std::exception& Exception) {
m_log << MSG::ERROR << "exception caught while trying to open root"
<< " file for appending: " << Exception.what() << std::endl
<< " -> file probably corrupt." << endmsg;
filename));
} catch (...) {
m_log << MSG::ERROR << "Problems opening output file \"" << filename
<< "\" for append: probably corrupt" << endmsg;
filename));
}
if (!f->IsOpen()) {
m_log << MSG::ERROR << "Unable to open output file \"" << filename
<< "\" for appending" << endmsg;
filename));
}
filename));
} else if (newMode == THistSvc::SHARE) {
// SHARE file type
//For SHARE files, all data will be stored in a temp file and will be merged into the target file
//in write() when finalize(), this help to solve some confliction. e.g. with storegate
static int ishared = 0;
string realfilename=filename;
out << ishared++;
filename = string("tmp_THistSvc_")+out.str()+string(".root");
m_log << MSG::DEBUG << "Creating temp file \"" << filename
<< "\" and realfilename="<<realfilename << endmsg;
m_sharedFiles[stream]=realfilename;
try {
f = TFile::Open(filename.c_str(),"NEW",stream.c_str(),cl);
} catch (const std::exception& Exception) {
m_log << MSG::ERROR << "exception caught while trying to open root"
<< " file for appending: " << Exception.what() << std::endl
<< " -> file probably corrupt." << endmsg;
filename));
} catch (...) {
m_log << MSG::ERROR << "Problems opening output file \"" << filename
<< "\" for append: probably corrupt" << endmsg;
filename));
}
if (!f->IsOpen()) {
m_log << MSG::ERROR << "Unable to open output file \"" << filename
<< "\" for appending" << endmsg;
filename));
}
filename));
} else if (newMode == THistSvc::UPDATE) {
// update file
try {
f = TFile::Open(filename.c_str(),"RECREATE",stream.c_str(),cl);
} catch (const std::exception& Exception) {
m_log << MSG::ERROR << "exception caught while trying to open root"
<< " file for updating: " << Exception.what() << std::endl
<< " -> file probably corrupt." << endmsg;
filename));
} catch (...) {
m_log << MSG::ERROR << "Problems opening output file \"" << filename
<< "\" for update: probably corrupt" << endmsg;
filename));
}
if (!f->IsOpen()) {
m_log << MSG::ERROR << "Unable to open output file \"" << filename
<< "\" for updating" << endmsg;
filename));
}
filename));
}
m_files[stream] = make_pair(f, newMode);
m_fileStreams.insert(make_pair(filename, stream));
m_log << MSG::DEBUG << "Opening TFile \"" << filename << "\" stream: \""
<< stream << "\" mode: \"" << typ << "\"" << " comp level: " << cl
<< endmsg;
}
void THistSvc::copyFileLayout ( TDirectory *  dst,
TDirectory *  src 
)
private

helper function to recursively copy the layout of a TFile into a new TFile

Definition at line 1974 of file THistSvc.cpp.

{
<< "copyFileLayout() to dst path: " << dst->GetPath () << endmsg;
// strip out URLs
TString path ((char*)strstr (dst->GetPath(), ":"));
path.Remove (0, 2);
src->cd (path);
TDirectory *cur_src_dir = gDirectory;
// loop over all keys in this directory
TList *key_list = cur_src_dir->GetListOfKeys ();
int n = key_list->GetEntries ();
for ( int j = 0; j < n; ++j ) {
TKey *k = (TKey*)key_list->At (j);
const std::string src_pathname = cur_src_dir->GetPath()
+ std::string("/")
+ k->GetName();
TObject *o=src->Get (src_pathname.c_str());
if (o != NULL && o->IsA()->InheritsFrom ("TDirectory")) {
m_log << MSG::VERBOSE << " subdir [" << o->GetName() << "]..."
<< endmsg;
dst->cd ();
TDirectory * dst_dir = dst->mkdir (o->GetName(), o->GetTitle());
copyFileLayout (dst_dir, src);
}
} // loop over keys
return;
}
StatusCode THistSvc::deReg ( TObject *  obj)
virtual

Definition at line 909 of file THistSvc.cpp.

{
if (itr != m_tobjs.end()) {
THistID hid = itr->second;
uidMap::iterator itr2 = m_uids.find(hid.id);
if (itr2 == m_uids.end()) {
m_log << MSG::ERROR << "Problems deregistering TObject \""
<< obj->GetName()
<< "\" with id \"" << hid.id << "\"" << endmsg;
}
std::string id,root,rem;
parseString(hid.id, root, rem);
bool found(false);
if (mitr.first == mitr.second) {
m_log << MSG::ERROR << "Problems deregistering TObject \""
<< obj->GetName()
<< "\" with id \"" << hid.id << "\"" << endmsg;
} else {
for (itr3 = mitr.first; itr3 != mitr.second; ++itr3) {
if (itr3->second.obj == obj) {
found = true;
break;
}
}
if (!found) {
m_log << MSG::ERROR << "Problems deregistering TObject \""
<< obj->GetName()
<< "\" with id \"" << hid.id << "\"" << endmsg;
}
}
m_tobjs.erase(itr);
m_uids.erase(itr2);
m_ids.erase(itr3);
} else {
m_log << MSG::ERROR << "Cannot unregister TObject \"" << obj->GetName()
<< "\": not known to THistSvc" << endmsg;
}
}
StatusCode THistSvc::deReg ( const std::string name)
virtual

Definition at line 967 of file THistSvc.cpp.

{
if (itr == m_uids.end()) {
m_log << MSG::ERROR << "Problems deregistering id \""
<< id << "\"" << endmsg;
}
TObject* obj = itr->second.obj;
return deReg(obj);
}
std::string THistSvc::dirname ( std::string dir) const
private

Definition at line 1784 of file THistSvc.cpp.

{
string::size_type i = dir.find("/");
if (i == string::npos) {
return "";
}
if ( i == 0 ) {
dir.erase(0,1);
return dirname(dir);
}
string root = dir.substr(0,i);
dir.erase(0,i);
return root;
}
bool THistSvc::exists ( const std::string name) const
virtual

Definition at line 1908 of file THistSvc.cpp.

{
TH1* h;
return getHist_i(name,h,true).isSuccess();
}
StatusCode THistSvc::finalize ( )
virtual

Reimplemented from Service.

Definition at line 212 of file THistSvc.cpp.

{
m_log << MSG::DEBUG << "THistSvc::finalize" << endmsg;
#ifndef NDEBUG
if (m_log.level() <= MSG::DEBUG) {
for (uitr=m_uids.begin(); uitr != m_uids.end(); ++uitr) {
TObject* to = uitr->second.obj;
string dirname("none");
if (to && to->IsA()->InheritsFrom("TTree")) {
TTree* tr = dynamic_cast<TTree*>(to);
if (tr->GetDirectory() != 0) {
dirname = tr->GetDirectory()->GetPath();
}
} else if (to && to->IsA()->InheritsFrom("TGraph")) {
if (!uitr->second.temp) {
dirname = uitr->second.file->GetPath();
string id2(uitr->second.id);
id2.erase(0,id2.find("/",1));
id2.erase(id2.rfind("/"), id2.length());
if (id2.find("/") == 0) {
id2.erase(0,1);
}
dirname += id2;
} else {
dirname = "/tmp";
}
} else if (to && to->IsA()->InheritsFrom("TH1")) {
TH1* th = dynamic_cast<TH1*>(to);
if (th == 0) {
m_log << MSG::ERROR << "Couldn't dcast: " << uitr->first << endmsg;
} else {
if (th->GetDirectory() != 0) {
dirname = th->GetDirectory()->GetPath();
}
}
} else if (! to ) {
m_log << MSG::WARNING << uitr->first << " has NULL TObject ptr"
<< endmsg;
}
m_log << MSG::DEBUG << "uid: \"" << uitr->first << "\" temp: "
<< uitr->second.temp << " dir: " << dirname
<< endmsg;
}
}
#endif
if (sc.isFailure()) {
m_log << MSG::ERROR << "problems writing histograms" << endmsg;
}
if (m_print) {
m_log << MSG::INFO << "Listing contents of ROOT files: " << endmsg;
}
vector<TFile*> deleted_files;
map<string, pair<TFile*,Mode> >::const_iterator itr;
for (itr = m_files.begin(); itr != m_files.end(); ++itr) {
if (find(deleted_files.begin(), deleted_files.end(), itr->second.first) ==
deleted_files.end()) {
deleted_files.push_back(itr->second.first);
#ifndef NDEBUG
m_log << MSG::DEBUG << "finalizing stream/file " << itr->first << ":"
<< itr->second.first->GetName()
<< endmsg;
#endif
} else {
#ifndef NDEBUG
m_log << MSG::DEBUG << "already finalized stream " << itr->first << endmsg;
#endif
continue;
}
if (m_print && m_log.level() <= MSG::INFO) {
m_log << "==> File: " << itr->second.first->GetName()
<< " stream: " << itr->first << endmsg;
itr->second.first->Print("base");
}
string tmpfn=itr->second.first->GetName();
itr->second.first->Close();
if (service("IncidentSvc",pi).isFailure()) {
m_log << MSG::ERROR << "Unable to get the IncidentSvc" << endmsg;
}
if (itr->second.second==SHARE) {
TFile *outputfile;
//Merge File
try {
m_log << MSG::DEBUG << "Opening Final Output File: "
<< m_sharedFiles[itr->first].c_str() << endmsg;
outputfile = new TFile(m_sharedFiles[itr->first].c_str(), "UPDATE");
} catch (const std::exception& Exception) {
m_log << MSG::ERROR << "exception caught while trying to open root"
<< " file for appending: " << Exception.what() << std::endl
<< " -> file probably corrupt." << endmsg;
m_sharedFiles[itr->first]));
} catch (...) {
m_log << MSG::ERROR << "Problems opening output file \""
<< m_sharedFiles[itr->first]
<< "\" for append: probably corrupt" << endmsg;
m_sharedFiles[itr->first]));
}
m_sharedFiles[itr->first]));
m_log << MSG::DEBUG << "THistSvc::write()::Merging Rootfile "<<endmsg;
TFile *inputfile;
try {
m_log << MSG::DEBUG << "Openning again Temporary File: "
<< tmpfn.c_str() << endmsg;
inputfile=new TFile(tmpfn.c_str(),"READ");
} catch (const std::exception& Exception) {
m_log << MSG::ERROR << "exception caught while trying to open root"
<< " file for appending: " << Exception.what() << std::endl
<< " -> file probably corrupt." << endmsg;
} catch (...) {
m_log << MSG::ERROR << "Problems opening output file \""
<< tmpfn.c_str()
<< "\" for append: probably corrupt" << endmsg;
}
outputfile->SetCompressionLevel( inputfile->GetCompressionLevel() );
MergeRootFile(outputfile, inputfile);
outputfile->Write();
outputfile->Close();
inputfile->Close();
m_log << MSG::DEBUG << "Trying to remove temporary file \"" << tmpfn
<< "\""<<endmsg;
std::remove(tmpfn.c_str());
}
delete itr->second.first;
}
}
bool THistSvc::findStream ( const std::string name,
std::string root,
std::string rem,
TFile *&  file 
) const
private

Definition at line 1190 of file THistSvc.cpp.

{
string::size_type pos = id.find("/");
if (pos == string::npos) {
stream = "temp";
rem = id;
} else if (pos != 0) {
stream = "temp";
rem = id;
} else {
string::size_type pos2 = id.find("/",pos+1);
if (pos2 == string::npos) {
m_log << MSG::ERROR << "badly formed Hist/Tree id: \"" << id << "\""
<< endmsg;
return false;
}
parseString(id,stream,rem);
}
if (stream == "temp") {
file = 0;
return true;
}
map< string,pair<TFile*,Mode> >::const_iterator itr = m_files.find(stream);
if (itr != m_files.end()) {
file = itr->second.first;
} else {
file = 0;
m_log << MSG::WARNING << "no stream \"" << stream
<< "\" associated with id: \"" << id << "\""
<< endmsg;
}
return true;
}
StatusCode THistSvc::getGraph ( const std::string name,
TGraph *&  hist 
) const
virtual

Definition at line 1134 of file THistSvc.cpp.

{
return getHist_i(id, hist);
}
std::vector< std::string > THistSvc::getGraphs ( ) const
virtual

Definition at line 1141 of file THistSvc.cpp.

{
names.reserve(m_uids.size());
for (itr = m_uids.begin(); itr != m_uids.end(); ++itr) {
THistID tid = itr->second;
if (tid.obj->IsA()->InheritsFrom("TGraph")) {
names.push_back(itr->first);
}
}
return names;
}
StatusCode THistSvc::getHist ( const std::string name,
TH1 *&  hist 
) const
virtual

Definition at line 1064 of file THistSvc.cpp.

{
return getHist_i(id, hist);
}
StatusCode THistSvc::getHist ( const std::string name,
TH2 *&  hist 
) const
virtual

Definition at line 1071 of file THistSvc.cpp.

{
return getHist_i(id, hist);
}
StatusCode THistSvc::getHist ( const std::string name,
TH3 *&  hist 
) const
virtual

Definition at line 1078 of file THistSvc.cpp.

{
return getHist_i(id, hist);
}
template<typename T >
StatusCode THistSvc::getHist_i ( const std::string name,
T *&  hist,
bool  quiet = false 
) const
private
std::vector< std::string > THistSvc::getHists ( ) const
virtual

Definition at line 1085 of file THistSvc.cpp.

{
names.reserve(m_uids.size());
for (itr = m_uids.begin(); itr != m_uids.end(); ++itr) {
THistID tid = itr->second;
if (tid.obj->IsA()->InheritsFrom("TH1")) {
names.push_back(itr->first);
}
}
return names;
}
StatusCode THistSvc::getTHists ( TDirectory *  td,
TList &  tl,
bool  recurse = false 
) const
virtual

Definition at line 439 of file THistSvc.cpp.

{
gErrorIgnoreLevel = kBreak;
if (!td->cd()) {
m_log << MSG::ERROR << "getTHists: No such TDirectory \"" << td->GetPath()
<< "\"" << endmsg;
}
m_log << MSG::DEBUG << "getTHists: \"" << td->GetPath() << "\": found "
<< td->GetListOfKeys()->GetSize() << " keys" << endmsg;
TIter nextkey(td->GetListOfKeys());
while (TKey *key = (TKey*)nextkey()) {
m_log << MSG::DEBUG << " key: " << key->GetName();
TObject *obj = key->ReadObj();
if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
m_log << " (" << obj->IsA()->GetName() << ")";
} else if (obj != 0 && obj->IsA()->InheritsFrom("TH1")) {
m_log << " (" << obj->IsA()->GetName() << ")";
tl.Add(obj);
} else if (obj != 0) {
m_log << " [" << obj->IsA()->GetName() << "]";
}
}
// operate recursively
if (rcs) {
nextkey = td->GetListOfKeys();
while (TKey *key = (TKey*)nextkey()) {
TObject *obj = key->ReadObj();
if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
TDirectory *tt = dynamic_cast<TDirectory*>(obj);
getTHists(tt, tl, rcs);
}
}
}
}
StatusCode THistSvc::getTHists ( const std::string name,
TList &  tl,
bool  recurse = false 
) const
virtual

Definition at line 494 of file THistSvc.cpp.

{
gErrorIgnoreLevel = kBreak;
std::string stream,rem,r2;
parseString(dir,stream,rem);
map< string,pair<TFile*,Mode> >::const_iterator itr = m_files.find(stream);
if (itr != m_files.end()) {
r2 = itr->second.first->GetName();
r2 += ":/";
r2 += rem;
m_log << MSG::DEBUG << "getTHists: \"" << dir
<< "\" looks like a stream name." << " associated TFile: \""
<< itr->second.first->GetName() << "\"" << endmsg;
if (gDirectory->cd(r2.c_str())) {
m_curstream = stream;
sc = getTHists(gDirectory,tl,rcs);
return sc;
} else {
m_log << MSG::DEBUG << "getTHists: no such TDirectory \""
<< r2 << "\"" << endmsg;
}
} else {
m_log << MSG::DEBUG << "getTHists: stream \"" << stream << "\" not found"
<< endmsg;
}
if (!gDirectory->cd(dir.c_str())) {
m_log << MSG::ERROR << "getTHists: No such TDirectory/stream \"" << dir
<< "\"" << endmsg;
} else {
sc = getTHists(gDirectory,tl,rcs);
}
return sc;
}
StatusCode THistSvc::getTHists ( TDirectory *  td,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
virtual

Definition at line 652 of file THistSvc.cpp.

{
gErrorIgnoreLevel = kBreak;
if (!td->cd()) {
m_log << MSG::ERROR << "getTHists: No such TDirectory \"" << td->GetPath()
<< "\"" << endmsg;
}
m_log << MSG::DEBUG << "getTHists: \"" << td->GetPath() << "\": found "
<< td->GetListOfKeys()->GetSize() << " keys" << endmsg;
TIter nextkey(td->GetListOfKeys());
while (TKey *key = (TKey*)nextkey()) {
m_log << MSG::DEBUG << " key: " << key->GetName();
TObject *obj = key->ReadObj();
if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
m_log << " (" << obj->IsA()->GetName() << ")";
} else if (obj != 0 && obj->IsA()->InheritsFrom("TH1")) {
m_log << " (" << obj->IsA()->GetName() << ")";
tl.Add(obj);
if (reg && m_curstream != "") {
string dir = td->GetPath();
string fil = td->GetFile()->GetName();
dir.erase(0,fil.length()+1);
string id = "/" + m_curstream;
if ( dir == "/" ) {
id = id + "/" + key->GetName();
} else {
id = id + dir + "/" + key->GetName();
}
if (!exists(id)) {
m_log << " reg as \"" << id << "\"";
regHist(id).ignore();
} else {
m_log << " already registered";
}
}
} else if (obj != 0) {
m_log << " [" << obj->IsA()->GetName() << "]";
}
}
// operate recursively
if (rcs) {
nextkey = td->GetListOfKeys();
while (TKey *key = (TKey*)nextkey()) {
TObject *obj = key->ReadObj();
if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
TDirectory *tt = dynamic_cast<TDirectory*>(obj);
getTHists(tt, tl, rcs, reg);
}
}
}
}
StatusCode THistSvc::getTHists ( const std::string name,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
virtual

Definition at line 726 of file THistSvc.cpp.

{
gErrorIgnoreLevel = kBreak;
std::string stream,rem,r2;
parseString(dir,stream,rem);
map< string,pair<TFile*,Mode> >::const_iterator itr = m_files.find(stream);
if (itr != m_files.end()) {
r2 = itr->second.first->GetName();
r2 += ":/";
r2 += rem;
m_log << MSG::DEBUG << "getTHists: \"" << dir
<< "\" looks like a stream name." << " associated TFile: \""
<< itr->second.first->GetName() << "\"" << endmsg;
if (gDirectory->cd(r2.c_str())) {
m_curstream = stream;
sc = getTHists(gDirectory,tl,rcs,reg);
return sc;
} else {
m_log << MSG::DEBUG << "getTHists: no such TDirectory \""
<< r2 << "\"" << endmsg;
}
} else {
m_log << MSG::DEBUG << "getTHists: stream \"" << stream << "\" not found"
<< endmsg;
}
if (!gDirectory->cd(dir.c_str())) {
m_log << MSG::ERROR << "getTHists: No such TDirectory/stream \"" << dir
<< "\"" << endmsg;
} else {
if (reg) {
m_log << MSG::WARNING << "Unable to register histograms automatically "
<< "without a valid stream name" << endmsg;
reg = false;
}
sc = getTHists(gDirectory,tl,rcs,reg);
}
return sc;
}
StatusCode THistSvc::getTree ( const std::string name,
TTree *&  hist 
) const
virtual

Definition at line 1106 of file THistSvc.cpp.

{
return getHist_i(id, hist);
}
std::vector< std::string > THistSvc::getTrees ( ) const
virtual

Definition at line 1113 of file THistSvc.cpp.

{
names.reserve(m_uids.size());
for (itr = m_uids.begin(); itr != m_uids.end(); ++itr) {
THistID tid = itr->second;
if (tid.obj->IsA()->InheritsFrom("TTree")) {
names.push_back(itr->first);
}
}
return names;
}
StatusCode THistSvc::getTTrees ( TDirectory *  td,
TList &  tl,
bool  recurse = false 
) const
virtual

Definition at line 547 of file THistSvc.cpp.

{
gErrorIgnoreLevel = kBreak;
if (!td->cd()) {
m_log << MSG::ERROR << "getTTrees: No such TDirectory \""
<< td->GetPath() << "\"" << endmsg;
}
m_log << MSG::DEBUG << "getTHists: \"" << td->GetPath() << "\": found "
<< td->GetListOfKeys()->GetSize() << " keys" << endmsg;
TIter nextkey(td->GetListOfKeys());
while (TKey *key = (TKey*)nextkey()) {
m_log << MSG::DEBUG << " key: " << key->GetName();
TObject *obj = key->ReadObj();
if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
m_log << " (" << obj->IsA()->GetName() << ")";
} else if (obj != 0 && obj->IsA()->InheritsFrom("TTree")) {
m_log << " (" << obj->IsA()->GetName() << ")";
tl.Add(obj);
} else if (obj != 0) {
m_log << " [" << obj->IsA()->GetName() << "]";
}
}
// operate recursively
if (rcs) {
nextkey = td->GetListOfKeys();
while (TKey *key = (TKey*)nextkey()) {
TObject *obj = key->ReadObj();
if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
TDirectory *tt = dynamic_cast<TDirectory*>(obj);
getTTrees(tt, tl, rcs);
}
}
}
}
StatusCode THistSvc::getTTrees ( const std::string name,
TList &  tl,
bool  recurse = false 
) const
virtual

Definition at line 600 of file THistSvc.cpp.

{
gErrorIgnoreLevel = kBreak;
std::string stream,rem,r2;
parseString(dir,stream,rem);
map< string,pair<TFile*,Mode> >::const_iterator itr = m_files.find(stream);
if (itr != m_files.end()) {
r2 = itr->second.first->GetName();
r2 += ":/";
r2 += rem;
m_log << MSG::DEBUG << "getTTrees: \"" << dir
<< "\" looks like a stream name." << " associated TFile: \""
<< itr->second.first->GetName() << "\"" << endmsg;
if (gDirectory->cd(r2.c_str())) {
return getTTrees(gDirectory,tl,rcs);
} else {
m_log << MSG::DEBUG << "getTTrees: no such TDirectory \""
<< r2 << "\"" << endmsg;
}
} else {
m_log << MSG::DEBUG << "getTTrees: stream \"" << stream << "\" not found"
<< endmsg;
}
if (!gDirectory->cd(dir.c_str())) {
m_log << MSG::ERROR << "getTTrees: No such TDirectory/stream \"" << dir
<< "\"" << endmsg;
} else {
sc = getTTrees(gDirectory,tl,rcs);
}
return sc;
}
StatusCode THistSvc::getTTrees ( TDirectory *  td,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
virtual

Definition at line 784 of file THistSvc.cpp.

{
gErrorIgnoreLevel = kBreak;
if (!td->cd()) {
m_log << MSG::ERROR << "getTTrees: No such TDirectory \""
<< td->GetPath() << "\"" << endmsg;
}
m_log << MSG::DEBUG << "getTHists: \"" << td->GetPath() << "\": found "
<< td->GetListOfKeys()->GetSize() << " keys" << endmsg;
TIter nextkey(td->GetListOfKeys());
while (TKey *key = (TKey*)nextkey()) {
m_log << MSG::DEBUG << " key: " << key->GetName();
TObject *obj = key->ReadObj();
if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
m_log << " (" << obj->IsA()->GetName() << ")";
} else if (obj != 0 && obj->IsA()->InheritsFrom("TTree")) {
m_log << " (" << obj->IsA()->GetName() << ")";
tl.Add(obj);
if (reg && m_curstream != "") {
string dir = td->GetPath();
string fil = td->GetFile()->GetName();
dir.erase(0,fil.length()+1);
string id = "/" + m_curstream;
if ( dir == "/" ) {
id = id + "/" + key->GetName();
} else {
id = id + dir + "/" + key->GetName();
}
if (!exists(id)) {
m_log << " reg as \"" << id << "\"";
regHist(id).ignore();
} else {
m_log << " already registered";
}
}
} else if (obj != 0) {
m_log << " [" << obj->IsA()->GetName() << "]";
}
}
// operate recursively
if (rcs) {
nextkey = td->GetListOfKeys();
while (TKey *key = (TKey*)nextkey()) {
TObject *obj = key->ReadObj();
if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
TDirectory *tt = dynamic_cast<TDirectory*>(obj);
getTTrees(tt, tl, rcs, reg);
}
}
}
}
StatusCode THistSvc::getTTrees ( const std::string name,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
virtual

Definition at line 858 of file THistSvc.cpp.

{
gErrorIgnoreLevel = kBreak;
std::string stream,rem,r2;
parseString(dir,stream,rem);
map< string,pair<TFile*,Mode> >::const_iterator itr = m_files.find(stream);
if (itr != m_files.end()) {
r2 = itr->second.first->GetName();
r2 += ":/";
r2 += rem;
m_log << MSG::DEBUG << "getTTrees: \"" << dir
<< "\" looks like a stream name." << " associated TFile: \""
<< itr->second.first->GetName() << "\"" << endmsg;
if (gDirectory->cd(r2.c_str())) {
return getTTrees(gDirectory,tl,rcs,reg);
} else {
m_log << MSG::DEBUG << "getTTrees: no such TDirectory \""
<< r2 << "\"" << endmsg;
}
} else {
m_log << MSG::DEBUG << "getTTrees: stream \"" << stream << "\" not found"
<< endmsg;
}
if (!gDirectory->cd(dir.c_str())) {
m_log << MSG::ERROR << "getTTrees: No such TDirectory/stream \"" << dir
<< "\"" << endmsg;
} else {
sc = getTTrees(gDirectory,tl,rcs,reg);
}
return sc;
}
void THistSvc::handle ( const Incident )

Definition at line 1920 of file THistSvc.cpp.

{
if (signaledStop) return ;
// convert to bytes.
Long64_t mfs = (Long64_t)m_maxFileSize.value() * (Long64_t)1048576;
Long64_t mfs_warn = mfs * 95 / 100;
map<string, pair<TFile*,Mode> >::const_iterator itr;
for (itr=m_files.begin(); itr!= m_files.end(); ++itr) {
TFile* tf = itr->second.first;
#ifndef NDEBUG
m_log << MSG::DEBUG << "stream: " << itr->first << " name: "
<< tf->GetName() << " size: " << tf->GetSize()
<< endmsg;
#endif
// Signal job to terminate if output file is too large
if (tf->GetSize() > mfs) {
signaledStop = true;
m_log << MSG::FATAL << "file \"" << tf->GetName()
<< "\" associated with stream \"" << itr->first
<< "\" has exceeded the max file size of "
<< m_maxFileSize.value() << "MB. Terminating Job."
<< endmsg;
if (service("ApplicationMgr", evt, true).isSuccess()) {
evt->stopRun();
evt->release();
} else {
abort();
}
} else if (tf->GetSize() > mfs_warn) {
m_log << MSG::WARNING << "file \"" << tf->GetName()
<< "\" associated with stream \"" << itr->first
<< "\" is at 95% of its maximum allowable file size of "
<< m_maxFileSize.value() << "MB"
<< endmsg;
}
}
}
StatusCode THistSvc::initialize ( )
virtual

Reimplemented from Service.

Definition at line 70 of file THistSvc.cpp.

{
// Super ugly hack to make sure we have the OutputLevel set first, so we
// can see DEBUG printouts in update handlers.
IJobOptionsSvc* jos(0);
if( serviceLocator()->service( "JobOptionsSvc", jos, true ).isSuccess() ) {
const std::vector<const Property*> *props = jos->getProperties( name() );
if (props != NULL) {
cur != props->end(); cur++) {
if ( (*cur)->name() == "OutputLevel" ) {
setProperty( **cur ).ignore();
break;
}
}
}
}
if (status.isFailure()) {
m_log << MSG::ERROR << "initializing service" << endmsg;
return status;
}
try {
} catch ( GaudiException& err ) {
<< "Caught: " << err << endmsg;
}
try {
} catch ( GaudiException& err ) {
<< "Caught: " << err << endmsg;
}
// Protect against multiple instances of TROOT
if ( 0 == gROOT ) {
static TROOT root("root","ROOT I/O");
// gDebug = 99;
} else {
m_log << MSG::VERBOSE << "ROOT already initialized, debug = "
<< gDebug<< endmsg;
}
IIncidentSvc* p_incSvc(0);
if (service("IncidentSvc", p_incSvc, true).isFailure()) {
m_log << MSG::ERROR << "unable to get the IncidentSvc" << endmsg;
} else {
p_incSvc->addListener( this, "EndEvent", 100, true);
}
IIoComponentMgr* iomgr(0);
if (service("IoComponentMgr", iomgr, true).isFailure()) {
m_log << MSG::ERROR << "unable to get the IoComponentMgr" << endmsg;
} else {
if ( !iomgr->io_register (this).isSuccess() ) {
<< "could not register with the I/O component manager !"
<< endmsg;
} else {
bool all_good = true;
// register input/output files...
for ( Registry_t::const_iterator
ireg = m_files.begin(),
iend = m_files.end();
ireg != iend;
++ireg ) {
const std::string fname = ireg->second.first->GetName();
( ireg->second.second==THistSvc::READ
if ( !iomgr->io_register (this, iomode, fname).isSuccess () ) {
m_log << MSG::WARNING << "could not register file ["
<< fname << "] with the I/O component manager..." << endmsg;
all_good = false;
} else {
m_log << MSG::INFO << "registered file [" << fname << "]... [ok]"
<< endmsg;
}
}
if (!all_good) {
<< "problem while registering input/output files with "
<< "the I/O component manager !" << endmsg;
}
}
}
if (st.isFailure()) {
m_log << MSG::FATAL << "Unable to initialize THistSvc" << endmsg;
}
return st;
}
StatusCode THistSvc::io_reinit ( )
virtual

callback method to reinitialize the internal state of the component for I/O purposes (e.g.

upon fork(2))

Definition at line 2014 of file THistSvc.cpp.

{
bool all_good = true;
m_log << MSG::DEBUG << "reinitializing I/O..." << endmsg;
// retrieve the I/O component manager...
IIoComponentMgr* iomgr(0);
if (service("IoComponentMgr", iomgr, true).isFailure()) {
m_log << MSG::ERROR << "could not retrieve I/O component manager !"
<< endmsg;
}
// to hide the expected errors upon closing the files whose
// file descriptors have been swept under the rug...
gErrorIgnoreLevel = kFatal;
for (FileReg_t::iterator ifile = m_files.begin(), iend=m_files.end();
ifile != iend; ++ifile) {
TFile *f = ifile->second.first;
std::string fname = f->GetName();
m_log << MSG::DEBUG << "file [" << fname << "] mode: ["
<< f->GetOption() << "] r:"
<< f->GetFileBytesRead()
<< " w:" << f->GetFileBytesWritten()
<< " cnt:" << f->GetFileCounter()
<< endmsg;
if ( ifile->second.second == READ ) {
<< " TFile opened in READ mode: not reassigning names" << endmsg;
continue;
}
if ( !iomgr->io_retrieve (this, fname).isSuccess () ) {
m_log << MSG::ERROR << "could not retrieve new name for [" << fname
<< "] !!" << endmsg;
all_good = false;
continue;
} else {
m_log << MSG::DEBUG << "got a new name [" << fname << "]..." << endmsg;
}
// create a new TFile
TFile *newfile = TFile::Open (fname.c_str(), f->GetOption());
if (ifile->second.second != THistSvc::READ) {
copyFileLayout (newfile, f);
}
// loop over all uids and migrate them to the new file
// XXX FIXME: this double loop sucks...
for ( uidMap::iterator uid = m_uids.begin(), uid_end = m_uids.end();
uid != uid_end;
++uid ) {
THistID& hid = uid->second;
if ( hid.file != f ) {
continue;
}
TDirectory *olddir = this->changeDir (hid);
hid.file = newfile;
ifile->second.first = newfile;
// side-effect: create needed directories...
TDirectory *newdir = this->changeDir (hid);
TClass *cl = hid.obj->IsA();
// migrate the objects to the new file.
// thanks to the object model of ROOT, it is super easy.
if (cl->InheritsFrom ("TTree")) {
dynamic_cast<TTree*> (hid.obj)->SetDirectory (newdir);
dynamic_cast<TTree*> (hid.obj)->Reset();
}
else if (cl->InheritsFrom ("TH1")) {
dynamic_cast<TH1*> (hid.obj)->SetDirectory (newdir);
dynamic_cast<TH1*> (hid.obj)->Reset();
}
else if (cl->InheritsFrom ("TGraph")) {
olddir->Remove (hid.obj);
newdir->Append (hid.obj);
} else {
<< "id: \"" << hid.id << "\" is not a inheriting from a class "
<< "we know how to handle (received [" << cl->GetName()
<< "], " << "expected [TTree, TH1 or TGraph]) !"
<< endmsg
<< "attaching to current dir [" << newdir->GetPath() << "] "
<< "nonetheless..." << endmsg;
olddir->Remove (hid.obj);
newdir->Append (hid.obj);
}
}
f->ReOpen ("READ");
f->Close();
f = newfile;
}
}
void THistSvc::MergeRootFile ( TDirectory *  target,
TDirectory *  source 
)
private

Definition at line 1832 of file THistSvc.cpp.

{
m_log <<MSG::DEBUG << "Target path: " << target->GetPath() << endmsg;
TString path( (char*)strstr(target->GetPath(), ":") );
path.Remove( 0, 2);
source->cd(path);
TDirectory *current_sourcedir = gDirectory;
// loop over all keys in this directory
TList *lkeys=current_sourcedir->GetListOfKeys();
int nkeys=lkeys->GetEntries();
TKey *key;
for (int jj=0; jj<nkeys; jj++) {
key=(TKey*) lkeys->At(jj);
string pathnameinsource=current_sourcedir->GetPath()+string("/")+key->GetName();
m_log <<MSG::DEBUG << "Reading Key:" << pathnameinsource << endmsg;
//key->Dump();
//TObject *obj=key->ReadObj();
TObject *obj=source->Get(pathnameinsource.c_str());
if (obj) {
if (obj->IsA()->InheritsFrom("TDirectory") ) {
// it's a subdirectory
m_log <<MSG::DEBUG << "Found subdirectory " << obj->GetName()
<< endmsg;
// create a new subdir of same name and title in the target file
target->cd();
TDirectory *newtargetdir =
target->mkdir(obj->GetName(), obj->GetTitle() );
MergeRootFile(newtargetdir, source);
} else if (obj->IsA()->InheritsFrom("TTree")) {
m_log <<MSG::DEBUG << "Found TTree " << obj->GetName() << endmsg;
TTree *mytree=dynamic_cast<TTree*>(obj);
int nentries=(int) mytree->GetEntries();
mytree->SetBranchStatus("*",1);
m_log <<MSG::DEBUG << "Dumping TTree " << nentries <<" entries"
<< endmsg;
//mytree->Print();
//for (int ij=0; ij<nentries; ij++) {
//m_log <<MSG::DEBUG << "Dumping TTree Show( " << ij <<" )"
//<< endmsg;
//mytree->Show(ij);
//}
target->cd();
mytree->CloneTree();
//m_log <<MSG::DEBUG << "Writing TTree to target file: ( "
//<< mycopiedtree->Write(key->GetName()) <<" ) bytes written"
//<< endmsg;
} else {
target->cd();
obj->Write(key->GetName() );
}
}
} // while ( ( TKey *key = (TKey*)nextkey() ) )
// save modifications to target file
}
void THistSvc::parseString ( const std::string id,
std::string root,
std::string rem 
) const
private

Definition at line 1237 of file THistSvc.cpp.

{
string::size_type pos = id.find("/");
if (pos == string::npos) {
root = "";
rem = id;
return;
}
if (pos == 0) {
parseString(id.substr(1,id.length()),root,rem);
} else {
root = id.substr(0,pos);
rem = id.substr(pos+1,id.length());
}
}
StatusCode THistSvc::readHist ( const std::string name,
TH1 *&  hist 
) const
private

Definition at line 1162 of file THistSvc.cpp.

{
return readHist_i(id, hist);
}
StatusCode THistSvc::readHist ( const std::string name,
TH2 *&  hist 
) const
private

Definition at line 1169 of file THistSvc.cpp.

{
return readHist_i(id, hist);
}
StatusCode THistSvc::readHist ( const std::string name,
TH3 *&  hist 
) const
private

Definition at line 1176 of file THistSvc.cpp.

{
return readHist_i(id, hist);
}
template<typename T >
StatusCode THistSvc::readHist_i ( const std::string name,
T *&  hist 
) const
private
StatusCode THistSvc::readTree ( const std::string name,
TTree *&  hist 
) const
private

Definition at line 1183 of file THistSvc.cpp.

{
return readHist_i(id, hist);
}
StatusCode THistSvc::regGraph ( const std::string name)
virtual

Definition at line 1036 of file THistSvc.cpp.

{
TGraph *hist(0);
return regHist_i(hist, id);
}
StatusCode THistSvc::regGraph ( const std::string name,
TGraph *  hist 
)
virtual

Definition at line 1044 of file THistSvc.cpp.

{
if ( strcmp(hist->GetName(),"Graph") == 0 ) {
std::string id2(id);
string::size_type i = id2.rfind("/");
if (i != string::npos) {
id2.erase(0,i+1);
}
m_log << MSG::INFO << "setting name of TGraph id: \"" << id << "\" to \""
<< id2 << "\" since it is unset" << endmsg;
hist->SetName(id2.c_str());
}
return regHist_i(hist, id);
}
StatusCode THistSvc::regHist ( const std::string name)
virtual

Definition at line 984 of file THistSvc.cpp.

{
TH1 *hist(0);
return regHist_i(hist, id);
}
StatusCode THistSvc::regHist ( const std::string name,
TH1 *  hist 
)
virtual

Definition at line 994 of file THistSvc.cpp.

{
return regHist_i(hist, id);
}
StatusCode THistSvc::regHist ( const std::string name,
TH2 *  hist 
)
virtual

Definition at line 1001 of file THistSvc.cpp.

{
return regHist_i(hist, id);
}
StatusCode THistSvc::regHist ( const std::string name,
TH3 *  hist 
)
virtual

Definition at line 1008 of file THistSvc.cpp.

{
return regHist_i(hist, id);
}
template<typename T >
StatusCode THistSvc::regHist_i ( T *  hist,
const std::string name 
)
private
StatusCode THistSvc::regTree ( const std::string name)
virtual

Definition at line 1015 of file THistSvc.cpp.

{
TTree *hist(0);
return regHist_i(hist, id);
}
StatusCode THistSvc::regTree ( const std::string name,
TTree *  hist 
)
virtual

Definition at line 1023 of file THistSvc.cpp.

{
StatusCode sc = regHist_i(hist, id);
if (hist != 0 && sc.isSuccess()) {
if (m_autoSave != 0)
hist->SetAutoSave(m_autoSave);
hist->SetAutoFlush(m_autoFlush);
}
return sc;
}
StatusCode THistSvc::reinitialize ( )
virtual

Reimplemented from Service.

Definition at line 198 of file THistSvc.cpp.

{
m_log << MSG::WARNING << "reinitialize not implemented" << endmsg;
}
void THistSvc::removeDoubleSlash ( std::string id) const
private

Definition at line 1822 of file THistSvc.cpp.

{
while (id.find("//") != std::string::npos) {
id.replace(id.find("//"),2,"/");
}
}
void THistSvc::setupCompressionLevel ( Property cmp)
private

Definition at line 1258 of file THistSvc.cpp.

{
m_log << MSG::WARNING << "\"CompressionLevel\" Property has been deprecated. "
<< "Set it via the \"CL=\" parameter in the \"Output\" Property"
<< endmsg;
}
void THistSvc::setupInputFile ( Property inputfile)
private

call-back method to handle input stream property

Definition at line 1271 of file THistSvc.cpp.

{
itr = m_inputfile.value().begin(),
iEnd = m_inputfile.value().end();
itr != iEnd;
++itr ) {
if ( connect(*itr).isFailure() ) {
} else {
}
}
}
if ( !sc.isSuccess() ) {
throw GaudiException( "Problem connecting inputfile !!", name(),
}
return;
}
void THistSvc::setupOutputFile ( Property outputfile)
private

call-back method to handle output stream property

Definition at line 1301 of file THistSvc.cpp.

{
itr = m_outputfile.value().begin(),
iEnd = m_outputfile.value().end();
itr != iEnd;
++itr ) {
if ( connect(*itr).isFailure() ) {
} else {
}
}
}
if ( !sc.isSuccess() ) {
throw GaudiException( "Problem connecting outputfile !!", name(),
}
return;
}
void THistSvc::updateFiles ( )
private

Definition at line 1331 of file THistSvc.cpp.

{
// If TTrees grow beyond TTree::fgMaxFileSize, a new file is
// automatically created by root, and the old one closed. We
// need to migrate all the UIDs over to show the correct file
// pointer. This is ugly.
m_log << MSG::DEBUG << "updateFiles()" << endmsg;
uidMap::iterator uitr, uitr2;
for (uitr=m_uids.begin(); uitr != m_uids.end(); ++uitr) {
#ifndef NDEBUG
m_log << MSG::VERBOSE << " update: " << uitr->first << " "
<< uitr->second.id << endmsg;
#endif
TObject* to = uitr->second.obj;
TFile* oldFile = uitr->second.file;
if (!to) {
m_log << MSG::WARNING << uitr->first << ": TObject == 0" << endmsg;
} else if (to->IsA()->InheritsFrom("TTree")) {
TTree* tr = dynamic_cast<TTree*>(to);
TFile* newFile = tr->GetCurrentFile();
if (oldFile != newFile) {
std::string newFileName = newFile->GetName();
std::string oldFileName(""), streamName, rem;
TFile* dummy;
findStream(uitr->second.id, streamName, rem, dummy);
for (itr=m_files.begin(); itr!= m_files.end(); ++itr) {
if (itr->second.first == oldFile) {
itr->second.first = newFile;
}
}
uitr2 = uitr;
for (; uitr2 != m_uids.end(); ++uitr2) {
if (uitr2->second.file == oldFile) {
uitr2->second.file = newFile;
}
}
for (sitr = m_fileStreams.begin(); sitr!=m_fileStreams.end(); ++sitr) {
if (sitr->second == streamName) {
oldFileName = sitr->first;
break;
}
}
#ifndef NDEBUG
m_log << MSG::DEBUG << "migrating uid: " << uitr->second.id
<< " stream: " << streamName
<< " oldFile: " << oldFileName
<< " newFile: " << newFileName
<< endmsg;
#endif
if (oldFileName != "") {
while ( (sitr=m_fileStreams.find(oldFileName)) != m_fileStreams.end() ) {
#ifndef NDEBUG
m_log << MSG::DEBUG << "changing filename \"" << oldFileName
<< "\" to \"" << newFileName << "\" for stream \""
<< sitr->second << "\"" << endmsg;
#endif
m_fileStreams.insert( make_pair(newFileName, streamName) );
}
} else {
<< "Problems updating fileStreams with new file name" << endmsg;
}
}
}
}
}
StatusCode THistSvc::write ( )
private

Definition at line 1426 of file THistSvc.cpp.

{
map<string, pair<TFile*,Mode> >::const_iterator itr;
for (itr=m_files.begin(); itr!= m_files.end(); ++itr) {
if (itr->second.second == WRITE || itr->second.second == UPDATE
||itr->second.second==SHARE) {
itr->second.first->Write("",TObject::kOverwrite);
} else if (itr->second.second == APPEND) {
itr->second.first->Write("");
}
}
m_log << MSG::DEBUG << "THistSvc::write()::List of Files connected in ROOT "
<< endmsg;
TSeqCollection *filelist=gROOT->GetListOfFiles();
for (int ii=0; ii<filelist->GetEntries(); ii++) {
<< "THistSvc::write()::List of Files connected in ROOT: \""
<< filelist->At(ii)->GetName()<<"\""<<endmsg;
}
}

Member Data Documentation

std::set<std::string> THistSvc::m_alreadyConnectedInFiles
private

list of already connected files.

This is to keep track of files registered by the setupInputFile callback method

Definition at line 183 of file THistSvc.h.

std::set<std::string> THistSvc::m_alreadyConnectedOutFiles
private

list of already connected files.

This is to keep track of files registered by the setupOutputFile callback method

Definition at line 187 of file THistSvc.h.

IntegerProperty THistSvc::m_autoFlush
private

Definition at line 178 of file THistSvc.h.

IntegerProperty THistSvc::m_autoSave
private

Definition at line 178 of file THistSvc.h.

IntegerProperty THistSvc::m_compressionLevel
private

Definition at line 178 of file THistSvc.h.

std::string THistSvc::m_curstream
mutableprivate

Definition at line 203 of file THistSvc.h.

std::map<std::string, std::pair<TFile*,Mode> > THistSvc::m_files
private

Definition at line 195 of file THistSvc.h.

streamMap THistSvc::m_fileStreams
private

Definition at line 196 of file THistSvc.h.

idMap THistSvc::m_ids
private

Definition at line 192 of file THistSvc.h.

StringArrayProperty THistSvc::m_inputfile
private

Definition at line 176 of file THistSvc.h.

MsgStream THistSvc::m_log
mutableprivate

Definition at line 132 of file THistSvc.h.

IntegerProperty THistSvc::m_maxFileSize
private

Definition at line 178 of file THistSvc.h.

StringArrayProperty THistSvc::m_outputfile
private

Definition at line 176 of file THistSvc.h.

BooleanProperty THistSvc::m_print
private

Definition at line 179 of file THistSvc.h.

std::vector<std::string> THistSvc::m_Rstream
private

Definition at line 177 of file THistSvc.h.

std::map<std::string, std::string > THistSvc::m_sharedFiles
private

Definition at line 198 of file THistSvc.h.

objMap THistSvc::m_tobjs
private

Definition at line 193 of file THistSvc.h.

uidMap THistSvc::m_uids
private

Definition at line 191 of file THistSvc.h.

std::vector<std::string> THistSvc::m_Wstream
private

Definition at line 177 of file THistSvc.h.

bool THistSvc::signaledStop
private

Definition at line 201 of file THistSvc.h.


The documentation for this class was generated from the following files:

Generated at Thu Jul 18 2013 12:18:12 for Gaudi Framework, version v23r9 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004