RootWriter.hh
Go to the documentation of this file.00001
00007 #ifndef ROOTWRITER_h
00008 #define ROOTWRITER_h
00009
00010 #include "BaseModule.hh"
00011 #include <iostream>
00012 #include <string>
00013
00014
00015 class TFile;
00016 class TTree;
00017 class RootWriter;
00018
00019
00023 class BranchEnabler{
00024 public:
00025 RootWriter* writer;
00026 BranchEnabler(RootWriter* w) : writer(w) {}
00027 };
00028
00032 class BranchDisabler{
00033 public:
00034 RootWriter* writer;
00035 BranchDisabler(RootWriter* w) : writer(w) {}
00036 };
00037
00042 class RootWriter : public BaseModule{
00043 public:
00044 static const std::string GetDefaultName(){ return "RootWriter"; }
00045 RootWriter();
00046 ~RootWriter();
00047
00049 TTree* GetTree(){ return _tree; }
00050 int Initialize();
00051 int Finalize();
00052 int Process(EventPtr evt);
00053
00055 const std::string GetFilename(){ return _filename; }
00057 void SetFilename(const std::string& name){ _filename=name; }
00059 static const std::string GetDefaultFilename(){ return "out.root"; }
00060
00062 void EnableBranch(const char* classname, const char* branchname,
00063 bool enable=true);
00065 void DisableBranch(const char* classname, const char* branchname);
00066
00067 private:
00068 void SaveConfig();
00069 std::string _filename;
00070 std::string _directory;
00071 std::string _mode;
00072 TFile* _outfile;
00073 TTree* _tree;
00074 bool default_saveall;
00075 BranchEnabler enabler;
00076 BranchDisabler disabler;
00077 };
00078
00080 inline std::istream& operator>>(std::istream& in, BranchEnabler& e)
00081 {
00082 std::string dummy;
00083 in>>dummy;
00084 size_t pos = dummy.find('.');
00085 if(pos == std::string::npos){
00086 Message(ERROR)<<"Branches to be enabled should follow the syntax CLASS.BRANCH.\n";
00087 return in;
00088 }
00089 e.writer->EnableBranch(dummy.substr(0,pos).c_str(),
00090 dummy.substr(pos+1).c_str());
00091 return in;
00092 }
00093
00095 inline std::istream& operator>>(std::istream& in, BranchDisabler& d)
00096 {
00097 std::string dummy;
00098 in>>dummy;
00099 size_t pos = dummy.find('.');
00100 if(pos == std::string::npos){
00101 Message(ERROR)<<"Branches to be disabled should follow the syntax CLASS.BRANCH.\n";
00102 return in;
00103 }
00104 d.writer->DisableBranch(dummy.substr(0,pos).c_str(),
00105 dummy.substr(pos+1).c_str());
00106 return in;
00107 }
00108
00110 inline std::ostream& operator<<(std::ostream& out, const BranchEnabler& )
00111 { return out; }
00113 inline std::ostream& operator<<(std::ostream&out, const BranchDisabler& )
00114 { return out; }
00115
00116 #endif