4 #ifndef tools_xml_aidas
5 #define tools_xml_aidas
7 #include "../raxml_out"
10 #include "../histo/h1d"
11 #include "../histo/h2d"
12 #include "../histo/h3d"
13 #include "../histo/p1d"
14 #include "../histo/p2d"
15 #include "../histo/c1d"
16 #include "../histo/c2d"
17 #include "../histo/c3d"
18 #include "../histo/dps"
19 #include "../aida_ntuple"
20 #include "../S_STRING"
35 typedef std::map<std::string,reader>
readers;
53 bool a_check =
false){
59 std::map<std::string,reader>::const_iterator it =
m_readers.find(a_class);
60 if(it!=
m_readers.end())
return (*it).second;
139 a_tags.push_back(s_aida());
141 a_tags.push_back(s_histogram1d());
142 a_tags.push_back(s_histogram2d());
143 a_tags.push_back(s_histogram3d());
144 a_tags.push_back(s_profile1d());
145 a_tags.push_back(s_profile2d());
146 a_tags.push_back(
s_axis());
147 a_tags.push_back(s_statistics());
148 a_tags.push_back(s_data1d());
149 a_tags.push_back(s_data2d());
150 a_tags.push_back(s_data3d());
152 a_tags.push_back(s_tuple());
153 a_tags.push_back(s_columns());
154 a_tags.push_back(s_rows());
155 a_tags.push_back(s_row());
156 a_tags.push_back(s_entryITuple());
157 a_tags.push_back(s_entryTuple());
159 a_tags.push_back(s_cloud1d());
160 a_tags.push_back(s_cloud2d());
161 a_tags.push_back(s_cloud3d());
162 a_tags.push_back(s_entries1d());
163 a_tags.push_back(s_entries2d());
164 a_tags.push_back(s_entries3d());
165 a_tags.push_back(s_dataPointSet());
166 a_tags.push_back(s_dataPoint());
187 return read_histo(a_tree,a_out,a_verbose,1,
false);
190 return read_histo(a_tree,a_out,a_verbose,2,
false);
193 return read_histo(a_tree,a_out,a_verbose,3,
false);
196 return read_histo(a_tree,a_out,a_verbose,1,
true);
199 return read_histo(a_tree,a_out,a_verbose,2,
true);
217 a_out <<
"tools::xml::aidas::read_dps :"
218 <<
" with name " <<
sout(sname)
219 <<
"..." << std::endl;
229 unsigned int dim = 0;
248 a_out <<
"tools::xml::aidas::read_dps :"
249 <<
" with name " <<
sout(sname)
250 <<
" and title " <<
sout(stitle)
251 <<
" done." << std::endl;
254 return raxml_out(hdl,sclass,spath,sname);
261 std::ostream& a_out,
bool a_verbose,
262 unsigned int a_dim,
bool a_is_prof){
268 a_out <<
"tools::xml::aidas::read_histo :"
269 <<
" with name " <<
sout(sname)
270 <<
"..." << std::endl;
280 std::vector<bn_t> bins(a_dim);
281 std::vector<double> mns(a_dim);
282 std::vector<double> mxs(a_dim);
283 std::vector< std::vector<double> > edges(a_dim);
287 unsigned int found = 0;
288 bool isVariableBins =
false;
296 std::vector<double> borders;
299 if(iaxis!=not_found) {
300 if((iaxis<0)||(iaxis>=(
int)a_dim))
return raxml_out();
304 edges[iaxis] = borders;
305 if(variableBins) isVariableBins =
true;
313 for(
unsigned int iaxis=0;iaxis<a_dim;iaxis++) {
328 histo =
new histo::p1d(stitle,bins[0],mns[0],mxs[0]);
338 if(!
read_bins(*_tree,hd,a_out,a_is_prof)) {
352 }
else if(a_dim==2) {
355 histo =
new histo::p2d(stitle,edges[0],edges[1]);
357 histo =
new histo::p2d(stitle,bins[0],mns[0],mxs[0],bins[1],mns[1],mxs[1]);
366 if(!
read_bins(*_tree,hd,a_out,a_is_prof)) {
385 histo =
new histo::h1d(stitle,bins[0],mns[0],mxs[0]);
394 if(!
read_bins(*_tree,hd,a_out,a_is_prof)) {
407 }
else if(a_dim==2) {
410 histo =
new histo::h2d(stitle,edges[0],edges[1]);
412 histo =
new histo::h2d(stitle,bins[0],mns[0],mxs[0],bins[1],mns[1],mxs[1]);
421 if(!
read_bins(*_tree,hd,a_out,a_is_prof)) {
434 }
else if(a_dim==3) {
437 histo =
new histo::h3d(stitle,edges[0],edges[1],edges[2]);
439 histo =
new histo::h3d(stitle,bins[0],mns[0],mxs[0],
440 bins[1],mns[1],mxs[1],
441 bins[2],mns[2],mxs[2]);
450 if(!
read_bins(*_tree,hd,a_out,a_is_prof)) {
469 a_out <<
"tools::xml::aidas::read_histo :"
470 <<
" with name " <<
sout(sname)
471 <<
" and title " <<
sout(stitle)
472 <<
" done." << std::endl;
475 return raxml_out(hdl,sclass,spath,sname);
484 a_out <<
"tools::xml::aidas::read_cloud :"
485 <<
" name " <<
sout(sname)
486 <<
"..." << std::endl;
498 int max_entries = -1;
501 if(!to<int>(svalue,ival))
return raxml_out();
524 }
else if(a_dim==2) {
540 }
else if(a_dim==3) {
560 a_out <<
"tools::xml::aidas::read_cloud :"
561 <<
" with name " <<
sout(sname)
562 <<
" and title " <<
sout(stitle)
563 <<
" done." << std::endl;
566 return raxml_out(hdl,sclass,spath,sname);
581 ,std::vector<double>& aEdges
591 aVariableBins =
false;
593 const std::string& tagName = a_tree.
tag_name();
601 if(!to<bn_t>(svalue,ival))
return false;
602 aNumberOfBins = ival;}
605 if(!to<double>(svalue,aMin))
return false;
608 if(!to<double>(svalue,aMax))
return false;
611 if(!
axis_index(a_dim,svalue,aAxis))
return false;
613 aEdges.push_back(aMin);
617 if(_elem->name()==s_binBorder()) {
618 if(!_elem->attribute_value(s_value(),svalue))
return false;
620 if(!to<double>(svalue,
value))
return false;
621 aEdges.push_back(
value);
622 aVariableBins =
true;
626 aEdges.push_back(aMax);
628 if(aEdges.size()!=aNumberOfBins+1)
return false;
635 static bool to_double(
const std::string& a_s,
double& a_v,std::ostream& a_out,
const std::string& a_what) {
636 if(!to<double>(a_s,a_v)) {
637 a_out <<
"tools::xml::aidas::read_bins :"
638 <<
" problem converting a " << a_what
639 <<
" attribute to a double."
640 <<
" Value was " <<
sout(a_s) <<
"."
648 const std::string& tagName = a_tree.
tag_name();
656 }
else if(tagName==
"statistics") {
663 unsigned int found = 0;
668 if(_elem->name()==s_statistic()) {
670 if(!_elem->attribute_value(s_mean(),svalue))
return false;
671 if(!to<double>(svalue,mean))
return false;
673 if(!_elem->attribute_value(s_rms(),svalue))
return false;
674 if(!to<double>(svalue,rms))
return false;
676 if(!_elem->attribute_value(s_direction(),svalue))
return false;
691 }
else if(tagName==
s_axis()) {
697 unsigned int dimension = 0;
698 if(tagName==s_data1d()) {
700 }
else if(tagName==s_data2d()) {
702 }
else if(tagName==s_data3d()) {
711 sprintf(sbin,32,
"bin%dd",dimension);
716 if(_elem->name()==sbin) {
718 std::vector<int>
is(dimension);
720 unsigned int entries = 0;
723 double weightedMean = 0;
724 double weightedMeanX = 0;
725 double weightedMeanY = 0;
726 double weightedMeanZ = 0;
727 double weightedRms = 0;
728 double weightedRmsX = 0;
729 double weightedRmsY = 0;
730 double weightedRmsZ = 0;
734 if(!_elem->attribute_value(s_entries(),svalue)) {
735 a_out <<
"tools::xml::aidas::read_bins :"
736 <<
" a <bin1d> has no " <<
"entries"
741 if(!to<unsigned int>(svalue,entries)) {
742 a_out <<
"tools::xml::aidas::read_bins :"
743 <<
" problem converting a entries attribute to an unsigned int."
744 <<
" Value was " <<
sout(svalue) <<
"."
751 if(_elem->attribute_value(s_height(),svalue)) {
752 if(!
to_double(svalue,height,a_out,s_height()))
return false;
759 height = double(entries);
760 height_given =
false;
763 if(_elem->attribute_value(s_error(),svalue)) {
764 if(!
to_double(svalue,error,a_out,s_error()))
return false;
777 error = ::sqrt(::fabs( ((height*height)/entries) ));
785 error = ::sqrt(::fabs(
double(entries)));
789 if(_elem->attribute_value(s_rms(),svalue)) {
790 if(!
to_double(svalue,rms,a_out,s_rms()))
return false;
794 if(_elem->attribute_value(s_weightedMean(),svalue)) {
795 if(!
to_double(svalue,weightedMean,a_out,s_weightedMean()))
return false;
797 if(_elem->attribute_value(s_weightedRms(),svalue)) {
798 if(!
to_double(svalue,weightedRms,a_out,s_weightedRms()))
return false;
800 }
else if(dimension==2) {
801 if(_elem->attribute_value(s_weightedMeanX(),svalue)) {
802 if(!
to_double(svalue,weightedMeanX,a_out,s_weightedMeanX()))
return false;
804 if(_elem->attribute_value(s_weightedMeanY(),svalue)) {
805 if(!
to_double(svalue,weightedMeanY,a_out,s_weightedMeanY()))
return false;
807 if(_elem->attribute_value(s_weightedRmsX(),svalue)) {
808 if(!
to_double(svalue,weightedRmsX,a_out,s_weightedRmsX()))
return false;
810 if(_elem->attribute_value(s_weightedRmsY(),svalue)) {
811 if(!
to_double(svalue,weightedRmsY,a_out,s_weightedRmsY()))
return false;
813 }
else if(dimension==3) {
814 if(_elem->attribute_value(s_weightedMeanX(),svalue)) {
815 if(!
to_double(svalue,weightedMeanX,a_out,s_weightedMeanX()))
return false;
817 if(_elem->attribute_value(s_weightedMeanY(),svalue)) {
818 if(!
to_double(svalue,weightedMeanY,a_out,s_weightedMeanY()))
return false;
820 if(_elem->attribute_value(s_weightedMeanZ(),svalue)) {
821 if(!
to_double(svalue,weightedMeanZ,a_out,s_weightedMeanZ()))
return false;
823 if(_elem->attribute_value(s_weightedRmsX(),svalue)) {
824 if(!
to_double(svalue,weightedRmsX,a_out,s_weightedRmsX()))
return false;
826 if(_elem->attribute_value(s_weightedRmsY(),svalue)) {
827 if(!
to_double(svalue,weightedRmsY,a_out,s_weightedRmsY()))
return false;
829 if(_elem->attribute_value(s_weightedRmsZ(),svalue)) {
830 if(!
to_double(svalue,weightedRmsZ,a_out,s_weightedRmsZ()))
return false;
834 {
for(
unsigned int index=0;index<dimension;index++) {
835 std::string s =
"binNum";
837 if(index==0) s +=
"X";
838 else if(index==1) s +=
"Y";
839 else if(index==2) s +=
"Z";
841 if(!_elem->attribute_value(s,svalue)) {
842 a_out <<
"tools::xml::aidas::read_bins :"
843 <<
" a <bin1d> has no " << s << std::endl;
846 if(svalue==
"UNDERFLOW") {
848 }
else if(svalue==
"OVERFLOW") {
852 if(!to<int>(svalue,ival)) {
853 a_out <<
"tools::xml::aidas::read_bins :"
854 <<
" problem converting binNum to an int."
855 <<
" Value was " <<
sout(svalue) <<
"."
860 if( (ibin<0) || (ibin>=(
int)aData.
m_axes[index].bins()) ) {
861 a_out <<
"tools::xml::aidas::read_bins :"
862 <<
" a binNum is out of range."
887 aData.
m_bin_Sxw[offset][0] = weightedMean * sw;
889 (weightedRms * weightedRms + weightedMean * weightedMean) * sw;
890 }
else if(dimension==2){
892 aData.
m_bin_Sxw[offset][0] = weightedMeanX * sw;
894 (weightedRmsX*weightedRmsX + weightedMeanX*weightedMeanX) * sw;
896 aData.
m_bin_Sxw[offset][1] = weightedMeanY * sw;
898 (weightedRmsY*weightedRmsY + weightedMeanY*weightedMeanY) * sw;
899 }
else if(dimension==3){
901 aData.
m_bin_Sxw[offset][0] = weightedMeanX * sw;
903 (weightedRmsX*weightedRmsX + weightedMeanX*weightedMeanX) * sw;
905 aData.
m_bin_Sxw[offset][1] = weightedMeanY * sw;
907 (weightedRmsY*weightedRmsY + weightedMeanY*weightedMeanY) * sw;
909 aData.
m_bin_Sxw[offset][2] = weightedMeanZ * sw;
911 (weightedRmsZ*weightedRmsZ + weightedMeanZ*weightedMeanZ) * sw;
944 sw = (double)entries;
946 double r_e = rms/error;
952 aData.
m_bin_Sxw[offset][0] = weightedMean * sw;
954 (weightedRms * weightedRms + weightedMean * weightedMean) * sw;
955 }
else if(dimension==2){
956 aData.
m_bin_Sxw[offset][0] = weightedMeanX * sw;
957 aData.
m_bin_Sxw[offset][1] = weightedMeanY * sw;
959 (weightedRmsX*weightedRmsX + weightedMeanX*weightedMeanX) * sw;
961 (weightedRmsY*weightedRmsY + weightedMeanY*weightedMeanY) * sw;
964 aData.
m_bin_Sv2w[offset] = sw * (rms * rms + height * height);
976 static bool axis_index(
unsigned int a_dim,
const std::string& a_axis,
int& a_index) {
978 if(a_axis==
"x") {a_index = 0;
return true;}
979 }
else if(a_dim==2) {
980 if(a_axis==
"x") {a_index = 0;
return true;}
981 else if(a_axis==
"y") {a_index = 1;
return true;}
982 }
else if(a_dim==3) {
983 if(a_axis==
"x") {a_index = 0;
return true;}
984 else if(a_axis==
"y") {a_index = 1;
return true;}
985 else if(a_axis==
"z") {a_index = 2;
return true;}
996 const std::string& a_name,
997 const std::string& a_s,
1009 if(&a_from==
this)
return *
this;
1030 std::vector<colbook>& a_booking,
1031 std::ostream& a_out){
1035 const std::string& tag_name = a_tree.
tag_name();
1037 if(tag_name==
"columns") {
1042 if(_elem->name()==
"column") {
1044 if(!_elem->attribute_value(s_type(),
stype)) {
1045 a_out <<
"tools::xml::aidas::read_ntu_columns :"
1046 <<
" atb type missing on <column>"
1051 if(!_elem->attribute_value(s_name(),sname)) {
1052 a_out <<
"tools::xml::aidas::read_ntu_columns :"
1053 <<
" atb name missing on <column>"
1059 if(_elem->attribute_value(s_booking(),s)) {
1061 }
else if(_elem->attribute_value(s_default(),s)) {
1078 std::ostream& a_out){
1081 const std::string& tag_name = a_tree.
tag_name();
1087 }
else if(tag_name==s_columns()) {
1091 }
else if(tag_name==s_rows()) {
1098 a_out <<
"tools::xml::aidas::read_ntu_rows :"
1099 <<
" sub read_ntu_rows failed."
1110 }
else if(tag_name==s_row()) {
1112 const std::vector<aida::base_col*>& cols = a_ntu.
columns();
1114 std::vector<unsigned int> intus;
1115 std::vector<unsigned int> inot_ntus;
1116 {
unsigned int index = 0;
1118 if(safe_cast<aida::base_col,aida::aida_col_ntu>(*(*it))) {
1119 intus.push_back(index);
1121 inot_ntus.push_back(index);
1128 {
unsigned int icol = 0;
1133 if(_elem->name()==s_entry()) {
1134 if(!_elem->attribute_value(s_value(),svalue)) {
1135 a_out <<
"tools::xml::aidas::read_ntu_rows :"
1136 <<
" can't get \"value\" attribute." << std::endl;
1139 if(icol>=inot_ntus.size()) {
1140 a_out <<
"tools::xml::aidas::read_ntu_rows :"
1141 <<
" too much <entry>." << std::endl;
1144 if(inot_ntus[icol]>=cols.size()) {
1145 a_out <<
"tools::xml::aidas::read_ntu_rows :"
1146 <<
" too much <entry>." << std::endl;
1153 safe_cast<aida::base_col,aida::aida_base_col>(*bcol);
1155 if(!abcol->
s_fill(svalue)) {
1156 a_out <<
"tools::xml::aidas::read_ntu_rows :"
1157 <<
" can't get \"value\" attribute." << std::endl;
1166 {
unsigned int icol = 0;
1171 const std::string& _tag_name = _tree->tag_name();
1172 if( (_tag_name==s_entryITuple()) ||
1173 (_tag_name==s_entryTuple()) ){
1174 if(icol>=intus.size()) {
1175 a_out <<
"tools::xml::aidas::read_ntu_rows :"
1176 <<
" too much <entry>." << std::endl;
1179 if(intus[icol]>=cols.size()) {
1180 a_out <<
"tools::xml::aidas::read_ntu_rows :"
1181 <<
" too much <entry>." << std::endl;
1188 a_out <<
"tools::xml::aidas::read_ntu_rows :"
1189 <<
" can't cast to bcol_ntu."
1195 a_out <<
"tools::xml::aidas::read_ntu_rows :"
1196 <<
" get_to_fill() returned null."
1213 a_out <<
"tools::xml::aidas::read_ntu_rows :"
1214 <<
" can't add row to ntuple."
1223 a_out <<
"tools::xml::aidas::read_ntu_rows :"
1224 <<
" unknown item class " <<
sout(tag_name) << std::endl;
1234 a_out <<
"tools::xml::aidas::read_ntu :"
1235 <<
" with name " <<
sout(sname)
1236 <<
"..." << std::endl;
1248 std::vector<colbook> booking;
1260 a_out <<
"tools::xml::aidas::read_ntu :"
1261 <<
" for ntuple name " <<
sout(sname)
1262 <<
" unable to read columns..." << std::endl;
1280 a_out <<
"tools::xml::aidas::read_ntu :"
1281 <<
" for ntuple name " <<
sout(sname)
1282 <<
" unable to create a aida::ntuple." << std::endl;
1294 a_out <<
"tools::xml::aidas::read_ntu :"
1295 <<
" for ntuple name " <<
sout(sname)
1296 <<
" unable to read rows." << std::endl;
1305 a_out <<
"tools::xml::aidas::read_ntu :"
1306 <<
" name " <<
sout(sname)
1307 <<
" done." << std::endl;
1320 std::ostream& a_out){
1321 const std::string& tagName = a_tree.
tag_name();
1329 }
else if(tagName==s_entries1d()) {
1333 if(_elem->name()==s_entry1d()) {
1335 if(!_elem->attribute_value(s_valueX(),x))
return false;
1337 if(_elem->attribute_value(s_weight(),svalue)) {
1338 if(!to<double>(svalue,w))
return false;
1340 if(!aCloud.
fill(x,w))
return false;
1345 }
else if(tagName==s_histogram1d()) {
1365 std::ostream& a_out){
1366 const std::string& tagName = a_tree.
tag_name();
1374 }
else if(tagName==s_entries2d()) {
1378 if(_elem->name()==s_entry2d()) {
1380 if(!_elem->attribute_value(s_valueX(),x))
return false;
1382 if(!_elem->attribute_value(s_valueY(),y))
return false;
1384 if(_elem->attribute_value(s_weight(),svalue)) {
1385 if(!to<double>(svalue,w))
return false;
1387 if(!aCloud.
fill(x,y,w))
return false;
1392 }
else if(tagName==s_histogram2d()) {
1412 std::ostream& a_out){
1413 const std::string& tagName = a_tree.
tag_name();
1421 }
else if(tagName==s_entries3d()) {
1425 if(_elem->name()==s_entry3d()) {
1427 if(!_elem->attribute_value(s_valueX(),x))
return false;
1429 if(!_elem->attribute_value(s_valueY(),y))
return false;
1431 if(!_elem->attribute_value(s_valueZ(),z))
return false;
1433 if(_elem->attribute_value(s_weight(),svalue)) {
1434 if(!to<double>(svalue,w))
return false;
1436 if(!aCloud.
fill(x,y,z,w))
return false;
1441 }
else if(tagName==s_histogram3d()) {
1459 const std::string& tagName = a_tree.
tag_name();
1467 }
else if(tagName==s_dataPoint()) {
1471 unsigned int coord = 0;
1475 if(_elem->name()==s_measurement()) {
1476 if(coord>=a_dps.
dimension())
return false;
1478 if(!_elem->attribute_value(s_value(),
value))
return false;
1479 double errorPlus = 0;
1480 if(_elem->attribute_value(s_errorPlus(),svalue)) {
1481 if(!to<double>(svalue,errorPlus))
return false;
1483 double errorMinus = 0;
1484 if(_elem->attribute_value(s_errorMinus(),svalue)) {
1485 if(!to<double>(svalue,errorMinus))
return false;