-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdrsreadn.cpp
More file actions
216 lines (184 loc) · 5.23 KB
/
drsreadn.cpp
File metadata and controls
216 lines (184 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include "drsreadn.h"
DrsReadN::DrsReadN()
{
}
DrsReadN::~DrsReadN()
{
}
TypeData DrsReadN::checkTypeOfDrsData(string filename)
{
/**
\brief Статическая функция предназначенная для определения типа данных.
После добавления новых типов следует править эту функцию и добавить новый тип в TypeData.
\param filename имя входного файла
\return Тип данных, либо определенный тип DRS, либо unknown
*/
ifstream dataIn;
dataIn.open(filename.c_str(), ios_base::binary);
TypeData type;
if (!dataIn)
{
cerr << RED_SH << " file doesn`t exist or error open " << ENDCOLOR << endl;
dataIn.close();
exit(1);
}
char ifDRSformat[5];
dataIn.read((char*)&ifDRSformat,4*sizeof(char));
ifDRSformat[4]='\0';
if (strcmp(ifDRSformat,drs4Mark.c_str())==0)
{
type = TypeData::drs40;
}
else if (strcmp(ifDRSformat,drs450Mark.c_str())==0)
{
type = TypeData::drs450;
}
else
{
type = TypeData::unknown;
}
dataIn.close();
return type;
}
void DrsReadN::useSafetyMode()
{
/**
\brief Включить безопасный режим. Использовать, если количество используемых каналов изменялось во время набора
*/
cout << YELLOW_SH << "Safety mode " << ENDCOLOR << endl;
cout << endl;
nChannels = maxNumOfChannels;
cout << " Used number of channels\t"<< BLUE_SH << nChannels << ENDCOLOR << endl;
cout << "----------" << endl;
}
unsigned short DrsReadN::getNumOfChannels()
{
/**
\brief Возвращает число задействованных каналов
*/
return nChannels;
}
unsigned short DrsReadN::getNumOfSamples()
{
/**
\brief Возвращает число сэмплов в единичном импульсе
*/
return nSamples;
}
void DrsReadN::setMaxNumOfChannels(short nCh)
{
maxNumOfChannels = nCh;
}
void DrsReadN::drsStreamOpen(string filename)
{
drsInput.open(filename.c_str(), ios_base::binary);
if (!drsInput)
{
cerr << RED_SH << " File doesn`t exist or error open " << ENDCOLOR << endl;
drsInput.close();
exit(1);
}
drsInput.seekg (0, ios::end);
pos_mark_end = drsInput.tellg();
drsInput.seekg(ios_base::beg);
}
void DrsReadN::drsStreamClose()
{
cout << " File close " << endl;
drsInput.close();
}
void DrsReadN::drsFileSeekBegin()
{
if (!drsInput.good())
{
drsInput.clear();
}
drsInput.seekg(ios_base::beg);
pos_mark = drsInput.tellg();
isEndFile = false;
}
std::string DrsReadN::getNameOfDataFile()
{
return fileDataName;
}
/*vector<long>*/std::pair<unsigned long,unsigned long> DrsReadN::getTimeStampsOfEvents()
{
/**
\brief Возвращает вектор TimeStamps событий. Записаны в секундах с 1.1.1970
\return вектор TimeStamps событий
*/
return timeStamps;
}
bool DrsReadN::updateFileInfo()
{
struct stat buffer;
stat(fileDataName.c_str(),&buffer);
unsigned long size = buffer.st_size;
if (size > sizeOfFile)
{
// cout << " file updated " << endl;
sizeOfFile = size;
isUpdatedfile = true;
// cout << " file new size: " << sizeOfFile << endl;
}
else
{
isUpdatedfile = false;
}
return isUpdatedfile;
}
vector<unsigned short> DrsReadN::getChannelsInBoard()
{
vector<unsigned short> x;
x.push_back(nChannels);
return x;
}
void DrsReadN::drsCheckFileStream()
{
pos_mark = drsInput.tellg();
if (!drsInput.good())
{
drsInput.clear();
}
drsInput.seekg(pos_mark,ios_base::beg);
}
void DrsReadN::readTimeInfo(DataMarker position)
{
/* If isBegin = true is begin of reading of data
* if isBegin = false is end
*/
// struct tm timeinfo;
short tYear,tMon,tDay,tHour,tMin,tSec,tmSec;
if (position == DataMarker::begin || position == DataMarker::end)
{
drsInput.read((char*)&tYear,sizeof(short));
drsInput.read((char*)&tMon,sizeof(short));
drsInput.read((char*)&tDay,sizeof(short));
drsInput.read((char*)&tHour,sizeof(short));
drsInput.read((char*)&tMin,sizeof(short));
drsInput.read((char*)&tSec,sizeof(short));
drsInput.read((char*)&tmSec,sizeof(short));
drsInput.seekg(sizeof(short int),ios::cur);
timeinfo.tm_year = (int)(tYear - 1900);
timeinfo.tm_mon = (int)(tMon - 1);
timeinfo.tm_mday = (int)tDay;
timeinfo.tm_hour = (int)tHour;
timeinfo.tm_min = (int)tMin;
timeinfo.tm_sec = (int)tSec;
}
if (position == DataMarker::body)
{
drsInput.seekg(8*sizeof(short int),ios::cur);
}
if (position == DataMarker::begin)
{
time_t date = mktime(&timeinfo);
//date = mktime(timeinfo);
timeStamps.first = date;//*1000+tmSec;
}
if (position == DataMarker::end)
{
time_t date = mktime(&timeinfo);
timeStamps.second = (unsigned long)date;//*1000+tmSec;
}
}