Tuesday, July 12, 2011

Editing PDF files on linux, Two solutions

Since most our meetings and seminars are presented as PDF files. I finally realised that I need some way to edit them on Linux. Something as simple as adding comments and such would do. couple of research attempts lead me to the following link:
http://www.cyberciti.biz/tips/open-source-linux-pdf-writer.html


I tried PDFedit instantly and it did deliver what it promised. the only problem is the limited selection of arrow shapes (hard to use for Feynman diagrams).


To install and run:
$ sudo apt-get install pdfedit
$ pdfedit /path/to/pdf.file & 

The code runs smoothly but has it's limits; If the document had symbols unrecognised by it (Say Japanese characters or Math symbols). It will open but with many of it's functions missing. 

Another option is Open office! They new release (3.0 and after) has a package that is able to open PDF files on a drawing pad. you will even get to stick comments and such. This approach also suffers when opening some unrecognised set of fonts or objects. It will still be fully functional but the locations will be misset up as well as missing some symbols. 

We conclude this note with Images. Where your best bed is with GIMP. Which is a standard release in UBUNTU. Once you do the changes make sure to save as xcf. then using the command:
$  convert file.xcf file.pdf

You will get he new file in the required form.

Sunday, July 3, 2011

ROOT after a little bit of C++

I made a recent revision for Malik's excellent book about C++. This time I made it up to chapter 14 where I learned a lot about pointers. It turns out that this concept is heavily used in ROOT. For example here is a snippet of a code I am using to create plots of publication quality:

#include
#include "TInterpreter.h"
#include "TCanvas.h"
#include "TLatex.h"
#include "TROOT.h"
#include "TH2F.h"
#include "TGraphErrors.h"
#include "TLegend.h"
#include "TPad.h"


