Cat
UsbFTInterfaceTest.cpp
Go to the documentation of this file.
1 // $Id: UsbFTInterfaceTest.cpp,v 1.4 2006/03/16 17:08:23 fmachefe Exp $
2 
3 // Include files
4 #include <ctime>
5 
6 // ROOT include files
7 #include "TRandom.h"
8 #include "TH1D.h"
9 
10 // local
11 #include "UsbFTInterface.h"
12 #include "UsbFTInterfaceTest.h"
13 
14 //-----------------------------------------------------------------------------
15 // Implementation file for class : UsbFTInterfaceTest
16 //
17 // 2004-07-23 : Fr�d�ric Machefert
18 //-----------------------------------------------------------------------------
19 
20 //=============================================================================
21 // Standard constructor, initializes variables
22 //=============================================================================
24  m_address(1),
25  m_size (64),
26  m_mean (30000.),
27  m_sigma(10000.)
28  {
29  setName ( "UsbFTInterfaceTest" );
30  setType ( "UsbFTInterface" );
31  setTitle( "UsbFTInterface test" );
32 }
33 
34 //=========================================================================
35 // virtual function intialize
36 //=========================================================================
38  openRootFile ();
39  m_write=new TH1D( "Write" , "Write" , 1000 , 0. , 65535. );
40  m_read =new TH1D( "Read" , "Read" , 1000 , 0. , 65535. );
41  m_error=new TH1D( "Error" , "Error" , 1000 , 0. , 65535. );
42  m_rnd =new TRandom();
43  addDataStream("Write","Written values");
44  addDataStream("ErrorWrite","Error - Written values if Error");
45  addDataStream("ErrorRead","Error - Read values if Error");
46  addDataStream("TimeWrite","Time to write");
47  addDataStream("TimeRead","Time to read");
48  // addHisto1d( m_write );
49  // addHisto1d( m_read );
50  return StatusCode::SUCCESS;
51 }
52 
53 //=========================================================================
54 // Virtual function execute
55 //=========================================================================
57 
58  // prepare vector to be written
59  std::vector<U32> write,read;
60  write.reserve(m_size);
61  read.reserve(m_size);
62  for (unsigned int i=0; i<m_size; ++i){
63  write.push_back((unsigned int)((U16)(m_rnd->Gaus(m_mean,m_sigma))));
64  }
65 
66  // fetch the usb interface
67  UsbFTInterface *usb=dynamic_cast<UsbFTInterface*>( element() );
69 
70  // write / read and measure times
71  float tw,tr;
72  clock_t start;
73  start=clock();
74  usb->usbWrite(m_address,write);
75  tw=elapsedTime(start);
76  start=clock();
77  usb->usbRead(m_address,m_size,read);
78  tr=elapsedTime(start);
79  dataFill("TimeWrite",tw);
80  dataFill("TimeRead",tr);
81 
82  // store values and check errors
83  float w,r;
84  for (unsigned int i=0; i<m_size; ++i){
85  w=write[i];
86  r=read[i];
87  dataFill("Write",w);
88  m_write->Fill(w);
89  m_read->Fill(r);
90  if (w!=r){
91  warning("Error!");
92  m_error->Fill(w);
93  dataFill("ErrorWrite",w);
94  dataFill("ErrorRead",r);
95  }
96  }
97  return StatusCode::SUCCESS;
98 }
99 
100 //=========================================================================
101 // Virtual function finalize
102 //=========================================================================
104  closeRootFile(); // Deletes the histos -> do not make it yourself !!!
105  return StatusCode::SUCCESS;
106 }
void openRootFile()
Definition: Processus.cpp:146
StatusCode usbRead(unsigned long int, unsigned long int, std::vector< U32 > &)
StatusCode usbWrite(unsigned long int, std::vector< U32 >)
void setName(std::string name)
Definition: Object.h:51
virtual StatusCode initialize()
Destructor.
void addDataStream(std::string name, std::string title)
Definition: Processus.h:153
void closeRootFile()
Definition: Processus.cpp:160
double elapsedTime()
Definition: Processus.h:340
void setType(std::string type)
Definition: Object.h:52
UsbFTInterfaceTest()
Standard constructor.
void setTitle(std::string title)
Definition: Object.h:54
virtual StatusCode finalize()
Element * element()
Definition: Processus.h:231
virtual StatusCode execute()
void setWordSize(unsigned long wordSize)
StatusCode dataFill(int i, double val)
Definition: Processus.h:175
void warning(std::string mymsg)
Definition: Object.h:39