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 
158 
160 
163  e.getByLabel(fedRawDataCollectionTag_, rawdata);
164 
165  // create the collection of Ecal Digis
166  auto productEb = std::make_unique<EBDigiCollection>();
167 
168  // YM create the collection of Ecal Endcap Digis
169  auto productEe = std::make_unique<EEDigiCollection>();
170 
171  // create the collection of Matacq Digi
172  auto productMatacq = std::make_unique<EcalMatacqDigiCollection>();
173 
174  // create the collection of Ecal PN's
175  auto productPN = std::make_unique<EcalPnDiodeDigiCollection>();
176 
177  //create the collection of Ecal DCC Header
178  auto productDCCHeader = std::make_unique<EcalRawDataCollection>();
179 
180  // create the collection with trigger primitives, bits and flags
181  auto productTriggerPrimitives = std::make_unique<EcalTrigPrimDigiCollection>();
182 
183  // create the collection of Ecal Integrity DCC Size
184  auto productDCCSize = std::make_unique<EBDetIdCollection>();
185 
186  // create the collection of Ecal Integrity TT Id
187  auto productTTId = std::make_unique<EcalElectronicsIdCollection>();
188 
189  // create the collection of Ecal Integrity TT Block Size
190  auto productBlockSize = std::make_unique<EcalElectronicsIdCollection>();
191 
192  // create the collection of Ecal Integrity Ch Id
193  auto productChId = std::make_unique<EBDetIdCollection>();
194 
195  // create the collection of Ecal Integrity Gain
196  auto productGain = std::make_unique<EBDetIdCollection>();
197 
198  // create the collection of Ecal Integrity Gain Switch
199  auto productGainSwitch = std::make_unique<EBDetIdCollection>();
200 
201  // create the collection of Ecal Integrity Mem towerBlock_id errors
202  auto productMemTtId = std::make_unique<EcalElectronicsIdCollection>();
203 
204  // create the collection of Ecal Integrity Mem gain errors
205  auto productMemBlockSize = std::make_unique<EcalElectronicsIdCollection>();
206 
207  // create the collection of Ecal Integrity Mem gain errors
208  auto productMemGain = std::make_unique<EcalElectronicsIdCollection>();
209 
210  // create the collection of Ecal Integrity Mem ch_id errors
211  auto productMemChIdErrors = std::make_unique<EcalElectronicsIdCollection>();
212 
213  // create the collection of TB specifics data
214  auto productHodo = std::make_unique<EcalTBHodoscopeRawInfo>();
215  auto productTdc = std::make_unique<EcalTBTDCRawInfo>();
216  auto productHeader = std::make_unique<EcalTBEventHeader>();
217 
218  try {
219  for (int id = 0; id <= FEDNumbering::MAXFEDID; ++id) {
220  // edm::LogInfo("EcalDCCTB07UnpackingModule") << "EcalDCCTB07UnpackingModule::Got FED ID "<< id <<" ";
221  const FEDRawData& data = rawdata->FEDData(id);
222  // edm::LogInfo("EcalDCCTB07UnpackingModule") << " Fed data size " << data.size() ;
223 
224  //std::cout <<"1 Fed id: "<<dec<<id<< " Fed data size: " <<data.size() << std::endl;
225  // const unsigned char * pData = data.data();
226  // int length = data.size();
227  // if(length >0 ){
228  // if(length >= 40){length = 40;}
229  // std::cout<<"##############################################################"<<std::endl;
230  // for( int i=0; i<length; i++ ) {
231  // std::cout << std::hex << std::setw(8) << int(pData[i]) << " ";
232  // if( (i+1)%8 == 0 ) std::cout << std::endl;
233  // }
234  // std::cout<<"##############################################################"<<std::endl;
235  // }
236  if (data.size() > 16) {
237  if ((id >= BEG_DCC_FED_ID && id <= END_DCC_FED_ID) ||
238  (BEG_DCC_FED_ID_GLOBAL <= id &&
239  id <= END_DCC_FED_ID_GLOBAL)) { // do the DCC data unpacking and fill the collections
240 
241  (*productHeader).setSmInBeam(id);
242  // YM add productEe to the list of arguments of the formatter
244  *productEb,
245  *productEe,
246  *productPN,
247  *productDCCHeader,
248  *productDCCSize,
249  *productTTId,
250  *productBlockSize,
251  *productChId,
252  *productGain,
253  *productGainSwitch,
254  *productMemTtId,
255  *productMemBlockSize,
256  *productMemGain,
257  *productMemChIdErrors,
258  *productTriggerPrimitives);
259  int runType = (*productDCCHeader)[0].getRunType();
261  (*productHeader).setTriggerMask(0x1);
262  else if (runType == 4 || runType == 5 || runType == 6) //laser runs
263  (*productHeader).setTriggerMask(0x2000);
264  else if (runType == 9 || runType == 10 || runType == 11) //pedestal runs
265  (*productHeader).setTriggerMask(0x800);
266  LogDebug("EcalDCCTB07UnpackingModule")
267  << "Event type is " << (*productHeader).eventType() << " dbEventType " << (*productHeader).dbEventType();
268  } else if (id == ECAL_SUPERVISOR_FED_ID)
270  else if (id == TBCAMAC_FED_ID)
271  camacTBformatter_->interpretRawData(data, *productHeader, *productHodo, *productTdc);
272  else if (id == TABLE_FED_ID)
273  tableFormatter_->interpretRawData(data, *productHeader);
274  else if (id == MATACQ_FED_ID)
275  matacqFormatter_->interpretRawData(data, *productMatacq);
276  } // endif
277  } //endfor
278 
279  // commit to the event
280  e.put(std::move(productPN));
281  if (ProduceEBDigis_)
282  e.put(std::move(productEb), "ebDigis");
283  if (ProduceEEDigis_)
284  e.put(std::move(productEe), "eeDigis");
285  e.put(std::move(productMatacq));
286  e.put(std::move(productDCCHeader));
287  e.put(std::move(productTriggerPrimitives), "EBTT");
288 
289  if (ProduceEBDigis_)
290  e.put(std::move(productDCCSize), "EcalIntegrityDCCSizeErrors");
291  if (ProduceEBDigis_)
292  e.put(std::move(productTTId), "EcalIntegrityTTIdErrors");
293  if (ProduceEBDigis_)
294  e.put(std::move(productBlockSize), "EcalIntegrityBlockSizeErrors");
295  if (ProduceEBDigis_)
296  e.put(std::move(productChId), "EcalIntegrityChIdErrors");
297  if (ProduceEBDigis_)
298  e.put(std::move(productGain), "EcalIntegrityGainErrors");
299  if (ProduceEBDigis_)
300  e.put(std::move(productGainSwitch), "EcalIntegrityGainSwitchErrors");
301 
302  if (ProduceEBDigis_)
303  e.put(std::move(productMemTtId), "EcalIntegrityMemTtIdErrors");
304  if (ProduceEBDigis_)
305  e.put(std::move(productMemBlockSize), "EcalIntegrityMemBlockSize");
306  if (ProduceEBDigis_)
307  e.put(std::move(productMemChIdErrors), "EcalIntegrityMemChIdErrors");
308  if (ProduceEBDigis_)
309  e.put(std::move(productMemGain), "EcalIntegrityMemGainErrors");
310 
311  e.put(std::move(productHodo));
312  e.put(std::move(productTdc));
313  e.put(std::move(productHeader));
314 
315  } catch (ECALTBParserException& e) {
316  std::cout << "[EcalDCCTB07UnpackingModule] " << e.what() << std::endl;
317  } catch (ECALTBParserBlockException& e) {
318  std::cout << "[EcalDCCTB07UnpackingModule] " << e.what() << std::endl;
319  } catch (cms::Exception& e) {
320  std::cout << "[EcalDCCTB07UnpackingModule] " << e.what() << std::endl;
321  } catch (...) {
322  std::cout << "[EcalDCCTB07UnpackingModule] Unknown exception ..." << std::endl;
323  }
324 }
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)