I am processing a file in a linux script. Inside that script, I am creating some variables and I want to import them to root. The file to be processed has the format
if test $1 ; then
if [ -f $1.evnt ] ; then
rm -f $1.dat
sed -n ‘2p’ $1.evnt | (read v1 v2 v3
for filename in $1*.evnt ; do
echo -e “Processing file $filename"
sed ‘$d’ < $filename > $1_tmp
sed -i ‘/Kmax/d’ $1_tmp
sed -i ‘/^’”$v1"’ ‘"$v2"’ /d’ $1_tmp
cat $1_tmp >> $1.dat
done
v3=wc -l $1.dat | awk '{print $1}'
echo -e “$v1 $v2 $v3” > .$1.dat
rm -f $1_tmp)
else
echo -e "\a!!!"
echo -e " Event file $1.evnt doesn’t exist !!!"
echo -e "!!!"
fi
else
echo -e "\a!!!"
echo -e "!!! Give name for event files !!!"
echo -e "!!!"
fi
awk -v channels=4096 ‘NR<=2{next}{for (i=1;i<=NF;i++) $i=$i-(i-1)*channels} END{detectors=NF;}1’ $1.dat >$1_Processed.dat
rm -f $1.dat
exit 0[/code]
As you can see I am creating the variables channels and detectors. I tried to use them-in a raw manner- inside root but with no luck at all. My macro is the following
I am not interested in text manipulation. I have manipulated my data outside root, using awk.
My question is on how to import a variable I have defined and assigned a value in it, in root.
Check this line of my code(it’s the 4th counting from bottom
There I am defining two variables
[ul]channels[/ul]
[ul]detectors[/ul]
I want those two variables to be imported in root.
Is this possible?
if you have already preprocessed your data and you have it parsed and at disposal in your c++ application, the next natural step to take advantage of the ROOT data analysis and persistency facilities would be to use a TTree or, maybe more suited for this case, a TNtuple.
A decent point to start seeing this concepts in action is this tutorial: root.cern.ch/root/html/tutorials … sic.C.html
If you look at my first post, I have a code that does exactly this.
I have already have a code that makes the ntuple.
My question is different to that, though.
In my Ntuple code, I am using the same variables that I have defined in my linux script to process the data.
So it would be rather convenient to define the variables only once, preferably in the linux script.
The root code I am providing is just a test code to check whether the variables are parsed/imported into root. Check this thread to see my macro code.
Sorry I don’t get what we are trying to achieve here. Probably I don’t get the meaning of “automated way”.
To recap:
o You have your nicely formatted input data as text file.
o You have the code which uses ROOT to fill the histograms to do your analysis.
What is exactly missing?
To do the processing I need to define some variables, which I do in the script.
To create the ntuple, I want to use the exact same variables(that will have the exact same value) in my root code, so I have to redefine(and reassign) the exact same variables.
That’s why I need to import the variable to root.
Is it clear enough now?
but again it didn’t work. I got the following error message
[quote]thanos@thanos-laptop:~/Desktop$ root 'AutoNTuple.C(“c+Au”)'
root [0]
Processing AutoNTuple.C(“c+Au”)…
Error: Symbol detectors is not defined in current scope AutoNTuple.C:12:
*** Interpreter error recovered ***
[/quote]
In your shell, what is the output of your script?
The GetFromPipe method returns a TString which contains the output of your script. Then you have to parse this TString to extract your variables (“detector” and so on).
My output is a .dat file that root uses to make the ntuple.
I also define the variables “detectors” and “channels” as well as assigning them values.
I used a print command in awk(in my script) to check if it’s working properly and my variables indeed have a value assigned.
But those variables(as well as their value) cannot pass to root, giving me the error message I wrote above.