Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:14

0001 // -*- C++ -*-
0002 //
0003 // Package:    EcalTrigTowerConstituentsMapBuilder
0004 // Class:      EcalTrigTowerConstituentsMapBuilder
0005 //
0006 /**\class EcalTrigTowerConstituentsMapBuilder EcalTrigTowerConstituentsMapBuilder.h tmp/EcalTrigTowerConstituentsMapBuilder/interface/EcalTrigTowerConstituentsMapBuilder.h
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Paolo Meridiani
0015 //
0016 //
0017 
0018 #include "Geometry/CaloEventSetup/plugins/EcalTrigTowerConstituentsMapBuilder.h"
0019 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0020 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0021 
0022 #include <fstream>
0023 
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025 
0026 EcalTrigTowerConstituentsMapBuilder::EcalTrigTowerConstituentsMapBuilder(const edm::ParameterSet& iConfig)
0027     : mapFile_(iConfig.getUntrackedParameter<std::string>("MapFile", "")) {
0028   setWhatProduced(this);
0029 }
0030 
0031 EcalTrigTowerConstituentsMapBuilder::~EcalTrigTowerConstituentsMapBuilder() {}
0032 
0033 EcalTrigTowerConstituentsMapBuilder::ReturnType EcalTrigTowerConstituentsMapBuilder::produce(
0034     const IdealGeometryRecord& iRecord) {
0035   auto prod = std::make_unique<EcalTrigTowerConstituentsMap>();
0036 
0037   if (!mapFile_.empty()) {
0038     parseTextMap(mapFile_, *prod);
0039   }
0040   return prod;
0041 }
0042 
0043 void EcalTrigTowerConstituentsMapBuilder::parseTextMap(const std::string& filename,
0044                                                        EcalTrigTowerConstituentsMap& theMap) {
0045   edm::FileInPath eff(filename);
0046 
0047   std::ifstream f(eff.fullPath().c_str());
0048   if (!f.good())
0049     return;
0050 
0051   int ietaTower, iphiTower;
0052   int ix, iy, iz;
0053   char line[80];  // a buffer for the line to read
0054   char ch;        // a temporary for holding the end of line
0055   while ((ch = f.peek()) != '-') {
0056     f.get(line, 80, '\n');  // read 80 characters to end of line
0057     f.get(ch);              // eat out the '\n'
0058     // extract the numbers
0059 
0060     int nread = sscanf(line, " %d %d %d %d %d", &ix, &iy, &iz, &ietaTower, &iphiTower);
0061     if (nread == 5) {
0062       EEDetId eeid(ix, iy, iz, 0);
0063       EcalTrigTowerDetId etid(iz, EcalEndcap, ietaTower, iphiTower);
0064       theMap.assign(DetId(eeid), etid);
0065     }
0066   }
0067   // Pass comment line
0068   f.get(line, 80, '\n');  // read 80 characters to end of line
0069   f.get(ch);              // eat out the '\n'
0070   // Next info line
0071   f.get(line, 80, '\n');  // read 80 characters to end of line
0072   f.get(ch);              // eat out the '\n'
0073   f.close();
0074   return;
0075 }