File indexing completed on 2025-08-06 08:14:12
0001 #ifndef noiMsgTree__h
0002 #define noiMsgTree__h
0003 class noiMsgTree {
0004 private:
0005 string b_msg;
0006 TTree tree;
0007 public:
0008 bool echo_to_cout {false};
0009 noiMsgTree(bool set_echo) :
0010 b_msg{""},
0011 tree{"Messages", "Tree of messages"}
0012 {
0013 tree.Branch("messages", &b_msg);
0014 dash();
0015 msg(" Start of msg tree ");
0016 dash();
0017 echo_to_cout = set_echo;
0018 };
0019 void msg(string msg) {
0020 b_msg = msg;
0021 if (echo_to_cout) cout << b_msg << endl;
0022 tree.Fill();
0023 };
0024 void msg(vector<string> messages) {
0025 for (auto& msg : messages) {
0026 b_msg = msg;
0027 if (echo_to_cout) cout << b_msg << endl;
0028 tree.Fill();
0029 }
0030 };
0031 void dash() {
0032 b_msg = "---------------";
0033 if (echo_to_cout) cout << b_msg << endl;
0034 tree.Fill();
0035 };
0036 void write(){
0037 tree.Write();
0038 };
0039 static void read_messages(const char* f_name){
0040 cout << " Reading file: " << f_name << endl;
0041
0042 TFile* fin = new TFile(f_name, "read");
0043 if (!fin->IsOpen()) {
0044 cout << " Input file: " << f_name << " is not open." << endl;
0045 delete fin;
0046 return;
0047 }
0048 TTreeReader myReader("Messages",fin);
0049 TTreeReaderValue<string> msg(myReader, "messages");
0050 cout << " Contents of TFile(\""<<f_name<<"\") TTree(\"Messages\"):" << endl;
0051 while (myReader.Next()) cout << " " << *msg << endl;
0052 fin->Close();
0053 delete fin;
0054
0055 };
0056 void slurp_file(const char* which_file) {
0057
0058 msg(Form("--Begin contents of file \"%s\"",which_file));
0059 ifstream f_in {which_file};
0060 if (!f_in.is_open()) {
0061 msg(Form(" error: couldn't open file \"%s\"",which_file));
0062 } else {
0063 string line;
0064 while (getline(f_in,line)) msg(line);
0065 }
0066 msg(Form("--End contents of file \"%s\"",which_file));
0067 return;
0068 };
0069 };
0070 #endif
0071