CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DetectorDescription/Core/src/Specific.cc

Go to the documentation of this file.
00001 #include "DetectorDescription/Core/src/Specific.h"
00002 #include "DetectorDescription/Core/interface/DDCompactView.h"
00003 
00004 // Message logger.
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 
00007 #include <assert.h>
00008 
00009 namespace DDI {
00010    
00011    Specific::Specific(const std::vector<std::string>& selections,
00012                       const DDsvalues_type & specs,
00013                       bool doRegex)
00014    : specifics_(specs), 
00015    partSelections_(0), 
00016    valid_(false),
00017    doRegex_(doRegex)                    
00018    {
00019       std::vector<std::string>::const_iterator it = selections.begin();
00020       for(; it != selections.end(); ++it) {
00021          createPartSelections(*it);
00022       }
00023    }
00024    
00025    Specific::Specific(const std::vector<DDPartSelection> & selections,
00026                       const DDsvalues_type & specs)
00027    : specifics_(specs), partSelections_(selections), valid_(false), doRegex_(false)        
00028    { }             
00029    
00030    void Specific::createPartSelections(const std::string & selString)
00031    {
00032       
00033       std::vector<DDPartSelRegExpLevel> regv;
00034       std::vector<DDPartSelection> temp;
00035       DDTokenize2(selString,regv);
00036       
00037       if (!regv.size()) throw cms::Exception("DDException") << "Could not evaluate the selection-std::string ->" << selString << "<-";
00038       std::vector<DDPartSelRegExpLevel>::const_iterator it = regv.begin();
00039       std::pair<bool,std::string> res;
00040       for (; it != regv.end(); ++it) {
00041          std::vector<DDLogicalPart> lpv;
00042          res = DDIsValid(it->ns_,it->nm_,lpv,doRegex_);
00043          if (!res.first) {
00044             std::string msg("Could not process q-name of a DDLogicalPart, reason:\n"+res.second);
00045             msg+="\nSpecPar selection is:\n" + selString + "\n";
00046             //throw cms::Exception("DDException") << "Could not process q-name of a DDLogicalPart, reason:\n" << res.second;
00047             edm::LogError("Specific") << msg;
00048             break; //EXIT for loop
00049          }
00050          //edm::LogInfo ("Specific") << "call addSelectionLevel" << std::endl;
00051          addSelectionLevel(lpv,it->copyno_,it->selectionType_,temp);
00052       }
00053       if ( res.first ) { // i.e. it wasn't "thrown" out of the loop
00054          std::vector<DDPartSelection>::const_iterator iit = temp.begin();
00055          partSelections_.reserve(temp.size() + partSelections_.size());
00056          for (; iit != temp.end(); ++iit) {
00057             partSelections_.push_back(*iit);
00058             //edm::LogInfo ("Specific") << *iit << std::endl;
00059          } 
00060       }
00061    }
00062    
00063    
00064    
00065    void Specific::addSelectionLevel(std::vector<DDLogicalPart> & lpv, int copyno, ddselection_type st, 
00066                                     std::vector<DDPartSelection> & selv)
00067    {
00068       //static int count =0;
00069       //++count;
00070       //edm::LogInfo ("Specific") << "count=" << count << " " << flush;
00071       if (!selv.size()) { // create one, no entry yet!
00072          selv.push_back(DDPartSelection());
00073       }
00074       typedef std::vector<DDLogicalPart>::size_type lpv_sizetype;
00075       typedef std::vector<DDPartSelection>::size_type ps_sizetype;
00076       ps_sizetype ps_sz = selv.size();
00077       lpv_sizetype lpv_sz = lpv.size();
00078       //edm::LogInfo ("Specific") << "lpv_sz=" << lpv_sz << std::endl;
00079       lpv_sizetype lpv_i = 0;
00080       std::vector<DDPartSelection> result;
00081       for (; lpv_i < lpv_sz; ++lpv_i) {
00082          std::vector<DDPartSelection>::const_iterator ps_it = selv.begin();
00083          for (; ps_it != selv.end(); ++ps_it) {
00084             result.push_back(*ps_it);
00085          }
00086       }
00087       //edm::LogInfo ("Specific") << "result-size=" << result.size() << std::endl;
00088       //ps_sizetype ps_sz = result.size();
00089       ps_sizetype ps_i = 0;
00090       for(lpv_i=0; lpv_i < lpv_sz; ++lpv_i) {
00091          for(ps_i = ps_sz*lpv_i; ps_i < ps_sz*(lpv_i+1); ++ps_i) {
00092             result[ps_i].push_back(DDPartSelectionLevel(lpv[lpv_i],copyno,st));
00093          }
00094       }    
00095       selv = result;
00096    }                   
00097    
00098    const std::vector<DDPartSelection> & Specific::selection() const 
00099    {
00100       return partSelections_; 
00101    }  
00102    
00103    
00104    void Specific::stream(std::ostream &  os) const
00105    {
00106       //  os << " no output available yet, sorry. ";
00107       os << " Size: " << specifics_.size() << std::endl;
00108       os << "\tSelections:" << std::endl;
00109       partsel_type::const_iterator pit(partSelections_.begin()), pend(partSelections_.end());
00110       for (;pit!=pend;++pit) {
00111          os << *pit << std::endl;
00112       }
00113       
00114       DDsvalues_type::const_iterator vit(specifics_.begin()), ved(specifics_.end());
00115       for (;vit!=ved;++vit) {
00116          const DDValue & v = vit->second;
00117          os << "\tParameter name= \"" << v.name() << "\" " << std::endl;
00118          os << "\t\t Value pairs: " << std::endl;
00119          size_t s=v.size();
00120          size_t i=0;
00121          if ( v.isEvaluated() ) {
00122             for (; i<s; ++i) {
00123                os << "\t\t\t\"" << v[i].first << "\"" << ", " << v[i].second << std::endl;
00124             }
00125          } else { // v is not evaluated
00126             const std::vector<std::string>& vs =  v.strings();
00127             for (; i<s; ++i) {
00128                os << "\t\t\t\"" << vs[i] << "\"" << ", not evaluated" << std::endl;
00129             }
00130          }
00131       } 
00132    }
00133    
00134    void Specific::updateLogicalPart(std::vector<std::pair<DDLogicalPart, std::pair<DDPartSelection*,DDsvalues_type*> > >& result) const
00135    {
00136       if (partSelections_.size()) {
00137          partsel_type::const_iterator it = partSelections_.begin();
00138          DDsvalues_type* sv = const_cast<DDsvalues_type*>(&specifics_);
00139          for (; it != partSelections_.end(); ++it) {
00140             DDLogicalPart logp = it->back().lp_; 
00141             /*if (!logp.isDefined().second) {
00142              throw DDException("Specific::updateLogicalPart(..): LogicalPart not defined, name=" + std::string(logp.ddname()));
00143              }*/
00144             DDPartSelection * ps = const_cast<DDPartSelection*>(&(*it));
00145             assert(ps); 
00146             assert(sv);
00147             std::pair<DDPartSelection*,DDsvalues_type*> pssv(ps,sv);
00148             result.push_back(std::make_pair(logp,pssv));
00149          }  
00150       }  
00151    }
00152    
00161    std::pair<bool,DDExpandedView> Specific::node() const
00162    {
00163       DDCompactView c;
00164       DDExpandedView e(c);
00165       
00166       if (partSelections_.size() != 1) {
00167          edm::LogError("Specific") << " >> more or less than one part-selector, currently NOT SUPPORTED! <<" << std::endl;
00168          return std::make_pair(false,e);
00169       }
00170       const DDPartSelection & ps = partSelections_[0];
00171       
00172       DDPartSelection::const_iterator it = ps.begin();
00173       DDPartSelection::const_iterator ed = ps.end();
00174       if ( (it != ed) && ( it->selectionType_ != ddanyposp) ) {
00175          edm::LogError("Specific") << " >> part-selector must start with //Name[no] ! << " << std::endl;
00176          return std::make_pair(false,e);
00177       }
00178       ++it;
00179       for (; it != ps.end(); ++it) {
00180          if ( it->selectionType_ != ddchildposp ) {
00181             edm::LogError("Specific") << " >> part-selector must be a concatenation of direct children\n"
00182             << "   including their copy-number only, CURRENT LIMITATION! <<" << std::endl;
00183             return std::make_pair(false,e);             
00184          }  
00185       } 
00186       
00187       it = ps.begin();
00188       bool result = true;
00189       for (; it != ed; ++it) {
00190          while(result) {
00191             if( (it->copyno_ == e.copyno()) && (it->lp_ == e.logicalPart())) {
00192                break;
00193             }
00194             else {
00195                result = e.nextSibling();
00196             }
00197          }
00198          if ((ed-it)>1) {
00199             result = e.firstChild();  
00200          }  
00201       }
00202       return std::make_pair(result,e);
00203    }
00204    
00205    
00206    Specific::~Specific()
00207    {
00208       //   DDsvalues_type::iterator it = specifics_.begin();
00209       //   for (; it != specifics_.end(); ++it) {
00210       //     it->second.clear();
00211       //   }
00212    }
00213    
00214 }