source: Idarraga/mpxdataconverter/MediPixROOTConverter.cpp @ 277

Last change on this file since 277 was 277, checked in by idarraga, 12 years ago
File size: 6.0 KB
Line 
1/*
2 * John Idarraga <idarraga@cern.ch>
3 *
4 */
5
6#include <iostream>
7#include <string>
8#include <vector>
9
10#include "TH2.h"
11#include "TCanvas.h"
12#include "TApplication.h"
13#include "TColor.h"
14#include "TPaletteAxis.h"
15#include "TStyle.h"
16#include "TROOT.h"
17#include "TPaveLabel.h"
18#include "TControlBar.h"
19#include "TObject.h"
20#include "TString.h"
21
22#include "MediPixViewer.h"
23#include "listHandler.h"
24#include "control.h"
25#include "MediPixWriteToEntuple.h"
26#include "allpix_dm.h"
27
28using namespace std;
29
30void checkParameters(int, char**, TString *);
31void histoProperties(TH2I *, TCanvas *);
32TApplication * g_theApp = new TApplication("Output", 0, NULL);
33Int_t g_direction = 0;
34
35int main(int argc, char ** argv){
36
37  /////////////////////////////////////
38  // check flags
39  TString tempScratchDir = "";
40  checkParameters(argc, argv, &tempScratchDir);
41
42  // create ntuple and FramesHandler
43  TString dataset = argv[2];
44  WriteToNtuple MPXnTuple(dataset, tempScratchDir);
45  FramesHandler frames(dataset);
46
47  long int skipFrames = 0;
48  if(argc == 5)
49          skipFrames = atoi(argv[4]);
50
51  /////////////////////////////////////
52  // Handle the list of files
53  ListHandler handlerL(argv[1]);
54  std::vector<std::string> listOfFiles = handlerL.getListToLoop(tempScratchDir, FRAME_FILES);
55  std::cout << "[INFO] there are " << listOfFiles.size() << " frame files in directory" << std::endl;
56
57  std::vector<std::string> listOfDSCFiles = handlerL.getListToLoop(tempScratchDir, DSC_FILES);
58  std::cout << "[INFO] there are " << listOfDSCFiles.size() << " DSC files in directory" << std::endl;
59
60
61  if(listOfFiles.empty()){
62    std::cout << "[ERROR] I could not find any frame files in the specified directory," << std::endl;
63    std::cout << "        or the dir does not exist at all ... leaving" << std::endl;
64    exit(1);
65  }
66
67  /* make sure frames list and DSC list match alright */
68  if(listOfDSCFiles.size() != 0)
69    listOfDSCFiles = handlerL.OrderFilesPairMatch(listOfFiles, listOfDSCFiles);
70
71/*
72  vector<std::string>::iterator itrr = listOfDSCFiles.begin();
73  for( ; itrr != listOfDSCFiles.end() ; itrr++){
74          cout << *itrr << endl;
75  }
76  exit(1);
77*/
78
79  if((listOfFiles.size() != listOfDSCFiles.size()) && listOfDSCFiles.size() != 0)
80    {
81      std::cout << "[ERROR] you have a different amount of dsc and frame files." << std::endl;
82      std::cout << "        You probably have an extra file that doesn't correspond" << std::endl;
83      std::cout << "        to the data taking ... check it out.  Giving up." << std::endl;
84      exit(1);
85    }
86
87
88  Long_t filesItr;
89  std::string oneFileName = "";
90  std::string oneDSCFileName = "";
91
92  for(filesItr = 0 ; filesItr < (Int_t)listOfFiles.size() ; filesItr++)
93    {
94
95          if(filesItr < skipFrames) continue; // skip if needed
96
97          oneFileName = listOfFiles[filesItr];
98      oneDSCFileName = listOfDSCFiles[filesItr];
99      //frames.getAFrameMatrix((TString) oneFileName, (TString) oneDSCFileName);
100      bool frameread = frames.readOneFrame((TString) oneFileName, (TString) oneDSCFileName);
101
102      if(frameread) {
103          MPXnTuple.fillVars(&frames);
104      }
105
106    }
107
108  MPXnTuple.closeNtuple();
109
110  std::cout << "[ OK ] done with the conversion.  Check your output file --> " 
111            << MPXnTuple.GetNtupleFileName() << std::endl;
112
113
114  // erasing possible remaining working files
115
116  std::string command0 = "/bin/bash -c 'if [ -e ";
117  if(tempScratchDir.Length() > 0) { command0 += tempScratchDir.Data(); command0 += "/"; }
118  command0 += "listOfFiles.txt ] ; then rm -f ";
119  if(tempScratchDir.Length() > 0) { command0 += tempScratchDir.Data(); command0 += "/"; }
120  command0 += "listOfFiles.txt ; fi'";
121
122  std::string command02 = "/bin/bash -c 'if [ -e ";
123  if(tempScratchDir.Length() > 0) { command02 += tempScratchDir.Data(); command02 += "/"; }
124  command02 += "listOfFiles.dsc.txt ] ; then rm -f ";
125  if(tempScratchDir.Length() > 0) { command02 += tempScratchDir.Data(); command02 += "/"; }
126  command02 += "listOfFiles.dsc.txt ; fi'";
127
128  system(command0.c_str());
129  system(command02.c_str());
130
131  return 0;
132}
133
134void checkParameters(int argc, char ** argv, TString * tempScratchDir){
135
136  if(argc < 3)
137    {
138      std::cout << "  use:" << std::endl;
139      std::cout << "      " << argv[0] << " pathToData  outputFileName  tempScratchDir(optional.  ./ default)  skip(optional)" << std::endl;
140      std::cout << "       pathToData   : Directory where your have stored your data in ascii" << std::endl;
141      std::cout << "                      format (uncompressed). Can be an absolute or " << std::endl; 
142      std::cout << "                      relative path." << std::endl;
143      std::cout << "       dataSetNumber: A short string to easily identify your data later on." << std::endl;
144      std::cout << "                      Example --> MediPix_SPS_TOTmode_25-06-2007" << std::endl;
145      std::cout << "                      please do not use special character or spaces." << std::endl;
146      std::cout << "       tempFilesDir : In case you can only read from the directory" << std::endl;
147      std::cout << "                      containing the data but can't write, you can" << std::endl;
148      std::cout << "                      tell " << argv[0] << "to use a different temp dir."<< std::endl;
149      std::cout << "       skip         : Number of events to skip optional (int)" << std::endl;
150
151      exit(1);
152    }
153
154  TString dataSet = argv[2];
155
156  if (dataSet == "" || dataSet.Contains(' '))
157    {
158      std::cout << "[ERROR] badformat in dataSet !" << std::endl;
159      std::cout << "        dataSetNumber: example --> MediPix_SPS_TOTmode_25-06-2007" << std::endl;
160      std::cout << "        please do not use special character or spaces." << std::endl;
161      exit(1);
162    }
163
164  // user decided to use a different scratch dir
165  // optional
166  if(argc > 2){
167    *tempScratchDir += argv[3];
168    if(tempScratchDir->Length() == 0) *tempScratchDir = "./";
169    std::cout << "[INFO] working directory is " << *tempScratchDir << std::endl;
170  }
171
172}
173
174
175void histoProperties(TH2I * h1, TCanvas * c){
176
177  h1->SetStats(false);
178  gStyle->SetPalette(1,0); 
179
180  c->SetBorderMode(0);
181  c->SetFillColor(kWhite);
182
183  c->Update();
184
185}
Note: See TracBrowser for help on using the repository browser.