CMS 3D CMS Logo

EcalFEDWithCRCErrorProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EcalFEDWithCRCErrorProducer
4 // Class: EcalFEDWithCRCErrorProducer
5 //
13 //
14 // Original Author: Giovanni FRANZONI
15 // Created: Tue Jan 22 13:55:00 CET 2008
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
24 
27 
31 
32 #include <string>
33 #include <iostream>
34 #include <vector>
35 #include <iomanip>
36 
40 //
41 // class declaration
42 //
43 
45 public:
48 
49 private:
50  void produce(edm::Event&, const edm::EventSetup&) override;
51 
52  // ----------member data ---------------------------
53 
55  std::vector<int> fedUnpackList_;
57 };
58 
59 //
60 // constructors and destructor
61 //
63  //now do what ever initialization is needed
64 
65  DataLabel_ = iConfig.getParameter<edm::InputTag>("InputLabel");
66  fedUnpackList_ = iConfig.getUntrackedParameter<std::vector<int> >("FEDs", std::vector<int>());
67  writeAllEcalFEDs_ = iConfig.getUntrackedParameter<bool>("writeAllEcalFED", false);
68  if (fedUnpackList_.empty())
70  fedUnpackList_.push_back(i);
71 
72  produces<FEDRawDataCollection>();
73 }
74 
76  // do anything here that needs to be done at desctruction time
77  // (e.g. close files, deallocate resources etc.)
78 }
79 
80 //
81 // member functions
82 //
83 
84 // ------------ method called on each new Event ------------
86  using namespace edm;
87 
89  iEvent.getByLabel(DataLabel_, rawdata);
90 
91  auto producedData = std::make_unique<FEDRawDataCollection>();
92  // get fed raw data and SM id
93 
94  // loop over FEDS
95  for (std::vector<int>::const_iterator i = fedUnpackList_.begin(); i != fedUnpackList_.end(); i++) {
96  // get fed raw data and SM id
97  const FEDRawData& fedData = rawdata->FEDData(*i);
98  int length = fedData.size() / sizeof(uint64_t);
99 
100  // LogDebug("EcalRawToDigi") << "raw data length: " << length ;
101  //if data size is not null interpret data
102  if (length >= 1) {
103  uint64_t* pData = (uint64_t*)(fedData.data());
104  //When crc error is found return true
105  uint64_t* fedTrailer = pData + (length - 1);
106  bool crcError = (*fedTrailer >> 2) & 0x1;
107  // this fed has data -- lets copy it
108  if (writeAllEcalFEDs_ || crcError) {
109  FEDRawData& fedDataProd = producedData->FEDData(*i);
110  if (fedDataProd.size() != 0) {
111  // std::cout << " More than one FEDRawDataCollection with data in FED ";
112  // std::cout << j << " Skipping the 2nd\n";
113  continue;
114  }
115  fedDataProd.resize(fedData.size());
116  unsigned char* dataProd = fedDataProd.data();
117  const unsigned char* data = fedData.data();
118  for (unsigned int k = 0; k < fedData.size(); ++k) {
119  dataProd[k] = data[k];
120  }
121  }
122  }
123  }
124 
125  iEvent.put(std::move(producedData));
126 }
127 
128 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
void resize(size_t newsize)
Definition: FEDRawData.cc:28
EcalFEDWithCRCErrorProducer(const edm::ParameterSet &)
void produce(edm::Event &, const edm::EventSetup &) override
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
unsigned long long uint64_t
Definition: Time.h:13
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
def move(src, dest)
Definition: eostools.py:511