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  DataToken_ = consumes<FEDRawDataCollection>(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 
88  const edm::Handle<FEDRawDataCollection>& rawdata = iEvent.getHandle(DataToken_);
89 
90  auto producedData = std::make_unique<FEDRawDataCollection>();
91  // get fed raw data and SM id
92 
93  // loop over FEDS
94  for (std::vector<int>::const_iterator i = fedUnpackList_.begin(); i != fedUnpackList_.end(); i++) {
95  // get fed raw data and SM id
96  const FEDRawData& fedData = rawdata->FEDData(*i);
97  int length = fedData.size() / sizeof(uint64_t);
98 
99  // LogDebug("EcalRawToDigi") << "raw data length: " << length ;
100  //if data size is not null interpret data
101  if (length >= 1) {
102  uint64_t* pData = (uint64_t*)(fedData.data());
103  //When crc error is found return true
104  uint64_t* fedTrailer = pData + (length - 1);
105  bool crcError = (*fedTrailer >> 2) & 0x1;
106  // this fed has data -- lets copy it
107  if (writeAllEcalFEDs_ || crcError) {
108  FEDRawData& fedDataProd = producedData->FEDData(*i);
109  if (fedDataProd.size() != 0) {
110  // edm::LogVerbatim("EcalTools") << " More than one FEDRawDataCollection with data in FED ";
111  // << j << " Skipping the 2nd";
112  continue;
113  }
114  fedDataProd.resize(fedData.size());
115  unsigned char* dataProd = fedDataProd.data();
116  const unsigned char* data = fedData.data();
117  for (unsigned int k = 0; k < fedData.size(); ++k) {
118  dataProd[k] = data[k];
119  }
120  }
121  }
122  }
123 
124  iEvent.put(std::move(producedData));
125 }
126 
127 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< FEDRawDataCollection > DataToken_
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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