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