CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDCC07UnpackingModule.cc
Go to the documentation of this file.
1 /* \file EcalDCCTB07UnpackingModule.h
2  *
3  * $Date: 2009/12/14 22:22:37 $
4  * $Revision: 1.12 $
5  * \author Y. Maravin
6  * \author G. Franzoni
7  * \author G. Della Ricca
8  */
9 
27 
28 
29 #include <iostream>
30 #include <iomanip>
31 
32 // in full CMS this range cannot be used (allocated to pixel, see DataFormats/ FEDRawData/ src/ FEDNumbering.cc)
33 #define BEG_DCC_FED_ID 0
34 #define END_DCC_FED_ID 0
35 #define BEG_DCC_FED_ID_GLOBAL 0
36 #define END_DCC_FED_ID_GLOBAL 0
37 
38 #define ECAL_SUPERVISOR_FED_ID 40
39 #define TBCAMAC_FED_ID 41
40 #define TABLE_FED_ID 42
41 #define MATACQ_FED_ID 43
42 
44 
45  std::string tbName = pset.getUntrackedParameter<std::string >("tbName", std::string("h2") );
46 
47  ProduceEEDigis_ = pset.getUntrackedParameter<bool >("produceEEdigi", true );
48  ProduceEBDigis_ = pset.getUntrackedParameter<bool >("produceEBdigi", false );
49 
50  // index of crystal <-> tower ID (DQM plots) position <-> stripIDs <-> channelIDs for the test beam (2007)
51  std::vector<int> ics = pset.getUntrackedParameter<std::vector<int> >("ics", std::vector<int>());
52  std::vector<int> towerIDs = pset.getUntrackedParameter<std::vector<int> >("towerIDs", std::vector<int>());
53  std::vector<int> stripIDs = pset.getUntrackedParameter<std::vector<int> >("stripIDs", std::vector<int>());
54  std::vector<int> channelIDs = pset.getUntrackedParameter<std::vector<int> >("channelIDs", std::vector<int>());
55 
56  // status id <-> tower CCU ID <-> DQM plots position mapping for the test beam (2007)
57  std::vector<int> statusIDs = pset.getUntrackedParameter<std::vector<int> >("statusIDs", std::vector<int>());
58  std::vector<int> ccuIDs = pset.getUntrackedParameter<std::vector<int> >("ccuIDs", std::vector<int>());
59  std::vector<int> positionIDs = pset.getUntrackedParameter<std::vector<int> >("positionIDs", std::vector<int>());
60 
61  // check if vectors are filled
62  if ( ics.size() == 0 || towerIDs.size() == 0 || stripIDs.size() == 0 || channelIDs.size() == 0 ){
63  edm::LogError("EcalDCCTB07UnpackingModule") << "Some of the mapping info is missing! Check config files! " <<
64  " Size of IC vector is " << ics.size() <<
65  " Size of Tower ID vector is " << towerIDs.size() <<
66  " Size of Strip ID vector is " << stripIDs.size() <<
67  " Size of Channel ID vector is " << channelIDs.size();
68  }
69  if ( statusIDs.size() == 0 || ccuIDs.size() == 0 || positionIDs.size() == 0 ) {
70  edm::LogError("EcalDCCTB07UnpackingModule") << "Some of the mapping info is missing! Check config files! " <<
71  " Size of status ID vector is " << statusIDs.size() <<
72  " Size of ccu ID vector is " << ccuIDs.size() <<
73  " positionIDs size is " << positionIDs.size();
74  }
75 
76  // check if vectors have the same size
77  if ( ics.size() != towerIDs.size() || ics.size() != stripIDs.size() || ics.size() != channelIDs.size() ||
78  towerIDs.size() != stripIDs.size() || towerIDs.size() != channelIDs.size() ||
79  stripIDs.size() != channelIDs.size() )
80  edm::LogError("EcalDCCTB07UnpackingModule") << "Mapping information is corrupted. " <<
81  "Tower/DQM position/strip/channel vectors are of different size! Check cfi files! \n" <<
82  " Size of IC vector is " << ics.size() <<
83  " Size of Tower ID vector is " << towerIDs.size() <<
84  " Size of Strip ID vector is " << stripIDs.size() <<
85  " Size of Channel ID vector is " << channelIDs.size();
86 
87  if ( statusIDs.size() != ccuIDs.size() || statusIDs.size() != positionIDs.size() ||
88  ccuIDs.size() != positionIDs.size() )
89  edm::LogError("EcalDCCTB07UnpackingModule") << "Mapping information is corrupted. " <<
90  "Status/CCU ID/DQM position vectors are of different size! Check cfi files! \n" <<
91  " Size of status ID vector is " << statusIDs.size() <<
92  " Size of ccu ID vector is " << ccuIDs.size() <<
93  " positionIDs size is " << positionIDs.size();
94 
95  int cryIcMap[68][5][5];
96  int tbStatusToLocation[71];
97  int tbTowerIDToLocation[201];
98  for (unsigned it=1; it <= 68; ++it )
99  for (unsigned is=1; is <=5; ++is )
100  for (unsigned ic=1; ic <=5; ++ic)
101  cryIcMap[it-1][is-1][ic-1] = 1700;
102 
103  for (unsigned it=1; it <=71; ++it)
104  tbStatusToLocation[it-1] = it - 1;
105 
106  for (unsigned it=1; it <= 201; ++it)
107  tbTowerIDToLocation[it-1] = it - 1;
108 
109  // Fill the cry IC map
110  for(unsigned int i=0; i < ics.size(); ++i) {
111  int tower = towerIDs[i];
112  int strip = stripIDs[i];
113  int channel = channelIDs[i];
114  int ic = ics[i];
115  cryIcMap[tower-1][strip-1][channel-1] = ic;
116  }
117  for(unsigned int i = 0; i < statusIDs.size(); ++i) {
118  int is = statusIDs[i];
119  int it = ccuIDs[i];
120  int itEB = positionIDs[i];
121 
122  tbStatusToLocation[is] = itEB;
123  tbTowerIDToLocation[it] = itEB;
124  }
125 
126  formatter_ = new EcalTB07DaqFormatter(tbName, cryIcMap, tbStatusToLocation, tbTowerIDToLocation);
131 
132 
133  // digis
134  produces<EBDigiCollection>("ebDigis");
135  produces<EEDigiCollection>("eeDigis");
136  produces<EcalMatacqDigiCollection>();
137  produces<EcalPnDiodeDigiCollection>();
138  produces<EcalRawDataCollection>();
139  produces<EcalTrigPrimDigiCollection>("EBTT");
140 
141  //TB specifics data
142  produces<EcalTBHodoscopeRawInfo>();
143  produces<EcalTBTDCRawInfo>();
144  produces<EcalTBEventHeader>();
145 
146  // crystals' integrity
147  produces<EBDetIdCollection>("EcalIntegrityDCCSizeErrors");
148  produces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors");
149  produces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors");
150  produces<EBDetIdCollection>("EcalIntegrityChIdErrors");
151  produces<EBDetIdCollection>("EcalIntegrityGainErrors");
152  produces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors");
153 
154  // mem channels' integrity
155  produces<EcalElectronicsIdCollection>("EcalIntegrityMemTtIdErrors");
156  produces<EcalElectronicsIdCollection>("EcalIntegrityMemBlockSize");
157  produces<EcalElectronicsIdCollection>("EcalIntegrityMemChIdErrors");
158  produces<EcalElectronicsIdCollection>("EcalIntegrityMemGainErrors");
159 }
160 
161 
163 
164  delete formatter_;
165 
166 }
167 
169 
170 }
171 
173 
174 }
175 
177 
179  e.getByType(rawdata);
180 
181 
182  // create the collection of Ecal Digis
183  std::auto_ptr<EBDigiCollection> productEb(new EBDigiCollection);
184 
185  // YM create the collection of Ecal Endcap Digis
186  std::auto_ptr<EEDigiCollection> productEe(new EEDigiCollection);
187 
188  // create the collection of Matacq Digi
189  std::auto_ptr<EcalMatacqDigiCollection> productMatacq(new EcalMatacqDigiCollection());
190 
191  // create the collection of Ecal PN's
192  std::auto_ptr<EcalPnDiodeDigiCollection> productPN(new EcalPnDiodeDigiCollection);
193 
194  //create the collection of Ecal DCC Header
195  std::auto_ptr<EcalRawDataCollection> productDCCHeader(new EcalRawDataCollection);
196 
197  // create the collection with trigger primitives, bits and flags
198  std::auto_ptr<EcalTrigPrimDigiCollection> productTriggerPrimitives(new EcalTrigPrimDigiCollection);
199 
200  // create the collection of Ecal Integrity DCC Size
201  std::auto_ptr<EBDetIdCollection> productDCCSize(new EBDetIdCollection);
202 
203  // create the collection of Ecal Integrity TT Id
204  std::auto_ptr<EcalElectronicsIdCollection> productTTId(new EcalElectronicsIdCollection);
205 
206  // create the collection of Ecal Integrity TT Block Size
207  std::auto_ptr<EcalElectronicsIdCollection> productBlockSize(new EcalElectronicsIdCollection);
208 
209  // create the collection of Ecal Integrity Ch Id
210  std::auto_ptr<EBDetIdCollection> productChId(new EBDetIdCollection);
211 
212  // create the collection of Ecal Integrity Gain
213  std::auto_ptr<EBDetIdCollection> productGain(new EBDetIdCollection);
214 
215  // create the collection of Ecal Integrity Gain Switch
216  std::auto_ptr<EBDetIdCollection> productGainSwitch(new EBDetIdCollection);
217 
218  // create the collection of Ecal Integrity Mem towerBlock_id errors
219  std::auto_ptr<EcalElectronicsIdCollection> productMemTtId(new EcalElectronicsIdCollection);
220 
221  // create the collection of Ecal Integrity Mem gain errors
222  std::auto_ptr< EcalElectronicsIdCollection> productMemBlockSize(new EcalElectronicsIdCollection);
223 
224  // create the collection of Ecal Integrity Mem gain errors
225  std::auto_ptr< EcalElectronicsIdCollection> productMemGain(new EcalElectronicsIdCollection);
226 
227  // create the collection of Ecal Integrity Mem ch_id errors
228  std::auto_ptr<EcalElectronicsIdCollection> productMemChIdErrors(new EcalElectronicsIdCollection);
229 
230  // create the collection of TB specifics data
231  std::auto_ptr<EcalTBHodoscopeRawInfo> productHodo(new EcalTBHodoscopeRawInfo());
232  std::auto_ptr<EcalTBTDCRawInfo> productTdc(new EcalTBTDCRawInfo());
233  std::auto_ptr<EcalTBEventHeader> productHeader(new EcalTBEventHeader());
234 
235 
236  try {
237 
238  for (int id= 0; id<=FEDNumbering::MAXFEDID; ++id){
239 
240  // edm::LogInfo("EcalDCCTB07UnpackingModule") << "EcalDCCTB07UnpackingModule::Got FED ID "<< id <<" ";
241  const FEDRawData& data = rawdata->FEDData(id);
242  // edm::LogInfo("EcalDCCTB07UnpackingModule") << " Fed data size " << data.size() ;
243 
244  //std::cout <<"1 Fed id: "<<dec<<id<< " Fed data size: " <<data.size() << std::endl;
245 // const unsigned char * pData = data.data();
246 // int length = data.size();
247 // if(length >0 ){
248 // if(length >= 40){length = 40;}
249 // std::cout<<"##############################################################"<<std::endl;
250 // for( int i=0; i<length; i++ ) {
251 // std::cout << std::hex << std::setw(8) << int(pData[i]) << " ";
252 // if( (i+1)%8 == 0 ) std::cout << std::endl;
253 // }
254 // std::cout<<"##############################################################"<<std::endl;
255 // }
256  if (data.size()>16){
257 
258  if ( (id >= BEG_DCC_FED_ID && id <= END_DCC_FED_ID) ||
260  )
261  { // do the DCC data unpacking and fill the collections
262 
263  (*productHeader).setSmInBeam(id);
264  // YM add productEe to the list of arguments of the formatter
265  formatter_->interpretRawData(data, *productEb, *productEe, *productPN,
266  *productDCCHeader,
267  *productDCCSize,
268  *productTTId, *productBlockSize,
269  *productChId, *productGain, *productGainSwitch,
270  *productMemTtId, *productMemBlockSize,
271  *productMemGain, *productMemChIdErrors,
272  *productTriggerPrimitives);
273  int runType = (*productDCCHeader)[0].getRunType();
274  if ( runType == EcalDCCHeaderBlock::COSMIC || runType == EcalDCCHeaderBlock::BEAMH4 )
275  (*productHeader).setTriggerMask(0x1);
276  else if ( runType == 4 || runType == 5 || runType == 6 ) //laser runs
277  (*productHeader).setTriggerMask(0x2000);
278  else if ( runType == 9 || runType == 10 || runType == 11 ) //pedestal runs
279  (*productHeader).setTriggerMask(0x800);
280  LogDebug("EcalDCCTB07UnpackingModule") << "Event type is " << (*productHeader).eventType() << " dbEventType " << (*productHeader).dbEventType();
281  }
282  else if ( id == ECAL_SUPERVISOR_FED_ID )
283  ecalSupervisorFormatter_->interpretRawData(data, *productHeader);
284  else if ( id == TBCAMAC_FED_ID )
285  camacTBformatter_->interpretRawData(data, *productHeader,*productHodo, *productTdc );
286  else if ( id == TABLE_FED_ID )
287  tableFormatter_->interpretRawData(data, *productHeader);
288  else if ( id == MATACQ_FED_ID )
289  matacqFormatter_->interpretRawData(data, *productMatacq);
290  }// endif
291  }//endfor
292 
293 
294  // commit to the event
295  e.put(productPN);
296  if (ProduceEBDigis_) e.put(productEb,"ebDigis");
297  if (ProduceEEDigis_) e.put(productEe,"eeDigis");
298  e.put(productMatacq);
299  e.put(productDCCHeader);
300  e.put(productTriggerPrimitives, "EBTT");
301 
302  if (ProduceEBDigis_) e.put(productDCCSize,"EcalIntegrityDCCSizeErrors");
303  if (ProduceEBDigis_) e.put(productTTId,"EcalIntegrityTTIdErrors");
304  if (ProduceEBDigis_) e.put(productBlockSize,"EcalIntegrityBlockSizeErrors");
305  if (ProduceEBDigis_) e.put(productChId,"EcalIntegrityChIdErrors");
306  if (ProduceEBDigis_) e.put(productGain,"EcalIntegrityGainErrors");
307  if (ProduceEBDigis_) e.put(productGainSwitch,"EcalIntegrityGainSwitchErrors");
308 
309  if (ProduceEBDigis_) e.put(productMemTtId,"EcalIntegrityMemTtIdErrors");
310  if (ProduceEBDigis_) e.put(productMemBlockSize,"EcalIntegrityMemBlockSize");
311  if (ProduceEBDigis_) e.put(productMemChIdErrors,"EcalIntegrityMemChIdErrors");
312  if (ProduceEBDigis_) e.put(productMemGain,"EcalIntegrityMemGainErrors");
313 
314  e.put(productHodo);
315  e.put(productTdc);
316  e.put(productHeader);
317 
318  } catch (ECALTBParserException &e) {
319  std::cout << "[EcalDCCTB07UnpackingModule] " << e.what() << std::endl;
320  } catch (ECALTBParserBlockException &e) {
321  std::cout << "[EcalDCCTB07UnpackingModule] " << e.what() << std::endl;
322  } catch (cms::Exception &e) {
323  std::cout << "[EcalDCCTB07UnpackingModule] " << e.what() << std::endl;
324  } catch (...) {
325  std::cout << "[EcalDCCTB07UnpackingModule] Unknown exception ..." << std::endl;
326  }
327 
328 }
#define LogDebug(id)
virtual char const * what() const
Definition: Exception.cc:141
T getUntrackedParameter(std::string const &, T const &) const
TableDataFormatter * tableFormatter_
int i
Definition: DBlmapReader.cc:9
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
edm::SortedCollection< EcalMatacqDigi > EcalMatacqDigiCollection
#define BEG_DCC_FED_ID
#define END_DCC_FED_ID_GLOBAL
EcalTB07DaqFormatter * formatter_
bool getByType(Handle< PROD > &result) const
Definition: Event.h:398
#define END_DCC_FED_ID
#define MATACQ_FED_ID
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
void interpretRawData(const FEDRawData &data, EcalMatacqDigiCollection &matacqDigiCollection)
void produce(edm::Event &e, const edm::EventSetup &c)
Produce digis out of raw data.
CamacTBDataFormatter * camacTBformatter_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
virtual ~EcalDCCTB07UnpackingModule()
Destructor.
MatacqTBDataFormatter * matacqFormatter_
EcalSupervisorTBDataFormatter * ecalSupervisorFormatter_
void interpretRawData(const FEDRawData &data, EcalTBEventHeader &tbEventHeader)
void interpretRawData(const FEDRawData &data, EcalTBEventHeader &tbEventHeader)
void interpretRawData(const FEDRawData &data, EBDigiCollection &digicollection, EEDigiCollection &eeDigiCollection, EcalPnDiodeDigiCollection &pndigicollection, EcalRawDataCollection &DCCheaderCollection, EBDetIdCollection &dccsizecollection, EcalElectronicsIdCollection &ttidcollection, EcalElectronicsIdCollection &blocksizecollection, EBDetIdCollection &chidcollection, EBDetIdCollection &gaincollection, EBDetIdCollection &gainswitchcollection, EcalElectronicsIdCollection &memttidcollection, EcalElectronicsIdCollection &memblocksizecollection, EcalElectronicsIdCollection &memgaincollection, EcalElectronicsIdCollection &memchidcollection, EcalTrigPrimDigiCollection &tpcollection)
#define ECAL_SUPERVISOR_FED_ID
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const char * what() const
tuple cout
Definition: gather_cfg.py:121
dictionary rawdata
Definition: lumiPlot.py:393
#define BEG_DCC_FED_ID_GLOBAL
#define TBCAMAC_FED_ID
EcalDCCTB07UnpackingModule(const edm::ParameterSet &pset)
Constructor.
#define TABLE_FED_ID
void interpretRawData(const FEDRawData &data, EcalTBEventHeader &tbEventHeader, EcalTBHodoscopeRawInfo &hodoRaw, EcalTBTDCRawInfo &tdcRawInfo)