CMS 3D CMS Logo

HcalPatternSource Class Reference

Date
2006/09/29 17:57:40
Revision
1.1
More...

#include <IORawData/CaloPatterns/src/HcalPatternSource.h>

Inheritance diagram for HcalPatternSource:

edm::ConfigurableInputSource edm::InputSource edm::ProductRegistryHelper

List of all members.

Public Member Functions

 HcalPatternSource (const edm::ParameterSet &pset, edm::InputSourceDescription const &desc)

Protected Member Functions

virtual void beginJob (edm::EventSetup const &es)
virtual bool produce (edm::Event &e)

Private Member Functions

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

Private Attributes

std::vector< intbunches_
const HcalElectronicsMapelecmap_
std::vector< HcalFiberPatternpatterns_
int presamples_
int samples_


Detailed Description

Date
2006/09/29 17:57:40
Revision
1.1

Author:
J. Mans - Minnesota

Definition at line 16 of file HcalPatternSource.h.


Constructor & Destructor Documentation

HcalPatternSource::HcalPatternSource ( const edm::ParameterSet pset,
edm::InputSourceDescription const &  desc 
)

Definition at line 13 of file HcalPatternSource.cc.

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

00013                                                                                                         : 
00014   edm::ConfigurableInputSource(pset,desc),
00015   bunches_(pset.getUntrackedParameter<std::vector<int> >("Bunches",std::vector<int>())),
00016   presamples_(pset.getUntrackedParameter<int>("Presamples",4)),
00017   samples_(pset.getUntrackedParameter<int>("Samples",10))
00018 {
00019   loadPatterns(pset.getUntrackedParameter<std::string>("Patterns"));
00020   produces<HBHEDigiCollection>();
00021   produces<HODigiCollection>();
00022   produces<HFDigiCollection>();
00023 }


Member Function Documentation

void HcalPatternSource::beginJob ( edm::EventSetup const &  es  )  [protected, virtual]

Reimplemented from edm::InputSource.

Definition at line 25 of file HcalPatternSource.cc.

References elecmap_, edm::EventSetup::get(), and edm::ESHandle< T >::product().

00025                                                         {
00026   edm::ESHandle<HcalElectronicsMap> item;
00027   es.get<HcalElectronicsMapRcd>().get(item);
00028   elecmap_=item.product();
00029 }

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

Definition at line 102 of file HcalPatternSource.cc.

References parseConfig::block, data, element(), Exception, f, i, j, params, HcalPatternXMLParser::parse(), indexGen::parser, patterns_, and SiStripLorentzAngle_cfi::read.

Referenced by loadPatterns().

00102                                                                  {
00103   HcalPatternXMLParser parser;
00104   std::string buffer, element;
00105   std::map<std::string,std::string> params;
00106   std::vector<uint32_t> data;
00107 
00108   FILE* f=fopen(filename.c_str(), "r");
00109   if (f==0) return;
00110   else {
00111     char block[4096];
00112     while (!feof(f)) {
00113       int read=fread(block,1,4096,f);
00114       buffer.append(block,block+read);
00115     }  
00116     fclose(f);
00117   }
00118   if (buffer.find("<?xml")!=0) {
00119     throw cms::Exception("InvalidFormat") << "Not a valid XML file: " << filename;
00120   }
00121   std::string::size_type i=0,j;
00122   while (buffer.find("<CFGBrick>",i)!=std::string::npos) {
00123     i=buffer.find("<CFGBrick>",i);
00124     j=buffer.find("</CFGBrick>",i);
00125     element="<?xml version='1.0'?>\n";
00126     element.append(buffer,i,j-i);
00127     element.append("</CFGBrick>");
00128     //    LogDebug("HCAL") << element;
00129     params.clear();
00130     data.clear();
00131     parser.parse(element,params,data);
00132     patterns_.push_back(HcalFiberPattern(params,data));
00133     i=j+5;
00134   }
00135   
00136   
00137 }

void HcalPatternSource::loadPatterns ( const std::string &  patspec  )  [private]

Definition at line 88 of file HcalPatternSource.cc.

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

Referenced by HcalPatternSource().

