1 #include "DAQDataFormats/RawDAQData.h" 2 #include "DAQDataFormats/BitFields.h" 3 #include "DAQDataFormats/NOvACheckSum.h" 4 #include <DAQDataFormats/Macros.h> 5 #include <DAQDataFormats/DataFormatException.h> 7 #include <boost/lexical_cast.hpp> 8 #include <boost/format.hpp> 16 ,_shouldBufferBeInternal (false)
19 ,_function_sizeofdata (NULL)
20 ,_function_print (&
RawDAQData::printUnknownVersion)
21 ,_function_readData (&
RawDAQData::readDataUnknownVersion)
22 ,_function_setBufferSource(&
RawDAQData::setBufferSource)
31 ,_function_sizeofdata (NULL)
42 ,_function_sizeofdata (NULL)
75 ,_function_sizeofdata (NULL)
86 ,_function_init ((
init_t)init_function_pointer)
87 ,_function_sizeofdata (NULL)
94 Init_t(init_function_pointer),
99 ,_function_init ((
init_t)init_function_pointer)
108 Init_t(init_function_pointer),
114 ,_function_init ((
init_t)init_function_pointer)
123 Init_t(init_function_pointer),
131 ,_function_init ((
init_t)init_function_pointer)
144 ,_function_init (copy_in._function_init)
145 ,_function_sizeofdata (copy_in._function_sizeofdata)
146 ,_function_print (copy_in._function_print)
147 ,_function_readData (copy_in._function_readData)
148 ,_function_setBufferSource(copy_in._function_setBufferSource)
154 if(copy_in.
_Buffer == NULL)
return;
162 PRINT_ON_DEBUG(
"From RawDAQData::copy. Buffer is External. Using setBufferSource.");
204 const uint32_t*
buffer = (
const uint32_t*)buffer_void;
206 if(buffer == 0){
return 0;}
214 int32_t words_to_assign = int32_t(
_InternalBuffer.size()) - int32_t(buffer_start_position);
216 PRINT_ON_DEBUG (
"Size="<<
_InternalBuffer.size()<<
" buffer_start_pos="<<buffer_start_position<<
" size_of_data_to_read="<<size_of_data_to_read);
218 EXECUTE_ON_DEBUG(
if(words_to_assign < 0) {
std::cout<<
"FROM "<<__PRETTY_FUNCTION__<<
"words_to_assign is negative("<<words_to_assign<<
"). SOMETHING MUST BE WRONG\n";
exit(1);});
221 if(words_to_assign > 0)
222 words_to_assign =
std::min(int32_t(size_of_data_to_read), words_to_assign);
231 for(; i < uint32_t(words_to_assign); ++
i ){
236 for(; i < size_of_data_to_read; ++
i ){
242 for(uint32_t
i = 0;
i < size_of_data_to_read; ++
i ){
249 return (
void*)(buffer + size_of_data_to_read);
261 const ssize_t
ss = read(fd,
_Buffer, (
size_t)size_of_data*
sizeof(uint32_t));
263 if (ss == -1 || ss == 0)
return rds_error;
265 if ((uint32_t)ss == size_of_data*
sizeof(uint32_t))
return rds_complete;
285 for(uint32_t
i = 0;
i < size_of_data; ++
i)
304 if(buffer == 0){
return 0;}
306 uint32_t* write_buffer = (uint32_t*)buffer;
310 for(uint32_t
i = 0;
i < size_of_data; ++
i){
331 ,
const bool print_offset
332 ,
const bool print_ascii
333 ,
const bool print_buffer_address
334 ,
const bool print_internal_buffer
335 ,
const bool print_size_of_data
341 if(print_buffer_address){
343 uint32_t* buf = (uint32_t*)
_Buffer;
344 out_stream<<
"Buffer address is "<<buf<<
std::endl;
348 if(print_internal_buffer){
356 out_stream<<
"Using Internal Buffer.";
358 out_stream<<
"Using External Buffer.";
364 out_stream<<
"Internal Buffer size is ZERO"<<
std::endl;
372 if(print_size_of_data)
373 out_stream<<
"Size of data = "<<size_of_data<<
std::endl;
376 uint32_t* data_buffer = (uint32_t*)
_Buffer;
379 char* ascii_buffer = (
char*)
_Buffer;
382 for(uint32_t
i = 0;
i < size_of_data; ++
i){
385 if((print_offset && !(
i % cols))){
386 out_stream<<
boost::format(
"[Offset=%08x bytes] \t")%(uint32_t)((data_buffer-(uint32_t*)
_Buffer)*
sizeof(uint32_t));
394 if((
i + 1) % cols == 0 ||
i == size_of_data-1){
399 uint32_t nsymbols =
cols;
401 if(
i == size_of_data-1){
402 nsymbols = size_of_data %
cols;
407 if(size_of_data / cols){
408 for(uint32_t itab = 0; itab < cols - nsymbols; ++itab)
412 out_stream<<
"(ASCII=";
415 for(uint32_t
j = 0;
j <
sizeof(uint32_t) * nsymbols; ++
j){
418 if( (*ascii_buffer < 32) || (*ascii_buffer > 126)){
431 out_stream<<separation_between_lines;
442 const uint32_t rawbuf =
RAWBUFF32[iword];
446 if(is_bynary_printing){
458 uint32_t value_copy =
value;
460 const int SHIFT = 8 *
sizeof( unsigned ) - 1;
461 const unsigned MASK = 1 << SHIFT;
463 for (
int i = 1;
i <= SHIFT + 1;
i++ ){
464 out_stream << ( value_copy & MASK ?
'1' :
'0' );
467 if (
i % 8 == 0 ) out_stream <<
' ';
480 const uint32_t*
buffer = (uint32_t*)buffer0;
481 for(uint32_t iword = 0; iword <
size; ++iword){
490 const uint32_t*
buffer = (uint32_t*)buffer0;
491 for(uint32_t iword = 0; iword <
size; ++iword){
506 std::ostringstream
str;
510 output_string = str.str();
520 output_stream<<
"----------General printing of a DAQDataFormat member-----------size="<<size_of_data<<
std::endl;
521 output_stream<<std::endl<<
"nRAW:";
522 for(uint32_t
i = 0;
i < size_of_data; ++
i){
527 output_stream<<
"\nRAW:";
528 for(uint32_t
i = 0;
i < size_of_data; ++
i){
529 if(
i > 0)output_stream<<
" ";
586 for(uint32_t
i = 0;
i < size_of_data; ++
i)
673 PRINT_ON_DEBUG(__PRETTY_FUNCTION__<<
" 3 (after resizing InternalBuffer, before assigning _Buffer pointer)");
678 PRINT_ON_DEBUG(__PRETTY_FUNCTION__<<
" 4 (after assigning _Buffer pointer)");
685 PRINT_ON_DEBUG (__PRETTY_FUNCTION__<<
" 5 (after setting Function pointers)");
686 PRINT_ON_DEBUG (
"sizeofdata_function_pointer="<<_function_sizeofdata);
690 PRINT_ON_DEBUG (__PRETTY_FUNCTION__<<
" 6 (about to do resizeBuffer)");
700 PRINT_ON_DEBUG (__PRETTY_FUNCTION__<<
" 7 (about to call reset_buffer_source)");
748 PRINT_ON_DEBUG (__PRETTY_FUNCTION__<<
" 3 (after resizing InternalBuffer, before assigning _Buffer pointer)");
753 PRINT_ON_DEBUG (__PRETTY_FUNCTION__<<
" 4 (after assigning _Buffer pointer)");
760 PRINT_ON_DEBUG (__PRETTY_FUNCTION__<<
" 5 (after setting Function pointers)");
763 PRINT_ON_DEBUG (__PRETTY_FUNCTION__<<
" 6 (about to do resizeBuffer)");
773 PRINT_ON_DEBUG (__PRETTY_FUNCTION__<<
" 7 (about to call reset_buffer_source)");
859 PRINT_ON_DEBUG(__PRETTY_FUNCTION__ <<
" 32 (about to do setBufferSource)");
867 std::cout<<
"Something is wrong in RawDAQData::copy";
890 const uint32_t* next_block_pointer = ((uint32_t*)(pointer)) + dataformat.
sizeofdata();
891 PRINT_ON_DEBUG(__PRETTY_FUNCTION__<<
" Size of data="<<dataformat.
sizeofdata()<<
". Next pointer will be"<<next_block_pointer);
892 return (
void*)next_block_pointer;
911 out_low_word = input_data & 0xffffffff;
912 out_hi_word = input_data >> 32;
954 +
". Whereas the maximum version allowed is " + boost::lexical_cast<std::string>(maximum_version);
967 if(
function.
size() > 0){
968 output_message =
"\nFunction " +
function +
" ";
971 output_message =
"Operation ";
974 output_message.append(
" is Not allowed");
975 output_message.append(
" for version " + boost::lexical_cast<std::string>(
_version));
976 output_message.append(
".");
978 if(message.size() > 0)
979 output_message +=
" " + message;
996 if(mask == 0x0)
return 0;
1000 for(; ibit < 32; ++ibit){
1003 if(mask & (0
x1 << ibit))
return ibit;
1014 dataformat.
print(os);
#define EXECUTE_FUNCTION(FULLFUNCTIONNAME)
Execute and return the delegate.
Float_t x1[n_points_granero]
::xsd::cxx::tree::buffer< char > buffer
#define RETURN_FUNCTION(FULLFUNCTIONNAME)
const XML_Char int const XML_Char * value
#define EXECUTE_GENERAL_FUNCTION(FULLFUNCTIONNAME)
Macro to execute the function given a function pointer.
std::string format(const int32_t &value, const int &ndigits=8)
#define ResetBufferSource_t(FUNC)
#define resetBufferSource_t
#define setBufferSource_t
#define PRINT_ON_DEBUG(x)
T min(const caf::Proxy< T > &a, T b)
#define DELEGATE(CLASS, FUNC, OUTPUT,...)
Delegate (or function pointer)