FEDRA emulsion software from the OPERA Collaboration
edbtools.C File Reference
#include "EdbCluster.h"
#include "EdbFrame.h"
#include "EdbView.h"
#include "EdbSegment.h"
#include "EdbDataSet.h"
#include "TEventList.h"
#include "Riostream.h"
#include "stdlib.h"
#include "TCut.h"
Include dependency graph for edbtools.C:

Functions

int main (int argc, char *argv[])
 
Int_t RemoveViews (const char *infile, const char *outfname, const char *cutstr, const char *options="")
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
124 {
125  char fname[9][256] ;
126  char* outname;
127  char cutstr[256];
128  char options[256];
129  sprintf(cutstr,"") ;
130 
131  int nfiles = 0;
132 
133  bool printusage=(argc<3)?true:false;
134  for (int i = 1; i < argc; i++) { // Skip argv[0] (program name)
135  if (!strcmp(argv[i], "-cutv")) { // Process optional arguments
136  if (i + 1 <= argc - 1) sprintf(cutstr,argv[++i]);
137  else printusage=true;
138  }
139  else if (!strcmp(argv[i], "-nocl")) strcat(options,"NOCL") ;
140  else if (!strcmp(argv[i], "-bot")) sprintf(cutstr,"eNframesBot") ;
141  else if (!strcmp(argv[i], "-top")) sprintf(cutstr,"eNframesTop") ;
142  else { // Process non-optional arguments here
143  sprintf(fname[nfiles++],argv[i]);
144  }
145  }
146  if(printusage) {
147  cout << endl << " usage: edbtools <file1> <file2> .... <outfile> [options] " << endl << endl;
148  cout << " merge file1 file2 (up to 8) [if only one input file copy file1 to outfile]" << endl;
149  cout << " options: -top = extract top views" << endl;
150  cout << " -bot = extract bottom views" << endl;
151  cout << " -nocl = do not add the clusters" << endl;
152  cout << " -cutv \"cutview\" = apply the cut \"cutview\" to the views" << endl;
153  cout << " example -cutv \"eAreaID==10\" [extract the fragment 10]" << endl;
154  return 0;
155  };
156 
157  outname = fname[nfiles-1] ;
158 
159  int n_input = nfiles-1 ;
160  cout << " input file(s) : " ;
161  for(int j=0;j<n_input;j++) cout<< fname[j] <<" " ;
162  cout <<endl;
163  cout << " output file : " << outname << endl;
164  cout << " cut views : " << cutstr << endl;
165  cout << " options : " << options << endl;
166 
167 
168  RemoveViews(fname[0], outname, cutstr ,options);
169  strcat(options,"UPDATE") ;
170  for(int j=1;j<n_input;j++) RemoveViews(fname[j], outname, cutstr ,options);
171 
172  return 0;
173 }
Int_t RemoveViews(const char *infile, const char *outfname, const char *cutstr, const char *options="")
Definition: edbtools.C:15
const char * fname
Definition: mc2raw.cxx:41

◆ RemoveViews()

