Jpp
18.5.0
the software that should make you happy
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
software
JGizmo
JStack1D.cc
Go to the documentation of this file.
1
#include <string>
2
#include <iostream>
3
#include <iomanip>
4
5
#include "TROOT.h"
6
#include "TFile.h"
7
#include "TObject.h"
8
#include "TKey.h"
9
#include "TH1.h"
10
#include "THStack.h"
11
#include "TString.h"
12
#include "TRegexp.h"
13
14
#include "
JGizmo/JRootObjectID.hh
"
15
#include "
JGizmo/JGizmoToolkit.hh
"
16
17
#include "
Jeep/JPrint.hh
"
18
#include "
Jeep/JParser.hh
"
19
#include "
Jeep/JMessage.hh
"
20
21
22
/**
23
* \file
24
*
25
* Auxiliary program to make stack of ROOT histograms.
26
* The option <tt>-f</tt> corresponds to <tt><file name>:<object name></tt>.
27
* \author mdejong
28
*/
29
int
main
(
int
argc,
char
**argv)
30
{
31
using namespace
std;
32
using namespace
JPP;
33
34
vector<JRootObjectID>
inputFile;
35
string
outputFile
;
36
int
debug
;
37
38
try
{
39
40
JParser<>
zap(
"Auxiliary program to make stack of ROOT histograms."
);
41
42
zap[
'f'
] =
make_field
(inputFile,
"<input file>:<object name>"
);
43
zap[
'o'
] =
make_field
(
outputFile
,
"ROOT file with histogram(s)"
) =
"stack.root"
;
44
zap[
'd'
] =
make_field
(
debug
) = 0;
45
46
zap(argc, argv);
47
}
48
catch
(
const
exception &error) {
49
FATAL
(error.what() << endl);
50
}
51
52
53
THStack* hs = NULL;
54
55
for
(
vector<JRootObjectID>::const_iterator
input = inputFile.begin(); input != inputFile.end(); ++input) {
56
57
DEBUG
(
"Input: "
<< *input << endl);
58
59
TDirectory* dir =
getDirectory
(*input);
60
61
if
(dir == NULL) {
62
ERROR
(
"File: "
<< input->getFullFilename() <<
" not opened."
<< endl);
63
continue
;
64
}
65
66
const
TRegexp regexp(input->getObjectName());
67
68
TIter iter(dir->GetListOfKeys());
69
70
for
(TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
71
72
const
TString tag(key->GetName());
73
74
DEBUG
(
"Key: "
<< tag <<
" match = "
<< tag.Contains(regexp) << endl);
75
76
// option match
77
78
if
(tag.Contains(regexp) &&
isTObject
(key)) {
79
80
TH1* h1 =
dynamic_cast<
TH1*
>
(key->ReadObj());
81
82
if
(h1 != NULL) {
83
84
if
(hs == NULL) {
85
hs =
new
THStack(
MAKE_CSTRING
(h1->GetName() <<
"_s"
), NULL);
86
}
87
88
hs->Add(h1);
89
}
90
}
91
}
92
}
93
94
if
(hs != NULL) {
95
96
TFile out(
outputFile
.c_str(),
"recreate"
);
97
98
out.WriteTObject(hs);
99
100
out.Write();
101
out.Close();
102
}
103
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1514
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
MAKE_CSTRING
#define MAKE_CSTRING(A)
Make C-string.
Definition:
JPrint.hh:136
outputFile
string outputFile
Definition:
JDAQTimesliceSelector.cc:37
std::vector
Definition:
JSTDTypes.hh:12
JPrint.hh
I/O formatting auxiliaries.
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1989
ERROR
#define ERROR(A)
Definition:
JMessage.hh:66
JGizmoToolkit.hh
JRootObjectID.hh
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JParser.hh
Utility class to parse command line options.
JGIZMO::isTObject
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
Definition:
JGizmoToolkit.hh:1520
JGIZMO::getDirectory
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
Definition:
JGizmoToolkit.hh:140
debug
int debug
debug level
Definition:
archive-put-wiki-detectors.sh:92
DEBUG
#define DEBUG(A)
Message macros.
Definition:
JMessage.hh:62
Generated by
1.8.5