| 1 | #include <TSystem.h> | 
|---|
| 2 |  | 
|---|
| 3 | #include <TFile.h> | 
|---|
| 4 | #include <TTree.h> | 
|---|
| 5 | #include <TBranch.h> | 
|---|
| 6 |  | 
|---|
| 7 | #include "MParList.h" | 
|---|
| 8 | #include "MTaskList.h" | 
|---|
| 9 | #include "MEvtLoop.h" | 
|---|
| 10 |  | 
|---|
| 11 | #include "MLog.h" | 
|---|
| 12 | #include "MLogManip.h" | 
|---|
| 13 |  | 
|---|
| 14 | #include "MArgs.h" | 
|---|
| 15 | #include "MTime.h" | 
|---|
| 16 | #include "MRawRunHeader.h" | 
|---|
| 17 | #include "MRawEvtHeader.h" | 
|---|
| 18 | #include "MRawEvtData.h" | 
|---|
| 19 | #include "MRawCrateArray.h" | 
|---|
| 20 | #include "MInputStreamID.h" | 
|---|
| 21 |  | 
|---|
| 22 | #include "MMcEvt.hxx" | 
|---|
| 23 | #include "MMcTrig.hxx" | 
|---|
| 24 |  | 
|---|
| 25 | using namespace std; | 
|---|
| 26 |  | 
|---|
| 27 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 28 | // | 
|---|
| 29 | // This is an demonstration how to read in a merpped root file | 
|---|
| 30 | // This is a demonstration how to use root, not how you should | 
|---|
| 31 | // read a merpped file! | 
|---|
| 32 | // | 
|---|
| 33 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 34 |  | 
|---|
| 35 | static void StartUpMessage() | 
|---|
| 36 | { | 
|---|
| 37 | gLog << all << endl; | 
|---|
| 38 |  | 
|---|
| 39 | //                1         2         3         4         5 | 
|---|
| 40 | //       12345678901234567890123456789012345678901234567890 | 
|---|
| 41 | gLog << "==================================================" << endl; | 
|---|
| 42 | gLog << "              ReadRaw - MARS V" << MARSVER          << endl; | 
|---|
| 43 | gLog << "       MARS - Read and print raw data files"        << endl; | 
|---|
| 44 | gLog << "   Compiled with ROOT v" << ROOT_RELEASE << " on <" << __DATE__ << ">" << endl; | 
|---|
| 45 | gLog << "==================================================" << endl; | 
|---|
| 46 | gLog << endl; | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | static void Usage() | 
|---|
| 50 | { | 
|---|
| 51 | gLog << all << endl; | 
|---|
| 52 | gLog << "Sorry the usage is:" << endl; | 
|---|
| 53 | gLog << "   readraw [-h] [-?] [-vn] [-dec] [-a0] inputfile[.root]" << endl << endl; | 
|---|
| 54 | gLog << "     input file:   Magic DAQ binary file." << endl; | 
|---|
| 55 | gLog.Usage(); | 
|---|
| 56 | gLog << "     -d, --dec: print data in decimal values" << endl; | 
|---|
| 57 | gLog << "     -a, --no-colors: Do not use Ansii color codes" << endl; | 
|---|
| 58 | gLog << "     -?,-h,--help: This help" << endl << endl; | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | void EnableBranch(TTree *t, TString name, void *ptr) | 
|---|
| 62 | { | 
|---|
| 63 | if (!t->GetBranch(name+".")) | 
|---|
| 64 | return; | 
|---|
| 65 |  | 
|---|
| 66 | t->GetBranch(name+".")->SetAddress(ptr); | 
|---|
| 67 | gLog << " Found '" << name << "'" << endl; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | int main(int argc, char **argv) | 
|---|
| 71 | { | 
|---|
| 72 | if (!MARS::CheckRootVer()) | 
|---|
| 73 | return 0xff; | 
|---|
| 74 |  | 
|---|
| 75 | MLog::RedirectErrorHandler(MLog::kColor); | 
|---|
| 76 |  | 
|---|
| 77 | // Evaluate arguments | 
|---|
| 78 | MArgs arg(argc, argv); | 
|---|
| 79 | gLog.Setup(arg); | 
|---|
| 80 |  | 
|---|
| 81 | StartUpMessage(); | 
|---|
| 82 |  | 
|---|
| 83 | // check for the right usage of the program | 
|---|
| 84 | if (arg.HasOption("-?") || arg.HasOption("-h") || arg.HasOption("--help") || | 
|---|
| 85 | arg.GetNumArguments()!=1) | 
|---|
| 86 | { | 
|---|
| 87 | Usage(); | 
|---|
| 88 | return 2; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | arg.RemoveRootArgs(); | 
|---|
| 92 |  | 
|---|
| 93 | // Set usage of decimal values | 
|---|
| 94 | const bool kDecimal = arg.HasOnlyAndRemove("-d") || arg.HasOnlyAndRemove("--dec"); | 
|---|
| 95 |  | 
|---|
| 96 | // | 
|---|
| 97 | // check for unidentified options | 
|---|
| 98 | // | 
|---|
| 99 | if (arg.GetNumOptions()>0) | 
|---|
| 100 | { | 
|---|
| 101 | gLog << warn << "WARNING - unknown commandline options..." << endl; | 
|---|
| 102 | arg.Print("options"); | 
|---|
| 103 | gLog << endl; | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | // | 
|---|
| 107 | // Initialize Non-GUI (batch) mode | 
|---|
| 108 | // | 
|---|
| 109 | gROOT->SetBatch(); | 
|---|
| 110 |  | 
|---|
| 111 | // | 
|---|
| 112 | // This is to make argv[i] more readable insidethe code | 
|---|
| 113 | // | 
|---|
| 114 | TString kNamein = arg.GetArgumentStr(0); | 
|---|
| 115 |  | 
|---|
| 116 | // | 
|---|
| 117 | // check whether the given files are OK. | 
|---|
| 118 | // | 
|---|
| 119 | if (gSystem->AccessPathName(kNamein, kFileExists)) | 
|---|
| 120 | { | 
|---|
| 121 | if (!kNamein.EndsWith(".root")) | 
|---|
| 122 | kNamein += ".root"; | 
|---|
| 123 |  | 
|---|
| 124 | if (gSystem->AccessPathName(kNamein, kFileExists)) | 
|---|
| 125 | { | 
|---|
| 126 | gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl; | 
|---|
| 127 | return 2; | 
|---|
| 128 | } | 
|---|
| 129 | } | 
|---|
| 130 |  | 
|---|
| 131 | // | 
|---|
| 132 | //  open the file | 
|---|
| 133 | // | 
|---|
| 134 | gLog << inf << " Open the file '" << kNamein << "'" << endl; | 
|---|
| 135 | TFile input(kNamein, "READ"); | 
|---|
| 136 |  | 
|---|
| 137 | // | 
|---|
| 138 | // open the Run Header and read in | 
|---|
| 139 | // | 
|---|
| 140 | gLog << " Check for Tree 'RunHeaders'" << endl; | 
|---|
| 141 | TTree *runtree = (TTree*)input.Get("RunHeaders"); | 
|---|
| 142 | if (!runtree) | 
|---|
| 143 | gLog << warn << " WARNING - This file has no Tree 'RunHeaders'" << endl << endl; | 
|---|
| 144 | else | 
|---|
| 145 | { | 
|---|
| 146 | gLog << " Entries in Tree RunHeaders: " << dec << runtree->GetEntries() << endl; | 
|---|
| 147 |  | 
|---|
| 148 | MRawRunHeader *runheader = NULL; | 
|---|
| 149 | runtree->GetBranch("MRawRunHeader.")->SetAddress(&runheader); | 
|---|
| 150 | runtree->GetEvent(0); | 
|---|
| 151 | runheader->Print(); | 
|---|
| 152 | } | 
|---|
| 153 |  | 
|---|
| 154 | // | 
|---|
| 155 | // open the DataTree and read in | 
|---|
| 156 | // | 
|---|
| 157 | gLog << inf << " Check the Tree 'Events'" << endl ; | 
|---|
| 158 | TTree *evttree = (TTree*)input.Get("Events") ; | 
|---|
| 159 | if (!evttree) | 
|---|
| 160 | { | 
|---|
| 161 | gLog << err << "Tree 'Events' not found in file... exit!" << endl; | 
|---|
| 162 | return 2; | 
|---|
| 163 | } | 
|---|
| 164 |  | 
|---|
| 165 | // | 
|---|
| 166 | //  check the branches in the Tree | 
|---|
| 167 | // | 
|---|
| 168 | gLog << " Check all the Branches in the Tree." << endl; | 
|---|
| 169 | gLog << endl; | 
|---|
| 170 |  | 
|---|
| 171 | MRawEvtHeader  *evtheader = NULL; | 
|---|
| 172 | MTime          *evttime   = NULL; | 
|---|
| 173 | MRawEvtData    *evtdata   = NULL; | 
|---|
| 174 | MRawEvtData    *evtdata2  = NULL; | 
|---|
| 175 | MRawCrateArray *evtcrate  = NULL; | 
|---|
| 176 | MMcEvt         *evtmc     = NULL; | 
|---|
| 177 | MMcTrig        *trigmc    = NULL; | 
|---|
| 178 |  | 
|---|
| 179 | EnableBranch(evttree, "MRawEvtHeader",  &evtheader); | 
|---|
| 180 | EnableBranch(evttree, "MTime",          &evttime); | 
|---|
| 181 | EnableBranch(evttree, "MRawEvtData",    &evtdata); | 
|---|
| 182 | EnableBranch(evttree, "MRawEvtData2",   &evtdata2); | 
|---|
| 183 | EnableBranch(evttree, "MRawCrateArray", &evtcrate); | 
|---|
| 184 | EnableBranch(evttree, "MMcEvt",         &evtmc); | 
|---|
| 185 | EnableBranch(evttree, "MMcTrig",        &trigmc); | 
|---|
| 186 |  | 
|---|
| 187 | // | 
|---|
| 188 | // loop over all entries | 
|---|
| 189 | // | 
|---|
| 190 | const Int_t nent = (Int_t)evttree->GetEntries(); | 
|---|
| 191 |  | 
|---|
| 192 | gLog << " Entries in Tree Data: " << dec << nent << endl; | 
|---|
| 193 | gLog << endl; | 
|---|
| 194 |  | 
|---|
| 195 | for (Int_t i = 0; i<nent; i++) | 
|---|
| 196 | { | 
|---|
| 197 | gLog << all << "Entry: " << i << endl; | 
|---|
| 198 |  | 
|---|
| 199 | // | 
|---|
| 200 | // readin event with the selected branches | 
|---|
| 201 | // | 
|---|
| 202 | evttree->GetEvent(i); | 
|---|
| 203 |  | 
|---|
| 204 | if (evtmc) | 
|---|
| 205 | evtmc->Print(); | 
|---|
| 206 | if (trigmc) | 
|---|
| 207 | trigmc->Print("short"); | 
|---|
| 208 | if (evtheader) | 
|---|
| 209 | evtheader->Print(); | 
|---|
| 210 | if (evttime) | 
|---|
| 211 | evttime->Print(); | 
|---|
| 212 | if (evtcrate) | 
|---|
| 213 | evtcrate->Print(); | 
|---|
| 214 | if (evtdata) | 
|---|
| 215 | evtdata->Print(kDecimal?"dec":"hex"); | 
|---|
| 216 | if (evtdata2) | 
|---|
| 217 | evtdata2->Print(kDecimal?"dec":"hex"); | 
|---|
| 218 |  | 
|---|
| 219 | gLog << endl; | 
|---|
| 220 | } | 
|---|
| 221 |  | 
|---|
| 222 | // end of small readin program | 
|---|
| 223 |  | 
|---|
| 224 | return 0; | 
|---|
| 225 | } | 
|---|