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