CMS 3D CMS Logo

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