CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCDigiToRaw.cc
Go to the documentation of this file.
1 
13 #include "boost/dynamic_bitset.hpp"
14 #include "boost/foreach.hpp"
23 #include <algorithm>
24 
25 using namespace edm;
26 using namespace std;
27 
28 namespace cscd2r {
30  CSCDetId chamberID(const CSCDetId & cscDetId) {
31  CSCDetId chamberId = cscDetId.chamberId();
32  if(chamberId.ring() ==4)
33  {
34  chamberId = CSCDetId(chamberId.endcap(), chamberId.station(), 1, chamberId.chamber(), 0);
35  }
36  return chamberId;
37  }
38 
39  template<typename LCTCollection>
40  bool accept(const CSCDetId & cscId, const LCTCollection & lcts,
41  int bxMin, int bxMax)
42  {
43  if(bxMin == -999) return true;
44  int nominalBX = 6;
45  CSCDetId chamberId = chamberID(cscId);
46  typename LCTCollection::Range lctRange = lcts.get(chamberId);
47  bool result = false;
48  for(typename LCTCollection::const_iterator lctItr = lctRange.first;
49  lctItr != lctRange.second; ++lctItr)
50  {
51  int bx = lctItr->getBX() - nominalBX;
52  if(bx >= bxMin && bx <= bxMax)
53  {
54  result = true;
55  break;
56  }
57  }
58  return result;
59  }
60 
61  // need to specialize for pretriggers, since they don't have a getBX()
62  template<>
63  bool accept(const CSCDetId & cscId, const CSCCLCTPreTriggerCollection & lcts,
64  int bxMin, int bxMax)
65  {
66  if(bxMin == -999) return true;
67  int nominalBX = 6;
68  CSCDetId chamberId = chamberID(cscId);
69  CSCCLCTPreTriggerCollection::Range lctRange = lcts.get(chamberId);
70  bool result = false;
71  for(CSCCLCTPreTriggerCollection::const_iterator lctItr = lctRange.first;
72  lctItr != lctRange.second; ++lctItr)
73  {
74  int bx = *lctItr - nominalBX;
75  if(bx >= bxMin && bx <= bxMax)
76  {
77  result = true;
78  break;
79  }
80  }
81  return result;
82  }
83 
84 }
85 
86 
88 : alctWindowMin_(pset.getParameter<int>("alctWindowMin")),
89  alctWindowMax_(pset.getParameter<int>("alctWindowMax")),
90  clctWindowMin_(pset.getParameter<int>("clctWindowMin")),
91  clctWindowMax_(pset.getParameter<int>("clctWindowMax")),
92  preTriggerWindowMin_(pset.getParameter<int>("preTriggerWindowMin")),
93  preTriggerWindowMax_(pset.getParameter<int>("preTriggerWindowMax"))
94 {}
95 
97 {
98  theChamberDataMap.clear();
100 }
101 
102 
104 {
105  CSCDetId chamberId = cscd2r::chamberID(cscDetId);
106  // find the entry into the map
107  map<CSCDetId, CSCEventData>::iterator chamberMapItr = theChamberDataMap.find(chamberId);
108  if(chamberMapItr == theChamberDataMap.end())
109  {
110  // make an entry, telling it the correct chamberType
111  int chamberType = chamberId.iChamberType();
112  chamberMapItr = theChamberDataMap.insert(pair<CSCDetId, CSCEventData>(chamberId, CSCEventData(chamberType))).first;
113  }
114  CSCEventData & cscData = chamberMapItr->second;
115  cscData.dmbHeader()->setCrateAddress(theElectronicsMap->crate(cscDetId), theElectronicsMap->dmb(cscDetId));
116  return cscData;
117 }
118 
119 
120 
122  const CSCCLCTPreTriggerCollection & preTriggers)
123 { //iterate over chambers with strip digis in them
124  for (CSCStripDigiCollection::DigiRangeIterator j=stripDigis.begin(); j!=stripDigis.end(); ++j)
125  {
126  CSCDetId cscDetId=(*j).first;
127  // only digitize if there are pre-triggers
128  if(cscd2r::accept(cscDetId, preTriggers, preTriggerWindowMin_, preTriggerWindowMax_))
129  {
130  bool me1a = (cscDetId.station()==1) && (cscDetId.ring()==4);
131  bool zplus = (cscDetId.endcap() == 1);
132  bool me1b = (cscDetId.station()==1) && (cscDetId.ring()==1);
133 
134  CSCEventData & cscData = findEventData(cscDetId);
135 
136  std::vector<CSCStripDigi>::const_iterator digiItr = (*j).second.first;
137  std::vector<CSCStripDigi>::const_iterator last = (*j).second.second;
138  for( ; digiItr != last; ++digiItr)
139  {
140  CSCStripDigi digi = *digiItr;
141  int strip = digi.getStrip();
142  if ( me1a && zplus ) { digi.setStrip(17-strip); } // 1-16 -> 16-1
143  if ( me1b && !zplus) { digi.setStrip(65-strip);} // 1-64 -> 64-1
144  if ( me1a ) { strip = digi.getStrip(); digi.setStrip(strip+64);} // reset back 1-16 to 65-80 digi
145  cscData.add(digi, cscDetId.layer() );
146  }
147  }
148  }
149 }
150 
151 
153  const CSCALCTDigiCollection & alctDigis)
154 {
155  add(alctDigis);
156  for (CSCWireDigiCollection::DigiRangeIterator j=wireDigis.begin(); j!=wireDigis.end(); ++j)
157  {
158  CSCDetId cscDetId=(*j).first;
159  if(cscd2r::accept(cscDetId, alctDigis, alctWindowMin_, alctWindowMax_))
160  {
161  CSCEventData & cscData = findEventData(cscDetId);
162  std::vector<CSCWireDigi>::const_iterator digiItr = (*j).second.first;
163  std::vector<CSCWireDigi>::const_iterator last = (*j).second.second;
164  for( ; digiItr != last; ++digiItr)
165  {
166  cscData.add(*digiItr, cscDetId.layer() );
167  }
168  }
169  }
170 
171 }
172 
173 void CSCDigiToRaw::add(const CSCComparatorDigiCollection & comparatorDigis,
174  const CSCCLCTDigiCollection & clctDigis)
175 {
176  add(clctDigis);
177  for (CSCComparatorDigiCollection::DigiRangeIterator j=comparatorDigis.begin(); j!=comparatorDigis.end(); ++j)
178  {
179  CSCDetId cscDetId=(*j).first;
180  CSCEventData & cscData = findEventData(cscDetId);
181  if(cscd2r::accept(cscDetId, clctDigis, clctWindowMin_, clctWindowMax_))
182  {
183  bool me1a = (cscDetId.station()==1) && (cscDetId.ring()==4);
184 
185  BOOST_FOREACH(CSCComparatorDigi digi, (*j).second)
186  {
187  // Move ME1/A comparators from CFEB=0 to CFEB=4 if this has not
188  // been done already.
189  if (me1a && digi.getStrip() <= 16) {
190  CSCComparatorDigi digi_corr(64+digi.getStrip(),
191  digi.getComparator(),
192  digi.getTimeBinWord());
193  cscData.add(digi_corr, cscDetId.layer());
194  }
195  else {
196  cscData.add(digi, cscDetId.layer());
197  }
198  }
199  }
200  }
201 }
202 
204 {
205  for (CSCALCTDigiCollection::DigiRangeIterator j=alctDigis.begin(); j!=alctDigis.end(); ++j)
206  {
207  CSCDetId cscDetId=(*j).first;
208  CSCEventData & cscData = findEventData(cscDetId);
209 
210  cscData.add(std::vector<CSCALCTDigi>((*j).second.first, (*j).second.second));
211  }
212 }
213 
215 {
216  for (CSCCLCTDigiCollection::DigiRangeIterator j=clctDigis.begin(); j!=clctDigis.end(); ++j)
217  {
218  CSCDetId cscDetId=(*j).first;
219  CSCEventData & cscData = findEventData(cscDetId);
220 
221  cscData.add(std::vector<CSCCLCTDigi>((*j).second.first, (*j).second.second));
222  }
223 }
224 
226 {
227  for (CSCCorrelatedLCTDigiCollection::DigiRangeIterator j=corrLCTDigis.begin(); j!=corrLCTDigis.end(); ++j)
228  {
229  CSCDetId cscDetId=(*j).first;
230  CSCEventData & cscData = findEventData(cscDetId);
231 
232  cscData.add(std::vector<CSCCorrelatedLCTDigi>((*j).second.first, (*j).second.second));
233  }
234 
235 }
236 
237 
239  const CSCWireDigiCollection& wireDigis,
240  const CSCComparatorDigiCollection& comparatorDigis,
241  const CSCALCTDigiCollection& alctDigis,
242  const CSCCLCTDigiCollection& clctDigis,
243  const CSCCLCTPreTriggerCollection & preTriggers,
244  const CSCCorrelatedLCTDigiCollection& correlatedLCTDigis,
245  FEDRawDataCollection& fed_buffers,
246  const CSCChamberMap* mapping,
247  Event & e)
248 {
249 
250  //bits of code from ORCA/Muon/METBFormatter - thanks, Rick:)!
251 
252  //get fed object from fed_buffers
253  // make a map from the index of a chamber to the event data from it
254  beginEvent(mapping);
255  add(stripDigis, preTriggers);
256  add(wireDigis, alctDigis);
257  add(comparatorDigis, clctDigis);
258  add(correlatedLCTDigis);
259 
260  int l1a=e.id().event(); //need to add increments or get it from lct digis
261  int bx = 0;//same as above
262  //int startingFED = FEDNumbering::MINCSCFEDID;
263 
264  std::map<int, CSCDCCEventData> dccMap;
265  for (int idcc=FEDNumbering::MINCSCFEDID;
266  idcc<=FEDNumbering::MAXCSCFEDID;++idcc)
267  {
268  //idcc goes from startingFed to startingFED+7
269  // @@ if ReadoutMapping changes, this'll have to change
270  // DCCs 1,2,4,5 have 5 DDUs. Otherwise, 4
271  //int nDDUs = (idcc < 2) || (idcc ==4) || (idcc ==5)
272  // ? 5 : 4;
273  //@@ WARNING some DCCs only have 4 DDUs, but I'm giving them all 5, for now
274  int nDDUs = 5;
275  dccMap.insert(std::pair<int, CSCDCCEventData>(idcc, CSCDCCEventData(idcc, nDDUs, bx, l1a) ) );
276 
277  // for every chamber with data, add to a DDU in this DCC Event
278  for(map<CSCDetId, CSCEventData>::iterator chamberItr = theChamberDataMap.begin();
279  chamberItr != theChamberDataMap.end(); ++chamberItr)
280  {
281  //std::cout<<"inside the pack loop" <<std::endl;
282  int indexDCC = mapping->slink(chamberItr->first);
283  if(indexDCC == idcc)
284  {
285  //FIXME (What does this mean? Is something wrong?)
286  std::map<int, CSCDCCEventData>::iterator dccMapItr = dccMap.find(indexDCC);
287  if(dccMapItr == dccMap.end())
288  {
289  throw cms::Exception("CSCDigiToRaw") << "Bad DCC number:" << indexDCC;
290  }
291  // get id's based on ChamberId from mapping
292 
293  int dduId = mapping->ddu(chamberItr->first);
294  int dduSlot = mapping->dduSlot(chamberItr->first);
295  int dduInput = mapping->dduInput(chamberItr->first);
296  int dmbId = mapping->dmb(chamberItr->first);
297  dccMapItr->second.addChamber(chamberItr->second, dduId, dduSlot, dduInput, dmbId);
298  }
299  }
300  }
301 
302  // FIXME: FEDRawData size set to 2*64 to add FED header and trailer
303  for(std::map<int, CSCDCCEventData>::iterator dccMapItr = dccMap.begin();
304  dccMapItr != dccMap.end(); ++dccMapItr)
305  {
306  boost::dynamic_bitset<> dccBits = dccMapItr->second.pack();
307  FEDRawData & fedRawData = fed_buffers.FEDData(dccMapItr->first);
308  fedRawData.resize(dccBits.size());
309  //fill data with dccEvent
310  bitset_utilities::bitsetToChar(dccBits, fedRawData.data());
311  FEDTrailer cscFEDTrailer(fedRawData.data()+(fedRawData.size()-8));
312  cscFEDTrailer.set(fedRawData.data()+(fedRawData.size()-8),
313  fedRawData.size()/8,
314  evf::compute_crc(fedRawData.data(),fedRawData.size()), 0, 0);
315  }
316 }
317 
318 
319 
01/20/05 A.Tumanov
int chamber() const
Definition: CSCDetId.h:70
EventNumber_t event() const
Definition: EventID.h:44
void add(const CSCStripDigiCollection &stripDigis, const CSCCLCTPreTriggerCollection &preTriggers)
int getStrip() const
Get the strip number.
void createFedBuffers(const CSCStripDigiCollection &stripDigis, const CSCWireDigiCollection &wireDigis, const CSCComparatorDigiCollection &comparatorDigis, const CSCALCTDigiCollection &alctDigis, const CSCCLCTDigiCollection &clctDigis, const CSCCLCTPreTriggerCollection &preTriggers, const CSCCorrelatedLCTDigiCollection &correlatedLCTDigis, FEDRawDataCollection &fed_buffers, const CSCChamberMap *theMapping, edm::Event &e)
Take a vector of digis and fill the FEDRawDataCollection.
const EcalElectronicsMapping * electronicsMap
int ddu(const CSCDetId &) const
ddu id for given DetId
int clctWindowMin_
Definition: CSCDigiToRaw.h:61
int dmb(const CSCDetId &) const
dmb id for given DetId
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:26
int getComparator() const
Get Comparator readings.
int layer() const
Definition: CSCDetId.h:63
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
int getStrip() const
Definition: CSCStripDigi.h:37
int endcap() const
Definition: CSCDetId.h:95
int alctWindowMax_
Definition: CSCDigiToRaw.h:60
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void setStrip(int istrip)
Definition: CSCStripDigi.h:51
const CSCChamberMap * theElectronicsMap
Definition: CSCDigiToRaw.h:58
void resize(size_t newsize)
Definition: FEDRawData.cc:32
int slink(const CSCDetId &) const
slink id for given DetId
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:67
tuple result
Definition: query.py:137
int alctWindowMin_
Definition: CSCDigiToRaw.h:59
int dduInput(const CSCDetId &) const
ddu input for given DetId
int j
Definition: DBlmapReader.cc:9
CSCDetId chamberId() const
Definition: CSCDetId.h:55
CSCDetId chamberID(const CSCDetId &cscDetId)
takes layer ID, converts to chamber ID, switching ME1A to ME11
Definition: CSCDigiToRaw.cc:30
CSCDigiToRaw(const edm::ParameterSet &pset)
Constructor.
Definition: CSCDigiToRaw.cc:87
int getTimeBinWord() const
Return the word with each bit corresponding to a time bin.
int clctWindowMax_
Definition: CSCDigiToRaw.h:62
void beginEvent(const CSCChamberMap *electronicsMap)
Definition: CSCDigiToRaw.cc:96
void setCrateAddress(int crate, int dmbId)
Definition: CSCDMBHeader.cc:91
int preTriggerWindowMin_
Definition: CSCDigiToRaw.h:63
unsigned short iChamberType()
Definition: CSCDetId.h:109
int preTriggerWindowMax_
Definition: CSCDigiToRaw.h:64
int ring() const
Definition: CSCDetId.h:77
PixelRecoRange< float > Range
std::map< CSCDetId, CSCEventData > theChamberDataMap
Definition: CSCDigiToRaw.h:57
void bitsetToChar(const boost::dynamic_bitset<> &bs, unsigned char *result)
this method takes bitset obj and returns char * array
int crate(const CSCDetId &) const
Interface required use in digi-to-raw.
std::vector< CSCCLCTPreTrigger >::const_iterator const_iterator
int dduSlot(const CSCDetId &) const
ddu slot for given DetId
CSCEventData & findEventData(const CSCDetId &cscDetId)
pick out the correct data object for this chamber
void add(const CSCStripDigi &, int layer)
routines to add digis to the data
edm::EventID id() const
Definition: EventBase.h:56
bool accept(const CSCDetId &cscId, const LCTCollection &lcts, int bxMin, int bxMax)
Definition: CSCDigiToRaw.cc:40
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
int station() const
Definition: CSCDetId.h:88
std::pair< const_iterator, const_iterator > Range
const CSCDMBHeader * dmbHeader() const
the DAQ motherboard header. A good place for event and chamber info
Definition: CSCEventData.h:90