1 #ifndef _det_XXMLManager_h_
2 #define _det_XXMLManager_h_
4 #include <det/VManager.h>
5 #include <det/ValidityStamp.h>
7 #include <utl/ErrorLogger.h>
8 #include <utl/Branch.h>
10 #include <boost/multi_index_container.hpp>
11 #include <boost/multi_index/member.hpp>
12 #include <boost/multi_index/ordered_index.hpp>
13 #include <boost/tokenizer.hpp>
14 #include <boost/lambda/lambda.hpp>
15 #include <boost/mpl/if.hpp>
16 #include <boost/mpl/empty_base.hpp>
184 public boost::mpl::if_c<
185 Info::kAllowMultiConfig,
186 detail::MultiConfigBase,
187 detail::MonoConfigBase
227 template<typename T, std::
size_t N>
247 template<
typename T, std::
size_t N>
256 for ( ; i < N &&
b; ++
i)
257 b = b.GetChild(path[i]);
282 template<
bool AllowMultiConfig,
int dummy = 0>
285 template<
typename T, std::
size_t N>
310 const utl::AttributeMap attr{{Info::kIdAtt, boost::lexical_cast<std::string>(n)}};
315 if (LookUpCoda(dest, br, path))
320 msg <<
"In configuration change, no branch "
322 <<
" was found for configuration number from "
326 <<
" used as attribute "
338 template<
typename T, std::
size_t N>
340 {
return LookUpCoda(dest, m.
fBranch, path); }
350 IdMatcher(
const std::string& i,
const std::string& compName,
bool report) :
353 fIsReportingErrors(report)
361 const std::string kAllTag(
"all");
365 all[Info::kIdAtt] = kAllTag;
376 std::istringstream
is(fId);
379 const bool b = lowerBound <= i && i <= upperBound;
382 }
else if (fIsReportingErrors) {
383 std::ostringstream warn;
386 <<
" specified for the component "
388 <<
" was ignored as it couldn't be interpreted as integer in range matching.";
398 std::istringstream
is(fId);
401 const bool b = i == id;
404 }
else if (fIsReportingErrors) {
405 std::ostringstream warn;
408 <<
" specified for the component "
410 <<
" was ignored as it couldn't be interpreted as integer in specific id matching";
425 template<
class Container>
431 fIsReportingErrors(report),
443 for (
int i = lowerBound; i<= upperBound; ++
i) {
476 template<
class Matcher>
478 const std::string& compName,
480 bool isReportingErrors);
490 template <
typename T, std::
size_t N>
506 const std::string& name)
const;
514 const std::string& prop,
515 const std::string& name,
537 const std::string& prop,
538 const std::string& name)
const;
552 const std::string& componentName,
553 const std::string& name)
const;
577 template <
typename T, std::
size_t N>
603 std::ostringstream warn;
604 warn <<
"No root branch found, wrong path: started with "
608 <<
" was configured as first element of the path.";
624 template<
class Matcher>
627 const std::string& compName,
629 bool isReportingErrors)
633 const char kInterRange =
',';
634 const char kIntraRange =
'-';
636 typedef boost::char_separator<char> Sep;
637 typedef boost::tokenizer<Sep> Tokenizer;
638 typedef Tokenizer::const_iterator It;
640 const Sep interSep(
string(1, kInterRange).c_str());
641 const Sep intraSep(
string(1, kIntraRange).c_str());
651 if (cB.GetName() == compName) {
655 const AttributeMap::const_iterator i = branchAtt.find(Info::kIdAtt);
658 if (branchAtt.end() !=
i) {
661 if (i->second.find(kIntraRange) != string::npos ||
662 i->second.find(kInterRange) != string::npos) {
665 Tokenizer ranges(i->second, interSep);
667 for (It rangesIt = ranges.begin(); rangesIt != ranges.end(); ++rangesIt) {
668 const string& rangeStr = *rangesIt;
669 Tokenizer range(rangeStr, intraSep);
676 for (It rangeIt = range.begin(); rangeIt != range.end(); ++rangeIt) {
677 const string& rangeVal = *rangeIt;
683 else if (upper.empty())
685 else if (isReportingErrors) {
687 warn <<
"The additional elements in the range "
689 <<
" specified for the component "
702 istringstream ls(lower);
703 istringstream us(upper);
704 if (ls >> lb && us >> ub) {
705 if (matcher(lb, ub)) {
709 }
else if (isReportingErrors) {
711 warn <<
"The elements in the range "
713 <<
" specified for the component "
715 <<
" were ignored as they couldn't be interpreted as integers.";
718 }
else if (isReportingErrors) {
722 <<
" specified for the component "
724 <<
" wasn't completely specified.";
732 istringstream
is(i->second);
738 }
else if (isReportingErrors) {
740 warn <<
"The id specified ("
742 <<
") specified for the component "
744 <<
" was ignored as it couldn't be interpreted as integer.";
787 const std::string& name)
795 const Branch specificModel = compBranch.
GetChild(Info::kModelsTag);
798 specificModel.
GetData(modelName);
809 if (componentModels) {
819 if (cB.GetName() == name) {
837 const AttributeMap::const_iterator i = att.find(Info::kIdAtt);
838 if (i != att.end()) {
843 modelName = i->second;
847 warn <<
"The actual models found for the component "
849 <<
" don't have an identification attribute.";
854 warn <<
"No actual models were found for the component " << name <<
".";
859 warn <<
"No actual models were found " << name <<
".";
867 if (modelsData && modelName.size()) {
876 a.insert(AttributeMap::value_type(Info::kIdAtt, modelName));
886 return modelsData.GetChild(name, a);
902 std::ostringstream err;
903 err <<
"Information without attributes was required with an scalar type.";
914 const std::string& componentName,
945 std::adjacent_find(t.begin(), t.end(), boost::lambda::_1 >= boost::lambda::_2) != t.end()) {
953 typename std::list<T>::const_iterator i =
954 std::adjacent_find(t.begin(), t.end(), boost::lambda::_1 == boost::lambda::_2);
958 std::ostringstream warn;
959 warn <<
"The id = " << *i <<
" "
960 "appears more than once in the XML file list. "
961 "This and other repetitions will be ignored.";
965 std::unique(t.begin(), t.end());
1005 const unsigned int nAttTotal = m.size();
1023 unsigned int nAttFound = 0;
1032 for (
unsigned int i = 0; curr && i <= Size(Info::kComponentsIds); ++
i) {
1046 const IndexMap::const_iterator attIt = i < Size(Info::kComponentsIds) ?
1047 m.find(Info::kComponentsIds[i]) :
1050 if (attIt != m.end()) {
1052 const string compName(Info::kComponentsNames[i]);
1061 if (nAttFound == nAttTotal) {
1064 bool isComponent =
false;
1076 for (
unsigned int j = i; !isComponent && j < Size(Info::kComponentsIds); ++j)
1077 isComponent = Info::kComponentsNames[j] == prop;
1151 msg +=
" not Found.";
1156 warn <<
"No data branch found:";
1157 for (
unsigned int i = 0; i < Size(Info::kDataRootPath); ++
i)
1158 warn <<
" " << Info::kDataRootPath[i];
General Manager for reading detectors descriptions in XML files.
bool operator()(const int lowerBound, const int upperBound)
Matches for a range.
unsigned int GetCurrentConfiguration() const
Number of configuration.
VMANAGER_GETDATA_CALL(GetDataInternal, double)
Helper struct to handle MultiConfig & MonoConfig cases.
Base class for the case when multiconfiguration is allowed. Not meant to be used directly by client c...
Matcher for accumulation.
Class to hold collection (x,y) points and provide interpolation between them.
det::VManager::Status GetDataInternal(T &t, const std::string &prop, const std::string &name, const det::VManager::IndexMap &m) const
Common template method for all types.
bool is(const double a, const double b)
std::map< std::string, std::string > AttributeMap
const bool fIsReportingErrors
AccumulatorMatcher(Container &ids, const bool report)
Construct.
Matcher for specific identificator.
const bool fIsReportingErrors
Interface for detector managers.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
void Initialize()
Some inits for the objects of this class, apart from those from VManager.
VMANAGER_GETDATA_DENIED(std::vector< std::string >)
AttributeMap GetAttributes() const
Get a map<string, string> containing all the attributes of this Branch.
Branch GetNextSibling() const
Get next sibling of this branch.
unsigned int fCurrentConfiguration
Class representing a document branch.
bool operator()(const int lowerBound, const int upperBound)
Fill the range.
Class to hold collection (x,y) points and provide interpolation between them, where y are complex num...
static std::string QueryInfoMessage(const Handle &returnData, const std::string &component)
IdMatcher(const std::string &i, const std::string &compName, bool report)
Construct.
#define VMANAGER_GETDATA_HANDLE_DENIED
const std::string & fCompName
void NextConfiguration()
Advances the current configuration index.
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
std::string GetName() const
function to get the Branch name
boost::mpl::empty_base MonoConfigBase
Base class for the case when multiconfiguration isn't allowed. Not meant to be used directly by clien...
utl::Branch operator()(const utl::Branch &b)
Matches against the specific Branch.
bool operator()(const int id)
Matches for an specific id.
void SetCurrentConfiguration(unsigned int n)
Set an specific configuration number.
utl::Branch FindModelBranch(const utl::Branch &componentModels, const utl::Branch &compBranch, const std::string &name) const
Helper function which retrieves the data branch that corresponds to the models specified in component...
utl::Branch FindRoot(const T(&path)[N]) const
Helper function from transversal from the configured branch until the desired roots.
MultiConfigBase()
Configuration number start in one.
std::map< std::string, std::string > IndexMap
static utl::Branch FindMatchingBranch(const utl::Branch &parent, const std::string &compName, Matcher &matcher, bool isReportingErrors)
Finds the matching branch among parent according to id.
static bool Handle(const XXMLManager &m, utl::Branch &dest, const T(&path)[N])
utl::Branch operator()(const utl::Branch &)
Never matches.
bool IsReportingErrors() const
Branch GetFirstChild() const
Get first child of this Branch.
bool operator()(const int id)
Add the id.
#define ERROR(message)
Macro for logging error messages.
bool IsModified() const
Returns if there were additions.
Status
Specifies success or (eventually) various possible failure modes.