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