Go to the documentation of this file.
4 #ifndef tools_aida_ntuple
5 #define tools_aida_ntuple
32 static const std::string s_v(
"tools::aida::base_col");
35 virtual void*
cast(
const std::string& a_class)
const {
36 if(
void* p = cmp_cast<base_col>(
this,a_class)) {
return p;}
42 virtual bool add() = 0;
48 base_col(std::ostream& a_out,
const std::string& a_name)
52 mem::increment(
s_class().c_str());
58 mem::decrement(
s_class().c_str());
67 mem::increment(
s_class().c_str());
88 static const std::string s_v(
"tools::aida::base_ntu");
91 virtual void*
cast(
const std::string& a_class)
const {
92 if(
void* p = cmp_cast<base_ntu>(
this,a_class)) {
return p;}
96 base_ntu(std::ostream& a_out,
const std::string& a_title)
99 mem::increment(
s_class().c_str());
105 mem::decrement(
s_class().c_str());
114 mem::increment(
s_class().c_str());
120 <<
" can't copy column."
122 safe_clear<base_col>(
m_cols);
130 if(&a_from==
this)
return *
this;
132 safe_clear<base_col>(
m_cols);
140 <<
" can't copy column."
142 safe_clear<base_col>(
m_cols);
156 #ifdef tools_aida_ntuple
169 if(
m_cols.empty())
return 0;
170 return m_cols.front()->num_elems();
173 if(
m_cols.empty()) {a_value = 0;
return false;}
174 a_value =
m_cols.front()->num_elems();
179 safe_clear<base_col>(
m_cols);
186 if(!(*it)->reset()) status =
false;
214 if(!(*it)->add()) status =
false;
220 return find_named<base_col>(
m_cols,a_name);
230 (*it)->set_index(a_index);
255 static const std::string s_v(
"short");
259 static const std::string s_v(
"int");
263 static const std::string s_v(
"float");
267 static const std::string s_v(
"double");
279 static const std::string s_v(
"boolean");
283 static const std::string s_v(
"string");
287 static const std::string s_v(
"long");
297 static const std::string s_v(
"ITuple");
305 static const std::string s_v(
"ushort");
309 static const std::string s_v(
"uint");
313 static const std::string s_v(
"ulong");
320 static const std::string s_v(
"tools::aida::aida_base_col");
323 virtual void*
cast(
const std::string& a_class)
const {
324 if(
void* p = cmp_cast<aida_base_col>(
this,a_class)) {
return p;}
331 virtual bool s_fill(
const std::string&) = 0;
347 inline bool s__fill(
const std::string& a_s,std::string& a_v) {
351 inline bool s__fill(
const std::string& a_s,
char& a_v) {
353 if(a_s.empty())
return false;
357 inline bool s__fill(
const std::string& a_s,
unsigned char& a_v) {
359 if(a_s.empty())
return false;
363 inline bool s__fill(
const std::string& a_s,
bool& a_v) {
366 inline bool s__fill(
const std::string& a_s,
short& a_v) {
367 return to<short>(a_s,a_v);
369 inline bool s__fill(
const std::string& a_s,
unsigned short& a_v) {
370 return to<unsigned short>(a_s,a_v);
372 inline bool s__fill(
const std::string& a_s,
int& a_v) {
373 return to<int>(a_s,a_v);
375 inline bool s__fill(
const std::string& a_s,
unsigned int& a_v) {
376 return to<unsigned int>(a_s,a_v);
379 return to<int64>(a_s,a_v);
382 return to<uint64>(a_s,a_v);
384 inline bool s__fill(
const std::string& a_s,
float& a_v) {
385 return to<float>(a_s,a_v);
387 inline bool s__fill(
const std::string& a_s,
double& a_v) {
388 return to<double>(a_s,a_v);
397 static const std::string s_v(
"tools::aida::aida_col<"+
stype(T())+
">");
400 virtual void*
cast(
const std::string& a_class)
const {
420 virtual bool s_value(std::string& a_s)
const {
421 typedef typename std::vector<T>::size_type sz_t;
427 virtual bool s_fill(
const std::string& a_s) {
431 <<
" can't convert " <<
sout(a_s) <<
"."
440 aida_col(std::ostream& a_out,
const std::string& a_name,
const T& a_def)
458 if(&a_from==
this)
return *
this;
466 bool fill(
const T& a_value) {
m_tmp = a_value;
return true;}
471 <<
". Vec size is " <<
m_data.size() <<
"."
477 typedef typename std::vector<T>::size_type sz_t;
486 <<
". Vec size is " <<
m_data.size() <<
"."
492 typedef typename std::vector<T>::size_type sz_t;
508 static const std::string s_v(
"tools::aida::ntuple");
511 virtual void*
cast(
const std::string& a_class)
const {
512 if(
void* p = cmp_cast<ntuple>(
this,a_class)) {
return p;}
517 ntuple(std::ostream& a_out,
const std::string& a_title)
530 if(find_named<base_col>(
m_cols,a_name)) {
532 <<
" a column with name " <<
sout(a_name) <<
" already exists."
539 <<
" can't create aida_col<T> " <<
sout(a_name) <<
"."
551 return safe_cast<base_col, aida_col<T> >(*col);
556 base_col* col = a_case_sensitive ? find_named<base_col>(
m_cols,a_name) : find_named_case_insensitive<base_col>(
m_cols,a_name);
557 if(!col) {a_col = 0;
return false;}
558 a_col = safe_cast<base_col, aida_col<T> >(*col);
559 return a_col?
true:
false;
563 base_col* col = a_case_sensitive ? find_named<base_col>(
m_cols,a_name) : find_named_case_insensitive<base_col>(
m_cols,a_name);
565 return safe_cast<base_col,aida_base_col>(*col);
571 if(!(*it)->fetch_entry()) status =
false;
580 if((*itc)->name()==(*itb).name()) {
581 (*itc)->set_user_variable((*itb).user_obj());
586 a_out <<
"tools::aida::ntuple :"
587 <<
" binding name " <<
sout((*itb).name()) <<
" does not match any ntuple column."
598 if(
m_cols.empty())
return false;
599 if(a_col>=
m_cols.size())
return false;
601 aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
602 if(!_col)
return false;
606 {
for(
uint64 row=0;row<_rows;row++) {
607 if(!
next()) {a_value = T();
return false;}
612 a_value = mn<T>(a_value,v);
621 if(
m_cols.empty())
return false;
622 if(a_col>=
m_cols.size())
return false;
624 aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
625 if(!_col)
return false;
629 {
for(
uint64 row=0;row<_rows;row++) {
630 if(!
next()) {a_value = T();
return false;}
635 a_value = mx<T>(a_value,v);
650 static const std::string s_v(
"tools::aida::aida_col_ntu");
653 virtual void*
cast(
const std::string& a_class)
const {
654 if(
void* p = cmp_cast<aida_col_ntu>(
this,a_class)) {
return p;}
667 <<
". Vec size is " <<
m_data.size() <<
"."
672 typedef std::vector<ntuple>::size_type sz_t;
681 <<
". Vec size is " <<
m_data.size() <<
"."
687 typedef std::vector<ntuple>::size_type sz_t;
711 if(&a_from==
this)
return *
this;
725 const std::vector<value>& a_vars,
726 bool a_verbose =
false){
730 a_ntu.
out() <<
"tools::aida::create_cols_from_vals :"
731 <<
" ITuple : " << (*it).label() <<
" : begin "
734 std::vector<value>* vars = (std::vector<value>*)(*it).get_void_star();
743 ntuple* sub_aida = safe_cast<base_ntu,ntuple>(*sub_base_ntu);
762 a_ntu.
out() <<
"tools::aida::create_cols_from_vals :"
763 <<
" " <<
stype <<
" : "
764 << (*it).label() <<
" : "
777 col = a_ntu.
create_col<
short>((*it).label(),(*it).get_short());
779 col = a_ntu.
create_col<
int>((*it).label(),(*it).get_int());
783 col = a_ntu.
create_col<
float>((*it).label(),(*it).get_float());
785 col = a_ntu.
create_col<
double>((*it).label(),(*it).get_double());
790 col = a_ntu.
create_col<
unsigned short>((*it).label(),(*it).get_unsigned_short());
792 col = a_ntu.
create_col<
unsigned int>((*it).label(),(*it).get_unsigned_int());
797 col = a_ntu.
create_col<
bool>((*it).label(),(*it).get_bool());
799 col = a_ntu.
create_col<std::string>((*it).label(),(*it).get_string());
809 a_ntu.
out() <<
"tools::aida::create_cols_from_vals :"
810 <<
" failed for " <<
stype <<
" : "
811 << (*it).label() <<
" : "
823 const std::string& a_type,
824 const std::string& a_name,
825 const std::string& a_s,
846 if(a_s.size()&&!to<short>(a_s,v)) {
847 a_ntu.
out() <<
"tools::aida::create_col :"
848 <<
" can't convert def " <<
sout(a_s)
849 <<
" to a " << a_type
854 a_ntu.
out() <<
"tools::aida::create_col :"
855 <<
" can't create column of type " <<
sout(a_type)
862 if(a_s.size()&&!to<int>(a_s,v)) {
863 a_ntu.
out() <<
"tools::aida::create_col :"
864 <<
" can't convert def " <<
sout(a_s)
865 <<
" to a " << a_type
870 a_ntu.
out() <<
"tools::aida::create_col :"
871 <<
" can't create column of type " <<
sout(a_type)
878 if(a_s.size()&&!to<int64>(a_s,v)) {
879 a_ntu.
out() <<
"tools::aida::create_col :"
880 <<
" can't convert def " <<
sout(a_s)
881 <<
" to a " << a_type
886 a_ntu.
out() <<
"tools::aida::create_col :"
887 <<
" can't create column of type " <<
sout(a_type)
894 if(a_s.size()&&!to<float>(a_s,v)) {
895 a_ntu.
out() <<
"tools::aida::create_col :"
896 <<
" can't convert def " <<
sout(a_s)
897 <<
" to a " << a_type
902 a_ntu.
out() <<
"tools::aida::create_col :"
903 <<
" can't create column of type " <<
sout(a_type)
911 if(a_s.size()&&!to<double>(a_s,v)) {
912 a_ntu.
out() <<
"tools::aida::create_col :"
913 <<
" can't convert def " <<
sout(a_s)
914 <<
" to a " << a_type
919 a_ntu.
out() <<
"tools::aida::create_col :"
920 <<
" can't create column of type " <<
sout(a_type)
948 }
else if(a_type==
s_aida_type((
unsigned short)0)) {
949 unsigned short v = 0;
950 if(a_s.size()&&!to<unsigned short>(a_s,v)) {
951 a_ntu.
out() <<
"tools::aida::create_col :"
952 <<
" can't convert def " <<
sout(a_s)
953 <<
" to a " << a_type
957 if(!a_ntu.
create_col<
unsigned short>(a_name,v)) {
958 a_ntu.
out() <<
"tools::aida::create_col :"
959 <<
" can't create column of type " <<
sout(a_type)
966 if(a_s.size()&&!to<unsigned int>(a_s,v)) {
967 a_ntu.
out() <<
"tools::aida::create_col :"
968 <<
" can't convert def " <<
sout(a_s)
969 <<
" to a " << a_type
973 if(!a_ntu.
create_col<
unsigned int>(a_name,v)) {
974 a_ntu.
out() <<
"tools::aida::create_col :"
975 <<
" can't create column of type " <<
sout(a_type)
982 if(a_s.size()&&!to<uint64>(a_s,v)) {
983 a_ntu.
out() <<
"tools::aida::create_col :"
984 <<
" can't convert def " <<
sout(a_s)
985 <<
" to a " << a_type
990 a_ntu.
out() <<
"tools::aida::create_col :"
991 <<
" can't create column of type " <<
sout(a_type)
1000 if(a_s.size()&&!
to(a_s,v)) {
1001 a_ntu.
out() <<
"tools::aida::create_col :"
1002 <<
" can't convert def " <<
sout(a_s)
1003 <<
" to a " << a_type
1008 a_ntu.
out() <<
"tools::aida::create_col :"
1009 <<
" can't create column of type " <<
sout(a_type)
1015 if(!a_ntu.
create_col<std::string>(a_name,a_s)) {
1016 a_ntu.
out() <<
"tools::aida::create_col :"
1017 <<
" can't create column of type " <<
sout(a_type)
1024 if(a_s.size()&&!to<int64>(a_s,v)) {
1025 a_ntu.
out() <<
"tools::aida::create_col :"
1026 <<
" can't convert def " <<
sout(a_s)
1027 <<
" to a " << a_type
1032 a_ntu.
out() <<
"tools::aida::create_col :"
1033 <<
" can't create column of type " <<
sout(a_type)
1042 a_ntu.
out() <<
"tools::aida::create_col :"
1043 <<
" mismatch a_is_ntu/a_type."
1048 a_ntu.
out() <<
"tools::aida::create_col :"
1049 <<
" empty booking string."
1056 a_ntu.
out() <<
"tools::aida::create_col :"
1057 <<
" find_variables() failed for " <<
sout(a_s) <<
"."
1065 if(!sub_base_ntu) {
delete col_ntu;
return false;}
1066 ntuple* sub_aida = safe_cast<base_ntu,ntuple>(*sub_base_ntu);
1067 if(!sub_aida) {
delete col_ntu;
return false;}
1069 std::vector<value> vars;f.
result(vars);
1081 a_ntu.
out() <<
"tools::aida::create_col :"
1082 <<
" col type " <<
sout(a_type)
1083 <<
" not yet handled."
1093 const std::string& a_booking,
1094 bool a_verbose =
false){
1096 if(a_booking.empty()) {
1097 a_ntu.
out() <<
"tools::aida::create_cols_from_string :"
1098 <<
" empty booking string."
1105 a_ntu.
out() <<
"tools::aida::create_cols_from_string :"
1106 <<
" find_variables() failed."
1110 std::vector<value> vars;f.
result(vars);
1125 return safe_cast<base_col, aida_col_ntu >(*col);
1132 static const std::string s_v(
"tools::aida::base_looper<"+
stype(T())+
">");
1141 mem::increment(
s_class().c_str());
1146 mem::decrement(
s_class().c_str());
1153 mem::increment(
s_class().c_str());
1159 std::vector<unsigned int>
is;
1163 <<
" find_is failed."
1169 <<
" find_is : col not found."
1183 <<
" _looper failed."
1191 std::vector<unsigned int>& a_is,
1197 const std::vector<base_col*>& cols = a_ntu.
columns();
1200 {
unsigned int index = 0;
1203 a_is.push_back(index);
1211 {
unsigned int index = 0;
1213 aida_col_ntu* col = safe_cast<base_col,aida_col_ntu>(*(*it));
1216 if(!
sub) {a_is.
clear();
return false;}
1217 a_is.push_back(index);
1218 if(!
find_is(*
sub,a_col,a_is,a_found)) {a_is.clear();
return false;}
1219 if(a_found)
return true;
1228 const std::vector<unsigned int>& a_is,
1229 unsigned int a_depth,
1231 if(a_depth>=a_is.size())
return false;
1233 unsigned int coli = a_is[a_depth];
1234 const std::vector<base_col*>& cols = a_sub.
columns();
1235 if(coli>=cols.size())
return false;
1237 if(a_depth==(a_is.size()-1)) {
1238 aida_col<T>* col = safe_cast<base_col, aida_col<T> >(*(cols[coli]));
1239 if(!col)
return false;
1241 while(a_sub.
next()) {
1244 if(!
action(v)) {a_stop =
true;
break;}
1247 aida_col_ntu* col = safe_cast<base_col,aida_col_ntu>(*(cols[coli]));
1248 if(!col)
return false;
1250 while(a_sub.
next()) {
1252 if(!ntu)
return false;
1254 while(ntu->
next()) {
1255 if(!
_looper(*ntu,a_is,a_depth+1,a_stop))
return false;
1317 if(&a_from==
this)
return *
this;
1356 T& a_mn,T& a_mx,T& a_S,T& a_S2,
1365 if(!status)
return false;
1366 if(!a_count)
return false;
1371 const std::vector<base_col*>& cols = a_ntu.
columns();
1373 aida_col_ntu* col = safe_cast<base_col,aida_col_ntu>(*(*it));
1378 if(fcol)
return fcol;
1380 if((*it)->name()==a_name)
return *it;
1389 const std::vector<base_col*>& cols = a_ntu.
columns();
1390 if(cols.empty())
return false;
1391 if(a_col>=cols.size())
return false;
1393 aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
1394 if(!_col)
return false;
1397 a_vec.resize(_rows);
1399 {
for(
uint64 row=0;row<_rows;row++) {
1400 if(!a_ntu.
next()) {a_vec.clear();
return false;}
#define tools_vforit(a__T, a__v, a__it)
#define tools_vforcit(a__T, a__v, a__it)