CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/Geometry/CaloEventSetup/plugins/CaloTowerConstituentsMapBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    CaloTowerConstituentsMapBuilder
00004 // Class:      CaloTowerConstituentsMapBuilder
00005 // 
00013 //
00014 // Original Author:  Jeremiah Mans
00015 //         Created:  Mon Oct  3 11:35:27 CDT 2005
00016 // $Id: CaloTowerConstituentsMapBuilder.cc,v 1.8 2012/10/26 09:47:48 yana Exp $
00017 //
00018 //
00019 
00020 
00021 // user include files
00022 #include "Geometry/CaloEventSetup/plugins/CaloTowerConstituentsMapBuilder.h"
00023 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00024 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00025 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00026 #include <zlib.h>
00027 #include <cstdio>
00028 #include <strings.h>
00029 
00030 //
00031 // constructors and destructor
00032 //
00033 CaloTowerConstituentsMapBuilder::CaloTowerConstituentsMapBuilder(const edm::ParameterSet& iConfig) :
00034     mapFile_(iConfig.getUntrackedParameter<std::string>("MapFile",""))
00035 {
00036     std::cout << "CaloTowerConstituentsMapBuilder::CaloTowerConstituentsMapBuilder" << std::endl;
00037     
00038    //the following line is needed to tell the framework what
00039    // data is being produced
00040    setWhatProduced(this);
00041 
00042    //now do what ever other initialization is needed
00043 }
00044 
00045 
00046 CaloTowerConstituentsMapBuilder::~CaloTowerConstituentsMapBuilder()
00047 { 
00048 }
00049 
00050 
00051 //
00052 // member functions
00053 //
00054 
00055 void
00056 CaloTowerConstituentsMapBuilder::fillDescriptions(edm::ConfigurationDescriptions & descriptions)
00057 {
00058   edm::ParameterSetDescription desc;
00059   desc.addUntracked<std::string>( "MapFile", "" );
00060   descriptions.add( "caloTowerConstituents", desc );
00061 }
00062 
00063 // ------------ method called to produce the data  ------------
00064 CaloTowerConstituentsMapBuilder::ReturnType
00065 CaloTowerConstituentsMapBuilder::produce(const IdealGeometryRecord& iRecord)
00066 {
00067    edm::ESHandle<HcalTopology> topology ;
00068    iRecord.get( topology ) ;
00069 
00070    std::auto_ptr<CaloTowerConstituentsMap> prod( new CaloTowerConstituentsMap( &*topology ));
00071 
00072    prod->useStandardHB(true);
00073    prod->useStandardHE(true);
00074    prod->useStandardHF(true);
00075    prod->useStandardHO(true);
00076    prod->useStandardEB(true);
00077 
00078    if (!mapFile_.empty()) {
00079      parseTextMap(mapFile_,*prod);
00080    }
00081    prod->sort();
00082    
00083    return prod;
00084 }
00085 
00086 void CaloTowerConstituentsMapBuilder::parseTextMap(const std::string& filename, CaloTowerConstituentsMap& theMap) {
00087   edm::FileInPath eff(filename);
00088 
00089   gzFile gzed=gzopen(eff.fullPath().c_str(),"rb");
00090   
00091   while (!gzeof(gzed)) {
00092     char line[1024];
00093     int ieta, iphi, rawid;
00094     gzgets(gzed,line,1023);
00095     if (index(line,'#')!=0)  *(index(line,'#'))=0;
00096     int ct=sscanf(line,"%i %d %d",&rawid,&ieta,&iphi);
00097     if (ct==3) {
00098       DetId detid(rawid);
00099       CaloTowerDetId tid(ieta,iphi);
00100       theMap.assign(detid,tid);
00101     }    
00102   }
00103   gzclose(gzed);
00104 
00105 }