Index: readers/DelphesProIO.cpp
===================================================================
--- readers/DelphesProIO.cpp	(revision 538edc46272c331367d124ea856b837bbfd34911)
+++ readers/DelphesProIO.cpp	(revision 6455202899ab4afd733c9cc0b4d78dd392cbb843)
@@ -18,39 +18,38 @@
  */
 
+#include <iostream>
+#include <memory>
+#include <sstream>
 #include <stdexcept>
-#include <iostream>
-#include <sstream>
-#include <memory>
 
 #include <map>
 
-#include <stdlib.h>
 #include <signal.h>
 #include <stdio.h>
-
+#include <stdlib.h>
+
+#include "TApplication.h"
 #include "TROOT.h"
-#include "TApplication.h"
-
+
+#include "TDatabasePDG.h"
 #include "TFile.h"
+#include "TLorentzVector.h"
 #include "TObjArray.h"
+#include "TParticlePDG.h"
 #include "TStopwatch.h"
-#include "TDatabasePDG.h"
-#include "TParticlePDG.h"
-#include "TLorentzVector.h"
-
-#include "modules/Delphes.h"
-#include "classes/DelphesStream.h"
+
 #include "classes/DelphesClasses.h"
 #include "classes/DelphesFactory.h"
-
+#include "classes/DelphesStream.h"
+#include "modules/Delphes.h"
+
+#include "ExRootAnalysis/ExRootProgressBar.h"
+#include "ExRootAnalysis/ExRootTreeBranch.h"
 #include "ExRootAnalysis/ExRootTreeWriter.h"
-#include "ExRootAnalysis/ExRootTreeBranch.h"
-#include "ExRootAnalysis/ExRootProgressBar.h"
-
-#include <proio/reader.h>
+
 #include <proio/event.h>
 #include <proio/model/mc.pb.h>
-namespace model=proio::model::mc;
-
+#include <proio/reader.h>
+namespace model = proio::model::mc;
 
 using namespace std;
@@ -59,5 +58,5 @@
 // This method dynamically checks the message type (varint or not) depending on
 // non-zero value of units momentumUnit and positionUnit.
