61 testInvariant ()
const
69 NTupleSvc (
const std::string& val_outputName)
70 :
m_file (0), m_tree (0), m_initialized (false),
75 m_outputName = val_outputName;
91 copyBranch (
const std::string&
name)
94 m_copyBranches.insert (
name);
100 copyBranchList (
const std::string&
fileName)
108 while (!
line.empty() && isspace (
line[0]))
112 if (!
line.empty() &&
line[0] !=
'#')
120 addWhiteFloat (
const std::string&
varName)
129 addWhiteArray (
const std::string&
varName)
148 getFilterPassed ()
const
157 setFilterPassed (
bool passed)
176 treeName (
const std::string& val_treeName)
179 m_treeName = val_treeName;
184 const char *NTupleSvc ::
188 return m_outputName.c_str();
197 RCU_REQUIRE2_SOFT (
job.outputHas (m_outputName), (
"output stream " + m_outputName +
" not configured. try:\n EL::OutputStream output (\"" + m_outputName +
"\");\n job.addOutput (output);").c_str());
198 return EL::StatusCode::SUCCESS;
208 return EL::StatusCode::SUCCESS;
217 m_file = wk()->getOutputFile (m_outputName);
218 std::string
name = m_treeName;
219 if (
name.empty())
name = wk()->tree()->GetName();
224 m_tree =
new TTree (
name.c_str(), m_tree_title.c_str());
232 m_tree->SetAutoSave(10000);
234 m_tree->SetAutoFlush( -30000000 );
235 TTree::SetBranchStyle(1);
237 return EL::StatusCode::SUCCESS;
247 return EL::StatusCode::SUCCESS;
259 return EL::StatusCode::SUCCESS;
263 for (whiteInfoMIter iter = m_whiteInfo.begin(),
264 end = m_whiteInfo.end(); iter !=
end; ++ iter)
270 m_whiteboard->getArray (iter->name,
size,
values);
273 iter->buffer[0] = m_whiteboard->getFloat (iter->name);
277 return EL::StatusCode::SUCCESS;
283 hasName (
const std::string&
name)
const
287 name ==
"NTupleSvc_" + m_outputName ||
288 name ==
"NTupleSvc_" + m_outputName +
"_" + m_treeName;
296 if (m_initialized ==
false)
298 m_initialized =
true;
300 std::set<std::string> branchList;
302 findBranches (branchList);
303 initOutput (branchList);
305 for (m_whiteFloatIter iter = m_whiteFloat.begin(),
306 end = m_whiteFloat.end(); iter !=
end; ++ iter)
311 m_whiteInfo.push_back (
info);
313 for (m_whiteArrayIter iter = m_whiteArray.begin(),
314 end = m_whiteArray.end(); iter !=
end; ++ iter)
319 m_whiteInfo.push_back (
info);
321 for (whiteInfoMIter iter = m_whiteInfo.begin(),
322 end = m_whiteInfo.end(); iter !=
end; ++ iter)
326 iter->pointer = &iter->buffer;
327 m_tree->Branch (iter->name.c_str(), &iter->pointer);
330 iter->buffer.resize (1);
331 m_tree->Branch (iter->name.c_str(), &iter->buffer[0], (iter->name +
"/F").c_str());
334 if (!m_whiteInfo.empty())
341 findBranches (std::set<std::string>& branchList)
343 for (m_copyBranchesIter iter = m_copyBranches.begin(),
344 end = m_copyBranches.end(); iter !=
end; ++ iter)
346 std::size_t
count = 0;
350 for (TIter branchIter (wk()->
tree()->GetListOfBranches());
351 (
object = branchIter());)
358 branchList.insert (
str.Data());
363 RCU_THROW_MSG (
"could not find any branch that matches pattern \"" + *iter +
"\"");
370 initOutput (
const std::string& branchName)
373 for (copyInfoMIter
branch = m_copyInfo.begin(),
376 if (
branch->name == branchName)
381 info.name = branchName;
382 info.source = wk()->tree()->FindBranch (branchName.c_str());
383 if (
info.source == 0)
384 RCU_THROW_MSG (
"could not find input branch: " + branchName);
390 static_cast<void*
>(0));
393 static std::map<std::string,std::string>
types;
396 types[
"Char_t"] =
"B";
397 types[
"UChar_t"] =
"b";
398 types[
"Short_t"] =
"S";
399 types[
"UShort_t"] =
"s";
400 types[
"Int_t"] =
"I";
401 types[
"UInt_t"] =
"i";
402 types[
"Float_t"] =
"F";
403 types[
"Double_t"] =
"D";
404 types[
"Long64_t"] =
"L";
405 types[
"ULong64_t"] =
"l";
406 types[
"Bool_t"] =
"O";
411 for (TIter iter =
info.source->GetListOfLeaves(); (
object = iter()); )
413 TLeaf *myleaf =
dynamic_cast<TLeaf*
>(
object);
417 std::string
typeName = myleaf->GetTypeName();
418 std::map<std::string,std::string>::const_iterator
type
425 leaves = leaves + myleaf->GetTitle() +
"/" +
type->second;
428 RCU_THROW_MSG (
"failed to scan leaves of branch " + branchName);
430 for (std::string::size_type
pos = 0;
431 (
pos = leaves.find (
"[",
pos)) != std::string::npos; )
434 std::string::size_type pos2 = leaves.find (
"]",
pos);
435 if (pos2 == std::string::npos)
436 RCU_THROW_MSG (
"failed to scan leaf dimensions for " + leaves);
437 std::string
dim = leaves.substr (
pos, pos2 -
pos);
438 if (!(
dim[0] >=
'0' &&
dim[0] <=
'9'))
441 info.target = m_tree->Branch (branchName.c_str(),
static_cast<void*
>(0),
444 m_copyInfo.push_back (
info);
450 initOutput (
const std::set<std::string>& branchList)
452 for (std::set<std::string>::const_iterator
branch = branchList.begin(),
464 for (copyInfoMIter
info = m_copyInfo.begin(),
467 info->source =
dynamic_cast<TBranch*
>
468 (wk()->tree()->GetBranch (
info->name.c_str()));
474 for (copyInfoMIter
info = m_copyInfo.begin(),
480 std::size_t
size =
sizeof (
void*);
482 for (TIter iter =
info->source->GetListOfLeaves();
485 TLeaf *myleaf =
dynamic_cast<TLeaf*
>(
object);
488 TLeaf *countleaf = myleaf->GetLeafCounter (countval);
490 countval = countleaf->GetMaximum();
492 RCU_THROW_MSG (std::string (
"could not determine size of leaf ") + myleaf->GetName() +
" in branch " +
info->name);
495 const std::size_t mysize
496 = myleaf->GetOffset() + myleaf->GetLenType() * countval;
501 info->source->SetStatus (1);
506 info->source->GetEntry (wk()->treeEntry(), 1);