| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DaqFormatFromBytes.cc

Go to the documentation of this file.
00001 /*
00002  *  DaqFormatFromBytes.cc
00003  *  RawFileReading
00004  *
00005  *  Created by Simon Patton on 7/18/10.
00006  *  Copyright 2010 DayaBay Collaboration. All rights reserved.
00007  *
00008  */
00009 #include "DaqReadoutFormat/ByteBuffer.h"
00010 #include "EventReadoutFormat/EventReadout.h"
00011 #include "FileReadoutFormat/CalibrationParametersRecord.h"
00012 #include "FileReadoutFormat/DataSeparatorRecord.h"
00013 #include "FileReadoutFormat/FileEndRecord.h"
00014 #include "FileReadoutFormat/FileTraits.h"
00015 #include "FileReadoutFormat/FileNameStrings.h"
00016 #include "FileReadoutFormat/FileStartRecord.h"
00017 #include "FileReadoutFormat/MetadataStrings.h"
00018 #include "FileReadoutFormat/RunParametersRecord.h"
00019 #include "FileReadoutFormat/DaqFormatFromBytes.h"
00020 
00021 using DybDaq::ByteBuffer;
00022 using DybDaq::CalibrationParametersRecord;
00023 using DybDaq::DataSeparatorRecord;
00024 using DybDaq::EventReadout;
00025 using DybDaq::FileBuffer;
00026 using DybDaq::FileEndRecord;
00027 using DybDaq::DaqFormatFromBytes;
00028 using DybDaq::FileNameStrings;
00029 using DybDaq::FileStartRecord;
00030 using DybDaq::MetadataStrings;
00031 using DybDaq::RunParametersRecord;
00032 
00033 static const unsigned int MINIMUM_CAPACITY = 2 * ByteBuffer::BYTES_IN_INT;
00034 
00035 DaqFormatFromBytes::DaqFormatFromBytes() :
00036 m_traits(&FileTraits::defaultTraits()),
00037 m_additionalCapacity(0) {
00038 }
00039 
00040 DaqFormatFromBytes::~DaqFormatFromBytes() {
00041 }
00042 
00043 const FileBuffer* DaqFormatFromBytes::processMarker(const ByteBuffer* buffer,
00044                                                                                                   unsigned int marker) {
00045         if (0 == m_traits || marker == m_traits->marker(FileTraits::kFileStartRecord)) {
00046                 FileStartRecord*  result = new FileStartRecord(*buffer,
00047                                                        *m_traits);
00048         buffer->release();
00049         const FileTraits* otherTraits = &(result->fileTraits());
00050         if (m_traits != otherTraits) {
00051             if (0 == otherTraits) {
00052                 delete result;
00053                 m_additionalCapacity = 0;
00054                 return 0;
00055             }
00056             m_traits = otherTraits;
00057         }
00058                 return result;
00059         }
00060         if (marker == m_traits->marker(FileTraits::kFileNameStrings)) {
00061                 const FileBuffer* result = new FileNameStrings(*buffer,
00062                                                                                                            *m_traits);
00063         buffer->release();
00064                 return result;
00065         }
00066         if (marker == m_traits->marker(FileTraits::kMetadataStrings)) {
00067                 const FileBuffer* result = new MetadataStrings(*buffer,
00068                                                                                                            *m_traits);
00069         buffer->release();
00070                 return result;
00071         }
00072         if (marker == m_traits->marker(FileTraits::kRunParametersRecord)) {
00073                 const FileBuffer* result = new RunParametersRecord(*buffer,
00074                                                                                                                    *m_traits);
00075         buffer->release();
00076                 return result;
00077         }
00078         if (marker == m_traits->marker(FileTraits::kCalibrationParametersRecord)) {
00079                 const FileBuffer* result = new CalibrationParametersRecord(*buffer,
00080                                                                                                                                    *m_traits);
00081         buffer->release();
00082                 return result;
00083         }
00084         if (marker == m_traits->marker(FileTraits::kDataSeparatorRecord)) {
00085                 DataSeparatorRecord* result = new DataSeparatorRecord(*buffer,
00086                                                                                                                           *m_traits);
00087                 unsigned int length = result->blockLength();
00088                 if (length  > buffer->remaining()) {
00089                         m_additionalCapacity = length - buffer->remaining();
00090                         delete result;
00091                         return 0;
00092                 }
00093                 const EventReadout* dataBlock = new EventReadout(*buffer);
00094         buffer->release();
00095                 result->setBlock(dataBlock);
00096                 return result;
00097         }
00098         if (marker == m_traits->marker(FileTraits::kFileEndRecord)) {
00099                 const FileBuffer* result = new FileEndRecord(*buffer,
00100                                                                                                          *m_traits);
00101         buffer->release();
00102                 return result;
00103         }
00104         m_additionalCapacity = 0;
00105         return 0;
00106 }
00107 
00108 unsigned int DaqFormatFromBytes::additionalCapacity() {
00109         return m_additionalCapacity;
00110 }
00111 
00112 const FileBuffer* DaqFormatFromBytes::createFileBuffer(const ByteBuffer* buffer) {
00113         unsigned int remaining = buffer->remaining();
00114         if (MINIMUM_CAPACITY > remaining) {
00115                 m_additionalCapacity = MINIMUM_CAPACITY - remaining;
00116                 return 0;
00117         }
00118         
00119         unsigned int size = buffer->readUnsignedInt(buffer->position() + ByteBuffer::BYTES_IN_INT);
00120         unsigned int lengthInBytes = size * ByteBuffer::BYTES_IN_INT;
00121         if (lengthInBytes >  remaining) {
00122                 m_additionalCapacity = lengthInBytes - remaining;
00123                 return 0;
00124         }       
00125         
00126         return processMarker(buffer,
00127                                                  buffer->readUnsignedInt(buffer->position()));
00128 }
00129 
00130 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:08:33 2011 for FileReadoutFormat by doxygen 1.4.7