Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-30 23:47:26

0001 #include "Geometry/CaloTopology/interface/HcalTopologyRestrictionParser.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include <boost/tokenizer.hpp>
0004 #include <sstream>
0005 #include <iostream>
0006 HcalTopologyRestrictionParser::HcalTopologyRestrictionParser(HcalTopology& target) : target_(target) {}
0007 
0008 static HcalSubdetector determineSubdet(const std::string& item) {
0009   if (item == "HB")
0010     return HcalBarrel;
0011   if (item == "HE")
0012     return HcalEndcap;
0013   if (item == "HF")
0014     return HcalForward;
0015   if (item == "HO")
0016     return HcalOuter;
0017   return (HcalSubdetector)0;
0018 }
0019 
0020 std::string HcalTopologyRestrictionParser::parse(const std::string& line) {
0021   std::ostringstream errors;
0022   boost::char_separator<char> sep(" \t", ";");
0023   typedef boost::tokenizer<boost::char_separator<char> > myTokType;
0024 
0025   std::string totaline(line);
0026   totaline += ';';  // terminate
0027   myTokType tok(totaline, sep);
0028   int ieta1 = 0, ieta2 = 0, iphi1 = -1, iphi2 = -1, depth1 = 1, depth2 = 4;
0029   HcalSubdetector subdet = (HcalSubdetector)0;
0030 
0031   int phase = 0;
0032   for (myTokType::iterator beg = tok.begin(); beg != tok.end() && phase >= 0; ++beg) {
0033     edm::LogVerbatim("HCalGeom") << phase << " : <" << *beg << ">";
0034     if (*beg == ";") {
0035       if (phase == 0)
0036         continue;  // empty
0037       if (phase != 1 && phase != 5 && phase != 7) {
0038         errors << "Expect 1, 5, or 7 arguments, got " << phase;
0039         phase = -1;
0040       } else {
0041         if (phase == 1) {  // reject whole subdetector...
0042           target_.excludeSubdetector(subdet);
0043         } else {
0044           target_.exclude(subdet, ieta1, ieta2, iphi1, iphi2, depth1, depth2);
0045         }
0046         phase = 0;
0047       }
0048     } else {
0049       switch (phase) {
0050         case (0):
0051           subdet = determineSubdet(*beg);
0052           break;
0053         case (1):
0054           ieta1 = atoi(beg->c_str());
0055           break;
0056         case (2):
0057           ieta2 = atoi(beg->c_str());
0058           break;
0059         case (3):
0060           iphi1 = atoi(beg->c_str());
0061           break;
0062         case (4):
0063           iphi2 = atoi(beg->c_str());
0064           depth1 = 1;
0065           depth2 = 4;
0066           break;  // also set defaults...
0067         case (5):
0068           depth1 = atoi(beg->c_str());
0069           break;
0070         case (6):
0071           depth2 = atoi(beg->c_str());
0072           break;
0073       }
0074       phase++;
0075     }
0076   }
0077 
0078   return errors.str();
0079 }