76 printf(
"\tError during fiff setup raw read.\n");
86 : file(p_FiffRawData.file)
87 , info(p_FiffRawData.info)
88 , first_samp(p_FiffRawData.first_samp)
89 , last_samp(p_FiffRawData.last_samp)
90 , cals(p_FiffRawData.cals)
91 , rawdir(p_FiffRawData.rawdir)
92 , proj(p_FiffRawData.proj)
93 , comp(p_FiffRawData.comp)
114 cals = RowVectorXd();
125 bool projAvailable =
true;
127 if (this->
proj.size() == 0)
128 projAvailable =
false;
144 printf(
"No data in this range\n");
147 printf(
"Reading %d ... %d = %9.3f ... %9.3f secs...", from, to, ((
float)from)/this->
info.
sfreq, ((
float)to)/this->info.sfreq);
155 typedef Eigen::Triplet<double> T;
156 std::vector<T> tripletList;
157 tripletList.reserve(nchan);
158 for(i = 0; i < nchan; ++i)
159 tripletList.push_back(T(i, i, this->
cals[i]));
161 SparseMatrix<double> cal(nchan, nchan);
162 cal.setFromTriplets(tripletList.begin(), tripletList.end());
169 data = MatrixXd(nchan, to-from+1);
171 if (projAvailable || this->
comp.
kind != -1)
174 mult_full = this->
comp.
data->data*cal;
176 mult_full = this->
proj*cal;
183 data = MatrixXd(sel.size(),to-from+1);
186 MatrixXd selVect(sel.size(), nchan);
190 if (!projAvailable && this->
comp.
kind == -1)
193 tripletList.reserve(sel.size());
194 for(i = 0; i < sel.size(); ++i)
195 tripletList.push_back(T(i, i, this->
cals[sel[i]]));
196 cal = SparseMatrix<double>(sel.size(), sel.size());
197 cal.setFromTriplets(tripletList.begin(), tripletList.end());
203 qDebug() <<
"This has to be debugged! #1";
204 for( i = 0; i < sel.size(); ++i)
205 selVect.row(i) = this->
comp.
data->data.block(sel[i],0,1,nchan);
206 mult_full = selVect*cal;
210 for( i = 0; i < sel.size(); ++i)
211 selVect.row(i) = this->
proj.block(sel[i],0,1,nchan);
213 mult_full = selVect*cal;
217 qDebug() <<
"This has to be debugged! #3";
218 for( i = 0; i < sel.size(); ++i)
219 selVect.row(i) = this->
proj.block(sel[i],0,1,nchan);
221 mult_full = selVect*this->
comp.
data->data*cal;
226 bool do_debug =
false;
231 tripletList.reserve(mult_full.rows()*mult_full.cols());
232 for(i = 0; i < mult_full.rows(); ++i)
233 for(k = 0; k < mult_full.cols(); ++k)
234 if(mult_full(i,k) != 0)
235 tripletList.push_back(T(i, k, mult_full(i,k)));
237 SparseMatrix<double> mult(mult_full.rows(),mult_full.cols());
238 if(tripletList.size() > 0)
239 mult.setFromTriplets(tripletList.begin(), tripletList.end());
245 if (!this->
file->device()->isOpen())
247 if (!this->
file->device()->open(QIODevice::ReadOnly))
249 printf(
"Cannot open file %s",this->
info.
filename.toUtf8().constData());
259 fiff_int_t first_pick, last_pick, picksamp;
260 for(k = 0; k < this->
rawdir.size(); ++k)
266 if (thisRawDir.
last > from)
276 one.resize(nchan,thisRawDir.
nsamp);
278 one.resize(sel.cols(),thisRawDir.
nsamp);
290 if (mult.cols() == 0)
294 if (t_pTag->type == FIFFT_DAU_PACK16)
295 one = cal*(Map< MatrixDau16 >( t_pTag->toDauPack16(),nchan, thisRawDir.
nsamp)).cast<
double>();
296 else if(t_pTag->type == FIFFT_INT)
297 one = cal*(Map< MatrixXi >( t_pTag->toInt(),nchan, thisRawDir.
nsamp)).cast<
double>();
298 else if(t_pTag->type == FIFFT_FLOAT)
299 one = cal*(Map< MatrixXf >( t_pTag->toFloat(),nchan, thisRawDir.
nsamp)).cast<
double>();
301 printf(
"Data Storage Format not known jet [1]!! Type: %d\n", t_pTag->type);
307 MatrixXd newData(sel.cols(), thisRawDir.
nsamp);
309 if (t_pTag->type == FIFFT_DAU_PACK16)
311 MatrixXd tmp_data = (Map< MatrixDau16 > ( t_pTag->toDauPack16(),nchan, thisRawDir.
nsamp)).cast<
double>();
313 for(r = 0; r < sel.size(); ++r)
314 newData.block(r,0,1,thisRawDir.
nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.
nsamp);
316 else if(t_pTag->type == FIFFT_INT)
318 MatrixXd tmp_data = (Map< MatrixXi >( t_pTag->toInt(),nchan, thisRawDir.
nsamp)).cast<
double>();
320 for(r = 0; r < sel.size(); ++r)
321 newData.block(r,0,1,thisRawDir.
nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.
nsamp);
323 else if(t_pTag->type == FIFFT_FLOAT)
325 MatrixXd tmp_data = (Map< MatrixXf > ( t_pTag->toFloat(),nchan, thisRawDir.
nsamp)).cast<
double>();
327 for(r = 0; r < sel.size(); ++r)
328 newData.block(r,0,1,thisRawDir.
nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.
nsamp);
332 printf(
"Data Storage Format not known jet [2]!! Type: %d\n", t_pTag->type);
340 if (t_pTag->type == FIFFT_DAU_PACK16)
341 one = mult*(Map< MatrixDau16 >( t_pTag->toDauPack16(),nchan, thisRawDir.
nsamp)).cast<
double>();
342 else if(t_pTag->type == FIFFT_INT)
343 one = mult*(Map< MatrixXi >( t_pTag->toInt(),nchan, thisRawDir.
nsamp)).cast<
double>();
344 else if(t_pTag->type == FIFFT_FLOAT)
345 one = mult*(Map< MatrixXf >( t_pTag->toFloat(),nchan, thisRawDir.
nsamp)).cast<
double>();
347 printf(
"Data Storage Format not known jet [3]!! Type: %d\n", t_pTag->type);
353 if (to >= thisRawDir.
last && from <= thisRawDir.
first)
359 last_pick = thisRawDir.
nsamp - 1;
363 else if (from > thisRawDir.
first)
365 first_pick = from - thisRawDir.
first;
366 if(to < thisRawDir.
last)
372 last_pick = thisRawDir.
nsamp + to - thisRawDir.
last - 1;
381 last_pick = thisRawDir.
nsamp - 1;
392 last_pick = to - thisRawDir.
first;
399 picksamp = last_pick - first_pick + 1;
403 qDebug() <<
"first_pick: " << first_pick;
404 qDebug() <<
"last_pick: " << last_pick;
405 qDebug() <<
"picksamp: " << picksamp;
413 data.block(0,dest,data.rows(),picksamp) = one.block(0, first_pick, data.rows(), picksamp);
421 if (thisRawDir.
last >= to)
430 times = MatrixXd(1, to-from+1);
432 for (i = 0; i < times.cols(); ++i)
433 times(0, i) = ((float)(from+i)) / this->
info.
sfreq;
441 bool FiffRawData::read_raw_segment(MatrixXd& data, MatrixXd& times, SparseMatrix<double>& multSegment, fiff_int_t from, fiff_int_t to,
const RowVectorXi& sel)
443 bool projAvailable =
true;
445 if (this->
proj.size() == 0)
446 projAvailable =
false;
462 printf(
"No data in this range\n");
465 printf(
"Reading %d ... %d = %9.3f ... %9.3f secs...", from, to, ((
float)from)/this->
info.
sfreq, ((
float)to)/this->info.sfreq);
473 typedef Eigen::Triplet<double> T;
474 std::vector<T> tripletList;
475 tripletList.reserve(nchan);
476 for(i = 0; i < nchan; ++i)
477 tripletList.push_back(T(i, i, this->
cals[i]));
479 SparseMatrix<double> cal(nchan, nchan);
480 cal.setFromTriplets(tripletList.begin(), tripletList.end());
487 data = MatrixXd(nchan, to-from+1);
489 if (projAvailable || this->
comp.
kind != -1)
492 mult_full = this->
comp.
data->data*cal;
494 mult_full = this->
proj*cal;
501 data = MatrixXd(sel.size(),to-from+1);
504 MatrixXd selVect(sel.size(), nchan);
508 if (!projAvailable && this->
comp.
kind == -1)
511 tripletList.reserve(sel.size());
512 for(i = 0; i < sel.size(); ++i)
513 tripletList.push_back(T(i, i, this->
cals[sel[i]]));
514 cal = SparseMatrix<double>(sel.size(), sel.size());
515 cal.setFromTriplets(tripletList.begin(), tripletList.end());
521 qDebug() <<
"This has to be debugged! #1";
522 for( i = 0; i < sel.size(); ++i)
523 selVect.row(i) = this->
comp.
data->data.block(sel[i],0,1,nchan);
524 mult_full = selVect*cal;
528 for( i = 0; i < sel.size(); ++i)
529 selVect.row(i) = this->
proj.block(sel[i],0,1,nchan);
531 mult_full = selVect*cal;
535 qDebug() <<
"This has to be debugged! #3";
536 for( i = 0; i < sel.size(); ++i)
537 selVect.row(i) = this->
proj.block(sel[i],0,1,nchan);
539 mult_full = selVect*this->
comp.
data->data*cal;
544 bool do_debug =
false;
549 tripletList.reserve(mult_full.rows()*mult_full.cols());
550 for(i = 0; i < mult_full.rows(); ++i)
551 for(k = 0; k < mult_full.cols(); ++k)
552 if(mult_full(i,k) != 0)
553 tripletList.push_back(T(i, k, mult_full(i,k)));
555 SparseMatrix<double> mult(mult_full.rows(),mult_full.cols());
556 if(tripletList.size() > 0)
557 mult.setFromTriplets(tripletList.begin(), tripletList.end());
563 if (!this->
file->device()->isOpen())
565 if (!this->
file->device()->open(QIODevice::ReadOnly))
567 printf(
"Cannot open file %s",this->
info.
filename.toUtf8().constData());
577 fiff_int_t first_pick, last_pick, picksamp;
578 for(k = 0; k < this->
rawdir.size(); ++k)
584 if (thisRawDir.
last > from)
594 one.resize(nchan,thisRawDir.
nsamp);
596 one.resize(sel.cols(),thisRawDir.
nsamp);
608 if (mult.cols() == 0)
612 if (t_pTag->type == FIFFT_DAU_PACK16)
613 one = cal*(Map< MatrixDau16 >( t_pTag->toDauPack16(),nchan, thisRawDir.
nsamp)).cast<
double>();
614 else if(t_pTag->type == FIFFT_INT)
615 one = cal*(Map< MatrixXi >( t_pTag->toInt(),nchan, thisRawDir.
nsamp)).cast<
double>();
616 else if(t_pTag->type == FIFFT_FLOAT)
617 one = cal*(Map< MatrixXf >( t_pTag->toFloat(),nchan, thisRawDir.
nsamp)).cast<
double>();
619 printf(
"Data Storage Format not known jet [1]!! Type: %d\n", t_pTag->type);
625 MatrixXd newData(sel.cols(), thisRawDir.
nsamp);
627 if (t_pTag->type == FIFFT_DAU_PACK16)
629 MatrixXd tmp_data = (Map< MatrixDau16 > ( t_pTag->toDauPack16(),nchan, thisRawDir.
nsamp)).cast<
double>();
631 for(r = 0; r < sel.size(); ++r)
632 newData.block(r,0,1,thisRawDir.
nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.
nsamp);
634 else if(t_pTag->type == FIFFT_INT)
636 MatrixXd tmp_data = (Map< MatrixXi >( t_pTag->toInt(),nchan, thisRawDir.
nsamp)).cast<
double>();
638 for(r = 0; r < sel.size(); ++r)
639 newData.block(r,0,1,thisRawDir.
nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.
nsamp);
641 else if(t_pTag->type == FIFFT_FLOAT)
643 MatrixXd tmp_data = (Map< MatrixXf > ( t_pTag->toFloat(),nchan, thisRawDir.
nsamp)).cast<
double>();
645 for(r = 0; r < sel.size(); ++r)
646 newData.block(r,0,1,thisRawDir.
nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.
nsamp);
650 printf(
"Data Storage Format not known jet [2]!! Type: %d\n", t_pTag->type);
658 if (t_pTag->type == FIFFT_DAU_PACK16)
659 one = mult*(Map< MatrixDau16 >( t_pTag->toDauPack16(),nchan, thisRawDir.
nsamp)).cast<
double>();
660 else if(t_pTag->type == FIFFT_INT)
661 one = mult*(Map< MatrixXi >( t_pTag->toInt(),nchan, thisRawDir.
nsamp)).cast<
double>();
662 else if(t_pTag->type == FIFFT_FLOAT)
663 one = mult*(Map< MatrixXf >( t_pTag->toFloat(),nchan, thisRawDir.
nsamp)).cast<
double>();
665 printf(
"Data Storage Format not known jet [3]!! Type: %d\n", t_pTag->type);
671 if (to >= thisRawDir.
last && from <= thisRawDir.
first)
677 last_pick = thisRawDir.
nsamp - 1;
681 else if (from > thisRawDir.
first)
683 first_pick = from - thisRawDir.
first;
684 if(to < thisRawDir.
last)
690 last_pick = thisRawDir.
nsamp + to - thisRawDir.
last - 1;
699 last_pick = thisRawDir.
nsamp - 1;
710 last_pick = to - thisRawDir.
first;
717 picksamp = last_pick - first_pick + 1;
721 qDebug() <<
"first_pick: " << first_pick;
722 qDebug() <<
"last_pick: " << last_pick;
723 qDebug() <<
"picksamp: " << picksamp;
731 data.block(0,dest,data.rows(),picksamp) = one.block(0, first_pick, data.rows(), picksamp);
739 if (thisRawDir.
last >= to)
752 times = MatrixXd(1, to-from+1);
754 for (i = 0; i < times.cols(); ++i)
755 times(0, i) = ((float)(from+i)) / this->
info.
sfreq;
QSharedPointer< FiffTag > SPtr
static bool read_tag(FiffStream *p_pStream, FiffTag::SPtr &p_pTag, qint64 pos=-1)
bool read_raw_segment_times(MatrixXd &data, MatrixXd ×, float from, float to, const RowVectorXi &sel=defaultRowVectorXi)
QList< FiffRawDir > rawdir
QSharedPointer< FiffStream > SPtr
FIFF raw measurement data.
static bool setup_read_raw(QIODevice &p_IODevice, FiffRawData &data, bool allow_maxshield=false)
bool read_raw_segment(MatrixXd &data, MatrixXd ×, fiff_int_t from=-1, fiff_int_t to=-1, const RowVectorXi &sel=defaultRowVectorXi)
FiffNamedMatrix::SDPtr data
FiffStream class declaration.
FiffRawData class declaration.
FiffTag class declaration, which provides fiff tag I/O and processing methods.