Cat
Acquisition.cpp
Go to the documentation of this file.
1 // $Id: $
2 
3 // include files
4 #include "TTree.h"
5 
6 // local
7 #include "FEB_v1.h"
8 #include "Acquisition.h"
9 
10 //-----------------------------------------------------------------------------
11 // Implementation file for class : Acquisition
12 //
13 // 2006-10-23 :
14 //-----------------------------------------------------------------------------
15 
16 //=============================================================================
17 // Standard constructor, initializes variables
18 //=============================================================================
20  m_store_tree(true),
21  m_store_hist(false),
22  m_store_sample(true),
23  m_channels(0xFF),
24  m_depth(5),
25  m_trig(true),
26  m_nsample(0),
27  m_nbins(100),
28  m_minRange(0.),
29  m_maxRange(4096.),
30  m_deadtime(1000.)
31 {
32  setName ( "Acquisition" );
33  setType ( "FEB_v1" );
34  setTitle( "CatCaloUpgrade data acquisition" );
35 }
36 //=============================================================================
37 // Destructor
38 //=============================================================================
40 
41 //=============================================================================
42 
43 //=========================================================================
44 //
45 //=========================================================================
47  debug("Acquisition" , "initialize");
48  info("" );
49  info("____________________________");
50  info("Acquisition run");
51  info(" =>" + element()->path() + " " +
52  element()->name() + " " + element()->type() );
53 
54  m_board=dynamic_cast<FEB_v1*>( element() );
55 
56  if (!m_board){
57  warning("Acquisition","No Proto40MHz_v1 board found. Interrupt." );
58  return false;
59  }
60  /*
61  m_pga=m_board->a3pe();
62  m_fifo = m_pga->storageRam();
63  m_pga->setFifoDepth(m_depth);
64  m_pga->setSoftwareTrigger(m_trig);
65  m_pga->setWriteStorageFifoUsb(false);
66 
67  m_nch=0;
68  char hname[25];
69  char title[50];
70  for (int c=0; c<8; c++){
71  m_chEnable[c]=0;
72  m_channel[c]=-1;
73  if ((m_channels>>c)&1) {
74  m_pga->setEnableADC(c,true);
75  if (m_store_hist){
76  sprintf(hname,"Average_Ch_%1i",c);
77  sprintf(title,"Average Ch %1i",c);
78  m_a[c]=new TH1D(hname, title, m_depth , -0.5, (float)(m_depth)-0.5);
79  sprintf(hname,"RMS_Ch_%1i",c);
80  sprintf(title,"RMS Ch %1i",c);
81  m_s[c]=new TH1D(hname, title, m_depth , -0.5, (float)(m_depth)-0.5);
82  addHisto1d(m_a[c]);
83  addHisto1d(m_s[c]);
84  }
85  if (m_store_sample){
86  sprintf(hname,"Acquisition_Ch_%1i_%1i",c,m_nsample);
87  sprintf(title,"Acquisition Ch %1i - Sample %1i",c,m_nsample);
88  m_hsample[c]=new TH1D(hname, title, m_nbins, m_minRange, m_maxRange);
89  addHisto1d( m_hsample[c] );
90  }
91  m_chEnable[c]=1;
92  m_nch++;
93  }
94  else {
95  // m_channel[c]=-1.;
96  m_pga->setEnableADC(c,false);
97  }
98  }
99  if (m_store_tree){
100  m_tree = new TTree("Acquisition",name().c_str());
101  m_tree->Branch("Run",&m_runNumber,"Run/I");
102  m_tree->Branch("Event",&m_evtNumber,"Event/I");
103  m_tree->Branch("Time",&m_timestamp,"Time/D");
104  m_tree->Branch("Sample",&m_sample,"Sample/I");
105  m_tree->Branch("Channel",m_channel,"Channel[8]/I");
106  m_tree->Branch("ChEnable",m_chEnable,"ChEnable[8]/I");
107  }
108  m_runNumber=application()->options()->runNumber();
109  */
110  return StatusCode::SUCCESS;
111 }
112 
113 //=========================================================================
114 //
115 //=========================================================================
117  debug("Acquisition" , "execute");
118  /*
119  m_pga->enableStorage();
120  m_evtNumber=application()->options()->nEvt()-1;
121  double time_unit=1.e8;
122  clock_t start=clock();
123  double deadtime=(float)(m_deadtime);
124  double elapsed=0.;
125  if (m_trig) {m_pga->trigger();}
126  bool dataready=false;
127  while ((!dataready)&&(deadtime-elapsed>0)){
128  m_timestamp=(double)(clock());
129 // wait(1);
130  elapsed++;
131 // elapsed=((double)(CLOCKS_PER_SEC))/time_unit*(m_timestamp-(double)(start));
132  dataready=m_pga->dataReady();
133 // if (0==((int(elapsed/10000.))%10)) warning("Waiting for the acknowledge");
134  }
135  if (!dataready){
136  warning("Acquisition deadtime reached ("+
137  itos(m_deadtime)+"). Execution stopped.");
138  return StatusCode::FAILURE;
139  }
140  m_fifo->read();
141  int nch, c;
142  for (int d=0; d<m_depth; ++d){
143  m_sample=d;
144  nch=0; c=0;
145  while (nch<m_nch) {
146  if(m_chEnable[c]>0){
147  m_channel[c]=decodeFormat(c,d,m_fifo);
148 // info("sample "+itos(d)+"- channel "+itos(c)+" - value="+itos(m_channel[c]));
149  if (m_store_hist) {
150  v[c+8*d]+=m_channel[c];
151  v2[c+8*d]+=m_channel[c]*m_channel[c];
152  }
153  if (m_nsample==d){
154  if (m_store_sample) m_hsample[c]->Fill(m_channel[c]);
155  }
156  nch++;
157  }
158  c++;
159  }
160  if (m_store_tree) m_tree->Fill();
161  }
162  */
163  return StatusCode::SUCCESS;
164 }
165 
166 //=========================================================================
167 //
168 //=========================================================================
170  int nch; int c;
171  double val,tmp;
172  /*
173  if (m_store_tree) m_tree->Print();
174  if (m_store_hist){
175  for (int d=0; d<m_depth; ++d){
176  nch=0; c=0;
177  while (nch<m_nch){
178  if((m_channels>>c)&1){
179  tmp=v[c+8*d]/(m_evtNumber+1);
180  m_a[c]->Fill(d,tmp);
181  if (m_evtNumber>0){
182  val=(v2[c+8*d]
183  -v[c+8*d]*tmp
184  )/(m_evtNumber);
185  m_s[c]->Fill(d,val>0.?sqrt(val):0.);
186  }
187  nch++;
188  }
189  c++;
190  }
191  }
192  }
193  */
194  return StatusCode::SUCCESS;
195 }
196 
197 //=========================================================================
198 //
199 //=========================================================================
200 StatusCode Acquisition::setDepth (unsigned int depth) {
201  if (depth>512){
202  warning("Cannot acquire more than 512 consecutive events. Interrupt.");
203  return StatusCode::FAILURE;
204  }
205  m_depth=depth;
206  return StatusCode::SUCCESS;
207 }
208 
209 //=========================================================================
210 //
211 //=========================================================================
213  if (channels>0xFF){
214  channels=(channels&0xFF);
215  warning("Channels coding not appropriate. Truncated at 0xFF.");
216  }
218  return StatusCode::SUCCESS;
219 }
220 
221 //=========================================================================
222 //
223 //=========================================================================
224 unsigned int Acquisition::decodeFormat (unsigned int channel, unsigned int evt, RAM* ram){
225  unsigned int val=0;
226  switch (channel) {
227  case 0:
228  val=ram->io()->dataU8(0+12*evt)+((ram->io()->dataU8(1+12*evt)&0xf)<<8);
229  break;
230  case 1:
231  val=(ram->io()->dataU8(1+12*evt)>>4)+(ram->io()->dataU8(2+12*evt)<<4);
232  break;
233  case 2:
234  val=ram->io()->dataU8(3+12*evt)+((ram->io()->dataU8(4+12*evt)&0xf)<<8);
235  break;
236  case 3:
237  val=(ram->io()->dataU8(4+12*evt)>>4)+(ram->io()->dataU8(5+12*evt)<<4);
238  break;
239  case 4:
240  val=ram->io()->dataU8(6+12*evt)+((ram->io()->dataU8(7+12*evt)&0xf)<<8);
241  break;
242  case 5:
243  val=(ram->io()->dataU8(7+12*evt)>>4)+(ram->io()->dataU8(8+12*evt)<<4);
244  break;
245  case 6:
246  val=ram->io()->dataU8(9+12*evt)+((ram->io()->dataU8(10+12*evt)&0xf)<<8);
247  break;
248  case 7:
249  val=(ram->io()->dataU8(10+12*evt)>>4)+(ram->io()->dataU8(11+12*evt)<<4);
250  break;
251  }
252  return val;
253 }
254 
void info(std::string mymsg)
Definition: Object.h:38
StatusCode setChannels(unsigned int)
Definition: RAM.h:16
virtual StatusCode finalize()
void setName(std::string name)
Definition: Object.h:51
Acquisition()
Standard constructor.
Definition: Acquisition.cpp:22
void setType(std::string type)
Definition: Object.h:52
void debug(std::string mymsg)
Definition: Object.h:37
virtual StatusCode execute()
Definition: FEB_v1.h:21
unsigned int decodeFormat(unsigned int, unsigned int, RAM *)
void setTitle(std::string title)
Definition: Object.h:54
Proto40MHz_v1 * m_board
Definition: Acquisition.h:119
unsigned int channels()
Definition: Acquisition.h:34
U8 * dataU8()
Definition: IOdata.h:214
std::string name() const
Definition: Object.h:28
virtual ~Acquisition()
Destructor.
Definition: Acquisition.cpp:42
unsigned int depth()
Definition: Acquisition.h:31
Element * element()
Definition: Processus.h:231
std::string type()
Definition: Object.h:29
void warning(std::string mymsg)
Definition: Object.h:39
StatusCode setDepth(unsigned int)
IOdata * io()
Definition: IOobject.h:66
virtual StatusCode initialize()
Definition: Acquisition.cpp:49