emcFEMList.C

Go to the documentation of this file.
00001 #include "emcFEMList.h"
00002 
00003 #include <algorithm>
00004 #include <cctype>
00005 #include <iostream>
00006 
00007 #include "EmcIndexer.h"
00008 
00009 namespace 
00010 {
00011   void pbsc(std::set<std::string>& sectors)
00012   {
00013     sectors.insert("W0");
00014     sectors.insert("W1");
00015     sectors.insert("W2");
00016     sectors.insert("W3");
00017     sectors.insert("E2");
00018     sectors.insert("E3");
00019   }
00020   
00021   void pbgl(std::set<std::string>& sectors)
00022   {
00023     sectors.insert("E0");
00024     sectors.insert("E1");
00025   }
00026 }
00027 
00028 //_____________________________________________________________________________
00029 emcFEMList::emcFEMList(const char* sectors)
00030 {
00031   std::string sparts = sectors;
00032   std::transform(sparts.begin(),sparts.end(), sparts.begin(),::toupper);
00033   
00034   if ( sparts == "EMCAL" || sparts == "PBSCPBGL" || sparts == "PBGLPBSC" )
00035     {
00036       pbsc(fSectors);
00037       pbgl(fSectors);
00038     }
00039   else if ( sparts == "PBSC" )
00040     {
00041       pbsc(fSectors);
00042     }
00043   else if ( sparts == "PBGL" )
00044     {
00045       pbgl(fSectors);
00046     }
00047   else
00048     {
00049       for ( int i = 0; i < 8; ++i )
00050         {
00051           std::string search = EmcIndexer::EmcSectorId(i);
00052           size_t f = sparts.find(search);
00053           if ( f < sparts.size() )
00054             {
00055               sparts.erase(f,f+search.size());
00056               fSectors.insert(search);
00057             }
00058         }
00059       
00060       if (!sparts.empty())
00061         {
00062           std::cerr << "<ERROR> " << __FILE__ << ":" << __LINE__
00063                     << " parts not empty. Remaining stuff="
00064                     << sparts
00065                     << "\n"
00066                     << "It's likely a syntax error that you must correct."
00067                     << "I will consider you want no EMCAL sector at all," 
00068                     << " so it's likely to crash later on..."
00069                     << std::endl;
00070           fSectors.clear();
00071         }
00072     }
00073   
00074   // We got our list of sectors. Now get the list of fems from there.
00075   std::set<std::string>::const_iterator it;
00076   for ( it = fSectors.begin(); it != fSectors.end(); ++it ) 
00077     {
00078       int is = EmcIndexer::EmcSectorNumber((*it).c_str());
00079       int nfems = 18;
00080       if ( is >= 6 )
00081         {
00082           nfems = 32;
00083         }
00084       for ( int i = 0; i < nfems; ++i ) 
00085         {
00086           int fem = EmcIndexer::iSiSM144_PXSM144(is,i);
00087           fFems.insert(fem);
00088         }
00089     }
00090 }
00091 
00092 //_____________________________________________________________________________
00093 std::set<int>
00094 emcFEMList::fems(const char* sname) const
00095 {
00096   std::set<int> rv;
00097 
00098   int is = EmcIndexer::EmcSectorNumber(sname);
00099   if ( is < 0 )
00100     {
00101       return rv;
00102     }
00103 
00104   int nfems = 18;
00105   if ( is >= 6 )
00106     {
00107       nfems = 32;
00108     }
00109   for ( int i = 0; i < nfems; ++i ) 
00110     {
00111       int fem = EmcIndexer::iSiSM144_PXSM144(is,i);
00112       rv.insert(fem);
00113     }
00114   return rv;
00115 }
00116 
00117 //_____________________________________________________________________________
00118 bool
00119 emcFEMList::hasFEM(int ifem) const
00120 {
00121   std::set<int>::const_iterator it = fFems.find(ifem);
00122 
00123   return ( it != fFems.end() );
00124 }
00125 
00126 //_____________________________________________________________________________
00127 bool
00128 emcFEMList::hasSector(const char* name) const
00129 {
00130   std::string sname = name;
00131   std::transform(sname.begin(),sname.end(),sname.begin(),::toupper);
00132   std::set<std::string>::const_iterator it = fSectors.find(sname);
00133 
00134   return ( it != fSectors.end() );
00135 }
00136 
00137 //_____________________________________________________________________________
00138 void
00139 emcFEMList::print(std::ostream& os) const
00140 {
00141   os << "emcFEMList sectors:";
00142   std::set<std::string>::const_iterator it;
00143   for ( it = fSectors.begin(); it != fSectors.end(); ++it ) 
00144     {
00145       os << (*it) << " ";
00146     }
00147 }