15 #include <Compression.h>
48 int main(
int argc,
char* argv[]);
55 clog <<
"\033[1;33;44signal received. You want to quit?\033[0m\n";
82 {
"noecalplus", no_argument, 0,
'e'},
83 {
"notrackerplus", no_argument, 0,
't'},
84 {
"disable", required_argument,
nullptr,
'd'},
85 {
"produce", required_argument,
nullptr,
'p'},
86 {
"nevents", required_argument, 0,
'n'},
87 {
"start", required_argument, 0,
's'},
88 {
"outdir", required_argument, 0,
'o'},
89 {
"help", no_argument, 0,
'h'},
94 fprintf(stderr,
"Usage:\t %s [-n <max_ev>] [-s <start_ev>] [-o <output_dir>] input_file_name1 input_file_name2 ...\n",name);
95 fprintf(stderr,
"Options:\n");
96 fprintf(stderr,
"\t -n, --nevents num \t Max number of event (default: all)\n");
97 fprintf(stderr,
"\t -s, --start num \t Start from event number (default: 0)\n");
98 fprintf(stderr,
"\t -o, --outdir out_dir \t The output dir for the DST files \n");
99 fprintf(stderr,
"\t \t (default: ./ )\n");
100 fprintf(stderr,
"\t -e, --noecalplus \t Not produces EcalPlus tree\n");
101 fprintf(stderr,
"\t -t, --notrackerplus \t Not produces TrackerPlus tree\n");
102 fprintf(stderr,
"\t -d, --disable <section>\t Disable producing of a section\n");
103 fprintf(stderr,
"\t -p, --produce <section>\t Only produce one section\n");
114 int option_index = 0;
116 printf(
"--------------------------------------------------\n");
120 c = getopt_long (argc, argv,
"s:n:o:p:d:het",
126 printf(
"Processing %d events\n", atoi(optarg));
131 printf(
"Starting from event %d\n", atoi(optarg));
136 printf(
"Writing the output files in %s\n", optarg);
142 printf(
"Not producing EcalPlus tree\n");
148 printf(
"Not producing TrackerPlus tree\n");
154 printf(
"Disabling section %s\n", optarg);
156 printf(
"Warning: Uknown section %s\n", optarg);
160 printf(
"Only produce section %s\n", optarg);
162 printf(
"Fatal: Unknown section %s, can not continue...\n", optarg);
172 printf(
"!!! Unknown option found !!!\n");
177 printf(
"--------------------------------------------------\n");
195 int main(
int argc,
char* argv[]){
206 int residualargc = (argc-optind);
210 if (istat<0 || residualargc<=0) {
211 if (istat<-1) fprintf(stderr,
"Error: from the command line\n");
218 AMSChain* ams =
new AMSChain();
219 for (
int ii=optind; ii<argc; ii++) {
221 TString fn = argv[ii];
223 if( fn.BeginsWith(
"/eos/") ) fn.Prepend(
"root://eosams.cern.ch/" );
224 if( fn.BeginsWith(
"/castor/") ) fn.Prepend(
"root://castorpublic.cern.ch/" );
225 if( fn.BeginsWith(
"root://castorpublic") and not fn.Contains(
"svcClass=amsuser") ) {
226 if( fn.Contains(
"?") )
227 fn.Append(
"&svcClass=amsuser");
229 fn.Append(
"?svcClass=amsuser");
233 static Long64_t oldentries=0;
234 Long64_t nentries = ams->GetEntries();
235 printf(
"Added rootupla = %s (%lld entries)\n", argv[ii], nentries-oldentries);
241 printf(
"TChain (%s) with %lld entries\n", ams->ClassName(), ams->GetEntries());
245 Long64_t nentries = ams->GetEntries();
247 Long64_t stop=nentries;
249 if (stop>nentries) stop=nentries;
265 std::vector<string> suffix;
266 std::vector<string> branchname;
267 suffix.assign(
gsection.enabled_sections.begin(),
gsection.enabled_sections.end() );
287 int n_branches=suffix.size();
288 TFile* f[n_branches];
293 myObject::Class()->IgnoreTObjectStreamer();
295 myEvent::Class()->IgnoreTObjectStreamer();
297 myParticle::Class()->IgnoreTObjectStreamer();
299 myTrdTrack::Class()->IgnoreTObjectStreamer();
300 myEcalShower::Class()->IgnoreTObjectStreamer();
301 myBeta::Class()->IgnoreTObjectStreamer();
302 myBetaH::Class()->IgnoreTObjectStreamer();
303 myRichRing::Class()->IgnoreTObjectStreamer();
304 myTrTrack::Class()->IgnoreTObjectStreamer();
306 myTrdK::Class()->IgnoreTObjectStreamer();
307 myTrdQtFromTrTrack::Class()->IgnoreTObjectStreamer();
308 myEcalShowerPlus::Class()->IgnoreTObjectStreamer();
309 myBetaPlus::Class()->IgnoreTObjectStreamer();
310 myBetaHPlus::Class()->IgnoreTObjectStreamer();
311 myRichRingPlus::Class()->IgnoreTObjectStreamer();
312 myTrTrackPlus::Class()->IgnoreTObjectStreamer();
313 myTrdTrackPlus::Class()->IgnoreTObjectStreamer();
315 myInfo::Class()->IgnoreTObjectStreamer();
317 myRTI::Class()->IgnoreTObjectStreamer();
319 myMC::Class()->IgnoreTObjectStreamer();
321 myHeader::Class()->IgnoreTObjectStreamer();
323 myStatus::Class()->IgnoreTObjectStreamer();
326 int complevel=ROOT::CompressionSettings(ROOT::kLZMA, 2);
328 TTree* t3[n_branches];
329 myEventFiller* me = myEventFiller::gethead();
346 std::vector<myTrdTrackPlus*>* vmup = &(mf->
vmup);
347 std::vector<myTrdK*>* vmuktp = &(mf->
vmuktp);
348 std::vector<myTrdK*>* vmukup = &(mf->
vmukup);
349 std::vector<myTrdQtFromTrTrack*>* vmuqtp = &(mf->
vmuqtp);
350 std::vector<myEcalShowerPlus*>* vmep = &(mf->
vmep);
351 std::vector<myBetaPlus*>* vmbp = &(mf->
vmbp);
352 std::vector<myBetaHPlus*>* vmbhp = &(mf->
vmbhp);
353 std::vector<myRichRingPlus*>* vmrp = &(mf->
vmrp);
354 std::vector<myTrTrackPlus*>* vmtp = &(mf->
vmtp);
358 branchname.resize(n_branches);
359 for (
int ii=0; ii<n_branches; ii++) {
360 section_t::mssit smit =
gsection.sections_map.find( suffix[ii] );
361 if( smit ==
gsection.sections_map.end() ){
362 printf(
"Unknown section %s, skipping...\n", suffix[ii].c_str());
365 branchname[ii] = smit->second;
368 TString filename = filename_base+
"_"+suffix[ii]+
".root";
369 printf(
"Opening %s...\n", filename.Data());
370 f[ii] =
new TFile(filename,
"recreate",
"File with Ntuplized AM1SRoot Tree", complevel);
373 if(branchname[ii]==
"fmyEvent") t3[ii] =
new TTree(
"AMSRootNtuplized", Form(
"AMSRootNtuplized (%s)", suffix[ii].c_str()));
374 else t3[ii] =
new TTree(Form(
"AMSRootNtuplized_%s", suffix[ii].c_str()), Form(
"AMSRootNtuplized (%s)", suffix[ii].c_str()));
377 printf(
"Creating branch %s...\n", branchname[ii].c_str());
380 if(branchname[ii]==
"fmyEvent") {
384 t3[ii]->Branch(branchname[ii].c_str(),
"myEvent", &mf, 32000, 100);
386 else if(branchname[ii]==
"ms") {
387 t3[ii]->Branch(branchname[ii].c_str(), &(mf->
ms), 32000, 100);
389 else if(branchname[ii]==
"RTI") {
390 t3[ii]->Branch(branchname[ii].c_str(), &(mf->
RTI), 32000, 100);
405 else if(branchname[ii]==
"vmup") {
406 t3[ii]->Branch(branchname[ii].c_str(),
"std::vector<myTrdTrackPlus*>", &vmup, 32000, 100);
408 else if(branchname[ii]==
"vmukp") {
409 t3[ii]->Branch(
"vmuktp",
"std::vector<myTrdK*>", &vmuktp, 32000, 100);
410 t3[ii]->Branch(
"vmukup",
"std::vector<myTrdK*>", &vmukup, 32000, 100);
412 else if(branchname[ii]==
"vmuqtp") {
413 t3[ii]->Branch(branchname[ii].c_str(),
"std::vector<myTrdQtFromTrTrack*>", &vmuqtp, 32000, 100);
415 else if(branchname[ii]==
"vmep") {
416 t3[ii]->Branch(branchname[ii].c_str(),
"std::vector<myEcalShowerPlus*>", &vmep, 32000, 100);
418 else if(branchname[ii]==
"vmbp") {
419 t3[ii]->Branch(branchname[ii].c_str(),
"std::vector<myBetaPlus*>", &vmbp, 32000, 100);
421 else if(branchname[ii]==
"vmbhp") {
422 t3[ii]->Branch(branchname[ii].c_str(),
"std::vector<myBetaHPlus*>", &vmbhp, 32000, 100);
424 else if(branchname[ii]==
"vmrp") {
425 t3[ii]->Branch(branchname[ii].c_str(),
"std::vector<myRichRingPlus*>", &vmrp, 32000, 100);
427 else if(branchname[ii]==
"vmtp") {
428 t3[ii]->Branch(branchname[ii].c_str(),
"std::vector<myTrTrackPlus*>", &vmtp, 32000, 100);
435 TBranch * branch = t3[ii]->GetBranch(branchname[ii].c_str());
436 if (branch) branch->SetCompressionLevel(6);
437 if (branchname[ii]!=
"RTI") {
439 printf(
"Adding Run and Event branches...\n");
441 t3[ii]->Branch(
"Run", &run);
442 t3[ii]->Branch(
"Event", &evtnum);
444 if (branchname[ii]==
"RTI" || branchname[ii]==
"fmyEvent") {
446 printf(
"Adding Time branch...\n");
448 t3[ii]->Branch(
"Time", &timejmdc);
451 t3[ii]->SetAutoSave(100000000);
452 t3[ii]->AutoSave(
"SaveSelf,Overwrite");
457 AMSEventR* ev = ams->GetEvent(0);
462 long long int accepted=0;
466 bool IsMC= (ev->nMCEventg()>0)?
true:
false,
467 IsISS = not IsMC and ev->Run() > 1305795600,
468 IsTB = not IsMC and ev->Run() < 1305795600;
472 AMSSetupR::LoadISSMC=
false;
475 AMSSetupR::SlowControlR::ReadFromExternalFile =
false;
477 TrdKCluster::IsReadGlobalAlignment =
false;
479 TrdKCluster::ForceReadCalibration =
false;
480 TrdKCluster::ForceReadAlignment =
false;
497 for (jentry=start; jentry<(stop); jentry++) {
501 ams->GetEvent(jentry);
503 Double_t pperc=(100.0*((jentry-start)+1))/(stop-start);
510 evtnum = ev->Event();
511 HeaderR* head = &(ev->fHeader);
512 timejmdc = head->Time[0];
514 printf(
"%lld) @@@@@@@@@@@@@@@@@@@ Run=%d, Event=%d\n", jentry, ev->Run(), ev->Event());
518 printf(
"Accepted %9lld\n",jentry);
523 TRMCFFKEY.NoiseType=1;
524 TRCLFFKEY.UseSensorAlign=1;
532 static TString origfile=
"";
533 Long64_t treeentrynumber = ams->GetTree()->GetReadEntry();
534 int treenumber = ams->GetTreeNumber();
535 TString currfile = ams->GetTree()->GetCurrentFile()->GetName();
536 if (currfile!=origfile) {
539 printf(
"%lld) @@@@@@@@@@@@@@@@@@@@@@@@ %s %d %lld\n", jentry, origfile.Data(), treenumber, treeentrynumber);
544 printf(
"Filling myEvent...\n");
546 me->Fill(treenumber, treeentrynumber);
548 printf(
"myEvent filled...\n");
555 printf(
"Ntuplize: %d\n", evtnum);
561 for (
int jj=0; jj<n_branches; jj++) {
564 printf(
"Filling branch %d (%s)...\n", jj, branchname[jj].c_str());
567 if (!t3[jj])
continue;
569 if (branchname[jj]!=
"RTI") {
585 printf(
"Processed %lld out of %lld: %d%% (accepted %lld, %d%%)\n", (jentry+1-start), stop-start, (
int)perc, accepted, (
int)((100.0*accepted)/(stop-start)));
594 printf(
"Processed %lld out of %lld: %d%% (accepted %lld, %d%%)\n", (jentry+1-start), stop-start, (
int)perc, accepted, (
int)((100.0*accepted)/(stop-start)));
596 for (
int ii=0; ii<n_branches; ii++) {
598 if (branchname[ii]!=
"fmyEvent" && branchname[ii]!=
"RTI") {
599 printf(
"Building index for TTree %d...\n", ii);
600 t3[ii]->BuildIndex(
"Run",
"Event");
602 else if (branchname[ii]==
"RTI") {
603 printf(
"Building index for TTree %d...\n", ii);
604 t3[ii]->BuildIndex(
"Time");
608 t3[ii]->GetUserInfo()->SetOwner(kFALSE);
610 t3[ii]->GetUserInfo()->Add(&myruninfo);
614 for (
int ii=0; ii<n_branches; ii++) {
615 f[ii]->Write(0, TObject::kOverwrite);
617 t3[ii]->GetUserInfo()->Clear(
"nodelete");
619 printf(
"Closing file %s (%d)...\n", f[ii]->GetName(), ii);
630 TString filename =
"dummyname_ntuplized.root";
633 printf(
" Ntuplize::CreateOutputFileName: The input tree pointer is empty\n");
639 ((TTree*)_InputTree)->GetEvent(0);
641 if (((TTree*)_InputTree)->GetEntries() != 0) {
642 rootfile = ((TTree*)_InputTree)->GetCurrentFile();
646 printf(
"The passed TTree/TChain doesn't contain any event! Did you already make TChain::Add()?!\n");
650 TString s(rootfile->GetName());
652 TObjArray* array = s.Tokenize(
"/");
653 for (
int ii=0; ii<array->GetEntries(); ii++) {
654 TString temp = ((TObjString*)array->At(ii))->GetString();
656 if (temp.Contains(
".root")) striped=temp;
660 array->SetOwner(kTRUE);
661 striped.ReplaceAll(
".root",
"");