These are preprocessor statements to include libraries and header files. the <> symbol is doe standard libraries. and the ones between quotes "" is for libraries made.
void readRFPAS2RHWZ2() {



This starts the function of the type void called readRFPAS2RHWZ2()




float x = 0.446127; //The coordinate of 900GeV labe (t1d, t2d, etc)
float y = 0.190389;
float x1 = 0.2000; //The coordinates for the legends.
float y1 = 0.326465;
float x2 = 0.50275;
float y2 = 0.551054;

Simple variable declaration.

 TInterpreter::Instance() -> LoadMacro("tdrstyle.C");
This is a bit odd as an expression. I am not sure how to interpret it but here is a try. There is a space TInterpreter with an class Instance that has an object LoadMacro. it is called as a pointer:

(*TInterpreter::Instance).LodMacro = tdrstyle.C

What this does is to ask our code to use that macro.
 gROOT -> Reset();

Basically calling another pointer.
(*gROOT).Reset();
 TInterpreter::Instance() -> Execute ("setTDRStyle","");

Same as above.

 TCanvas *c1 = new TCanvas("c1","different scales hists",600,600);

new means we are creating a dynamic variable. in this case of the type TCanvas. it is assigned to the pointer c1.

 c1->Range(-100,-100,10,10);

now c1 points to another object in TCanvas.
(*c1).Range = (-100,-100,10,10);

 TH1F *Dist_Nch_pT20_ = new TH1F("Dist_Nch_pT20_","title",100,-0.5,30);

also TH1F is a data type. with the pointer Dist_Nch_pT20_ is set with the address of the class named Dist_Nch_pT20_  with the parameters needed. next we assign the objects:
 Dist_Nch_pT20_->SetXTitle("N_{ch}");

etc.

So we conclude it is nothing but a bunch of dynamic classes assigned by pointers.

Friday, February 11, 2011

Fixing touch pad from shell

Today while I was working while watching a movie online. suddenly my touch-pad frozen. More specifically the left button option on my Dell Inspiron E1505. As hard as it was to surf the web this way. I found a lovely fix:

gconftool-2 --set --type boolean /desktop/gnome/peripherals/touchpad/touchpad_enabled true

Thanks to Ubuntu's website! 

Monday, January 17, 2011

Starting Open Office from shell

I ran across this excellent reference on how to start OO from shell. instead of that silly file name I just opened it on my desktop and dumped the code. What it worth mentioning is that it opens whatever release you currently have. for completion the code it below:

################
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

import java.io.IOException;
import java.io.InputStream;

/**
 *
 * @author bobohead2
 */
public class StartOpenOffice {
   
    private String unoUrl =
            "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager";
   
    /** Creates a new instance of StartOpenOffice */
    public StartOpenOffice() {
    }
   
    public boolean startOpenOffice(String p_scriptpfad){
        boolean loaded = false;
        try {
          // loads the script
            String cmd = p_scriptpfad     //home/bobohead2/OpenOffice.org1.1/ListenOffice.sh";
            Process process = Runtime.getRuntime().exec(cmd);
            InputStream processOut = process.getInputStream();
            InputStream processErr = process.getErrorStream();
           
        } catch (IOException ioe) {
            ioe.printStackTrace(System.out);
        }
        while(loaded == false){
            try{
               // open Office may take a while to open
                XComponentContext xLocalContext =
                       com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
               
                XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
               
                Object urlResolver  = xLocalServiceManager.createInstanceWithContext(
                        "com.sun.star.bridge.UnoUrlResolver", xLocalContext );
                // query XUnoUrlResolver interface from urlResolver object
                XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(
                        XUnoUrlResolver.class, urlResolver );
               
                // Second step: use xUrlResolver interface to import the remote StarOffice.ServiceManager,
                // retrieve its property DefaultContext and get the remote servicemanager
                Object initialObject = xUnoUrlResolver.resolve( unoUrl );
                loaded = true;
            }catch(Exception e){
                // open office is not ready yet
                loaded = false;
                // wait a liitle bit and try again
                for(int i=0;i< 10000;i++){
                   
                }
            }
        }
        return loaded;
    }
}
##########################

and to run it just type:
#!/bin/sh
/opt/openoffice.org2.0/program/soffice "-accept=socket,port=8100;urp;"

Thursday, December 16, 2010

fixing linux's shell worst pitfal: rm

When I started working with shell few yeas ago, I remember the first thing people warned me about: the rm command has no backup. So there is no copy saved in the Recycle bin or in Trash. Many books and tutorial will share this warning, and also the wisdom that no matter how careful you are. It is bound to happen that you will delete an important file wasting the work of hours or days.

Today I thought of a solution of this for my UBUNTU 9.10. We might mention that alias doesn't work since it doesn't take arguments. Also we should make the effort to find where "Trash" is, a matter that wasn't so simple [1] [2] So the next solution is to write a function and save it in .bashrc:

function rmv () { scp $* ~/.local/share/Trash/files/; }

so now:
$rmv test.f

will put it in the trash instead of deleting it forever. If you are an extensive user of rm you should be careful not to fill up the Trash directory so maybe writing a command that will clean it say every 24 hours or few days. Maybe I will do that one day...

Tuesday, December 14, 2010

fixing your webcam for skype

After updating to UBUNTU 9.10. Skype started running without any interferences. So the next step is to tackle the issue of webcams.Here is a good resource:

https://wiki.ubuntu.com/SkypeWebCams

 so now using lsusb:
Bus 003 Device 003: ID 045e:00f7 Microsoft Corp. LifeCam VX-1000

i get the details of my webcam and the link associated with it:
http://ubuntuforums.org/archive/index.php/t-914952.html
it turned out that the needed fix is to have the following command:
 env LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype

so i fixed it for the alias:
alias skype='env LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype'

and i fixed it on the launching pas:
System->Preference->Mainmenu.
I removed skype and put instead the required command.

my skype has a webcam access and life is good.

Thursday, December 2, 2010

Updating ROOT on your machine.

I was running ROOT 5.18 on my laptop and it has the interesting issue of saving the plots 90 degrees rotated. I never bothered myself with this until someone brought the issue on CMS's hypernews. The solutions she got were:

1- You can change the size of the canvas to be rectangle
TCanvas *c = new TCanvas("c","",800,850); Quite easy but we need to remember that the TDR style for CMS papers is 600 by 600.

2- It turned out that this issue is solved in the new releases (after 5.22).


So the challenge was to try to update my old ROOT release. These days they have clear instructions about installing ROOT. The problem is that this is not a full package and installing without care will create a mess! so doing the instructions you can use that release in the current shell. but not if you opened a new one.

I wanted something more "default". So here is the trick:

in 'root' edit file names: .bashrc
and at the bottom i added:
. $HOME/Desktop/Research/ROOT522/root/bin/thisroot.sh

which is the place where the new installation is.