CheckDAQChannelMap.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \version
3 ////////////////////////////////////////////////////////////////////////
4 #include "CheckDAQChannelMap.h"
5 #include "DAQChannelMap/DAQChannelMap.h"
6 #include <vector>
7 #include <cmath>
8 #include "TH1.h"
9 #include "TH2.h"
10 #include "TH3.h"
11 #include "TSystem.h"
12 #include "Config/Config.h"
13 #include "Config/Param.h"
14 #include "EventDataModel/EventHandle.h"
15 #include "CheckDAQChannelMap.h"
16 #include "JobControl/Exception.h"
17 #include "JobControl/ModuleFactory.h"
18 #include "RawData/DAQHeader.h"
19 #include "RawData/RawDigit.h"
20 //#include "NOvAFMWK/Utilities/EDMUtils.h"
21 #include "Geometry/geo.h"
22 #include "Geometry/PlaneGeo.h"
23 //#include "CMap/CMap.h"
24 #include "Header/Header.h"
25 
26 #include "XMLInterface/xmli.h"
27 #include "Config/cfg.h"
28 #include "JobControl/jobc.h"
29 #include "EventDataModel/edm.h"
30 #include "Geometry/Geometry.h"
31 //#include "NOvAFMWK/Utilities/RandomHandler.h"
32 
33 #include "DAQDataFormats/RawEvent.h"
34 
35 //#include "DAQ2RawDigit/FlatDAQData/FlatDAQData.h"
36 #include "DAQDataFormats/BitFields.h"
37 
38 #include "IoModules/RWFactory.h"
39 #include <cstdlib>
40 #include <iostream>
41 #include <JobControl/Module.h>
42 #include "Utilities/EDMUtils.h"
43 
44 static int nevents = 0;
45 
46 using namespace rawp;
47 using namespace daqdataformats;
48 using namespace daqchannelmap;
49 
51 
52 
53 //......................................................................
54 
56  jobc::Module("rawp::CheckDAQChannelMap")
57 {
58 
59  this->SetCfgVersion(version);
60  this->SetWatch("CheckDAQChannelMapping", "default");
61 
62 
63 }
64 
65 //......................................................................
66 
67 void CheckDAQChannelMap::Update(const cfg::Config& c) {
68  // if 0, then it means all
69  // Count from 1
70 
71  int diblock;
72  int dcm;
73  int dcmport;
74  int pixel;
75 
76  //c("detector").Get();
77  c("diblock").Get(diblock);
78  c("dcm").Get(dcm);
79  c("dcmport").Get(dcmport);
80  c("pixel").Get(pixel);
81 
82 
83  //_detector = NDOS_ID;
84 
85  _diblock = diblock;
86  _dcm = dcm;
87  _dcmport = dcmport;
88  _pixel = pixel;
89 
90 
91 
92 
93 
94 }
95 
96 //......................................................................
97 
99 {
100 }
101 
102 //......................................................................
103 
104 jobc::Result CheckDAQChannelMap::Reco(edm::EventHandle& evt)
105 {
106 evt.Header().SetEvent(nevents);
107 
108 
109 
110  std::cout << "From CheckDAQChannelMap::Reco. run : " << evt.Header().Run()
111  << " subrun : " << evt.Header().Subrun()
112  << " event : " << evt.Header().Event() << std::endl;
113 
114 
115 
117  std::string detector_gdml = geo.GDMLFile();
118 
119 
120  if ( detector_gdml.find("neardet")!= std::string::npos)
121  _detector = NEARDET_ID;
122  else if( detector_gdml.find("ndos")!= std::string::npos)
123  _detector = NDOS_ID;
124  else if( detector_gdml.find("fardet")!= std::string::npos)
125  _detector = FARDET_ID;
126  else {
127  std::cout<<"\nUnknown detector!!!!!!!!!!!!!";
128  return jobc::kFailed;
129  }
130 
131  std::cout<<"\nNeVents ="<<nevents<<"\n";
132 
133  ///setup the Header
134  //hdr::Header header;
135 
137  header.SetVersion ("MonteCarlo", "DAQsim");
138  header.SetRandomSeed ("DAQsim" , 0);
139  header.SetConfiguration("DAQsim" , "muons");
140  //header.SetConfiguration("Geometry" , "ndos.gdml");
141  //lsheader.SetConfiguration("DAQsim" , nova_jobc::XMLConfiguration());
142 
143 
144  //Create vector of Digit Lists
145  std::vector<rawdata::RawDigit> rawdigitlist(0);
146 
147  //ev.print();
148 
149  rawdata::RawDigit digit;
150 
151 
152  DAQChannelMap* chanMap = DAQChannelMap::getInstance();
153  //cmap::CMap &cmap = util::EDMUtils::GetCMap(evt);
154 
156 
157  int rawdigitnumber = 0;
158  for(uint32_t idiblock = _diblockLimit[0]; idiblock < _diblockLimit[1]; ++idiblock)
159  //for(uint32_t idiblock = 3; idiblock < 4; ++idiblock)
160  for(uint32_t idcm = _dcmLimit[0] ; idcm < _dcmLimit[1] ; ++idcm){
161 
162  if (_dcmport == 0)this->getDCMPortLimits(idiblock, idcm);
163 
164  //std::cout<<"\nDCMport limits "<<_dcmportLimit[0] << " | "<<_dcmportLimit[1];
165 
166  for(uint32_t idcmport = _dcmportLimit[0]; idcmport < _dcmportLimit[1]; ++idcmport){
167  //for(uint32_t idcmport = 33; idcmport < 51; ++idcmport){
168 
169 
170  idcmport = this->isForbidden(idiblock,idcm,idcmport);
171  //std::cout<<"\nport = "<< idcmport;
172 
173 
174  for(uint32_t ipixel = _pixelLimit[0] ; ipixel < _pixelLimit[1] ; ++ipixel){
175 
176  dchan daq_channel = chanMap->encodeDChan(_detector,
177  idiblock,
178  idcm,
179  idcmport,
180  ipixel);
181 
182  std::cout<<"\nport = "<<idiblock<<" "<<idcm<<" "<<idcmport;
183 
184 
185 
186  lchan offline_channel = chanMap->encodeLChan(daq_channel);
187 
188 
189  digit.SetChannel(offline_channel);
190  digit.SetTDC(0,1000 + 2000*idiblock + 100*idcm);
191  digit.SetTDC(0,1000);
192  digit.SetADC(0,1000);
193  rawdigitlist.push_back(digit);
194  ++rawdigitnumber;
195 
196  //std::cout<<"\nplaneHere="<<plane;
197  //std::cout<<" cellHere="<<cell;
198 
199  }
200  }
201  }
202 
203  std::cout<<"\n Total of "<<rawdigitnumber<<" RawDigits filled";
204 
205 
206 
207 
208 
209  /*
210  for(uint32_t plane = 0; plane < 186; ++plane){
211 
212  digit.SetChannel(this->getChannel(plane, 5));
213  digit.SetTDC(0,1000+i*10);
214  digit.SetADC(0,20+i*5);
215  rawdigitnumber++;
216  if(fillrawdigit == rawdigitnumber||fillrawdigit==0)rawdigitlist.push_back(digit);
217 
218  }//end of loop over planes
219 
220  */
221 
222 
223 
224 
225 
226 
227 
228  ///clear the evt as it is the same handle for every spill
229 
230 
231  //if(!fIsHeaderPut){
232  evt.Clear();
233  std::cout<<"From CheckDAQChannelMap::Reco. Putting the header\n";
234  evt.DAQ().Put(header, ".");
235  std::cout<<"From CheckDAQChannelMap::Reco. End of Pitting the header\n";
236  //}
237 
238  // Write the raw digits into the event
239  if(evt.Raw().GetFolder(".") == 0)
240  evt.Raw().MakeFolder(".");
241 
242  for (unsigned int i=0; i<rawdigitlist.size(); ++i) {
243  evt.Raw().Put(rawdigitlist[i],".");
244  }
245 
246 
247  std::cout<<"End of job\n";
248 
249 
250  ++nevents;
251  return jobc::kPassed;
252 
253 }
254 
255 ////////////////////////////////////////////////////////////////////////
256 
257 
258 uint32_t CheckDAQChannelMap::getChannel(uint32_t plane, uint32_t cell){
259 
260  uint32_t chan = 0x0;
263 
264  return chan;
265 }
266 
267 
268 
269 void CheckDAQChannelMap::getLimits(uint32_t diblock, uint32_t dcm, uint32_t dcmport, uint32_t pixel){
270 
271 
272 
273 
274 
275 
276  if(diblock == 0){
277  _diblockLimit[0] = 1;
278  _diblockLimit[1] = NUM_DIBLOCK_DET[_detector] + 1;
279  }
280  else{
281  _diblockLimit[0] = diblock;
282  _diblockLimit[1] = diblock + 1;
283  }
284  if(dcm == 0){
285  _dcmLimit[0] = 1;
286  _dcmLimit[1] = NUM_DCMS_DIBLOCK[_detector] + 1;
287  }
288  else{
289  _dcmLimit[0] = dcm;
290  _dcmLimit[1] = dcm + 1;
291  }
292  if(dcmport == 0){
293 
294  }
295  else{
296  _dcmportLimit[0] = dcmport;
297  _dcmportLimit[1] = dcmport + 1;
298  }
299  if(pixel == 0){
300  _pixelLimit[0] = 1;
301  _pixelLimit[1] = 33;
302  }
303  else{
304  _pixelLimit[0] = pixel;
305  _pixelLimit[1] = pixel + 1;
306  }
307 
308 
309 
310 }
311 
312 void CheckDAQChannelMap::getDCMPortLimits(uint32_t currentdiblock, uint32_t currentdcm){
313 
314  _dcmportLimit[0] = 1;
315 
316  if(_detector == NEARDET_ID || _detector == NDOS_ID){
317  if(currentdiblock < 3 && currentdcm < 3)
318  _dcmportLimit[1] = 64;
319  if(currentdiblock < 3 && currentdcm == 3)
320  _dcmportLimit[1] = 48;
321  if(currentdiblock == 3 && currentdcm == 1)
322  _dcmportLimit[1] = 65;
323  if(currentdiblock == 3 && currentdcm == 2)
324  _dcmportLimit[1] = 63;
325  if(currentdiblock == 3 && currentdcm == 3)
326  _dcmportLimit[1] = 47;
327  if(currentdiblock == 4 && currentdcm == 1)
328  _dcmportLimit[1] = 23;
329  if(currentdiblock == 4 && currentdcm == 2)
330  _dcmportLimit[1] = 24;
331  if(currentdiblock == 4 && currentdcm == 3)
332  _dcmportLimit[1] = 8;
333  return;
334  }
335 
336  // so it is the far detector alright
337  if(_detector == FARDET_ID){
338  if(DetectorDiBlockConfig[_detector][currentdiblock] == AB_BLOCK ||
339  DetectorDiBlockConfig[_detector][currentdiblock] == BA_BLOCK ){
340  _dcmportLimit[1] = 64;
341  return;
342  }
343 
344  int yplanes;
345  int xplanes;
346 
347 
348  // Calculate number of planes (since there is no BB block)
349  if(DetectorDiBlockConfig[_detector][currentdiblock] == AA_BLOCK){
350  yplanes = NUM_Y_PLANES_A_BLOCK * 2;
351  xplanes = NUM_X_PLANES_A_BLOCK * 2;
352  }
353  else{
354  yplanes = NUM_Y_PLANES_A_BLOCK + NUM_Y_PLANES_B_BLOCK;
355  xplanes = NUM_X_PLANES_A_BLOCK + NUM_X_PLANES_B_BLOCK;
356  }
357 
358  // y plane
359  if(currentdcm < NUM_X_DCMS_FARDET + START_CHAN_IDX)
360  _dcmportLimit[1] = 32 + xplanes + START_CHAN_IDX;
361  else
362  _dcmportLimit[1] = 32 + yplanes + START_CHAN_IDX;
363  }
364 
365 }
366 
367 uint32_t CheckDAQChannelMap::isForbidden(uint32_t idiblock,uint32_t idcm,uint32_t idcmport){
368 
369  if(_detector == NEARDET_ID || _detector == NDOS_ID){
370  if(idiblock == 4 && idcm == 1 && idcmport == 7) return 17;
371  if(idiblock == 4 && idcmport == 8) return 17;
372  if(idiblock < 3 && idcmport == 48) return 49;
373  if(idiblock == 3 && idcm == 2 && idcmport == 47) return 49;
374  if(idcm == 3 && idcmport == 17) return 33;
375  return idcmport;
376  }
377  // so it is the far detector alrigh
378 
379  else if(_detector == FARDET_ID){
380  int yplanes;
381  int xplanes;
382  unsigned int planes;
383  // Calculate number of planes (since there is no BB block)
384  if(DetectorDiBlockConfig[_detector][idiblock] == AA_BLOCK){
385  yplanes = NUM_Y_PLANES_A_BLOCK * 2 ;
386  xplanes = NUM_X_PLANES_A_BLOCK * 2;
387  }
388  else{
389  yplanes = NUM_Y_PLANES_A_BLOCK + NUM_Y_PLANES_B_BLOCK;
390  xplanes = NUM_X_PLANES_A_BLOCK + NUM_X_PLANES_B_BLOCK;
391  }
392 
393 
394  if(idcm < NUM_X_DCMS_FARDET + START_CHAN_IDX)planes = xplanes;
395  else planes = yplanes;
396 
397 
398  //std::cout<<"\nplanes = "<<xplanes<<" | "<<yplanes;
399 
400  if(idcmport == planes + 16 + 1)return 49;
401 
402 
403  }
404  return idcmport;
405 }
uint32_t isForbidden(uint32_t idiblock, uint32_t idcm, uint32_t idcmport)
diblock
print "ROW IS " print row
Definition: geo2elec.py:31
void SetTDC(int32_t iTDC)
Definition: RawDigit.cxx:116
A module to process the Flat files.
void SetChannel(uint32_t iChan)
Definition: RawDigit.h:99
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
uint32_t getChannel(uint32_t plane, uint32_t cell)
void getLimits(uint32_t diblock, uint32_t dcm, uint32_t dcmport, uint32_t pixel)
std::string Header(std::string label)
MODULE_DECL(rawp::CheckDAQChannelMap)
void SetADC(uint32_t i, int16_t iADC)
Definition: RawDigit.cxx:108
jobc::Result Reco(edm::EventHandle &evt)
void Update(const cfg::Config &c)
Diblock ID, (6bit), valid range 1-15.
int evt
The geometry of one entire detector (near, far, ipnd)
Definition: Geometry.h:23
CheckDAQChannelMap(const char *version)
DCM ID, (6bit), valid range 1-384.
std::string GDMLFile() const
Definition: GeometryBase.h:235
OStream cout
Definition: OStream.cxx:6
const XML_Char * version
Definition: expat.h:187
#define BITFIELDSET(block, data, mask, shift)
Definition: BitFields.h:24
static int nevents
void getDCMPortLimits(uint32_t currentdiblock, uint32_t currentdcm)
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
Class to hold the data from the FEBs in correct formats.
uint32_t dchan
< DAQ Channel Map Package
Helper for AttenCurve.
Definition: Path.h:10
Encapsulate the geometry of one entire detector (near, far, ndos)
GeomAnalyzerI * GetGeometry(void)
Definition: gAtmoEvGen.cxx:378
enum BeamMode string