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 
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.empty() || towerIDs.empty() || stripIDs.empty() || channelIDs.empty() ){
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.empty() || ccuIDs.empty() || positionIDs.empty() ) {
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  auto productEb = std::make_unique<EBDigiCollection>();
183 
184  // YM create the collection of Ecal Endcap Digis
185  auto productEe = std::make_unique<EEDigiCollection>();
186 
187  // create the collection of Matacq Digi
188  auto productMatacq = std::make_unique<EcalMatacqDigiCollection>();
189 
190  // create the collection of Ecal PN's
191  auto productPN = std::make_unique<EcalPnDiodeDigiCollection>();
192 
193  //create the collection of Ecal DCC Header
194  auto productDCCHeader = std::make_unique<EcalRawDataCollection>();
195 
196  // create the collection with trigger primitives, bits and flags
197  auto productTriggerPrimitives = std::make_unique<EcalTrigPrimDigiCollection>();
198 
199  // create the collection of Ecal Integrity DCC Size
200  auto productDCCSize = std::make_unique<EBDetIdCollection>();
201 
202  // create the collection of Ecal Integrity TT Id
203  auto productTTId = std::make_unique<EcalElectronicsIdCollection>();
204 
205  // create the collection of Ecal Integrity TT Block Size
206  auto productBlockSize = std::make_unique<EcalElectronicsIdCollection>();
207 
208  // create the collection of Ecal Integrity Ch Id
209  auto productChId = std::make_unique<EBDetIdCollection>();
210 
211  // create the collection of Ecal Integrity Gain
212  auto productGain = std::make_unique<EBDetIdCollection>();
213 
214  // create the collection of Ecal Integrity Gain Switch
215  auto productGainSwitch = std::make_unique<EBDetIdCollection>();
216 
217  // create the collection of Ecal Integrity Mem towerBlock_id errors
218  auto productMemTtId = std::make_unique<EcalElectronicsIdCollection>();
219 
220  // create the collection of Ecal Integrity Mem gain errors
221  auto productMemBlockSize = std::make_unique< EcalElectronicsIdCollection>();
222 
223  // create the collection of Ecal Integrity Mem gain errors
224  auto productMemGain = std::make_unique< EcalElectronicsIdCollection>();
225 
226  // create the collection of Ecal Integrity Mem ch_id errors
227  auto productMemChIdErrors = std::make_unique<EcalElectronicsIdCollection>();
228 
229  // create the collection of TB specifics data
230  auto productHodo = std::make_unique<EcalTBHodoscopeRawInfo>();
231  auto productTdc = std::make_unique<EcalTBTDCRawInfo>();
232  auto productHeader = std::make_unique<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(std::move(productPN));
295  if (ProduceEBDigis_) e.put(std::move(productEb),"ebDigis");
296  if (ProduceEEDigis_) e.put(std::move(productEe),"eeDigis");
297  e.put(std::move(productMatacq));
298  e.put(std::move(productDCCHeader));
299  e.put(std::move(productTriggerPrimitives), "EBTT");
300 
301  if (ProduceEBDigis_) e.put(std::move(productDCCSize),"EcalIntegrityDCCSizeErrors");
302  if (ProduceEBDigis_) e.put(std::move(productTTId),"EcalIntegrityTTIdErrors");
303  if (ProduceEBDigis_) e.put(std::move(productBlockSize),"EcalIntegrityBlockSizeErrors");
304  if (ProduceEBDigis_) e.put(std::move(productChId),"EcalIntegrityChIdErrors");
305  if (ProduceEBDigis_) e.put(std::move(productGain),"EcalIntegrityGainErrors");
306  if (ProduceEBDigis_) e.put(std::move(productGainSwitch),"EcalIntegrityGainSwitchErrors");
307 
308  if (ProduceEBDigis_) e.put(std::move(productMemTtId),"EcalIntegrityMemTtIdErrors");
309  if (ProduceEBDigis_) e.put(std::move(productMemBlockSize),"EcalIntegrityMemBlockSize");
310  if (ProduceEBDigis_) e.put(std::move(productMemChIdErrors),"EcalIntegrityMemChIdErrors");
311  if (ProduceEBDigis_) e.put(std::move(productMemGain),"EcalIntegrityMemGainErrors");
312 
313  e.put(std::move(productHodo));
314  e.put(std::move(productTdc));
315  e.put(std::move(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)
T getUntrackedParameter(std::string const &, T const &) const
TableDataFormatter * tableFormatter_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
#define BEG_DCC_FED_ID
#define END_DCC_FED_ID_GLOBAL
EcalTB07DaqFormatter * formatter_
char const * what() const override
Definition: Exception.cc:141
#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 produce(edm::Event &e, const edm::EventSetup &c) override
Produce digis out of raw data.
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void interpretRawData(const FEDRawData &data, EcalMatacqDigiCollection &matacqDigiCollection)
CamacTBDataFormatter * camacTBformatter_
MatacqTBDataFormatter * matacqFormatter_
EcalSupervisorTBDataFormatter * ecalSupervisorFormatter_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:475
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
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const char * what() const
~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:510
void interpretRawData(const FEDRawData &data, EcalTBEventHeader &tbEventHeader, EcalTBHodoscopeRawInfo &hodoRaw, EcalTBTDCRawInfo &tdcRawInfo)