Int_t RemoveViews ( const char *  infile,
const char *  outfname,
const char *  cutstr,
const char *  options = "" 
)
17 {
18  Bool_t addcl(true);
19  char openoption[256];
20  // SCAN OPTIONS
21  if (strstr(options,"NOCL") ) addcl=false;
22 
23  if (strstr(options,"UPDATE") ) sprintf(openoption,"UPDATE");
24  else sprintf(openoption,"RECREATE");
25 
26  // OPEN RAW DATA FILE AND CREATE A CONTAINER FOR ITS VIEWS
27  EdbRun* run1 = new EdbRun(infile,"READ");
28  EdbView* v1=0;
29  v1=run1->GetView();
30  EdbViewHeader* vh1 = v1->GetHeader();
31  TTree* tree = (TTree* ) gDirectory->Get("Views");
32 
33  // OPEN OUTPUT DATA FILE AND CREATE A CONTAINER FOR ITS VIEWS
34  EdbRun* outrun = new EdbRun(outfname,openoption);
35  EdbView* outv=0;
36  outv=outrun->GetView();
37  EdbViewHeader* outvh = outv->GetHeader();
38 
39  // SET THE RUN HEADER
40  EdbRunHeader* rh1 = run1->GetHeader() ;
41  EdbRunHeader* outrh = outrun->GetHeader() ;
42  *outrh = *rh1 ;
43 
44  //SET THE EVENT LIST (GET THE COUPLES WHICH HAVE AT LEAST ONE SEGMENT IN THE VIEW)
45  TCut cut;
46  cut= cutstr ;
47  cut.Print();
48  tree->Draw(">>lst", cut);
49  TEventList *lst = (TEventList*)gDirectory->GetList()->FindObject("lst");
50  Int_t nviews = (Int_t) lst->GetN();
51 
52  cout <<"nviews: "<<nviews <<endl;
53  cout <<endl;
54 
55  // START FILLING VIEWS...
56  printf("Start Filling... ... %3d%%", 0) ;
57 
58  *v1 = *outv ; // otherwise the first entry is empty !!!!!!!!!!!!!!!!!!!!!!!!!!
59 
60  EdbSegment* rawseg;
61  for(Int_t i=0; i<nviews; i++)
62  {
63  if(i%100==0) printf("\b\b\b\b%3d%%",(int)((double)i/double(nviews)*100.));
64  //v1->Clear() ;
65  //outv->Clear() ;
66 
67  v1 = run1->GetEntry(lst->GetEntry(i),1,addcl,1,0,1);
68  //Int_t side= v1->GetNframesTop()? 1 :0 ;
69 
70  /*
71  // copy view header
72  EdbAffine2D const * aff = vh1->GetAffine();
73  outvh->SetAffine(aff->A11(),aff->A12(),aff->A21(),aff->A22(),aff->B1(),aff->B2()) ;
74  outvh->SetAreaID(vh1->GetAreaID());
75  outvh->SetCoordXY(vh1->GetXview(), vh1->GetYview());
76  outvh->SetCoordZ(vh1->GetZ1(),vh1->GetZ2(), vh1->GetZ3(),vh1->GetZ4());
77  outvh->SetNframes(vh1->GetNframesTop(),vh1->GetNframesBot());
78  outvh->SetNsegments(nsegments);
79  outvh->SetViewID(vh1->GetViewID());
80 
81  //copy view frames
82  for(Int_t f=0; f< v1->GetNframes(); f++ ) {
83  EdbFrame* frame = (EdbFrame *) (v1->GetFrames())->At(f) ;
84  outv->AddFrame(frame->GetID(),frame->GetZ(),frame->GetNcl());
85  }
86 
87  if (addcl) v1->AttachClustersToSegments() ;
88  //cout <<"outv:"<< outv<<"\t "<< outv->GetHeader()->GetViewID()<<"\t "<<outv->Nsegments()<<"\t "<<outv->GetSegmentsAddr() <<"\t "<<outv->GetNframes()<< endl;
89  for(Int_t j=0; j<nsegments; j++) {
90  Int_t segID=lst->GetEntry(j);
91  couples->GetEntry(segID);
92  segp = side? s1: s2 ;
93  rawseg = v1->GetSegment(segp->Vid(1));
94  outv->AddSegment(rawseg);
95  if (addcl) {
96  EdbCluster *cl=0;
97  TObjArray *clusters = rawseg->GetElements();
98  if(!clusters) continue;
99  int ncl = clusters->GetLast()+1;
100  for(Int_t k=0; k<ncl; k++ ) {
101  cl = (EdbCluster*)clusters->At(k);
102  outv->AddCluster(cl) ;
103  }
104  }
105  }
106  outrun->AddView(outv);
107  */
108  *v1 = *outv ;
109  outrun->AddView(outv);
110  }
111  printf("\b\b\b\b%3d%%\n",100);
112  // outrun->Print();
113  run1->Close();
114  outrun->Close();
115  return 0;
116 }
TCut cut
Definition: check_shower.C:6
Definition: EdbRunHeader.h:94
Definition: EdbRun.h:74
void Close()
Definition: EdbRun.cxx:466
EdbRunHeader * GetHeader() const
Definition: EdbRun.h:137
EdbView * GetEntry(int entry, int ih=1, int icl=0, int iseg=1, int itr=0, int ifr=0)
Definition: EdbRun.cxx:489
void AddView()
Definition: EdbRun.cxx:332
EdbView * GetView() const
Definition: EdbRun.h:109
Definition: EdbSegment.h:61
Definition: EdbView.h:26
Definition: EdbView.h:134
EdbViewHeader * GetHeader() const
Definition: EdbView.h:163