00088                                                              {
00089   wordexp_t p;
00090   char** files;
00091 
00092   wordexp(patspec.c_str(),&p, WRDE_NOCMD); // do not run shell commands!
00093   files=p.we_wordv;
00094   for (unsigned int i=0; i<p.we_wordc; i++) {
00095     LogDebug ("HCAL") << "Reading pattern file '" << files[i] << "'";
00096     loadPatternFile(files[i]);
00097     LogDebug ("HCAL") << "Fibers so far " << patterns_.size();
00098   }
00099   wordfree(&p);
00100 }

bool HcalPatternSource::produce ( edm::Event e  )  [protected, virtual]

Implements edm::ConfigurableInputSource.

Definition at line 31 of file HcalPatternSource.cc.

References bunches_, elecmap_, HcalBarrel, HcalEndcap, HcalForward, HcalOuter, i, edm::Event::id(), HcalElectronicsMap::lookup(), patterns_, presamples_, edm::Event::put(), and samples_.

00031                                            {
00032   if (e.id().event()>bunches_.size()) return false;
00033 
00034   std::auto_ptr<HBHEDigiCollection> hbhe(new HBHEDigiCollection());
00035   std::auto_ptr<HFDigiCollection> hf(new HFDigiCollection());
00036   std::auto_ptr<HODigiCollection> ho(new HODigiCollection());
00037 
00038   int bc=bunches_[e.id().event()-1];
00039   for (std::vector<HcalFiberPattern>::iterator i=patterns_.begin(); i!=patterns_.end(); i++) {
00040     std::vector<HcalQIESample> samples;
00041     for (int fc=0; fc<3; fc++) {
00042       samples=i->getSamples(bc,presamples_, samples_, fc);
00043       HcalElectronicsId eid=i->getId(fc);
00044       HcalDetId did(elecmap_->lookup(eid));
00045 
00046       if (did.null()) {
00047         edm::LogWarning("HCAL") << "No electronics map match for id " << eid;
00048         continue;
00049       }
00050 
00051       switch (did.subdet()) {
00052       case (HcalBarrel):
00053       case (HcalEndcap):
00054         hbhe->push_back(HBHEDataFrame(did));
00055         hbhe->back().setSize(samples_);
00056         hbhe->back().setPresamples(presamples_);
00057         for (int i=0; i<samples_; i++) hbhe->back().setSample(i,samples[i]);
00058         hbhe->back().setReadoutIds(eid);
00059         break;
00060       case (HcalForward):
00061         hf->push_back(HFDataFrame(did));
00062         hf->back().setSize(samples_);
00063         hf->back().setPresamples(presamples_);
00064         for (int i=0; i<samples_; i++) hf->back().setSample(i,samples[i]);
00065         hf->back().setReadoutIds(eid);
00066         break;
00067       case (HcalOuter) :
00068         ho->push_back(HODataFrame(did));
00069         ho->back().setSize(samples_);
00070         ho->back().setPresamples(presamples_);
00071         for (int i=0; i<samples_; i++) ho->back().setSample(i,samples[i]);
00072         ho->back().setReadoutIds(eid);
00073         break;
00074       default: continue;
00075       }
00076     }        
00077   }
00078   hbhe->sort();
00079   ho->sort();
00080   hf->sort();
00081   
00082   e.put(hbhe);
00083   e.put(ho);
00084   e.put(hf);
00085   return true;
00086 }


Member Data Documentation

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

Definition at line 25 of file HcalPatternSource.h.

Referenced by produce().

const HcalElectronicsMap* HcalPatternSource::elecmap_ [private]

Definition at line 27 of file HcalPatternSource.h.

Referenced by beginJob(), and produce().

std::vector<HcalFiberPattern> HcalPatternSource::patterns_ [private]

Definition at line 26 of file HcalPatternSource.h.

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

int HcalPatternSource::presamples_ [private]

Definition at line 28 of file HcalPatternSource.h.

Referenced by produce().

int HcalPatternSource::samples_ [private]

Definition at line 28 of file HcalPatternSource.h.

Referenced by produce().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:23:48 2009 for CMSSW by  doxygen 1.5.4