10 using namespace Diana;
26 Debug(
"Requiring QObjects");
28 std::string AliasFileName = GetString(
"AliasFileName",
"cfg/aliases.txt");
29 if(AliasFileName !=
"") {
30 Debug(
"Adding aliases from %s",AliasFileName.c_str());
33 std::stringstream str;
35 Error(
"%s",str.str().c_str());
38 std::string CustomAliasFileName = GetString(
"CustomAliasFileName",
"",
false);
39 if(CustomAliasFileName !=
"") {
40 Debug(
"Adding aliases from %s",CustomAliasFileName.c_str());
43 std::stringstream str;
45 Error(
"%s",str.str().c_str());
49 fAliasMap = aliases.
Get() ;
50 if(fAliasMap.empty()) Warn(
"Alias list is empty");
51 fAddPackedNeighbours = GetBool(
"AddPackedNeighbours",
false,
false);
52 std::string neighboursPrefix;
53 if(fAddPackedNeighbours) {
54 neighboursPrefix = GetString(
"NeighboursPrefix",
"N",
false);
57 std::map<std::string,QAliases::AliasInfo>::iterator aliasIter = fAliasMap.begin();
58 for(;aliasIter != fAliasMap.end();aliasIter++) {
59 std::string alias = aliasIter->first;
61 if(GetBool(
"Alias:"+alias,
false,
false)) {
62 std::string path = aliasIter->second.fPath;
64 QObject** peventData = evi.Get(label.
owner.c_str(),label.
name.c_str());
65 if(!peventData)
continue;
66 QObject* eventData = (*peventData);
67 if(!eventData)
continue;
73 if(type ==
"Unknown"){
74 Error(
"Cannot handle type %s (variable %s)",type.c_str(),alias.c_str());
76 std::string brvariable = alias +
"/" + type;
80 branch.
type = brvariable.c_str();
81 eventData->SetIsRequired();
82 fAliasBranches.push_back(branch);
83 if(fAddPackedNeighbours) {
84 int nneigh = GetInt(
"MaximumNumberOfNeighbours",2);
85 if(nneigh < 1) Panic(
"MaximumNumberOfNeighbours = %d not allowed",nneigh);
86 for(
int n = 0; n < nneigh; n++) {
87 std::stringstream neighowner;
88 neighowner<<neighboursPrefix<<n+1<<
"_"<<label.
owner;
90 nLabel.
owner = neighowner.str();
92 peventData = evi.Get(nLabel.
owner.c_str(),nLabel.
name.c_str());
93 if(!peventData)
continue;
94 QObject* eventData = (*peventData);
95 if(!eventData)
continue;
98 std::stringstream nbranchAlias;
99 nbranchAlias<<neighboursPrefix<<n+1<<
"_"<<alias;
100 branch.
name = nbranchAlias.str();
101 brvariable = nbranchAlias.str() +
"/" + type;
102 branch.
type = brvariable.c_str();
103 eventData->SetIsRequired();
104 fAliasBranches.push_back(branch);
111 std::vector<QEventLabel> evDataLabels = evi.GetWriteLabels();
112 std::vector<QEventLabel>::const_iterator evLabelIter = evDataLabels.begin();
113 while(evLabelIter != evDataLabels.end()) {
115 QObject** peventData = evi.Get(label.
owner.c_str(),label.
name.c_str());
116 QObject* eventData = (*peventData);
119 bool process =
false;
120 if(GetBool(std::string(
"Member:") + labelstr,
false,
false)) {
122 }
else if(fAddPackedNeighbours && !neighboursPrefix.empty()
123 && labelstr[0] == neighboursPrefix[0]) {
124 int pos = labelstr.find_first_of(
"_");
125 QVdt num(labelstr.substr(1,pos-1));
126 std::string rest = labelstr.substr(pos+1,std::string::npos);
127 if(num.
GetType() ==
QVdt::Int_QVdt && GetBool(std::string(
"Member:") + rest,
false,
false)) process =
true;
131 std::string brnamestr = labelstr +
".";
133 branch.
name = brnamestr;
134 branch.
type = eventData->GetName();
136 eventData->SetIsRequired();
137 fBranches.push_back(branch);
139 std::map<std::string, std::string> branchAliasMap = aliases.
Find(label);
140 std::map<std::string, std::string>::const_iterator iter = branchAliasMap.begin();
141 while(iter != branchAliasMap.end()) {
143 if(iter->second ==
"") {
146 path = labelstr+std::string(
".")+iter->second;
148 fBranchAliasMap[iter->first] = path;
164 fFileName = filename;
166 fRootOutput =
new TFile(filename.c_str(),
"RECREATE");
167 std::string treeDescription = GetString(
"Description",
"Diana NTP",
false);
168 fTree =
new TTree(GetString(
"TreeName",
"qtree",
false).c_str(),treeDescription.c_str());
170 std::string saveMesg =
"";
172 for(
size_t i = 0; i < fAliasBranches.size(); i++) {
174 TBranch* br = fTree->Branch(branch.
name.c_str(),branch.
address,branch.
type.c_str());
176 Debug(
"Adding alias branch %s of type %s",branch.
name.c_str(),branch.
type.c_str());
177 saveMesg += branch.
name +
" ";
179 else Error(
"Cannot handle variable %s",branch.
name.c_str());
182 bool saveSomething =
false;
183 if(!saveMesg.empty()) {
184 Info(
"Saving aliases: %s",saveMesg.c_str());
185 saveSomething =
true;
190 for(
size_t i = 0; i < fBranches.size(); i++) {
191 Branch branch = fBranches[i];
192 Debug(
"Adding branch %s of type %s",branch.
name.c_str(),branch.
type.c_str());
193 saveMesg += branch.
name +
" ";
197 if(!saveMesg.empty()) {
198 Info(
"Saving full members: %s",saveMesg.c_str());
199 saveSomething =
true;
203 Error(
"Nothing is going to be written");
207 std::map<std::string,std::string>::const_iterator branchAliasIter = fBranchAliasMap.begin();
209 while(branchAliasIter != fBranchAliasMap.end()) {
210 const char* al = branchAliasIter->first.c_str();
211 const char*
ap = branchAliasIter->second.c_str();
212 Debug(
"Adding alias %s for %s",al,
ap);
213 fTree->SetAlias(al,
ap);
232 fRootOutput->Write();
233 fRootOutput->Close();
#define REGISTER_MODULE(clazz)
Diana::QObject ** address
void Require(const Diana::QEventInspector &evi)
void Open(const std::string &filename, const Diana::QEventInspector &evi)
Open file.
void Dump(const Diana::QEventInspector &evi)
Write event to file.
~MRootNtpDumper()
destructor
QError FillFromFile(const std::string &filename)
std::map< std::string, std::string > Find(const QEventLabel &label) const
std::map< std::string, AliasInfo > Get() const
error class with error type and description
Visitor class to inspect the QEvent content.
label for QObject in the QEvent
std::string GetStringLabel() const
get string in the format "owner@name"
std::string owner
owner of the QObject
std::string name
name of the QObject
MemberInfo FindBaseType(QObject *obj, const char *member)
QVdt_type GetType() const
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...