| 1 | ////////////////////////////////////////////////////////////////////////
|
|---|
| 2 | //
|
|---|
| 3 | // MRawFileWrite
|
|---|
| 4 | //
|
|---|
| 5 | // Here we write the root containers which contains the data from a
|
|---|
| 6 | // root binary file to a root file. See also MRawFileRead
|
|---|
| 7 | //
|
|---|
| 8 | ////////////////////////////////////////////////////////////////////////
|
|---|
| 9 |
|
|---|
| 10 | #include "MRawFileWrite.h"
|
|---|
| 11 |
|
|---|
| 12 | #include <TFile.h>
|
|---|
| 13 | #include <TTree.h>
|
|---|
| 14 | #include <TBranch.h>
|
|---|
| 15 |
|
|---|
| 16 | #include "MLog.h"
|
|---|
| 17 | #include "MLogManip.h"
|
|---|
| 18 |
|
|---|
| 19 | #include "MParList.h"
|
|---|
| 20 | #include "MRawRunHeader.h"
|
|---|
| 21 | #include "MRawEvtHeader.h"
|
|---|
| 22 | #include "MRawEvtData.h"
|
|---|
| 23 | #include "MRawCrateArray.h"
|
|---|
| 24 |
|
|---|
| 25 | ClassImp(MRawFileWrite)
|
|---|
| 26 |
|
|---|
| 27 | MRawFileWrite::MRawFileWrite(const char *fname, Option_t *opt,
|
|---|
| 28 | const char *ftitle, Int_t comp,
|
|---|
| 29 | const char *name, const char *title)
|
|---|
| 30 | {
|
|---|
| 31 | *fName = name ? name : "MRawFileWrite";
|
|---|
| 32 | *fTitle = title ? title : "Write task to write DAQ root files";
|
|---|
| 33 |
|
|---|
| 34 | // FIXME: move file open to preproc!
|
|---|
| 35 |
|
|---|
| 36 | //
|
|---|
| 37 | // Open a rootfile
|
|---|
| 38 | //
|
|---|
| 39 | fOut = new TFile(fname, opt, ftitle, comp);
|
|---|
| 40 |
|
|---|
| 41 | //
|
|---|
| 42 | // test whether file is now open or not
|
|---|
| 43 | //
|
|---|
| 44 | if (!fOut->IsOpen())
|
|---|
| 45 | {
|
|---|
| 46 | *fLog << "MRawFileWrite::MRawFileWrite: ERROR: Cannot open file '";
|
|---|
| 47 | *fLog << fname << "'" << endl;
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | Bool_t MRawFileWrite::PreProcess (MParList *pList)
|
|---|
| 52 | {
|
|---|
| 53 | //
|
|---|
| 54 | // remember the pointer to the parameter list fur further usage
|
|---|
| 55 | //
|
|---|
| 56 | pParList = pList;
|
|---|
| 57 |
|
|---|
| 58 | //
|
|---|
| 59 | // check if MEvtHeader exists in the Parameter list already.
|
|---|
| 60 | // if not create one and add them to the list
|
|---|
| 61 | //
|
|---|
| 62 | fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
|
|---|
| 63 | if (!fRawEvtHeader)
|
|---|
| 64 | {
|
|---|
| 65 | *fLog << "MRawFileWrite::PreProcess - ERROR: MRawEvtHeader not found... aborting." << endl;
|
|---|
| 66 | return kFALSE;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
|---|
| 70 | if (!fRawEvtData)
|
|---|
| 71 | {
|
|---|
| 72 | *fLog << "MRawFileWrite::PreProcess - ERROR: MRawEvtData not found... aborting." << endl;
|
|---|
| 73 | return kFALSE;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
|
|---|
| 77 | if (!fRawCrateArray)
|
|---|
| 78 | {
|
|---|
| 79 | *fLog << "MRawFileWrite::PreProcess - ERROR: MRawCrateArray not found... aborting." << endl;
|
|---|
| 80 | return kFALSE;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | fRawEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
|
|---|
| 84 | if (!fRawEvtTime)
|
|---|
| 85 | {
|
|---|
| 86 | *fLog << "MRawFileWrite::PreProcess - WARNING: MRawEvtTime not found... aborting." << endl;
|
|---|
| 87 | return kFALSE;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 91 | if (!fRawRunHeader)
|
|---|
| 92 | {
|
|---|
| 93 | *fLog << "MRawFileWrite::PreProcess - ERROR: MRawRunHeader not found... aborting." << endl;
|
|---|
| 94 | return kFALSE;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | //
|
|---|
| 98 | // Write the run header information to the file
|
|---|
| 99 | //
|
|---|
| 100 | TTree *rh = new TTree("RunHeaders", "Run headers of all runs in this file");
|
|---|
| 101 | TBranch *tb = rh->Branch("MRawRunHeader", "MRawRunHeader", &fRawRunHeader, 32000, 1);
|
|---|
| 102 | rh->Fill();
|
|---|
| 103 | rh->Write();
|
|---|
| 104 | delete tb;
|
|---|
| 105 | delete rh;
|
|---|
| 106 |
|
|---|
| 107 | //
|
|---|
| 108 | // create data trees for the three types of data
|
|---|
| 109 | //
|
|---|
| 110 | fTData = new TTree("Events", "Normal Triggered Events");
|
|---|
| 111 | fTPedestal = new TTree("PedEvents", "Pedestal Triggered Events");
|
|---|
| 112 | fTCalibration = new TTree("CalEvents", "Calibration Triggered Events");
|
|---|
| 113 |
|
|---|
| 114 | //
|
|---|
| 115 | // create all branches which are necessary
|
|---|
| 116 | //
|
|---|
| 117 | fTData ->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
|
|---|
| 118 | fTPedestal ->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
|
|---|
| 119 | fTCalibration->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
|
|---|
| 120 | fTData ->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
|
|---|
| 121 | fTPedestal ->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
|
|---|
| 122 | fTCalibration->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
|
|---|
| 123 | fTData ->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 32000, 1);
|
|---|
| 124 | fTPedestal ->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 320000, 1);
|
|---|
| 125 | fTCalibration->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 320000, 1);
|
|---|
| 126 | //fTree->Branch("MRawCrateArray", fRawCrateArray->GetArray(), 32000, 1);
|
|---|
| 127 | fTData ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
|
|---|
| 128 | fTPedestal ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
|
|---|
| 129 | fTCalibration->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
|
|---|
| 130 |
|
|---|
| 131 | return kTRUE;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | Bool_t MRawFileWrite::Process()
|
|---|
| 135 | {
|
|---|
| 136 | //
|
|---|
| 137 | // get the trigger type of the actual event
|
|---|
| 138 | //
|
|---|
| 139 | const UShort_t type = fRawEvtHeader->GetTrigType();
|
|---|
| 140 |
|
|---|
| 141 | //
|
|---|
| 142 | // writa data to the tree. the tree is choosen by the type of the event
|
|---|
| 143 | //
|
|---|
| 144 | switch (type)
|
|---|
| 145 | {
|
|---|
| 146 | case kTTEvent:
|
|---|
| 147 | fTData->Fill();
|
|---|
| 148 | return kTRUE;
|
|---|
| 149 |
|
|---|
| 150 | case kTTPedestal:
|
|---|
| 151 | fTPedestal->Fill();
|
|---|
| 152 | return kTRUE;
|
|---|
| 153 |
|
|---|
| 154 | case kTTCalibration:
|
|---|
| 155 | fTCalibration->Fill();
|
|---|
| 156 | return kTRUE;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | *fLog << dbginf << "Got wrong number for the trigger type: " << type;
|
|---|
| 160 | *fLog << " - skipping" << endl;
|
|---|
| 161 |
|
|---|
| 162 | return kCONTINUE;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | Bool_t MRawFileWrite::PostProcess()
|
|---|
| 166 | {
|
|---|
| 167 | //
|
|---|
| 168 | // empty data stream
|
|---|
| 169 | //
|
|---|
| 170 | fOut->Write();
|
|---|
| 171 |
|
|---|
| 172 | //
|
|---|
| 173 | // close root file
|
|---|
| 174 | //
|
|---|
| 175 | fOut->Close();
|
|---|
| 176 |
|
|---|
| 177 | //
|
|---|
| 178 | // delete instance
|
|---|
| 179 | //
|
|---|
| 180 | delete fOut;
|
|---|
| 181 |
|
|---|
| 182 | return kTRUE;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|