CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

HcalPatternSource Class Reference

#include <HcalPatternSource.h>

Inheritance diagram for HcalPatternSource:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 HcalPatternSource (const edm::ParameterSet &pset)
virtual void produce (edm::Event &e, const edm::EventSetup &c)

Private Member Functions

void loadPatternFile (const std::string &filename)
void loadPatterns (const std::string &patspec)

Private Attributes

std::vector< int > bunches_
std::vector< HcalFiberPatternpatterns_
int presamples_
int samples_

Detailed Description

Date:
2010/02/17 16:55:37
Revision:
1.2
Author:
J. Mans - Minnesota

Definition at line 14 of file HcalPatternSource.h.


Constructor & Destructor Documentation

HcalPatternSource::HcalPatternSource ( const edm::ParameterSet pset)

Definition at line 14 of file HcalPatternSource.cc.

References edm::ParameterSet::getUntrackedParameter(), loadPatterns(), and AlCaHLTBitMon_QueryRunRegistry::string.

                                                                 : 
  bunches_(pset.getUntrackedParameter<std::vector<int> >("Bunches",std::vector<int>())),
  presamples_(pset.getUntrackedParameter<int>("Presamples",4)),
  samples_(pset.getUntrackedParameter<int>("Samples",10))
{
  loadPatterns(pset.getUntrackedParameter<std::string>("Patterns"));
  produces<HBHEDigiCollection>();
  produces<HODigiCollection>();
  produces<HFDigiCollection>();
}

Member Function Documentation

void HcalPatternSource::loadPatternFile ( const std::string &  filename) [private]

Definition at line 99 of file HcalPatternSource.cc.

References Association::block, data, Exception, f, lut2db_cfg::filename, i, j, HcalPatternXMLParser::parse(), geometryXMLtoCSV::parser, patterns_, SiPixelLorentzAngle_cfi::read, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by loadPatterns().

                                                                 {
  HcalPatternXMLParser parser;
  std::string buffer, element;
  std::map<std::string,std::string> params;
  std::vector<uint32_t> data;
  FILE* f=fopen(filename.c_str(), "r");
  if (f==0) return;
  else {
    char block[4096];
    while (!feof(f)) {
      int read=fread(block,1,4096,f);
      buffer.append(block,block+read);
    }  
    fclose(f);
  }
  if (buffer.find("<?xml")!=0) {
    throw cms::Exception("InvalidFormat") << "Not a valid XML file: " << filename;
  }
  std::string::size_type i=0,j;
  while (buffer.find("<CFGBrick>",i)!=std::string::npos) {
    i=buffer.find("<CFGBrick>",i);
    j=buffer.find("</CFGBrick>",i);
    element="<?xml version='1.0'?>\n";
    element.append(buffer,i,j-i);
    element.append("</CFGBrick>");
    //    LogDebug("HCAL") << element;
    params.clear();
    data.clear();
    parser.parse(element,params,data);
    patterns_.push_back(HcalFiberPattern(params,data));
    i=j+5;
  }
  
  
}
void HcalPatternSource::loadPatterns ( const std::string &  patspec) [private]

Definition at line 86 of file HcalPatternSource.cc.

References linker::files, i, loadPatternFile(), LogDebug, AlCaHLTBitMon_ParallelJobs::p, and patterns_.

Referenced by HcalPatternSource().

                                                             {
  wordexp_t p;
  char** files;
  wordexp(patspec.c_str(),&p, WRDE_NOCMD); // do not run shell commands!
  files=p.we_wordv;
  for (unsigned int i=0; i<p.we_wordc; i++) {
    LogDebug ("HCAL") << "Reading pattern file '" << files[i] << "'";
    loadPatternFile(files[i]);
    LogDebug ("HCAL") << "Fibers so far " << patterns_.size();
  }
  wordfree(&p);
}
void HcalPatternSource::produce ( edm::Event e,
const edm::EventSetup c 
) [virtual]

Implements edm::EDProducer.

Definition at line 25 of file HcalPatternSource.cc.

References bunches_, edm::EventID::event(), benchmark_cfg::fc, edm::EventSetup::get(), HcalBarrel, HcalEndcap, HcalForward, HcalOuter, i, edm::EventBase::id(), HcalElectronicsMap::lookup(), patterns_, presamples_, edm::ESHandle< T >::product(), edm::Event::put(), and samples_.

                                                                    {
  if (e.id().event()>bunches_.size()) return;

  edm::ESHandle<HcalElectronicsMap> item;
  es.get<HcalElectronicsMapRcd>().get(item);
  const HcalElectronicsMap *elecmap=item.product();

  std::auto_ptr<HBHEDigiCollection> hbhe(new HBHEDigiCollection());
  std::auto_ptr<HFDigiCollection> hf(new HFDigiCollection());
  std::auto_ptr<HODigiCollection> ho(new HODigiCollection());

  int bc=bunches_[e.id().event()-1];
  for (std::vector<HcalFiberPattern>::iterator i=patterns_.begin(); i!=patterns_.end(); i++) {
    std::vector<HcalQIESample> samples;
    for (int fc=0; fc<3; fc++) {
      samples=i->getSamples(bc,presamples_, samples_, fc);
      HcalElectronicsId eid=i->getId(fc);

      HcalDetId did(elecmap->lookup(eid));

      if (did.null()) {
        edm::LogWarning("HCAL") << "No electronics map match for id " << eid;
        continue;
      }

      switch (did.subdet()) {
      case (HcalBarrel):
      case (HcalEndcap):
        hbhe->push_back(HBHEDataFrame(did));
        hbhe->back().setSize(samples_);
        hbhe->back().setPresamples(presamples_);
        for (int i=0; i<samples_; i++) hbhe->back().setSample(i,samples[i]);
        hbhe->back().setReadoutIds(eid);
        break;
      case (HcalForward):
        hf->push_back(HFDataFrame(did));
        hf->back().setSize(samples_);
        hf->back().setPresamples(presamples_);
        for (int i=0; i<samples_; i++) hf->back().setSample(i,samples[i]);
        hf->back().setReadoutIds(eid);
        break;
      case (HcalOuter) :
        ho->push_back(HODataFrame(did));
        ho->back().setSize(samples_);
        ho->back().setPresamples(presamples_);
        for (int i=0; i<samples_; i++) ho->back().setSample(i,samples[i]);
        ho->back().setReadoutIds(eid);
        break;
      default: continue;
      }
    }        
  }
  hbhe->sort();
  ho->sort();
  hf->sort();
  
  e.put(hbhe);
  e.put(ho);
  e.put(hf);
}

Member Data Documentation

std::vector<int> HcalPatternSource::bunches_ [private]

Definition at line 21 of file HcalPatternSource.h.

Referenced by produce().

Definition at line 22 of file HcalPatternSource.h.

Referenced by loadPatternFile(), loadPatterns(), and produce().

Definition at line 23 of file HcalPatternSource.h.

Referenced by produce().

Definition at line 23 of file HcalPatternSource.h.

Referenced by produce().