CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Geometry/CaloTopology/src/HcalTopologyRestrictionParser.cc

Go to the documentation of this file.
00001 #include "Geometry/CaloTopology/interface/HcalTopologyRestrictionParser.h"
00002 #include<boost/tokenizer.hpp>
00003 #include<sstream>
00004 #include<iostream>
00005 HcalTopologyRestrictionParser::HcalTopologyRestrictionParser(HcalTopology& target) : target_(target) {
00006 }
00007 
00008 static HcalSubdetector determineSubdet(const std::string& item) {
00009   if (item=="HB") return HcalBarrel;
00010   if (item=="HE") return HcalEndcap;
00011   if (item=="HF") return HcalForward;
00012   if (item=="HO") return HcalOuter;
00013   return (HcalSubdetector)0;
00014 }
00015 
00016 std::string HcalTopologyRestrictionParser::parse(const std::string& line) {
00017 
00018   std::ostringstream errors;
00019   boost::char_separator<char> sep(" \t",";");
00020   typedef boost::tokenizer<boost::char_separator<char> > myTokType;
00021 
00022   std::string totaline(line); totaline+=';'; // terminate
00023   myTokType tok(totaline, sep);
00024   int ieta1=0, ieta2=0, iphi1=-1, iphi2=-1, depth1=1, depth2=4;
00025   HcalSubdetector subdet=(HcalSubdetector)0;
00026 
00027   int phase=0; 
00028   for (myTokType::iterator beg=tok.begin(); beg!=tok.end() && phase>=0; ++beg){
00029     std::cout << phase << " : <" << *beg << ">\n";
00030     if (*beg==";") {
00031       if (phase==0) continue; // empty
00032       if (phase!=1 && phase!=5 && phase!=7) { 
00033         errors << "Expect 1, 5, or 7 arguments, got " << phase;
00034         phase=-1;
00035       } else {
00036         if (phase==1) { // reject whole subdetector...
00037           target_.excludeSubdetector(subdet);
00038         } else {
00039           target_.exclude(subdet,ieta1,ieta2,iphi1,iphi2,depth1,depth2);
00040         }
00041         phase=0;
00042       }
00043     } else {
00044       switch (phase) {
00045       case (0) : subdet=determineSubdet(*beg); break;
00046       case (1) : ieta1=atoi(beg->c_str()); break;
00047       case (2) : ieta2=atoi(beg->c_str()); break;
00048       case (3) : iphi1=atoi(beg->c_str()); break;
00049       case (4) : iphi2=atoi(beg->c_str()); depth1=1; depth2=4; break; // also set defaults...
00050       case (5) : depth1=atoi(beg->c_str()); break;
00051       case (6) : depth2=atoi(beg->c_str()); break;
00052       }
00053       phase++;
00054     }
00055   }
00056   
00057   return errors.str();
00058 
00059 }