Changeset 14136 for trunk/FACT++/src/smartfact.cc
- Timestamp:
- 06/09/12 21:32:09 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/smartfact.cc
r14114 r14136 526 526 527 527 template<class T> 528 void WriteBinary(const EventImp &d, const string &fname, const T &t, double scale, double offset=0) 529 { 530 const Statistics stat(t); 531 532 vector<uint8_t> val(t.size(), 0); 533 for (uint64_t i=0; i<t.size(); i++) 534 { 535 float range = nearbyint(128*(t[i]-offset)/scale); // [-2V; 2V] 536 if (range>127) 537 range=127; 538 if (range<0) 539 range=0; 540 val[i] = (uint8_t)range; 541 } 542 543 const char *ptr = reinterpret_cast<char*>(val.data()); 528 void WriteBinaryVec(const EventImp &d, const string &fname, const vector<T> &vec, double scale, double offset=0) 529 { 530 if (vec.size()==0) 531 return; 532 533 const Statistics stat(vec[0]); 544 534 545 535 ostringstream out; … … 550 540 out << stat.min << '\n'; 551 541 out << stat.med << '\n'; 552 out << stat.max << '\n'; 553 out.write(ptr, val.size()*sizeof(uint8_t)); 542 out << stat.max << '\0'; 543 for (auto it=vec.begin(); it!=vec.end(); it++) 544 { 545 // The valid range is from 1 to 127 546 // \0 is used to seperate different curves 547 vector<uint8_t> val(it->size()); 548 for (uint64_t i=0; i<it->size(); i++) 549 { 550 float range = nearbyint(126*(double(it->at(i))-offset)/scale)+1; // [-2V; 2V] 551 if (range>127) 552 range=127; 553 if (range<1) 554 range=1; 555 val[i] = (uint8_t)range; 556 } 557 558 const char *ptr = reinterpret_cast<char*>(val.data()); 559 out.write(ptr, val.size()*sizeof(uint8_t)); 560 out << '\0'; 561 } 554 562 555 563 ofstream(fPath+"/"+fname+".bin") << out.str(); 564 } 565 566 template<class T> 567 void WriteBinary(const EventImp &d, const string &fname, const T &t, double scale, double offset=0) 568 { 569 WriteBinaryVec(d, fname, vector<T>(&t, &t+1), scale, offset); 556 570 } 557 571
Note:
See TracChangeset
for help on using the changeset viewer.