CMS 3D CMS Logo

HcalPatternSource.cc
Go to the documentation of this file.
11 #include <wordexp.h>
12 #include <cstdio>
13 
15  : bunches_(pset.getUntrackedParameter<std::vector<int> >("Bunches", std::vector<int>())),
16  presamples_(pset.getUntrackedParameter<int>("Presamples", 4)),
17  samples_(pset.getUntrackedParameter<int>("Samples", 10)) {
19  produces<HBHEDigiCollection>();
20  produces<HODigiCollection>();
21  produces<HFDigiCollection>();
22 }
23 
25  if (e.id().event() > bunches_.size())
26  return;
27 
29  es.get<HcalElectronicsMapRcd>().get(item);
30  const HcalElectronicsMap* elecmap = item.product();
31 
32  auto hbhe = std::make_unique<HBHEDigiCollection>();
33  auto hf = std::make_unique<HFDigiCollection>();
34  auto ho = std::make_unique<HODigiCollection>();
35 
36  int bc = bunches_[e.id().event() - 1];
37  for (std::vector<HcalFiberPattern>::iterator i = patterns_.begin(); i != patterns_.end(); i++) {
38  std::vector<HcalQIESample> samples;
39  for (int fc = 0; fc < 3; fc++) {
40  samples = i->getSamples(bc, presamples_, samples_, fc);
41  HcalElectronicsId eid = i->getId(fc);
42 
43  HcalDetId did(elecmap->lookup(eid));
44 
45  if (did.null()) {
46  edm::LogWarning("HCAL") << "No electronics map match for id " << eid;
47  continue;
48  }
49 
50  switch (did.subdet()) {
51  case (HcalBarrel):
52  case (HcalEndcap):
53  hbhe->push_back(HBHEDataFrame(did));
54  hbhe->back().setSize(samples_);
55  hbhe->back().setPresamples(presamples_);
56  for (int i = 0; i < samples_; i++)
57  hbhe->back().setSample(i, samples[i]);
58  hbhe->back().setReadoutIds(eid);
59  break;
60  case (HcalForward):
61  hf->push_back(HFDataFrame(did));
62  hf->back().setSize(samples_);
63  hf->back().setPresamples(presamples_);
64  for (int i = 0; i < samples_; i++)
65  hf->back().setSample(i, samples[i]);
66  hf->back().setReadoutIds(eid);
67  break;
68  case (HcalOuter):
69  ho->push_back(HODataFrame(did));
70  ho->back().setSize(samples_);
71  ho->back().setPresamples(presamples_);
72  for (int i = 0; i < samples_; i++)
73  ho->back().setSample(i, samples[i]);
74  ho->back().setReadoutIds(eid);
75  break;
76  default:
77  continue;
78  }
79  }
80  }
81  hbhe->sort();
82  ho->sort();
83  hf->sort();
84 
85  e.put(std::move(hbhe));
86  e.put(std::move(ho));
87  e.put(std::move(hf));
88 }
89 
91  wordexp_t p;
92  char** files;
93  wordexp(patspec.c_str(), &p, WRDE_NOCMD); // do not run shell commands!
94  files = p.we_wordv;
95  for (unsigned int i = 0; i < p.we_wordc; i++) {
96  LogDebug("HCAL") << "Reading pattern file '" << files[i] << "'";
97  loadPatternFile(files[i]);
98  LogDebug("HCAL") << "Fibers so far " << patterns_.size();
99  }
100  wordfree(&p);
101 }
102 
105  std::string buffer, element;
106  std::map<std::string, std::string> params;
107  std::vector<uint32_t> data;
108  FILE* f = fopen(filename.c_str(), "r");
109  if (f == nullptr)
110  return;
111  else {
112  char block[4096];
113  while (!feof(f)) {
114  int read = fread(block, 1, 4096, f);
115  buffer.append(block, block + read);
116  }
117  fclose(f);
118  }
119  if (buffer.find("<?xml") != 0) {
120  throw cms::Exception("InvalidFormat") << "Not a valid XML file: " << filename;
121  }
122  std::string::size_type i = 0, j;
123  while (buffer.find("<CFGBrick>", i) != std::string::npos) {
124  i = buffer.find("<CFGBrick>", i);
125  j = buffer.find("</CFGBrick>", i);
126  element = "<?xml version='1.0'?>\n";
127  element.append(buffer, i, j - i);
128  element.append("</CFGBrick>");
129  // LogDebug("HCAL") << element;
130  params.clear();
131  data.clear();
132  parser.parse(element, params, data);
133  patterns_.push_back(HcalFiberPattern(params, data));
134  i = j + 5;
135  }
136 }
#define LogDebug(id)
void loadPatternFile(const std::string &filename)
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
void parse(const std::string &xmlDocument, std::map< std::string, std::string > &parameters, std::vector< std::string > &items, std::string &encoding)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void produce(edm::Event &e, const edm::EventSetup &c) override
void loadPatterns(const std::string &patspec)
uint16_t size_type
std::vector< int > bunches_
double f[11][100]
std::vector< HcalFiberPattern > patterns_
HcalPatternSource(const edm::ParameterSet &pset)
edm::EventID id() const
Definition: EventBase.h:59
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
T get() const
Definition: EventSetup.h:71
T const * product() const
Definition: ESHandle.h:86
Readout chain identification for Hcal.
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
def move(src, dest)
Definition: eostools.py:511