Cat
PhaserRampExec.cpp
Go to the documentation of this file.
1 // $Id: PhaserRampExec.cpp,v 1.4 2006/03/16 17:08:23 fmachefe Exp $
2 
3 // Include files
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <time.h>
7 #include <ctime>
8 
9 // ROOT include files
10 #include "TROOT.h"
11 #include "TObject.h"
12 #include "TFile.h"
13 #include "TH1F.h"
14 
15 
16 // CATCore include files
17 #include "Element.h"
18 #include "Phaser.h"
19 
20 // CATProc include files
21 #include "Histo1D.h"
22 #include "Plot.h"
23 
24 // local
25 #include "PhaserRampExec.h"
26 
27 //-----------------------------------------------------------------------------
28 // Implementation file for class : PhaserRampExec
29 //
30 // 2004-07-23 : Frédéric Machefert
31 //-----------------------------------------------------------------------------
32 
33 //=============================================================================
34 // Standard constructor, initializes variables
35 //=============================================================================
37  setName ( "PhaserRampExec" );
38  setType ( "Phaser" );
39  setTitle( "Phaser I2C Configuration Test" );
40 }
41 //=============================================================================
42 // Destructor
43 //=============================================================================
45 
46 //=========================================================================
47 // virtual function intialize
48 //=========================================================================
50 
51  info("" );
52  info("____________________________");
53  info("Phaser Configuration Control");
54  info(" =>" + element()->path() + " " +
55  element()->name() + " " + element()->type() );
56 
57  m_phaser=dynamic_cast<Phaser*>( element() );
58 
59  srand( (unsigned)time( NULL ) );
60 
61  m_phaser->read();
62 
63  m_initPhase[0]=m_phaser->phase(0);
64  m_initPhase[1]=m_phaser->phase(1);
65  m_initPhase[2]=m_phaser->phase(2);
66  m_initPhase[3]=m_phaser->phase(3);
67 
68  openRootFile ();
69 
70  hv1=new TH1D( "Delay1" , "Delay Channel 1" , 25 , 0. , 25. );
71  hv2=new TH1D( "Delay2" , "Delay Channel 2" , 25 , 0. , 25. );
72  hv3=new TH1D( "Delay3" , "Delay Channel 3" , 25 , 0. , 25. );
73  hv4=new TH1D( "Delay4" , "Delay Channel 4" , 25 , 0. , 25. );
74 
75  h1=new TH1D( "Error1" , "Error Channel 1" , 25 , 0. , 25. );
76  h2=new TH1D( "Error2" , "Error Channel 2" , 25 , 0. , 25. );
77  h3=new TH1D( "Error3" , "Error Channel 3" , 25 , 0. , 25. );
78  h4=new TH1D( "Error4" , "Error Channel 4" , 25 , 0. , 25. );
79 
81  errorCount=0;
82  startChrono();
83 
84  return StatusCode::SUCCESS;
85 }
86 
87 //=========================================================================
88 // Virtual function execute
89 //=========================================================================
91 
93 
94  int v1 = (int) ( (float)rand()/RAND_MAX * 25. );
95  int v2 = (int) ( (float)rand()/RAND_MAX * 25. );
96  int v3 = (int) ( (float)rand()/RAND_MAX * 25. );
97  int v4 = (int) ( (float)rand()/RAND_MAX * 25. );
98 
99  m_phaser->setPhase(v1,v2,v3,v4);
100  m_phaser->write();
101  m_phaser->read();
102 
103  int d0=m_phaser->phase(0);
104  int d1=m_phaser->phase(1);
105  int d2=m_phaser->phase(2);
106  int d3=m_phaser->phase(3);
107 
108  hv1->Fill(v1);
109  hv2->Fill(v2);
110  hv3->Fill(v3);
111  hv4->Fill(v4);
112 
113 
114  if( v1!=d0 || v2!=d1 || v3!=d2 || v4!=d3 ){
115 
116  if ( d0 != v1 ) h1->Fill(int(d0));
117  if ( d1 != v2 ) h2->Fill(int(d1));
118  if ( d2 != v3 ) h3->Fill(int(d2));
119  if ( d3 != v4 ) h4->Fill(int(d3));
120 
121  errorCount++;
122  info("WRITE/READ INCOMPATIBILTY ["+
123  itos(errorCount)+"] " +
124  itos(v1)+"/"+itos(d0)+" "+
125  itos(v2)+"/"+itos(d1)+" "+
126  itos(v3)+"/"+itos(d2)+" "+
127  itos(v4)+"/"+itos(d3),
128  "Phaser::ramp");
129  // return false;
130  }
131 
132  return StatusCode::SUCCESS;
133 }
134 
135 
136 //=========================================================================
137 // Virtual function finalize
138 //=========================================================================
140  info("__" );
141  info("Errors "+itos(errorCount));
142  info("Processed Events "+itos(m_nProcessedEvents));
143  info("Elapsed Time "+ftos(elapsedTime())+" s.");
144  info("****************************" );
145 
147  m_initPhase[1],
148  m_initPhase[2],
149  m_initPhase[3]);
150 
151  m_phaser->write();
152 
153  closeRootFile();
154 
155  hv1->Delete();
156  hv2->Delete();
157  hv3->Delete();
158  hv4->Delete();
159  h1->Delete();
160  h2->Delete();
161  h3->Delete();
162  h4->Delete();
163 
164  return StatusCode::SUCCESS;
165 }
void info(std::string mymsg)
Definition: Object.h:38
std::string itos(int)
Definition: Tools.cpp:46
void openRootFile()
Definition: Processus.cpp:146
virtual StatusCode execute()
std::string ftos(float)
Definition: Tools.cpp:53
Definition: Phaser.h:19
void setPhase(unsigned char channel, unsigned char value)
Definition: Phaser.h:42
void setName(std::string name)
Definition: Object.h:51
virtual ~PhaserRampExec()
Destructor.
PhaserRampExec()
Standard constructor.
void closeRootFile()
Definition: Processus.cpp:160
double elapsedTime()
Definition: Processus.h:340
void setType(std::string type)
Definition: Object.h:52
virtual StatusCode finalize()
virtual StatusCode initialize()
void setTitle(std::string title)
Definition: Object.h:54
unsigned long m_nProcessedEvents
void startChrono()
Definition: Processus.h:275
std::string name() const
Definition: Object.h:28
Element * element()
Definition: Processus.h:231
std::string type()
Definition: Object.h:29
unsigned int phase(unsigned int ch)
Definition: Phaser.h:63
unsigned long errorCount
void read()
Definition: Phaser.cpp:23
Phaser * m_phaser
void write()
Definition: Phaser.cpp:46