source: trunk/MagicSoft/Mars/mraw/MRawFileRead.cc@ 653

Last change on this file since 653 was 609, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 3.9 KB
Line 
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
24ClassImp(MRawFileRead)
25
26MRawFileRead::MRawFileRead(const char *fname, const char *name, const char *title)
27{
28 *fName = name ? name : "MRawFileRead";
29 *fTitle = title ? title : "Read task to read DAQ binary files";
30
31 //
32 // open the input stream
33 //
34 fIn = new ifstream(fname);
35
36 if (!(*fIn))
37 *fLog << "Error: Trying to open file '" << fname << "'" << endl;
38}
39
40Bool_t MRawFileRead::PreProcess (MParList *pList)
41{
42 //
43 // remember the pointer to the parameter list fur further usage
44 //
45 pParList = pList;
46
47 //
48 // check if all necessary containers exist in the Parameter list.
49 // if not create one and add them to the list
50 //
51 fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
52 if (!fRawRunHeader)
53 {
54 *fLog << "MRawFileRead::PreProcess - WARNING: MRawRunHeader not found... creating." << endl;
55 fRawRunHeader = new MRawRunHeader;
56 pList->AddToList(fRawRunHeader);
57 }
58
59 fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
60 if (!fRawEvtHeader)
61 {
62 *fLog << "MRawFileRead::PreProcess - WARNING: MRawEvtHeader not found... creating." << endl;
63 fRawEvtHeader = new MRawEvtHeader;
64 pList->AddToList(fRawEvtHeader);
65 }
66
67 fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
68 if (!fRawEvtData)
69 {
70 *fLog << "MRawFileRead::PreProcess - WARNING: MRawEvtData not found... creating." << endl;
71 fRawEvtData = new MRawEvtData;
72 pList->AddToList(fRawEvtData);
73 }
74
75 fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
76 if (!fRawCrateArray)
77 {
78 *fLog << "MRawFileRead::PreProcess - WARNING: MRawCrateArray not found... creating." << endl;
79 fRawCrateArray = new MRawCrateArray;
80 pList->AddToList(fRawCrateArray);
81 }
82
83 fRawEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
84 if (!fRawEvtTime)
85 {
86 *fLog << "MRawFileRead::PreProcess - WARNING: MRawEvtTime not found... creating." << endl;
87 fRawEvtTime = new MTime("MRawEvtTime");
88 pList->AddToList(fRawEvtTime);
89 }
90
91 //
92 // Read RUN HEADER (see specification) from input stream
93 //
94 fRawRunHeader->ReadEvt(*fIn);
95 fRawRunHeader->Print();
96
97 //
98 // Give the run header information to the 'sub-classes'
99 //
100 fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
101 fRawEvtData ->Init(fRawRunHeader);
102
103 return kTRUE;
104}
105
106Bool_t MRawFileRead::Process()
107{
108 //
109 // Read in the next EVENT HEADER (see specification),
110 // if there is no next event anymore stop eventloop
111 //
112 if (!fRawEvtHeader->ReadEvt(*fIn))
113 return kFALSE;
114 //fRawEvtHeader->Print();
115
116 //
117 // Delete arrays which stores the pixel information (time slices)
118 //
119 fRawEvtData->DeletePixels();
120
121 //
122 // clear the TClonesArray which stores the Crate Information
123 //
124 fRawCrateArray->Clear();
125
126 //
127 // Get number of crates from the run header
128 //
129 const UShort_t nc = fRawRunHeader->GetNumCrates();
130
131 //
132 // read the CRATE DATA (see specification) from file
133 //
134 for (int i=0; i<nc; i++)
135 {
136 fRawCrateArray->GetEntry(i)->ReadEvt(*fIn);
137 //fRawCrateArray->GetEntry(i)->Print();
138
139 fRawEvtData->ReadEvt(*fIn);
140 }
141 //fRawEvtData->Print();
142
143 return kTRUE;
144
145}
146
Note: See TracBrowser for help on using the repository browser.