-void ConvertInput(proio::Event *event, double momentumUnit, double positionUnit, 
+void ConvertInput(proio::Event *event, double momentumUnit, double positionUnit,
   ExRootTreeBranch *branch, DelphesFactory *factory,
   TObjArray *allParticleOutputArray, TObjArray *stableParticleOutputArray,
@@ -80,21 +79,22 @@
   element = static_cast<HepMCEvent *>(branch->NewEntry());
 
- int nID=0;
- double weight=0;
- int process_id=0;
- auto mcentries = event->TaggedEntries("MCParameters");
- for (uint64_t mcentryID : mcentries) {
-   auto mcpar = dynamic_cast<proio::model::mc::MCParameters *>(event->GetEntry(mcentryID));
-   nID=mcpar->number();
-   weight=mcpar->weight();
-   process_id=mcpar->processid();
-   break; // consider only most generic from 1st entry 
- };
+  int nID = 0;
+  double weight = 0;
+  int process_id = 0;
+  auto mcentries = event->TaggedEntries("MCParameters");
+  for(uint64_t mcentryID : mcentries)
+  {
+    auto mcpar = dynamic_cast<proio::model::mc::MCParameters *>(event->GetEntry(mcentryID));
+    nID = mcpar->number();
+    weight = mcpar->weight();
+    process_id = mcpar->processid();
+    break; // consider only most generic from 1st entry
+  };
 
   element->Number = nID;
-  element->ProcessID =process_id;
+  element->ProcessID = process_id;
   element->Weight = weight;
 
-/*
+  /*
   // Pythia8 specific
   element->MPI = mutableEvent->mpi();
@@ -114,142 +114,142 @@
   element->ProcTime = procStopWatch->RealTime();
 
-
-
- if ( momentumUnit >0 && positionUnit>0) {
-
-
-  auto entries = event->TaggedEntries("VarintPackedParticles");
-
-  for (uint64_t entryID : entries) {
-
-    auto mutableParticles = dynamic_cast<model::VarintPackedParticles *>(event->GetEntry(entryID));
-
-    for(int i = 0; i < mutableParticles->pdg_size(); ++i)
-   {
-    pid = mutableParticles->pdg(i);
-    status = mutableParticles->status(i);
-    px = mutableParticles->px(i)/momentumUnit;
-    py = mutableParticles->py(i)/momentumUnit;
-    pz = mutableParticles->pz(i)/momentumUnit;
-    mass = mutableParticles->mass(i)/momentumUnit;
-    x = mutableParticles->x(i)/positionUnit;
-    y = mutableParticles->y(i)/positionUnit;
-    z = mutableParticles->z(i)/positionUnit;
-    t = mutableParticles->t(i)/positionUnit;
-    
-    candidate = factory->NewCandidate();
-    candidate->PID = pid;
-    pdgCode = TMath::Abs(candidate->PID);
-    candidate->Status = status;
-    candidate->M1 = mutableParticles->parent1(i);
-    candidate->M2 = mutableParticles->parent2(i);
-    candidate->D1 = mutableParticles->child1(i);
-    candidate->D2 = mutableParticles->child2(i);
-    pdgParticle = pdg->GetParticle(pid);
-    candidate->Charge = mutableParticles->charge(i)/3.0;
-    //candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999;
-    candidate->Mass = mass;
-    candidate->Momentum.SetXYZM(px, py, pz, mass);
-    candidate->Position.SetXYZT(x, y, z, t);
-    allParticleOutputArray->Add(candidate);
-    if(!pdgParticle) continue;
-
-    if(status == 1)
+  if(momentumUnit > 0 && positionUnit > 0)
+  {
+
+    auto entries = event->TaggedEntries("VarintPackedParticles");
+
+    for(uint64_t entryID : entries)
     {
-      stableParticleOutputArray->Add(candidate);
-    }
-    else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
-    {
-      partonOutputArray->Add(candidate);
+
+      auto mutableParticles = dynamic_cast<model::VarintPackedParticles *>(event->GetEntry(entryID));
+
+      for(int i = 0; i < mutableParticles->pdg_size(); ++i)
+      {
+        pid = mutableParticles->pdg(i);
+        status = mutableParticles->status(i);
+        px = mutableParticles->px(i) / momentumUnit;
+        py = mutableParticles->py(i) / momentumUnit;
+        pz = mutableParticles->pz(i) / momentumUnit;
+        mass = mutableParticles->mass(i) / momentumUnit;
+        x = mutableParticles->x(i) / positionUnit;
+        y = mutableParticles->y(i) / positionUnit;
+        z = mutableParticles->z(i) / positionUnit;
+        t = mutableParticles->t(i) / positionUnit;
+
+        candidate = factory->NewCandidate();
+        candidate->PID = pid;
+        pdgCode = TMath::Abs(candidate->PID);
+        candidate->Status = status;
+        candidate->M1 = mutableParticles->parent1(i);
+        candidate->M2 = mutableParticles->parent2(i);
+        candidate->D1 = mutableParticles->child1(i);
+        candidate->D2 = mutableParticles->child2(i);
+        pdgParticle = pdg->GetParticle(pid);
+        candidate->Charge = mutableParticles->charge(i) / 3.0;
+        //candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999;
+        candidate->Mass = mass;
+        candidate->Momentum.SetXYZM(px, py, pz, mass);
+        candidate->Position.SetXYZT(x, y, z, t);
+        allParticleOutputArray->Add(candidate);
+        if(!pdgParticle) continue;
+
+        if(status == 1)
+        {
+          stableParticleOutputArray->Add(candidate);
+        }
+        else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
+        {
+          partonOutputArray->Add(candidate);
+        }
+      }
     }
   }
-
-  }
-
- } else {
-
-
- auto entries = event->TaggedEntries("Particle");
-
- for (uint64_t entryID : entries) {
-    auto part = dynamic_cast<model::Particle *>(event->GetEntry(entryID));
-    pid = part->pdg();
-    status = part->status();
-    model::XYZF pvector=part->p();
-    px=pvector.x();
-    py=pvector.y();
-    pz=pvector.z();
-    mass = part->mass();
-    auto v =part->vertex();
-    x=v.x();
-    y=v.y();
-    z=v.z();
-    t=v.t(); 
-
-    candidate = factory->NewCandidate();
-    candidate->PID = pid;
-    pdgCode = TMath::Abs(candidate->PID);
-    candidate->Status = status;
-
-    int M1=0;
-    int M2=0;
-    for (int k1=0; k1<part->parent_size(); k1++){
-       if (k1==0) {
-                   auto mother = dynamic_cast<model::Particle *>(event->GetEntry(part->parent(0)));
-                   M1=mother->barcode();
-       }
-       if (k1==1) {
-                   auto mother = dynamic_cast<model::Particle *>(event->GetEntry(part->parent(1)));
-                   M2=mother->barcode();
-       }
+  else
+  {
+
+    auto entries = event->TaggedEntries("Particle");
+
+    for(uint64_t entryID : entries)
+    {
+      auto part = dynamic_cast<model::Particle *>(event->GetEntry(entryID));
+      pid = part->pdg();
+      status = part->status();
+      model::XYZF pvector = part->p();
+      px = pvector.x();
+      py = pvector.y();
+      pz = pvector.z();
+      mass = part->mass();
+      auto v = part->vertex();
+      x = v.x();
+      y = v.y();
+      z = v.z();
+      t = v.t();
+
+      candidate = factory->NewCandidate();
+      candidate->PID = pid;
+      pdgCode = TMath::Abs(candidate->PID);
+      candidate->Status = status;
+
+      int M1 = 0;
+      int M2 = 0;
+      for(int k1 = 0; k1 < part->parent_size(); k1++)
+      {
+        if(k1 == 0)
+        {
+          auto mother = dynamic_cast<model::Particle *>(event->GetEntry(part->parent(0)));
+          M1 = mother->barcode();
+        }
+        if(k1 == 1)
+        {
+          auto mother = dynamic_cast<model::Particle *>(event->GetEntry(part->parent(1)));
+          M2 = mother->barcode();
+        }
+      }
+
+      int D1 = 0;
+      int D2 = 0;
+      for(int k1 = 0; k1 < part->child_size(); k1++)
+      {
+        if(k1 == 0)
+        {
+          auto child = dynamic_cast<model::Particle *>(event->GetEntry(part->child(0)));
+          D1 = child->barcode();
+        }
+
+        if(k1 == 1)
+        {
+          auto child = dynamic_cast<model::Particle *>(event->GetEntry(part->child(1)));
+          D2 = child->barcode();
+        };
+      }
+
+      candidate->M1 = M1;
+      candidate->M2 = M2;
+      candidate->D1 = D1;
+      candidate->D2 = D2;
+
+      pdgParticle = pdg->GetParticle(pid);
+      candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge() / 3.0) : -999;
+      candidate->Mass = mass;
+
+      candidate->Momentum.SetXYZM(px, py, pz, mass);
+
+      candidate->Position.SetXYZT(x, y, z, t);
+
+      allParticleOutputArray->Add(candidate);
+
+      if(!pdgParticle) continue;
+
+      if(status == 1)
+      {
+        stableParticleOutputArray->Add(candidate);
+      }
+      else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
+      {
+        partonOutputArray->Add(candidate);
+      }
     }
 
-
-    int D1=0;
-    int D2=0;
-    for (int k1=0; k1<part->child_size(); k1++){
-       if (k1==0) {
-                   auto child = dynamic_cast<model::Particle *>(event->GetEntry(part->child(0)));
-                   D1=child->barcode();
-       }
-
-      if (k1==1) {
-                   auto child = dynamic_cast<model::Particle *>(event->GetEntry(part->child(1)));
-                   D2=child->barcode();
-         };
-      }
-
-
-    candidate->M1 = M1;
-    candidate->M2 = M2;
-    candidate->D1 = D1;
-    candidate->D2 = D2;
-
-    pdgParticle = pdg->GetParticle(pid);
-    candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999;
-    candidate->Mass = mass;
-
-    candidate->Momentum.SetXYZM(px, py, pz, mass);
-
-    candidate->Position.SetXYZT(x, y, z, t);
-
-    allParticleOutputArray->Add(candidate);
-
-    if(!pdgParticle) continue;
-
-    if(status == 1)
-    {
-      stableParticleOutputArray->Add(candidate);
-    }
-    else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
-    {
-      partonOutputArray->Add(candidate);
-    }
-
-  }
-
-
-  } // end particle type 
-
+  } // end particle type
 }
 
@@ -283,5 +283,7 @@
   if(argc < 4)
   {
-    cout << " Usage: " << appName << " config_file" << " output_file" << " input_file(s)" << endl;
+    cout << " Usage: " << appName << " config_file"
+         << " output_file"
+         << " input_file(s)" << endl;
     cout << " config_file - configuration file in Tcl format," << endl;
     cout << " output_file - output file in ROOT format," << endl;
@@ -330,5 +332,5 @@
       cout << "** INFO: Reading " << argv[i] << endl;
 
-      inputFile=new proio::Reader( argv[i] );
+      inputFile = new proio::Reader(argv[i]);
 
       if(inputFile == NULL)
@@ -338,6 +340,5 @@
       }
 
-
-/*
+      /*
 // this is slow method, but general
       inputFile->SeekToStart(); 
@@ -350,22 +351,18 @@
 */
 
-
-    auto event = new proio::Event();
-
-
-   double varint_energy=0;
-   double varint_length=0;
-
-
-    auto max_n_events = std::numeric_limits<uint64_t>::max();
-    auto nn = inputFile->Skip(max_n_events);
-    cout << "** INFO: " << nn-1 << " events found in ProIO file" << endl;
-    inputFile->SeekToStart();
-    numberOfEvents = nn-1; // last event has only metadata (no particle record)
- 
-    if(numberOfEvents <= 0) continue;
-
-    ExRootProgressBar progressBar(numberOfEvents - 1);
-
+      auto event = new proio::Event();
+
+      double varint_energy = 0;
+      double varint_length = 0;
+
+      auto max_n_events = std::numeric_limits<uint64_t>::max();
+      auto nn = inputFile->Skip(max_n_events);
+      cout << "** INFO: " << nn - 1 << " events found in ProIO file" << endl;
+      inputFile->SeekToStart();
+      numberOfEvents = nn - 1; // last event has only metadata (no particle record)
+
+      if(numberOfEvents <= 0) continue;
+
+      ExRootProgressBar progressBar(numberOfEvents - 1);
 
       // Loop over all objects
@@ -376,20 +373,21 @@
       for(eventCounter = 0; eventCounter < numberOfEvents && !interrupted; ++eventCounter)
       {
-        inputFile->Next(event); 
+        inputFile->Next(event);
         if(event == 0) continue;
 
-       // get metadata
-       if (eventCounter == 0) {
-       auto metadata = event->Metadata();
-       std::cout << "** INFO: ProIO file metadata:" << std::endl;
-       for (auto element : metadata) { 
-        string key=(string)element.first;
-        string value=(string)(*element.second);
-     	std::cout << "** INFO:   " << key << " = " << value << std::endl;
-        if (key=="info:varint_energy") varint_energy=std::stod(value);
-        if (key=="info:varint_length") varint_length=std::stod(value);
-        }
-       }
-
+        // get metadata
+        if(eventCounter == 0)
+        {
+          auto metadata = event->Metadata();
+          std::cout << "** INFO: ProIO file metadata:" << std::endl;
+          for(auto element : metadata)
+          {
+            string key = (string)element.first;
+            string value = (string)(*element.second);
+            std::cout << "** INFO:   " << key << " = " << value << std::endl;
+            if(key == "info:varint_energy") varint_energy = std::stod(value);
+            if(key == "info:varint_length") varint_length = std::stod(value);
+          }
+        }
 
         readStopWatch.Stop();
@@ -397,9 +395,9 @@
         procStopWatch.Start();
 
-        ConvertInput(event, varint_energy, varint_length, 
+        ConvertInput(event, varint_energy, varint_length,
           branchEvent, factory,
           allParticleOutputArray, stableParticleOutputArray,
           partonOutputArray, &readStopWatch, &procStopWatch);
- 
+
         modularDelphes->ProcessTask();
         procStopWatch.Stop();
@@ -414,5 +412,4 @@
       }
 
-
       progressBar.Update(eventCounter, eventCounter, kTRUE);
       progressBar.Finish();
@@ -420,5 +417,4 @@
       delete inputFile;
     }
-
 
     modularDelphes->FinishTask();
