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