Hall C ROOT/C++ Analyzer (hcana)
THcConfigEvtHandler.cxx
Go to the documentation of this file.
1 
24 #include "THcConfigEvtHandler.h"
25 #include "THaEvData.h"
26 #include "THaGlobals.h"
27 #include "THcGlobals.h"
28 #include "THcParmList.h"
29 #include <cstring>
30 #include <cstdio>
31 #include <cstdlib>
32 #include <iostream>
33 #include <iomanip>
34 
35 using namespace std;
36 
37 THcConfigEvtHandler::THcConfigEvtHandler(const char *name, const char* description)
38  : THaEvtTypeHandler(name,description)
39 {
40 }
41 
43 {
44  // TODO: remove the parameters we've added to gHcParms
45 
47 }
48 
49 //Float_t THcConfigEvtHandler::GetData(const std::string& tag)
50 //{
51 // // A public method which other classes may use
52 // if (theDataMap.find(tag) == theDataMap.end())
53 // return 0;
54 // return theDataMap[tag];
55 //}
56 
58 {
59  // Clear the CrateInfoMap, deallocating its elements' dynamic memory
60 
61  //TODO: don't manage memory manually, contain the object, use STL vectors
62  typedef std::map<Int_t, CrateInfo_t *> cmap_t;
63  typedef std::map<Int_t, Int_t *> imap_t;
64  for( cmap_t::iterator it = CrateInfoMap.begin();
65  it != CrateInfoMap.end(); ++it ) {
66  CrateInfo_t* cinfo = it->second;
67  if( cinfo ) {
68  for( imap_t::iterator jt = cinfo->FADC250.thresholds.begin();
69  jt != cinfo->FADC250.thresholds.end(); ++jt ) {
70  delete [] jt->second;
71  }
72  delete cinfo;
73  }
74  }
75  CrateInfoMap.clear();
76 }
77 
79 {
80 
81  Bool_t ldebug = true; // FIXME: use fDebug
82 
83  if ( !IsMyEvent(evdata->GetEvType()) ) return -1;
84 
85  if (ldebug) cout << "------------------\n Event type 125"<<endl;
86 
87  Int_t evlen = evdata->GetEvLength();
88  Int_t ip = 0;
89  ip++;
90  UInt_t thisword = evdata->GetRawData(ip);
91  Int_t roc = thisword & 0xff;
92  cout << "THcConfigEvtHandler: " << roc << endl;
93  // Should check if this roc has already been seen
94  CrateInfo_t *cinfo = new CrateInfo_t;
95  cinfo->FADC250.nmodules=0;
96  cinfo->FADC250.present=0;
97  cinfo->CAEN1190.present=0;
98  cinfo->TI.present=0;
99  // FIXME: check if entry for this roc already present in the map
100  CrateInfoMap.insert(std::make_pair(roc, cinfo));
101  ip++;
102  // Three possible blocks of config data
103  // 0xdafadc01 - FADC information for the crate
104  // 0xdafadcff - Set of threshold by slot/channel
105  // 0xdedc1190 - 1190 TDC information for the crate
106  while(ip<evlen) {
107  thisword = evdata->GetRawData(ip);
108  if (thisword == 0xdafadcff) {
109  ip++;
110  thisword = evdata->GetRawData(ip);
111  cout << "ADC thresholds for slots ";
112  while((thisword & 0xfffff000)==0xfadcf000) {
113  Int_t slot = thisword&0x1f;
114  // Should check if this slot has already been SDC_WIRE_CENTER
115  cinfo->FADC250.nmodules++;
116  cout << " " << slot;
117  Int_t *thresholds = new Int_t [16];
118  cinfo->FADC250.thresholds.insert(std::make_pair(slot, thresholds));
119  for(Int_t i=0;i<16;i++) {
120  thresholds[i] = evdata->GetRawData(ip+1+i);
121  }
122  ip +=18;
123  if(ip>=evlen) {
124  if(ip>evlen) {
125  cout << endl << "Info event truncated" << endl;
126  }
127  break;
128  }
129  thisword = evdata->GetRawData(ip);
130  }
131  cout << endl;
132  } else if((thisword&0xffffff00) == 0xdafadc00) { // FADC250 information
133  cout << "ADC information: Block level " << (thisword&0xff) << endl;
134  cinfo->FADC250.present = 1;
135  cinfo->FADC250.blocklevel = thisword&0xff;
136  cinfo->FADC250.dac_level = evdata->GetRawData(ip+2);
137  cinfo->FADC250.threshold = evdata->GetRawData(ip+3);
138  cinfo->FADC250.mode = evdata->GetRawData(ip+4);
139  cinfo->FADC250.window_lat = evdata->GetRawData(ip+5);
140  cinfo->FADC250.window_width = evdata->GetRawData(ip+6);
141  cinfo->FADC250.nsb = evdata->GetRawData(ip+7);
142  cinfo->FADC250.nsa = evdata->GetRawData(ip+8);
143  cinfo->FADC250.np = evdata->GetRawData(ip+9);
144  cinfo->FADC250.nped = evdata->GetRawData(ip+10);
145  cinfo->FADC250.maxped = evdata->GetRawData(ip+11);
146  cinfo->FADC250.nsat = evdata->GetRawData(ip+12);
147  ip += 13;
148  } else if (thisword == 0xdedc1190) { // CAEN 1190 information
149  cout << "TDC information" << endl;
150  cinfo->CAEN1190.present = 1;
151  cinfo->CAEN1190.resolution = evdata->GetRawData(ip+2);
152  cinfo->CAEN1190.timewindow_offset = evdata->GetRawData(ip+3);
153  cinfo->CAEN1190.timewindow_width = evdata->GetRawData(ip+4);
154  ip += 6;
155  } else if (thisword == 0xd0000000) { // TI setup data
156  cinfo->TI.present = 1;
157  ip += 1;
158  UInt_t versionword = evdata->GetRawData(ip++);
159  if((versionword & 0xffff0000) != 0xabcd0000) {
160  cout << "Unexpected TI info word " << hex << thisword << dec << endl;
161  cout << " Expected 0xabcdNNNN" << endl;
162  ip += 1;
163  } else {
164  Int_t version = versionword & 0xffff;
165  cinfo->TI.num_prescales = 6;
166  cinfo->TI.nped = evdata->GetRawData(ip++);
167  if(version >= 2) {
168  cinfo->TI.scaler_period = evdata->GetRawData(ip++);
169  cinfo->TI.sync_count = evdata->GetRawData(ip++);
170  } else {
171  cinfo->TI.scaler_period = 2;
172  cinfo->TI.sync_count = -1;
173  }
174  for(Int_t i = 0; i<cinfo->TI.num_prescales; i++) {
175  cinfo->TI.prescales[i] = evdata->GetRawData(ip++);
176  }
177  UInt_t lastword = evdata->GetRawData(ip++);
178  if(lastword != 0xd000000f) {
179  cout << "Unexpected last word of TI information block "
180  << hex << lastword << dec << endl;
181  }
182  }
183  } else {
184  cout << "Expected header missing" << endl;
185  cout << ip << " " << hex << thisword << dec << endl;
186  ip = evlen;
187  }
188  }
189 
190  cout << "Making Parms for ROC " << roc << " Event type " << evdata->GetEvType() << endl;
191  MakeParms(roc);
192 
193  return 1;
194 }
195 
197 {
201  std::map<Int_t, CrateInfo_t *>::iterator it = CrateInfoMap.begin();
202  while(it != CrateInfoMap.end()) {
203  Int_t thisroc = it->first;
204  if(thisroc != roc) {
205  it++;
206  continue;
207  }
208  CrateInfo_t *cinfo = it->second;
209 
210  // CAEN 1190 TDC information
211  if (cinfo->CAEN1190.present) {
212  Int_t resolution = cinfo->CAEN1190.resolution;
213  gHcParms->Define(Form("g%s_tdc_resolution_%d",fName.Data(),roc),"TDC resolution",resolution);
214  Int_t offset = cinfo->CAEN1190.timewindow_offset;
215  gHcParms->Define(Form("g%s_tdc_offset_%d",fName.Data(),roc),"TDC Time Window Offset",offset);
216  Int_t width = cinfo->CAEN1190.timewindow_width;
217  gHcParms->Define(Form("g%s_tdc_width_%d",fName.Data(),roc),"TDC Time Window Width",width);
218  }
219  // FADC Thresholds
220  if (cinfo->FADC250.present) {
221  // Loop over FADC slots
222  std::map<Int_t, Int_t *>::iterator itt = cinfo->FADC250.thresholds.begin();
223  while(itt != cinfo->FADC250.thresholds.end()) {
224  Int_t slot = itt->first;
225 
226  // this memory would leak
227 // Int_t *thresholds = new Int_t[16];
228 // memcpy(thresholds,itt->second,16*sizeof(Int_t));
229 // gHcParms->Define(Form("g%s_adc_thresholds_%d_%d[16]",fName.Data(),roc,slot),"ADC Thresholds",*thresholds);
230  // Define the variable directly on the CrateInfo_t that resides in CrateInfoMap where it will stay
231  // until the end of the life of this object
232  gHcParms->Define(Form("g%s_adc_thresholds_%d_%d[16]",fName.Data(),roc,slot),"ADC Thresholds",*itt->second);
233 
234  Int_t mode = cinfo->FADC250.mode;
235  gHcParms->Define(Form("g%s_adc_mode_%d_%d",fName.Data(),roc,slot),"ADC Mode",mode);
236  Int_t latency = cinfo->FADC250.window_lat;
237  gHcParms->Define(Form("g%s_adc_latency_%d_%d",fName.Data(),roc,slot),"Window Latency",latency);
238 
239  Int_t width = cinfo->FADC250.window_width;
240  gHcParms->Define(Form("g%s_adc_width_%d_%d",fName.Data(),roc,slot),"Window Width",width);
241 
242  Int_t daclevel = cinfo->FADC250.dac_level;
243  gHcParms->Define(Form("g%s_adc_daclevely_%d_%d",fName.Data(),roc,slot),"DAC Level",daclevel);
244  Int_t nped = cinfo->FADC250.nped;
245  gHcParms->Define(Form("g%s_adc_nped_%d_%d",fName.Data(),roc,slot),"NPED",nped);
246  Int_t nsa = cinfo->FADC250.nsa;
247  gHcParms->Define(Form("g%s_adc_nsa_%d_%d",fName.Data(),roc,slot),"NSA",nsa);
248  Int_t maxped = cinfo->FADC250.maxped;
249  gHcParms->Define(Form("g%s_adc_maxped_%d_%d",fName.Data(),roc,slot),"MAXPED",maxped);
250  Int_t np = cinfo->FADC250.np;
251  gHcParms->Define(Form("g%s_adc_np_%d_%d",fName.Data(),roc,slot),"NP",np);
252 
253  itt++;
254  }
255  // TI Configuration
256  // We assume that this information is only provided by the master TI crate.
257  // If that is not true we will get "Variable XXX already exists." warnings
258  if(cinfo->TI.present) {
259  Int_t nped = cinfo->TI.nped;
260  gHcParms->Define(Form("g%s_ti_nped",fName.Data()),"Number of Pedestal events",nped);
261  Int_t scaler_period = cinfo->TI.scaler_period;
262  gHcParms->Define(Form("g%s_ti_scaler_period",fName.Data()),"Number of Pedestal events",scaler_period);
263  Int_t sync_count = cinfo->TI.sync_count;
264  gHcParms->Define(Form("g%s_ti_sync_count",fName.Data()),"Number of Pedestal events",sync_count);
265 
266  Int_t *ps_exps = new Int_t[cinfo->TI.num_prescales];
267  Int_t *ps_factors = new Int_t[cinfo->TI.num_prescales];
268  for(Int_t i=0;i<cinfo->TI.num_prescales;i++) {
269  ps_exps[i] = cinfo->TI.prescales[i];
270  if(ps_exps[i] > 0) {
271  ps_factors[i] = (1<<(ps_exps[i]-1)) + 1;
272  } else if (ps_exps[i] == 0) {
273  ps_factors[i] = 1;
274  } else {
275  ps_factors[i] = -1;
276  }
277  }
278  gHcParms->Define(Form("g%s_ti_ps[%d]",fName.Data(),cinfo->TI.num_prescales),"TI Event Prescale Internal Value",*ps_exps);
279  gHcParms->Define(Form("g%s_ti_ps_factors[%d]",fName.Data(),cinfo->TI.num_prescales),"TI Event Prescale Factor",*ps_factors);
280  }
281  }
282  it++;
283  }
284 }
285 
287 {
291  std::map<Int_t, CrateInfo_t *>::iterator it = CrateInfoMap.begin();
292  while(it != CrateInfoMap.end()) {
293  Int_t roc = it->first;
294  cout << "================= Configuration Data ROC " << roc << "==================" << endl;
295  CrateInfo_t *cinfo = it->second;
296  if(cinfo->CAEN1190.present) {
297  cout << " CAEN 1190 Configuration" << endl;
298  cout << " Resolution: " << cinfo->CAEN1190.resolution << " ps" << endl;
299  cout << " T Offset: " << cinfo->CAEN1190.timewindow_offset << endl;
300  cout << " T Width: " << cinfo->CAEN1190.timewindow_width << endl;
301  }
302  if (cinfo->FADC250.present) {
303  cout << " FADC250 Configuration" << endl;
304  cout << " Mode: " << cinfo->FADC250.mode << endl;
305  cout << " Latency: " << cinfo->FADC250.window_lat << " Width: "<< cinfo->FADC250.window_width << endl;
306  cout << " DAC Level: " << cinfo->FADC250.dac_level << " Threshold: " << cinfo->FADC250.threshold << endl;
307  cout << " NPED: " << cinfo->FADC250.nped << " NSA: " << cinfo->FADC250.nsa << " NSB: " << cinfo->FADC250.nsb << endl;
308  cout << " MAXPED: " << cinfo->FADC250.maxped << " NP: " << cinfo->FADC250.np << " NSAT: " << cinfo->FADC250.nsat << endl;
309 
310  // Loop over FADC slots
311  cout << " Thresholds";
312  std::map<Int_t, Int_t *>::iterator itt = cinfo->FADC250.thresholds.begin();
313  while(itt != cinfo->FADC250.thresholds.end()) {
314  Int_t slot = itt->first;
315  cout << " " << setw(5) << slot;
316  itt++;
317  }
318  cout << endl;
319  for(Int_t ichan=0;ichan<16;ichan++) {
320  cout << " " << setw(2) << ichan << " ";
321  std::map<Int_t, Int_t *>::iterator itt = cinfo->FADC250.thresholds.begin();
322  while(itt != cinfo->FADC250.thresholds.end()) {
323  Int_t *thresholds = itt->second;
324  cout << " " << setw(5) << thresholds[ichan];
325  itt++;
326  }
327  cout << endl;
328  }
329  }
330  if(cinfo->TI.present) {
331  cout << " TI Configuration" << endl;
332  cout << " N Pedestals: " << cinfo->TI.nped << " events" << endl;
333  cout << " Scaler Period: " << cinfo->TI.scaler_period << " seconds" << endl;
334  cout << " Sync interval: " << cinfo->TI.sync_count << " events" << endl;
335  cout << " Prescales: ";
336  for(Int_t i=0;i<cinfo->TI.num_prescales;i++) {
337  cout << " " << cinfo->TI.prescales[i];
338  }
339  cout << endl;
340  }
341  it++;
342  }
343 }
344 
346  if(CrateInfoMap.find(crate)!=CrateInfoMap.end()) {
347  CrateInfo_t *cinfo = CrateInfoMap[crate];
348  return cinfo->FADC250.present;
349  }
350  return(0);
351 }
353  if(CrateInfoMap.find(crate)!=CrateInfoMap.end()) {
354  CrateInfo_t *cinfo = CrateInfoMap[crate];
355  if(cinfo->FADC250.present > 0) return(cinfo->FADC250.nsa);
356  }
357  return(-1);
358 }
360  if(CrateInfoMap.find(crate)!=CrateInfoMap.end()) {
361  CrateInfo_t *cinfo = CrateInfoMap[crate];
362  if(cinfo->FADC250.present > 0) return(cinfo->FADC250.nsb);
363  }
364  return(-1);
365 }
367  if(CrateInfoMap.find(crate)!=CrateInfoMap.end()) {
368  CrateInfo_t *cinfo = CrateInfoMap[crate];
369  if(cinfo->FADC250.present > 0) return(cinfo->FADC250.nped);
370  }
371  return(-1);
372 }
374 {
375  eventtypes.push_back(evtype);
376 }
377 
378 THaAnalysisObject::EStatus THcConfigEvtHandler::Init(const TDatime& date)
379 {
380 
381  cout << "Howdy ! We are initializing THcConfigEvtHandler !! name = "<<fName<<endl;
382 
383  if(eventtypes.size()==0) {
384  eventtypes.push_back(125); // what events to look for
385  }
386 
388 
389  fStatus = kOK;
390  return kOK;
391 }
392 
virtual void AddEventType(Int_t evtype)
virtual Int_t GetNSA(Int_t crate)
virtual EStatus Init(const TDatime &run_time)
virtual Int_t IsPresent(Int_t crate)
int Int_t
bool Bool_t
STL namespace.
struct THcConfigEvtHandler::CrateInfo_t::TI TI
virtual void MakeParms(Int_t roc)
THcConfigEvtHandler(const char *name, const char *description)
UInt_t GetEvLength() const
struct THcConfigEvtHandler::CrateInfo_t::FADC250 FADC250
std::map< Int_t, CrateInfo_t * > CrateInfoMap
unsigned int UInt_t
Analyze Hall C Configuration events. (Event type 125).
char * Form(const char *fmt,...)
virtual Int_t GetNSB(Int_t crate)
virtual Int_t GetNPED(Int_t crate)
UInt_t GetEvType() const
ClassImp(THcDCLookupTTDConv) THcDCLookupTTDConv
virtual Int_t Analyze(THaEvData *evdata)
struct THcConfigEvtHandler::CrateInfo_t::CAEN1190 CAEN1190
UInt_t GetRawData(UInt_t crate, UInt_t slot, UInt_t hit) const
R__EXTERN class THcParmList * gHcParms
Definition: THcGlobals.h:11