CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTDigiToRaw.cc
Go to the documentation of this file.
3 
4 #include <math.h>
5 #include <iostream>
6 
7 using namespace edm;
8 using namespace std;
9 
11 {
12 
13  debug = pset.getUntrackedParameter<bool>("debugMode", false);
14  if (debug) cout << "[DTDigiToRaw]: constructor" << endl;
15 }
16 
17 
19  if (debug) cout << "[DTDigiToRaw]: destructor" << endl;
20 }
21 
22 
25 
26  int NROS = 12;
27  int NROB = 25;
28 
29  vector<uint32_t> words;
30 
31  uint32_t fakeROSHeaderWord =
34 
35  uint32_t fakeROSTrailerWord =
38 
39 
40  int NWords = 2;
41  words.push_back(0);
42  words.push_back(0);
43 
44 
45 
46  int NTDCMeaWords = 0;
47 
48 
49  int NLayers = 0;
50  int NDigis = 0;
51 
52  DTDigiCollection::DigiRangeIterator detUnitIt;detUnitIt = digis.begin();
53 
54 
55  bool b_ros[12] = {false, false, false, false, false, false,
56  false, false, false, false, false, false};
57  vector <uint32_t> w_ROBROS[12][25];
58 
59 
60  for (detUnitIt = digis.begin(); detUnitIt != digis.end(); ++detUnitIt) {
61 
62  NLayers++;
63 
64  const DTLayerId layerId = (*detUnitIt).first;
65  const DTDigiCollection::Range& digiRange = (*detUnitIt).second;
66  // Loop over all digis in the given range
67 
68 
69  for(DTDigiCollection::const_iterator digi = digiRange.first;
70  digi != digiRange.second;
71  digi++) {
72  NDigis++;
73  int dduId = -1, rosId = -1, robId = -1, tdcId = -1, channelId = -1;
74 
75  int layer = layerId.layer();
76  DTSuperLayerId superlayerID = layerId.superlayerId();
77  int superlayer = superlayerID.superlayer();
78  DTChamberId chamberID = superlayerID.chamberId();
79  int station = chamberID.station();
80  int wheel = chamberID.wheel();
81  int sector = chamberID.sector();
82 
83  int searchstatus = map->
84  geometryToReadOut(wheel, station, sector, superlayer, layer, (*digi).wire(),//"input"
85  dduId, rosId, robId, tdcId, channelId);//"output"
86 
87  if (searchstatus == 1 && debug)
88  cout << "[DTDigiToRaw]: warning, geometryToReadOut status = 1" << endl;
89 
90  //create FED corresponding to current ddu
91  if (dduID_ != dduId) continue;
92 
93 
94  DTTDCMeasurementWord dttdc_mw;
95  uint32_t word;
96  int ntdc = (*digi).countsTDC();
97  dttdc_mw.set(word, 0, 0, 0, tdcId, channelId, ntdc*4);//FIXME
98 
99  //provisional fix
100  DTTDCMeasurementWord tdcMeasurementWord(word);
101  int tdcIDCheck = tdcMeasurementWord.tdcID();
102  int tdcChannelCheck = tdcMeasurementWord.tdcChannel();
103  int tdcCountsCheck = tdcMeasurementWord.tdcTime();
104  if (tdcIDCheck == tdcId && channelId ==tdcChannelCheck && ntdc == tdcCountsCheck) {
105 
106  if (rosId <= NROS && rosId > 0) b_ros[rosId - 1] = true;
107  else if (debug) {
108  cout << "[DTDigiToRaw]: invalid value for rosId" << endl;
109  }
110 
111  NTDCMeaWords++;
112  w_ROBROS[rosId - 1][robId].push_back(word);
113 
114  }
115  }
116  }
117 
118  uint32_t therosList = 0;
119  for (int i_ros = 0; i_ros < NROS; i_ros++) {
120  if (b_ros[i_ros]) therosList += uint32_t(pow(2.0, i_ros));
121  }
122 
123  if (debug) cout << "[DTDigiToRaw]: therosList = " << therosList << endl;
124 
125 
126 
127 
128  for (int i_ros = 0; i_ros < NROS; i_ros++) {
129 
130  if (b_ros[i_ros]) {
131  words.push_back(fakeROSHeaderWord);
132  NWords++;
133  }
134 
135  for (int i_rob = 0; i_rob < NROB; i_rob++) {
136 
137  vector <uint32_t>::const_iterator i_robros;
138  if (w_ROBROS[i_ros][i_rob].begin() != w_ROBROS[i_ros][i_rob].end()) {
139  uint32_t word = 0;
140  DTROBHeaderWord rob_header;
141  rob_header.set(word, i_rob, 0, 0);
142  //static void set(uint32_t &word, int rob_id, int event_id, int bunch_id)
143  words.push_back(word);
144  NWords++;
145 
146  int n_robros = 0;
147  for (i_robros = w_ROBROS[i_ros][i_rob].begin(); i_robros != w_ROBROS[i_ros][i_rob].end(); i_robros++) {
148  NWords++;
149  words.push_back((*i_robros));
150  n_robros++;
151  }
152 
153  NWords++;
154  DTROBTrailerWord rob_trailer;
155  rob_trailer.set(word, i_rob, 0, n_robros + 2);
156  //static void set(uint32_t &word, int rob_id, int event_id, int word_count)
157  words.push_back(word);
158 
159  }
160  }
161 
162  if (b_ros[i_ros]) {
163  words.push_back(fakeROSTrailerWord);
164  NWords++;
165  }
166 
167  }
168 
169  if (NWords%2 == 1) {
170  words.push_back(0);
171  NWords++;
172  }
173 
174 
175 
176  NWords += 6;
177 
178  words.push_back(0);
179  words.push_back(0);
180  //include rosList in raw data information
181  uint32_t secondstatusword = therosList << 16;
182  words.push_back(secondstatusword);
183 
184  words.push_back(0);
185  words.push_back(0);
186  words.push_back(0);
187 
188 
189  // Write Raw Data
190  int dataSize = words.size()*sizeof(Word32);
191  FEDRawData* rawData = new FEDRawData(dataSize);
192  Word64 *word64 = reinterpret_cast<Word64*>(rawData->data());
193  for (unsigned int i = 0; i < words.size(); i += 2) {
194  *word64 = (Word64(words[i]) << 32) | words[i + 1];
195  word64++;
196  }
197 
198  return rawData;
199 
200 
201 }
202 
204  dduID_ = x;
205 }
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
DTDigiToRaw(const edm::ParameterSet &ps)
Constructor.
Definition: DTDigiToRaw.cc:10
DTChamberId chamberId() const
Return the corresponding ChamberId.
#define WORDCONTROLSHIFT
Definition: DTDDUWords.h:11
void SetdduID(int dduid)
Definition: DTDigiToRaw.cc:203
static void set(uint32_t &word, int rob_id, int event_id, int bunch_id)
Definition: DTDDUWords.h:436
static const uint32_t trailerControlWord
Definition: DTDDUWords.h:184
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
static void set(uint32_t &word, int rob_id, int event_id, int word_count)
Definition: DTDDUWords.h:484
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:61
int tdcChannel() const
Definition: DTDDUWords.h:644
unsigned int Word32
Definition: DTDigiToRaw.h:34
const edm::ParameterSet pset
Definition: DTDigiToRaw.h:36
int tdcTime() const
Definition: DTDDUWords.h:645
#define WORDTYPESHIFT
Definition: DTDDUWords.h:13
FEDRawData * createFedBuffers(const DTDigiCollection &digis, edm::ESHandle< DTReadOutMapping > &mapping)
Take a vector of digis and fill the FEDRawDataCollection.
Definition: DTDigiToRaw.cc:23
CSCDetId chamberID(const CSCDetId &cscDetId)
takes layer ID, converts to chamber ID, switching ME1A to ME11
Definition: CSCDigiToRaw.cc:32
#define end
Definition: vmac.h:38
long long Word64
Definition: DTDigiToRaw.h:35
int tdcID() const
&lt;== OBSOLETE!!
Definition: DTDDUWords.h:643
int superlayer() const
Return the superlayer number (deprecated method name)
static const uint32_t rosTypeWord
Word Type bits definitions.
Definition: DTDDUWords.h:192
std::vector< DigiType >::const_iterator const_iterator
static void set(uint32_t &word, int pc, int paf, int hu, int tdc_id, int tdc_channel, int tdc_time)
Definition: DTDDUWords.h:648
#define begin
Definition: vmac.h:31
int sector() const
Definition: DTChamberId.h:63
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
virtual ~DTDigiToRaw()
Destructor.
Definition: DTDigiToRaw.cc:18
static const uint32_t headerControlWord
Control bits definitions.
Definition: DTDDUWords.h:183
std::pair< const_iterator, const_iterator > Range
tuple cout
Definition: gather_cfg.py:121
int station() const
Return the station number.
Definition: DTChamberId.h:53
x
Definition: VDTMath.h:216
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40