Project

General

Profile

Feature #725 » InputCppDAQData.hh

Rogers, Chris, 12 October 2011 10:51

 
1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
2
 *
3
 * MAUS is free software: you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation, either version 3 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * MAUS is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
15
 *
16
 */
17

    
18
#ifndef _MAUS_SRC_INPUT_INPUTCPPDAQDATA_INPUTCPPDAQDATA_H__
19
#define _MAUS_SRC_INPUT_INPUTCPPDAQDATA_INPUTCPPDAQDATA_H__
20

    
21
#include <string>
22
#include <iostream>
23

    
24
#include "json/json.h"
25

    
26
#include "unpacking/event.h"
27
#include "unpacking/MDdateFile.h"
28
#include "unpacking/MDevent.h"
29
#include "unpacking/MDfileManager.h"
30
#include "unpacking/MDprocessManager.h"
31

    
32
#include "src/input/InputCppDAQData/UnpackEventLib.hh"
33
#include "Utils/DAQChannelMap.hh"
34
#include "Interface/Squeak.hh"
35

    
36
/** \class InputCppDAQData
37
* Load MICE raw data and unpack it into a JSON stream.
38
*
39
* This module reads data in the format of the MICE DAQ.  It drives the
40
* 'unpacker' library to do this conversion.  The end result is the MICE data
41
* in JSON format.  The data includes TDC and flash ADC values, so this
42
* information is low-level.
43
*
44
*/
45

    
46
class InputCppDAQData {
47

    
48
 public:
49

    
50
  /** Create an instance of InputCppDAQData.
51
  * 
52
  * This is the constructor for InputCppDAQData.
53
  *
54
  * \param[in] pDataPath The (directory) path to read the data from
55
  * \param[in] pFilename The filename to read from the pDataPath directory
56
  */
57
  InputCppDAQData(std::string pDataPath = "", std::string pFilename = "");
58

    
59
  /** Initialise the Unpacker.
60
  *
61
  * This prepares the unpacker to read the files given in the constructor.
62
  *
63
  * \return True if at least one file was opened sucessfully.
64
  */
65
  bool birth(std::string pJSONConfig);
66

    
67
  /** Read the next event from the file into memory.
68
  *
69
  * This function simply reads an event into memory,
70
  * it doesn't unpack the event anymore than required to read it.
71
  *
72
  * \return True if an event was read ready for unpacking.
73
  */
74
  bool readNextEvent();
75

    
76
  /** Unpack the current event into JSON.
77
  *
78
  * This unpacks the current event into _next_event and returns true on success.
79
  * Don't call this until readNextEvent() has been called and returned true at
80
  * least once!
81
  *
82
  * \return Bool indicating that the get was successful.
83
  */
84
  bool getCurEvent();
85

    
86
  /** Read the next event from the buffer and put it into _next_event
87
   *
88
   *  \return string containing the next event; or "" if unsuccessful
89
   */
90
  std::string getNextEvent();
91

    
92
  /** Return the spill number for some daq event
93
  */
94
  int getSpillNumber(Json::Value daq_event);
95

    
96
  /** Get a string containing the information for the next spill
97
  *
98
  * Unpacks all daq events in the spill and puts them into a json array. Writes
99
  * to string.
100
  *
101
  * \return string representing a json array containing daq data for all events
102
  *         in the spill
103
  */
104
  std::string getNextSpill();
105

    
106
  /** Disable one equipment type.
107
  * This disables the unpacking of the data produced by all equipment
108
	* with the specified type.
109
	*/
110
	void disableEquipment(std::string pEquipType) {
111
    _dataProcessManager.Disable(pEquipType);
112
  }
113

    
114
  /** Close the file and free memory.
115
  *
116
  * This function frees all resources allocated by Birth().
117
  * It is unlikely this will ever fail!
118
  *
119
  * \return True if successful.
120
  */
121
  bool death();
122

    
123
  /* Functions for python use only!
124
   * They are written in InputCppDAQData.i so that they
125
   * can use pure python code in the python bindings!
126
   */
127

    
128
  /** Internal emitter function.
129
  *
130
  * When called from C++, this function does nothing.
131
  * From python (where it is overriden by the bindings,
132
  * it returns an iterable result which allows access to all events.
133
  *
134
  * \return An empty string from C++.
135
  */
136
  std::string emitter() {
137
     return "";
138
  };
139

    
140
 private:
141

    
142
  /** Process manager object. */
143
  MDprocessManager _dataProcessManager;
144

    
145
  /** File manager object. */
146
  MDfileManager _dataFileManager;
147

    
148
  /** The DAQ channel map object.
149
  * It is used to group all measurements belonging to a given detector.*/
150
  DAQChannelMap _map;
151

    
152
  /** Processor for TDC particle event data. */
153
  V1290DataProcessor*  _v1290PartEventProc;
154

    
155
  /** Processor for fADC V1724 particle event data. */
156
  V1724DataProcessor*  _v1724PartEventProc;
157

    
158
  /** Processor for fADC V1731 particle event data. */
159
  V1731DataProcessor*  _v1731PartEventProc;
160

    
161
  /** Processor for scaler data. */
162
  V830DataProcessor*  _v830FragmentProc;
163

    
164
  /** Processor for VLSB data. */
165
  VLSBDataProcessor* _vLSBFragmentProc;
166

    
167
  /** Processor for DBB data. */
168
  DBBDataProcessor* _DBBFragmentProc;
169

    
170
  /** Pointer to the start of the current event. */
171
  unsigned char *_eventPtr;
172

    
173
  /** Paths to the data.
174
  * This string has to contain one or more space separated paths.
175
  */
176
  std::string _dataPaths;
177

    
178
  /** File and run names within _dataPaths.
179
  * This string has to contain one or more space separated
180
  * file names or run numbers.
181
  */
182
  std::string _datafiles;
183

    
184
  /** Enum of event types */
185
  enum {
186
    VmeTdc = 102,
187
    VmefAdc1724 = 120,
188
    VmefAdc1731 = 121,
189
    VmeScaler = 111,
190
    DBB = 141,
191
    VLSB_C = 80
192
  };
193

    
194
  /** Convert the DAQ event type (as coded in DATE) into string.
195
  * \param[in] pType The type of the event to be converted.
196
  * \return The type of the event as string.
197
  */
198
  std::string event_type_to_str(int pType);
199

    
200
  Json::Value _next_event;
201
};
202

    
203
#endif  // _MAUS_INPUTCPPDAQDATA_INPUTCPPDAQDATA_H__
(1-1/8)