CMS 3D CMS Logo

DTDigiToRaw.cc
Go to the documentation of this file.
3 
4 #include <cmath>
5 #include <iostream>
6 
7 using namespace edm;
8 using namespace std;
9 
11  debug = pset.getUntrackedParameter<bool>("debugMode", false);
12  if (debug)
13  cout << "[DTDigiToRaw]: constructor" << endl;
14 }
15 
17  if (debug)
18  cout << "[DTDigiToRaw]: destructor" << endl;
19 }
20 
22  int NROS = 12;
23  int NROB = 25;
24 
25  vector<uint32_t> words;
26 
28  << WORDTYPESHIFT;
29 
31  << WORDTYPESHIFT;
32 
33  int NWords = 2;
34  words.push_back(0);
35  words.push_back(0);
36 
37  int NTDCMeaWords = 0;
38 
39  int NLayers = 0;
40  int NDigis = 0;
41 
43  detUnitIt = digis.begin();
44 
45  bool b_ros[12] = {false, false, false, false, false, false, false, false, false, false, false, false};
46  vector<uint32_t> w_ROBROS[12][25];
47 
48  for (detUnitIt = digis.begin(); detUnitIt != digis.end(); ++detUnitIt) {
49  NLayers++;
50 
51  const DTLayerId layerId = (*detUnitIt).first;
52  const DTDigiCollection::Range& digiRange = (*detUnitIt).second;
53  // Loop over all digis in the given range
54 
55  for (DTDigiCollection::const_iterator digi = digiRange.first; digi != digiRange.second; digi++) {
56  NDigis++;
57  int dduId = -1, rosId = -1, robId = -1, tdcId = -1, channelId = -1;
58 
59  int layer = layerId.layer();
60  DTSuperLayerId superlayerID = layerId.superlayerId();
61  int superlayer = superlayerID.superlayer();
62  DTChamberId chamberID = superlayerID.chamberId();
63  int station = chamberID.station();
64  int wheel = chamberID.wheel();
65  int sector = chamberID.sector();
66 
67  int searchstatus = map->geometryToReadOut(wheel,
68  station,
69  sector,
70  superlayer,
71  layer,
72  (*digi).wire(), //"input"
73  dduId,
74  rosId,
75  robId,
76  tdcId,
77  channelId); //"output"
78 
79  if (searchstatus == 1 && debug)
80  cout << "[DTDigiToRaw]: warning, geometryToReadOut status = 1" << endl;
81 
82  //create FED corresponding to current ddu
83  if (dduID_ != dduId)
84  continue;
85 
86  DTTDCMeasurementWord dttdc_mw;
87  uint32_t word;
88  int ntdc = (*digi).countsTDC();
89  dttdc_mw.set(word, 0, 0, 0, tdcId, channelId, ntdc * 4); //FIXME
90 
91  //provisional fix
92  DTTDCMeasurementWord tdcMeasurementWord(word);
93  int tdcIDCheck = tdcMeasurementWord.tdcID();
94  int tdcChannelCheck = tdcMeasurementWord.tdcChannel();
95  int tdcCountsCheck = tdcMeasurementWord.tdcTime();
96  if (tdcIDCheck == tdcId && channelId == tdcChannelCheck && ntdc == tdcCountsCheck) {
97  if (rosId <= NROS && rosId > 0)
98  b_ros[rosId - 1] = true;
99  else if (debug) {
100  cout << "[DTDigiToRaw]: invalid value for rosId" << endl;
101  }
102 
103  NTDCMeaWords++;
104  w_ROBROS[rosId - 1][robId].push_back(word);
105  }
106  }
107  }
108 
109  uint32_t therosList = 0;
110  for (int i_ros = 0; i_ros < NROS; i_ros++) {
111  if (b_ros[i_ros])
112  therosList += uint32_t(pow(2.0, i_ros));
113  }
114 
115  if (debug)
116  cout << "[DTDigiToRaw]: therosList = " << therosList << endl;
117 
118  for (int i_ros = 0; i_ros < NROS; i_ros++) {
119  if (b_ros[i_ros]) {
120  words.push_back(fakeROSHeaderWord);
121  NWords++;
122  }
123 
124  for (int i_rob = 0; i_rob < NROB; i_rob++) {
125  vector<uint32_t>::const_iterator i_robros;
126  if (w_ROBROS[i_ros][i_rob].begin() != w_ROBROS[i_ros][i_rob].end()) {
127  uint32_t word = 0;
128  DTROBHeaderWord rob_header;
129  rob_header.set(word, i_rob, 0, 0);
130  //static void set(uint32_t &word, int rob_id, int event_id, int bunch_id)
131  words.push_back(word);
132  NWords++;
133 
134  int n_robros = 0;
135  for (i_robros = w_ROBROS[i_ros][i_rob].begin(); i_robros != w_ROBROS[i_ros][i_rob].end(); i_robros++) {
136  NWords++;
137  words.push_back((*i_robros));
138  n_robros++;
139  }
140 
141  NWords++;
142  DTROBTrailerWord rob_trailer;
143  rob_trailer.set(word, i_rob, 0, n_robros + 2);
144  //static void set(uint32_t &word, int rob_id, int event_id, int word_count)
145  words.push_back(word);
146  }
147  }
148 
149  if (b_ros[i_ros]) {
150  words.push_back(fakeROSTrailerWord);
151  NWords++;
152  }
153  }
154 
155  if (NWords % 2 == 1) {
156  words.push_back(0);
157  NWords++;
158  }
159 
160  words.push_back(0);
161  words.push_back(0);
162  //include rosList in raw data information
163  uint32_t secondstatusword = therosList << 16;
164  words.push_back(secondstatusword);
165 
166  words.push_back(0);
167  words.push_back(0);
168  words.push_back(0);
169 
170  // Write Raw Data
171  int dataSize = words.size() * sizeof(Word32);
172  FEDRawData* rawData = new FEDRawData(dataSize);
173  Word64* word64 = reinterpret_cast<Word64*>(rawData->data());
174  for (unsigned int i = 0; i < words.size(); i += 2) {
175  *word64 = (Word64(words[i]) << 32) | words[i + 1];
176  word64++;
177  }
178 
179  return rawData;
180 }
181 
182 void DTDigiToRaw::SetdduID(int x) { dduID_ = x; }
DTDigiToRaw(const edm::ParameterSet &ps)
Constructor.
Definition: DTDigiToRaw.cc:10
int tdcTime() const
Definition: DTDDUWords.h:492
#define WORDCONTROLSHIFT
Definition: DTDDUWords.h:11
void SetdduID(int dduid)
Definition: DTDigiToRaw.cc:182
int tdcChannel() const
Definition: DTDDUWords.h:491
static void set(uint32_t &word, int rob_id, int event_id, int bunch_id)
Definition: DTDDUWords.h:357
static const uint32_t trailerControlWord
Definition: DTDDUWords.h:180
static void set(uint32_t &word, int rob_id, int event_id, int word_count)
Definition: DTDDUWords.h:389
unsigned int Word32
Definition: DTDigiToRaw.h:28
int tdcID() const
<== OBSOLETE!!
Definition: DTDDUWords.h:490
T getUntrackedParameter(std::string const &, T const &) const
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
uint64_t word
const edm::ParameterSet pset
Definition: DTDigiToRaw.h:30
DTChamberId chamberId() const
Return the corresponding ChamberId.
CSCDetId chamberID(const CSCDetId &cscDetId)
#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:21
long long Word64
Definition: DTDigiToRaw.h:29
int superlayer() const
Return the superlayer number (deprecated method name)
int station() const
Definition: CSCDetId.h:79
uint8_t channelId(const VFATFrame &frame)
retrieve this channel identifier
std::pair< const_iterator, const_iterator > Range
static const uint32_t rosTypeWord
Word Type bits definitions.
Definition: DTDDUWords.h:188
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:494
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
HLT enums.
virtual ~DTDigiToRaw()
Destructor.
Definition: DTDigiToRaw.cc:16
float x
static const uint32_t headerControlWord
Control bits definitions.
Definition: DTDDUWords.h:179
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:45
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29