CMS 3D CMS Logo

HcalPatternSource.cc
Go to the documentation of this file.
10 #include <wordexp.h>
11 #include <cstdio>
12 
13 #include <vector>
16 
18 public:
20  ~HcalPatternSource() override;
21  void produce(edm::Event& e, const edm::EventSetup& c) override;
22 
23 private:
24  void loadPatterns(const std::string& patspec);
26  std::vector<int> bunches_;
27  std::vector<HcalFiberPattern> patterns_;
30 };
31 
33  : bunches_(pset.getUntrackedParameter<std::vector<int> >("Bunches", std::vector<int>())),
34  presamples_(pset.getUntrackedParameter<int>("Presamples", 4)),
35  samples_(pset.getUntrackedParameter<int>("Samples", 10)),
36  theHcalElectronicsMapToken_(esConsumes()) {
37  loadPatterns(pset.getUntrackedParameter<std::string>("Patterns"));
38  produces<HBHEDigiCollection>();
39  produces<HODigiCollection>();
40  produces<HFDigiCollection>();
41 }
42 
44 
46  if (e.id().event() > bunches_.size())
47  return;
48 
49  // Get HcalElectronicsMap from the Event setup
50  const auto elecmap = &iSetup.getData(theHcalElectronicsMapToken_);
51 
52  auto hbhe = std::make_unique<HBHEDigiCollection>();
53  auto hf = std::make_unique<HFDigiCollection>();
54  auto ho = std::make_unique<HODigiCollection>();
55 
56  int bc = bunches_[e.id().event() - 1];
57  for (std::vector<HcalFiberPattern>::iterator i = patterns_.begin(); i != patterns_.end(); i++) {
58  std::vector<HcalQIESample> samples;
59  for (int fc = 0; fc < 3; fc++) {
60  samples = i->getSamples(bc, presamples_, samples_, fc);
61  HcalElectronicsId eid = i->getId(fc);
62 
63  HcalDetId did(elecmap->lookup(eid));
64 
65  if (did.null()) {
66  edm::LogWarning("HcalPatternSource") << "No electronics map match for id " << eid;
67  continue;
68  }
69 
70  switch (did.subdet()) {
71  case (HcalBarrel):
72  case (HcalEndcap):
73  hbhe->push_back(HBHEDataFrame(did));
74  hbhe->back().setSize(samples_);
75  hbhe->back().setPresamples(presamples_);
76  for (int i = 0; i < samples_; i++)
77  hbhe->back().setSample(i, samples[i]);
78  hbhe->back().setReadoutIds(eid);
79  break;
80  case (HcalForward):
81  hf->push_back(HFDataFrame(did));
82  hf->back().setSize(samples_);
83  hf->back().setPresamples(presamples_);
84  for (int i = 0; i < samples_; i++)
85  hf->back().setSample(i, samples[i]);
86  hf->back().setReadoutIds(eid);
87  break;
88  case (HcalOuter):
89  ho->push_back(HODataFrame(did));
90  ho->back().setSize(samples_);
91  ho->back().setPresamples(presamples_);
92  for (int i = 0; i < samples_; i++)
93  ho->back().setSample(i, samples[i]);
94  ho->back().setReadoutIds(eid);
95  break;
96  default:
97  continue;
98  }
99  }
100  }
101  hbhe->sort();
102  ho->sort();
103  hf->sort();
104 
105  e.put(std::move(hbhe));
106  e.put(std::move(ho));
107  e.put(std::move(hf));
108 }
109 
111  wordexp_t p;
112  char** files;
113  wordexp(patspec.c_str(), &p, WRDE_NOCMD); // do not run shell commands!
114  files = p.we_wordv;
115  for (unsigned int i = 0; i < p.we_wordc; i++) {
116  LogDebug("HCAL") << "Reading pattern file '" << files[i] << "'";
118  LogDebug("HCAL") << "Fibers so far " << patterns_.size();
119  }
120  wordfree(&p);
121 }
122 
125  std::string buffer, element;
126  std::map<std::string, std::string> params;
127  std::vector<uint32_t> data;
128  FILE* f = fopen(filename.c_str(), "r");
129  if (f == nullptr)
130  return;
131  else {
132  char block[4096];
133  while (!feof(f)) {
134  int read = fread(block, 1, 4096, f);
135  buffer.append(block, block + read);
136  }
137  fclose(f);
138  }
139  if (buffer.find("<?xml") != 0) {
140  throw cms::Exception("InvalidFormat") << "Not a valid XML file: " << filename;
141  }
143  while (buffer.find("<CFGBrick>", i) != std::string::npos) {
144  i = buffer.find("<CFGBrick>", i);
145  j = buffer.find("</CFGBrick>", i);
146  element = "<?xml version='1.0'?>\n";
147  element.append(buffer, i, j - i);
148  element.append("</CFGBrick>");
149  // LogDebug("HCAL") << element;
150  params.clear();
151  data.clear();
152  parser.parse(element, params, data);
153  patterns_.push_back(HcalFiberPattern(params, data));
154  i = j + 5;
155  }
156 }
157 
void loadPatternFile(const std::string &filename)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void produce(edm::Event &e, const edm::EventSetup &c) override
void loadPatterns(const std::string &patspec)
uint16_t size_type
std::vector< int > bunches_
const edm::ESGetToken< HcalElectronicsMap, HcalElectronicsMapRcd > theHcalElectronicsMapToken_
double f[11][100]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getData(T &iHolder) const
Definition: EventSetup.h:122
std::vector< HcalFiberPattern > patterns_
~HcalPatternSource() override
HcalPatternSource(const edm::ParameterSet &pset)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
Log< level::Warning, false > LogWarning
Readout chain identification for Hcal.
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)