| 1 | ////////////////////////////////////////////////////////////////////////
|
|---|
| 2 | //
|
|---|
| 3 | // MRawFile
|
|---|
| 4 | //
|
|---|
| 5 | // This tasks reads the raw binary file like specified in the TDAS???
|
|---|
| 6 | // and writes the data in the corresponding containers which are
|
|---|
| 7 | // either retrieved from the parameter list or created and added.
|
|---|
| 8 | //
|
|---|
| 9 | ////////////////////////////////////////////////////////////////////////
|
|---|
| 10 |
|
|---|
| 11 | #include "MRawFileRead.h"
|
|---|
| 12 |
|
|---|
| 13 | #include <fstream.h>
|
|---|
| 14 |
|
|---|
| 15 | #include "MLog.h"
|
|---|
| 16 | #include "MTime.h"
|
|---|
| 17 | #include "MParList.h"
|
|---|
| 18 | #include "MRawRunHeader.h"
|
|---|
| 19 | #include "MRawEvtHeader.h"
|
|---|
| 20 | #include "MRawEvtData.h"
|
|---|
| 21 | #include "MRawCrateData.h"
|
|---|
| 22 | #include "MRawCrateArray.h"
|
|---|
| 23 |
|
|---|
| 24 | ClassImp(MRawFileRead)
|
|---|
| 25 |
|
|---|
| 26 | /*
|
|---|
| 27 | ----------- please don't delete ------------
|
|---|
| 28 | #define kBUFSZ 1024
|
|---|
| 29 |
|
|---|
| 30 | class bifstream : public istream, public streambuf
|
|---|
| 31 | {
|
|---|
| 32 | private:
|
|---|
| 33 | char fBuffer[kBUFSZ]; //!
|
|---|
| 34 | FILE *fd;
|
|---|
| 35 |
|
|---|
| 36 | int sync()
|
|---|
| 37 | {
|
|---|
| 38 | memset(fBuffer, 0, kBUFSZ);
|
|---|
| 39 | return 0;
|
|---|
| 40 | }
|
|---|
| 41 | int underflow()
|
|---|
| 42 | {
|
|---|
| 43 | int sz=fread(fBuffer, 1, kBUFSZ, fd);
|
|---|
| 44 | setg(fBuffer, fBuffer, fBuffer+kBUFSZ);
|
|---|
| 45 |
|
|---|
| 46 | return sz==kBUFSZ ? *(unsigned char*)fBuffer : EOF;//EOF;
|
|---|
| 47 | }
|
|---|
| 48 | public:
|
|---|
| 49 | bifstream(const char *name) : istream(this)
|
|---|
| 50 | {
|
|---|
| 51 | fd = fopen(name, "rb");
|
|---|
| 52 | setbuf(fBuffer, kBUFSZ);
|
|---|
| 53 | }
|
|---|
| 54 | };
|
|---|
| 55 | */
|
|---|
| 56 |
|
|---|
| 57 | MRawFileRead::MRawFileRead(const char *fname, const char *name, const char *title)
|
|---|
| 58 | {
|
|---|
| 59 | *fName = name ? name : "MRawFileRead";
|
|---|
| 60 | *fTitle = title ? title : "Read task to read DAQ binary files";
|
|---|
| 61 |
|
|---|
| 62 | //
|
|---|
| 63 | // open the input stream
|
|---|
| 64 | //
|
|---|
| 65 | fIn = new ifstream(fname);
|
|---|
| 66 |
|
|---|
| 67 | if (!(*fIn))
|
|---|
| 68 | *fLog << "Error: Trying to open file '" << fname << "'" << endl;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | MRawFileRead::~MRawFileRead()
|
|---|
| 72 | {
|
|---|
| 73 | delete fIn;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | Bool_t MRawFileRead::PreProcess(MParList *pList)
|
|---|
| 77 | {
|
|---|
| 78 | //
|
|---|
| 79 | // remember the pointer to the parameter list fur further usage
|
|---|
| 80 | //
|
|---|
| 81 |
|
|---|
| 82 | //
|
|---|
| 83 | // check if all necessary containers exist in the Parameter list.
|
|---|
| 84 | // if not create one and add them to the list
|
|---|
| 85 | //
|
|---|
| 86 | fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 87 | if (!fRawRunHeader)
|
|---|
| 88 | {
|
|---|
| 89 | *fLog << "MRawFileRead::PreProcess - WARNING: MRawRunHeader not found... creating." << endl;
|
|---|
| 90 | fRawRunHeader = new MRawRunHeader;
|
|---|
| 91 | pList->AddToList(fRawRunHeader);
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
|
|---|
| 95 | if (!fRawEvtHeader)
|
|---|
| 96 | {
|
|---|
| 97 | *fLog << "MRawFileRead::PreProcess - WARNING: MRawEvtHeader not found... creating." << endl;
|
|---|
| 98 | fRawEvtHeader = new MRawEvtHeader;
|
|---|
| 99 | pList->AddToList(fRawEvtHeader);
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
|---|
| 103 | if (!fRawEvtData)
|
|---|
| 104 | {
|
|---|
| 105 | *fLog << "MRawFileRead::PreProcess - WARNING: MRawEvtData not found... creating." << endl;
|
|---|
| 106 | fRawEvtData = new MRawEvtData;
|
|---|
| 107 | pList->AddToList(fRawEvtData);
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
|
|---|
| 111 | if (!fRawCrateArray)
|
|---|
| 112 | {
|
|---|
| 113 | *fLog << "MRawFileRead::PreProcess - WARNING: MRawCrateArray not found... creating." << endl;
|
|---|
| 114 | fRawCrateArray = new MRawCrateArray;
|
|---|
| 115 | pList->AddToList(fRawCrateArray);
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | fRawEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
|
|---|
| 119 | if (!fRawEvtTime)
|
|---|
| 120 | {
|
|---|
| 121 | *fLog << "MRawFileRead::PreProcess - WARNING: MRawEvtTime not found... creating." << endl;
|
|---|
| 122 | fRawEvtTime = new MTime("MRawEvtTime");
|
|---|
| 123 | pList->AddToList(fRawEvtTime);
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | //
|
|---|
| 127 | // Read RUN HEADER (see specification) from input stream
|
|---|
| 128 | //
|
|---|
| 129 | fRawRunHeader->ReadEvt(*fIn);
|
|---|
| 130 | fRawRunHeader->Print();
|
|---|
| 131 |
|
|---|
| 132 | //
|
|---|
| 133 | // Give the run header information to the 'sub-classes'
|
|---|
| 134 | //
|
|---|
| 135 | fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
|
|---|
| 136 | fRawEvtData ->Init(fRawRunHeader);
|
|---|
| 137 |
|
|---|
| 138 | return kTRUE;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | Bool_t MRawFileRead::Process()
|
|---|
| 142 | {
|
|---|
| 143 | //
|
|---|
| 144 | // Read in the next EVENT HEADER (see specification),
|
|---|
| 145 | // if there is no next event anymore stop eventloop
|
|---|
| 146 | //
|
|---|
| 147 | if (!fRawEvtHeader->ReadEvt(*fIn))
|
|---|
| 148 | return kFALSE;
|
|---|
| 149 |
|
|---|
| 150 | //
|
|---|
| 151 | // Delete arrays which stores the pixel information (time slices)
|
|---|
| 152 | //
|
|---|
| 153 | fRawEvtData->DeletePixels();
|
|---|
| 154 |
|
|---|
| 155 | //
|
|---|
| 156 | // clear the TClonesArray which stores the Crate Information
|
|---|
| 157 | //
|
|---|
| 158 | fRawCrateArray->Clear();
|
|---|
| 159 |
|
|---|
| 160 | //
|
|---|
| 161 | // Get number of crates from the run header
|
|---|
| 162 | //
|
|---|
| 163 | const UShort_t nc = fRawRunHeader->GetNumCrates();
|
|---|
| 164 |
|
|---|
| 165 | //
|
|---|
| 166 | // read the CRATE DATA (see specification) from file
|
|---|
| 167 | //
|
|---|
| 168 | for (int i=0; i<nc; i++)
|
|---|
| 169 | {
|
|---|
| 170 | fRawCrateArray->GetEntry(i)->ReadEvt(*fIn);
|
|---|
| 171 |
|
|---|
| 172 | fRawEvtData->ReadEvt(*fIn);
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | return kTRUE;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|