MilliSliceUnitTest.cpp
Go to the documentation of this file.
1 /*
2  * File: MilliSliceUnitTest.cpp
3  * Author: denis
4  *
5  * Created on September 24, 2012, 10:18 AM
6  */
7 //#include "DAQDataFormats/../unittest/RawDAQDataUnitTest.h"
8 //#include "DAQDataFormats/../unittest/MilliSliceConstructor.h"
9 #include "RawDAQDataUnitTest.h"
10 #include "MilliSliceConstructor.h"
13 
14 namespace daqdataformats {
15 
19  CPPUNIT_TEST(loopedcheckDeepCopyConstructor);
21  CPPUNIT_TEST(testReadDataIntoSameVersion);
23 public:
26 
29  void loopedcheckDeepCopyConstructor();
31 
33 
35 
36 private:
37  /// Check MilliSlice CRC
39 
40 private:
42 };
43 
44 //------------------------------------------------------------------------------
48 {
49 }
50 
51 //------------------------------------------------------------------------------
53 
54 //------------------------------------------------------------------------------
56 
57 
58  /// Loop over nanoslices
59  rawnano::NanoSliceConstructor nano_constructor;
60 
62  for(micro_constructor->_currentNanoSliceVersion = 0; micro_constructor->_currentNanoSliceVersion <= nano_constructor.getMaximumVersion(); ++(micro_constructor->_currentNanoSliceVersion)){
63 
64  /// Test filling of the MilliSlice
65  {
66  daqdataformats::RawMilliSlice* millislice = new RawMilliSlice();
67 
68  millislice->setDiblockId(5);
69  millislice->setPartition(6);
70  millislice->setTimeStartLow(7);
71  millislice->setTimeStartHigh(8);
72  millislice->setTimeLength(9);
73  millislice->setMilliSliceSEQ(10);
74  millislice->setMicroSliceTimeLength_usec(11);
75  millislice->setMonteCarloFlag(true);
76  millislice->setFrameSEQ(12);
77 
80  micro2->setTime(micro2->getTime() + 500);
81  millislice->addMicroSlice(micro1->getBuffer());
82  millislice->addMicroSlice(micro2->getBuffer());
83  millislice->close(true);
84 
85  CPPUNIT_ASSERT(compareDataFormats(millislice, micro1) == FIRST_CONTAINS_SECOND);
86  CPPUNIT_ASSERT(compareDataFormats(millislice, micro2) == FIRST_CONTAINS_SECOND);
87 
88  CPPUNIT_ASSERT(millislice->getMicrosliceNumber() == 2 );
89 
90 
91  CPPUNIT_ASSERT(millislice->sizeofdata() - micro1->sizeofdata() - micro2->sizeofdata() < 30);
92 
93  CPPUNIT_ASSERT(!isPrintDataFormatUnknownVersion(millislice));
94 
95  /// Testing CRC if the MilliSlice
96  testMilliSliceCRC(millislice);
97 
98 
99  CPPUNIT_ASSERT(_mainDFConstructor->getNanoSlicesVersion(millislice) == micro_constructor->_currentNanoSliceVersion);
100 
101 
102  delete micro1;
103  delete micro2;
104  delete millislice;
105  }// end of test filling MilliSlice
106 
107 
109  testMilliSliceCRC(df0);
110  CPPUNIT_ASSERT(df0->sizeofdata() < 100);
111 
113  testMilliSliceCRC(df1);
114  CPPUNIT_ASSERT(df1->sizeofdata() < 100);
115 
116  CPPUNIT_ASSERT(compareDataFormats(df0, df1) == DATAFORMATS_ARE_DIFFERENT);
117 
118  CPPUNIT_ASSERT(!isPrintDataFormatUnknownVersion(df0));
119  CPPUNIT_ASSERT(!isPrintDataFormatUnknownVersion(df1));
120 
121  delete df0;
122  delete df1;
123  }// end of loop over nanoslices
124 
125 }
126 
127 //------------------------------------------------------------------------------
128 // Checking MilliSlice CRC
130  CPPUNIT_ASSERT(millislice->isCRCCalculationUsed());
131  CPPUNIT_ASSERT(millislice->getCRC() > 0);
132  CPPUNIT_ASSERT(millislice->calculateCheckSum(0) == 0);
133 }
134 
135 
136 //------------------------------------------------------------------------------
137 void MilliSliceUnitTest::loopedcheckDeepCopyConstructor(){
138 
139  rawnano::NanoSliceConstructor nano_constructor;
140 
142 
143  for(micro_constructor->_currentNanoSliceVersion = 0; micro_constructor->_currentNanoSliceVersion <= nano_constructor.getMaximumVersion(); ++(micro_constructor->_currentNanoSliceVersion)){
144  LOG_DEBUG("UNITTEST")<< "From "<<__PRETTY_FUNCTION__<<". Checking Nano version "<<micro_constructor->_currentNanoSliceVersion<<std::endl;
146  }
147 
148 }
149 
150 //------------------------------------------------------------------------------
152 
153  rawnano::NanoSliceConstructor nano_constructor;
154 
156 
157  for(micro_constructor->_currentNanoSliceVersion = 0; micro_constructor->_currentNanoSliceVersion <= nano_constructor.getMaximumVersion(); ++(micro_constructor->_currentNanoSliceVersion)){
158  LOG_DEBUG("UNITTEST")<< "From "<<__PRETTY_FUNCTION__<<". Checking Nano version "<<micro_constructor->_currentNanoSliceVersion<<std::endl;
160  }
161 
162 }
163 
164 //CPPUNIT_TEST_SUITE_REGISTRATION(MilliSliceUnitTest);
166 CPPUNIT_REGISTRY_ADD_TO_DEFAULT("DAQDataFormats");
167 
168 }; // end of class
#define DEFINE_testReadDataIntoSameVersion
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
daqdataformats::RawDAQData * getFilledDataFormat(const version_t) const
bool setPartition(const uint32_t a)
Definition: RawMilliSlice.h:85
virtual DATAFORMAT_COMPARE_RESULTS compareDataFormats(const RawDAQData *, const RawDAQData *) const
Are the two data formats the same?
bool setFrameSEQ(const uint32_t a)
daqdataformats::RawDAQData * getFilledDataFormat(const daqdataformats::version_t) const
#define DEFINE_checkShallowCopyConstructor(CLASS)
Standard function that checks Shallow Copy Constructor.
void testMilliSliceCRC(RawMilliSlice *)
Check MilliSlice CRC.
bool setMilliSliceSEQ(const uint32_t a)
Definition: RawMilliSlice.h:96
virtual void checkShallowCopyConstructor()
Check Shallow Copy Constructors for all versions.
daqdataformats::RawDAQData * getEmptyDataFormat(const daqdataformats::version_t) const
method to create an empty dataformat with a given version
Base class for RawDAQData unittest.
void * getBuffer() const
Definition: RawDAQData.h:131
DEFINE_checkDeepCopyConstructor(RawMilliSlice) DEFINE_checkShallowCopyConstructor(RawMilliSlice) void loopedcheckDeepCopyConstructor()
bool setMicroSliceTimeLength_usec(const uint32_t a)
Definition: RawMilliSlice.h:97
bool close(const bool produce_crc=false)
uint64_t getTime() const
Get method for upper half of timing word.
bool setDiblockId(const uint32_t a)
Definition: RawMilliSlice.h:80
CPPUNIT_TEST(basicFieldGetAndSetChecks)
bool setTimeStartLow(const uint32_t a)
Definition: RawMilliSlice.h:87
uint32_t calculateCheckSum(const uint32_t skip_last_words) const
Definition: RawDAQData.cpp:541
uint32_t getMicrosliceNumber() const
Definition: RawMilliSlice.h:63
bool setMonteCarloFlag(const bool a)
Definition: RawMilliSlice.h:98
RawDAQDataConstructor * _dataFormatConstructor
Pointer to RawDAQDataConstructor.
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ConfigurationBlockUnitTest,"DAQDataFormats")
bool setTime(const uint64_t)
Set method for upper half of timing word.
Class to hold the MicroSlice data.
Definition: RawMicroSlice.h:48
CPPUNIT_TEST_SUITE(MilliSliceUnitTest)
bool setTimeLength(const uint32_t a)
Definition: RawMilliSlice.h:89
virtual void checkDeepCopyConstructor()
Check Deep Copy Constructors for all versions.
bool addMicroSlice(const void *microslice_buffer, const bool indexate=false, const bool check_mc_flag=false)
static const version_t DAQDATAFORMAT_UNKNOWN_VERSION
Definition: RawDAQData.h:81
uint32_t sizeofdata() const
Definition: RawMilliSlice.h:25
bool setTimeStartHigh(const uint32_t a)
Definition: RawMilliSlice.h:88
Class to hold the data from the FEBs in correct formats.
uint32_t isCRCCalculationUsed() const
Definition: RawMilliSlice.h:72
DEFINE_testReadDataIntoSameVersion void basicFieldGetAndSetChecks()
Check all field gets and sets for all versions.
version_t getNanoSlicesVersion(const RawMilliSlice *) const
Gets the NanoSlices version in the MilliSlice.
MilliSliceConstructor * _mainDFConstructor
bool isPrintDataFormatUnknownVersion(const RawDAQData *) const
Sometimes print() can print "DAQDataFormat is of unknown version".
CPPUNIT_REGISTRY_ADD_TO_DEFAULT("DAQDataFormats")