KaliVeda
Toolkit for HIC analysis
KVFAZIADB.cpp
1 //Created by KVClassFactory on Tue Jan 20 11:52:49 2015
2 //Author: ,,,
3 
4 #include "KVFAZIADB.h"
5 #include "TSystem.h"
6 #include "KVNumberList.h"
7 #include "KVDataSetManager.h"
8 #include "KVRunListLine.h"
9 
10 #include "KVDBParameterList.h"
11 #include "KVDBParameterSet.h"
12 #include "IRODS.h"
13 #include "TRandom.h"
14 #include "KVMultiDetArray.h"
15 
16 KVFAZIADB* gFaziaDB;
17 
19 
20 // BEGIN_HTML <!--
22 /* -->
23 <h2>KVFAZIADB</h2>
24 <h4>database for FAZIA detector</h4>
25 <!-- */
26 // --> END_HTML
28 
29 
30 
33 void KVFAZIADB::init()
34 {
35  //default initialisations
36 
37  fDBType = "FAZIADB";
38 
39  fExceptions = AddTable("Exceptions", "List signals with different PSA parameters");
40  fCalibrations = AddTable("Calibrations", "Available calibration for FAZIA detectors");
41  fOoODets = nullptr;
42  //filenames to manage the data transfer via IRODS
43  fDONEfile = "FromKVFAZIADB_transferdone.list";
44  fFAILEDfile = "FromKVFAZIADB_transferfailed.list";
45 
46  Info("init", "file names for tranfert:\n%s\n%s", fDONEfile.Data(), fFAILEDfile.Data());
47 }
48 
49 
50 
52 
54  "FAZIA experiment parameter database")
55 {
56  init();
57 }
58 
59 
60 
61 
63 
65  "FAZIA experiment parameter database")
66 {
67  init();
68 }
69 
70 
71 
74 
76 {
77  //reset global pointer gFaziaDB if it was pointing to this database
78 
79  if (gFaziaDB == this)
80  gFaziaDB = 0;
81 }
82 
83 
84 
86 
88 {
89  KVExpDB::cd();
90  gFaziaDB = this;
91 
92 }
93 
94 
95 
96 
100 
102 {
103 
104  //Use KVINDRARunListReader utility subclass to read complete runlist
105 
106  //get full path to runlist file, using environment variables for the current dataset
107 
108  ReadNewRunList();
109  ReadSystemList();
110  ReadExceptions();
113  ReadComments();
115  gMultiDetArray->MakeCalibrationTables(this);
117 
118 }
119 
120 
121 
126 
128 {
129  //Read first runlist.dat file if exists
130  //and then read
131  //runsheets
132  KVString line;
133  KVFAZIADBRun* run = 0;
134  TObjArray* toks = 0;
135 
136  std::ifstream fin;
137  if (!OpenCalibFile("Runlist", fin)) {
138  Error("ReadNewRunList()", "Could not open file %s",
139  GetCalibFileName("Runlist").Data());
140  return;
141  }
142  Info("ReadNewRunList()", "Reading run list ...");
143 
144  while (fin.good() && !fin.eof()) {
145  line.ReadLine(fin);
146  if (line.Length() > 1 && !line.BeginsWith("#") && !line.BeginsWith("Version")) {
147 
148  toks = line.Tokenize("|");
149  for (Int_t ii = 0; ii < toks->GetEntries(); ii += 1) {
150  KVString couple = ((TObjString*)toks->At(ii))->GetString();
151  couple.Begin("=");
152  KVString name = couple.Next();
153  name = name.Strip(TString::kBoth);
154  KVString value = "";
155  if (!couple.End()) {
156  value = couple.Next();
157  value = value.Strip(TString::kBoth);
158  }
159  if (name == "run") {
160  run = new KVFAZIADBRun(value.Atoi());
161  }
162  else if (name == "read events") {
163  run->SetEvents(value.Atoi());
164  }
165  else if (name == "good events") {
166  run->SetGoodEvents(value.Atoi());
167  }
168  else if (name == "starting date") {
169  run->SetStartDate(value);
170  }
171  else if (name == "stopping date") {
172  run->SetEndDate(value);
173  }
174  else if (name == "aqcuisition status") {
175  run->SetACQStatus(value);
176  }
177  else if (name == "wrong number of blocks") { //events rejected due to the wrong number of blocks
178  run->SetError_WrongNumberOfBlocks(value.Atoi());
179  }
180  else if (name == "block errors") { //events rejected due to internal error in one block
181  run->SetError_InternalBlockError(value.Atoi());
182  }
183  else if (name == "nfiles") { //number of acquisition files
184  run->SetNumberOfAcqFiles(value.Atoi());
185  }
186  else if (name == "duration") { //duration in seconds of the run
187  run->SetDuration(value.Atof());
188  }
189  else if (name == "frequency") { //number of evts per seconds (aquisition rate)
190  run->SetFrequency(value.Atof());
191  }
192  else if (name == "triggerrate") { //trigger rate
193  run->SetTriggerRate(value.Atof());
194  }
195  else if (name == "mtrigger") { //trigger multiplicity
196  run->SetTrigger(value.Atof());
197  }
198  else if (name == "deadtime") { //deadtime of the acquisition between 0 and 1
199  run->SetDeadTime(value.Atof());
200  }
201  else if (name == "trig info") { //number of trigger block in the acquisition file
202  run->SetNumberOfTriggerBlocks(value.Atoi());
203  }
204  else if (name == "size(GB)") { //size in GB
205  run->SetSize(value.Atof());
206  }
207  else {
208  //Info("ReadNewRunList","Unknown field %s=%s",name.Data(),value.Data());
209  }
210  }
211  delete toks;
212  if (run->GetNumber() < 1) {
213  delete run;
214  }
215  else {
216  //run->ReadRunSheet();
217  AddRun(run);
218  }
219  }
220  }
221  fin.close();
222 
223  std::ifstream ffin;
224  if (!OpenCalibFile("Runsheets", ffin)) {
225  Error("ReadNewRunList()", "Could not open file %s",
226  GetCalibFileName("Runsheets").Data());
227  return;
228  }
229  Info("ReadNewRunList()", "Reading run sheets ...");
230 
231  Bool_t newrun = kFALSE;
232  while (ffin.good() && !ffin.eof()) {
233  line.ReadLine(ffin);
234  if (line.Length() > 1 && !line.BeginsWith("#") && !line.BeginsWith("Version")) {
235 
236  toks = line.Tokenize("|");
237  for (Int_t ii = 0; ii < toks->GetEntries(); ii += 1) {
238  KVString couple = ((TObjString*)toks->At(ii))->GetString();
239  couple.Begin("=");
240  KVString name = couple.Next();
241  name = name.Strip(TString::kBoth);
242  KVString value = "";
243  if (!couple.End()) {
244  value = couple.Next();
245  value = value.Strip(TString::kBoth);
246  }
247  if (name == "run") {
248  Int_t number = value.Atoi();
249  newrun = kFALSE;
250  if (!(run = GetRun(number))) {
251  run = new KVFAZIADBRun(number);
252  newrun = kTRUE;
253  }
254  }
255  else if (name == "read events") {
256  run->SetEvents(value.Atoi());
257  }
258  else if (name == "good events") {
259  run->SetGoodEvents(value.Atoi());
260  }
261  else if (name == "starting date") {
262  run->SetStartDate(value);
263  }
264  else if (name == "stopping date") {
265  run->SetEndDate(value);
266  }
267  else if (name == "aqcuisition status") {
268  run->SetACQStatus(value);
269  }
270  else if (name == "wrong number of blocks") { //events rejected due to the wrong number of blocks
271  run->SetError_WrongNumberOfBlocks(value.Atoi());
272  }
273  else if (name == "block errors") { //events rejected due to internal error in one block
274  run->SetError_InternalBlockError(value.Atoi());
275  }
276  else if (name == "nfiles") { //number of acquisition files
277  run->SetNumberOfAcqFiles(value.Atoi());
278  }
279  else if (name == "duration") { //duration in seconds of the run
280  run->SetDuration(value.Atof());
281  }
282  else if (name == "frequency") { //number of evts per seconds (aquisition rate)
283  run->SetFrequency(value.Atof());
284  }
285  else if (name == "triggerrate") { //trigger rate
286  run->SetTriggerRate(value.Atof());
287  }
288  else if (name == "mtrigger") { //trigger multiplicity
289  run->SetTrigger(value.Atof());
290  }
291  else if (name == "deadtime") { //deadtime of the acquisition between 0 and 1
292  run->SetDeadTime(value.Atof());
293  }
294  else if (name == "trig info") { //number of trigger block in the acquisition file
295  run->SetNumberOfTriggerBlocks(value.Atoi());
296  }
297  else {
298  //Info("ReadNewRunList","Unknown field %s=%s",name.Data(),value.Data());
299  }
300  }
301  delete toks;
302  if (newrun) {
303  if (run->GetNumber() < 1) {
304  delete run;
305  }
306  else {
307  AddRun(run);
308  }
309  }
310  }
311  }
312  ffin.close();
313 }
314 
315 
316 
323 
325 {
326 //Perform the tranfer via irods to ccali for the indicated directory [file]
327 //return status of the iput command
328 // OK if the transfer is done
329 // not OK if it has failed
330 //
331 
332  IRODS ir;
333  Int_t retour = ir.put(
334  Form("-%s %s", option.Data(), file.Data()),
335  Form("%s/%s/%s", ccali_rep.Data(), gDataSet->GetDataPathSubdir(), gDataSet->GetDataTypeSubdir("bin").Data())
336  );
337  return (retour == 0);
338 
339  /*
340  //some lines to test all the process
341  Double_t val = gRandom->Uniform(0,1);
342  printf("%s %lf\n",file.Data(),val);
343  return (val<0.5);
344  */
345 
346 }
347 
348 
349 
354 
356 {
357 // test the status of the transfer
358 // write to the corresponding file : done or failed
359 //
360 
361  Bool_t retour = TransferAcquisitionFileToCcali(Form("%s/run%06d", path.Data(), run), ccali_rep, option);
362  if (retour) {
363  FILE* ff = fopen(fDONEfile.Data(), "a");
364  fprintf(ff, "%d\n", run);
365  fclose(ff);
366  }
367  else {
368  FILE* ff = fopen(fFAILEDfile.Data(), "a");
369  fprintf(ff, "%d\n", run);
370  fclose(ff);
371  }
372 
373  return retour;
374 
375 }
376 
377 
378 
382 
384 {
385 
386 //Remove file where failed tranfer runs are listed
387 //
388  KVNumberList lFAILED;
389  gSystem->Exec(Form("rm %s", fFAILEDfile.Data()));
390 
391 //Loop on run list
392 //If transfer fails, the run number is kept in a kvnumberlist
393 //for status at the end
394 //
395  lrun.Begin();
396  while (!lrun.End()) {
397  Int_t run = lrun.Next();
398  if (!TransferRunToCcali(run, path, ccali_rep, option)) {
399  lFAILED.Add(run);
400  }
401  }
402 
403 //print list of failed tranfers
404  if (!lFAILED.IsEmpty())
405  Warning("TransferRunListToCcali", "Transfer failed for %d runs :\n%s", lFAILED.GetNValues(), lFAILED.AsString());
406 
407 }
408 
409 
410 
412 
413 void KVFAZIADB::StartTransfer(TString filename, TString ccali_rep, TString option)
414 {
415 
416  Int_t run;
417  TString datadir = "";
418 
419 //-----------
420 // list of runs for which transfer failed during the last tentative
421 //-----------
422  KVNumberList lFAILED;
423  KVFileReader fr;
425  while (fr.IsOK()) {
426  fr.ReadLine(0);
427  if (fr.GetCurrentLine() != "") {
428  run = fr.GetCurrentLine().Atoi();
429  lFAILED.Add(run);
430  }
431  }
432  fr.CloseFile();
433 
434 //-----------
435 // list of runs for which transfer succeeded since the beginning
436 //-----------
437  KVNumberList lDONE;
438  fr.Clear();
440  while (fr.IsOK()) {
441  fr.ReadLine(0);
442  if (fr.GetCurrentLine() != "") {
443  run = fr.GetCurrentLine().Atoi();
444  lDONE.Add(run);
445  }
446  }
447  if (lDONE.GetNValues() > 0)
448  Info("StartTransfer", "%d runs already tranfered:\n%s", lDONE.GetNValues(), lDONE.AsString());
449  fr.CloseFile();
450 
451 //-----------
452 // all runs produced
453 //-----------
454 
455  KVNumberList lALL;
456  fr.Clear();
457  fr.OpenFileToRead(filename.Data());
458  while (fr.IsOK()) {
459 
460  fr.ReadLine("|");
461  if (fr.GetCurrentLine().BeginsWith("#")) {
463  line.ReplaceAll("#", "");
464  line = line.StripAllExtraWhiteSpace();
465  line.Begin("=");
466  KVString name = line.Next();
467  if (!line.End() && name == "--dir") {
468  datadir = line.Next();
469  Info("ReadDBFile", "acquisition file directory: %s", datadir.Data());
470  }
471  }
472  else {
473  if (datadir == "") {
474  fr.CloseFile();
475  Warning("ReadDBFile", "no data directory has been found ...");
476  return;
477  }
478  if (fr.GetNparRead() > 0) {
479  for (Int_t ii = 0; ii < fr.GetNparRead(); ii += 1) {
480 
481  KVString couple = fr.GetReadPar(ii);
482  couple.Begin("=");
483  KVString name = couple.Next();
484  name = name.Strip(TString::kBoth);
485  KVString value = "";
486  if (!couple.End()) {
487  value = couple.Next();
488  value = value.Strip(TString::kBoth);
489  }
490  if (name == "run") {
491  run = value.Atoi();
492  if (!lDONE.Contains(run))
493  lALL.Add(run);
494  }
495  }
496  }
497  }
498  }
499  fr.CloseFile();
500 
501  if (lALL.GetNValues() > 0) {
502  Info("StartTransfer", "Start transfer for %d runs:\n%s", lALL.GetNValues(), lALL.AsString());
503  TransferRunListToCcali(lALL, datadir.Data(), ccali_rep, option);
504  }
505  else
506  Info("StartTransfer", "no runs to tranfer ...");
507 
508 }
509 
510 
511 
512 
514 
515 const Char_t* KVFAZIADB::GetFileName(const Char_t* meth, const Char_t* keyw)
516 {
517 
518  TString basic_name = GetCalibFileName(keyw);
519  if (basic_name == "") {
520  Info(meth, "No name found for \"%s\" file", keyw);
521  return "";
522  }
523  Info(meth, "Search for %s for dataset %s ...", basic_name.Data(), gDataSet->GetName());
524  static TString fp;
525  fp = gDataSet->GetFullPathToDataSetFile(basic_name.Data());
526  if (fp == "") {
527  Info(meth, "\tNo file found ...");
528  return "";
529  }
530  return fp.Data();
531 
532 }
533 
534 
535 
537 
539 {
540 
541  TString fp = GetFileName(meth, keyw);
542  if (fp == "")
543  return 0;
544 
545  KVFileReader* fr = new KVFileReader();
546  if (!fr->OpenFileToRead(fp.Data())) {
547  Error(meth, "Error in opening file %s", fp.Data());
548  delete fr;
549  return 0;
550  }
551 
552  Info(meth, "Reading %s file", fp.Data());
553  return fr;
554 
555 }
556 
557 
558 
560 
561 TEnv* KVFAZIADB::GetFileTEnv(const Char_t* meth, const Char_t* keyw)
562 {
563 
564  TString fp = GetFileName(meth, keyw);
565  if (fp == "")
566  return 0;
567 
568  Info(meth, "Reading %s file", fp.Data());
569  TEnv* env = new TEnv();
570  env->ReadFile(fp.Data(), kEnvAll);
571  return env;
572 
573 }
574 
575 
576 
578 
580 {
581  KVFileReader* fr = GetKVFileReader("ReadExceptions()", "Exceptions");
582  if (!fr)
583  return;
584 
585  TList* ll = new TList();
586  KVNumberList lruns;
587  KVDBParameterList* dbp = 0;
588 
589  ll->SetOwner(kFALSE);
590  while (fr->IsOK()) {
591  fr->ReadLine(":");
592  if (fr->GetNparRead() == 2) {
593  if (fr->GetReadPar(0) == "RunRange") {
594  if (ll->GetEntries() > 0) {
595  LinkListToRunRange(ll, lruns);
596  ll->Clear();
597  }
598  lruns.SetList(fr->GetReadPar(1));
599  //printf("nouvelle plage : %s\n", lruns.AsString());
600  }
601  else {
602  KVString name(fr->GetReadPar(0));
603  name.Begin(".");
604  KVString sdet = name.Next();
605 
606  KVString sig = name.Next();
607  if (sig == "QH1" || sig == "QL1" || sig == "I1") sdet.Prepend("SI1-");
608  else if (sig == "Q2" || sig == "I2") sdet.Prepend("SI2-");
609  else if (sig == "Q3") sdet.Prepend("CSI-");
610 
611  KVString par = name.Next();
612  if (!(dbp = (KVDBParameterList*)ll->FindObject(Form("%s.%s", sdet.Data(), sig.Data())))) {
613  dbp = new KVDBParameterList(Form("%s.%s", sdet.Data(), sig.Data()), sdet.Data());
614  dbp->AddKey("Runs", "List of Runs");
615  fExceptions->AddRecord(dbp);
616  ll->Add(dbp);
617  dbp->GetParameters()->SetValue("RunRange", lruns.AsString());
618  dbp->GetParameters()->SetValue("Detector", sdet.Data());
619  dbp->GetParameters()->SetValue("Signal", sig.Data());
620  }
621  dbp->GetParameters()->SetValue(par.Data(), fr->GetDoubleReadPar(1));
622  }
623  }
624  }
625 
626  if (ll->GetEntries() > 0) {
627  LinkListToRunRange(ll, lruns);
628  ll->Clear();
629  }
630 
631  delete ll;
632  delete fr;
633 
634 }
635 
636 
638 
640 {
641  KVFileReader* fr = GetKVFileReader("ReadComments()", "Comments");
642  if (!fr)
643  return;
644 
645  KVFAZIADBRun* dbrun = 0;
646  while (fr->IsOK()) {
647  fr->ReadLine("|");
648  if (fr->GetCurrentLine().BeginsWith("#")) {
649 
650  }
651  else if (fr->GetCurrentLine() == "") {
652 
653  }
654  else {
655  if (fr->GetNparRead() == 2) {
656  KVString srun(fr->GetReadPar(0));
657  srun.Begin("=");
658  srun.Next();
659  KVNumberList lruns(srun.Next());
660  KVString comments(fr->GetReadPar(1));
661  lruns.Begin();
662  while (!lruns.End()) {
663  Int_t run = lruns.Next();
664  dbrun = (KVFAZIADBRun*)GetRun(run);
665  if (dbrun)
666  dbrun->SetComments(comments.Data());
667  }
668  }
669  }
670  }
671  delete fr;
672 
673 }
674 
675 
676 
678 
680 {
681 
682  TEnv* env = GetFileTEnv("ReadRutherfordCounting()", "RutherfordCounting");
683  if (!env)
684  return;
685 
686  TIter next(env->GetTable());
687  TEnvRec* rec = 0;
688  KVFAZIADBRun* dbrun = 0;
689  while ((rec = (TEnvRec*)next())) {
690  TString sname(rec->GetName());
691  dbrun = GetRun(sname.Atoi());
692  dbrun->SetRutherfordCount(TString(rec->GetValue()).Atoi());
693  }
694  delete env;
695 }
696 
697 
698 
700 
702 {
703  KVFileReader* fr = GetKVFileReader("ReadRutherfordCrossSection()", "RutherfordCrossSection");
704  if (!fr)
705  return;
706 
707  KVFAZIADBRun* dbrun = 0;
708  KVDBSystem* dbsys = 0;
709  while (fr->IsOK()) {
710  fr->ReadLine(":");
711  if (fr->GetCurrentLine().BeginsWith("#")) {
712 
713  }
714  else if (fr->GetCurrentLine() == "") {
715 
716  }
717  else {
718  if (fr->GetNparRead() == 2) {
719  dbsys = GetSystem(fr->GetReadPar(0));
720  if (dbsys) {
721  Double_t val = fr->GetDoubleReadPar(1);
722  TIter next(dbsys->GetRuns());
723  while ((dbrun = (KVFAZIADBRun*)next())) {
724  dbrun->SetRutherfordCrossSection(val);
725  }
726  }
727  }
728  }
729  }
730  fr->CloseFile();
731  delete fr;
732 
733 }
734 
735 
736 
738 
740 {
741 
742  KVFileReader* fr = GetKVFileReader("ReadCalibrationFiles()", "CalibrationFiles");
743  if (!fr)
744  return;
745 
746  while (fr->IsOK()) {
747  fr->ReadLine(0);
748  if (fr->GetCurrentLine().BeginsWith("#") || fr->GetCurrentLine() == "") {}
749  else {
751  }
752  }
753  fr->CloseFile();
754  delete fr;
755 
756 }
757 
758 
760 
761 void KVFAZIADB::ReadCalibFile(const Char_t* filename)
762 {
763 
764  Bool_t find = kFALSE;
765  TString fullpath = "";
766  if (gSystem->Exec(Form("test -e %s/%s", GetDataSetDir(), filename)) == 0) {
767  //Info("ReadCalibFile", "%s/%s do not exist", GetDataSetDir(), filename);
768  //return;
769  find = kTRUE;
770  fullpath.Form("%s/%s", GetDataSetDir(), filename);
771  }
772  else if (gSystem->Exec(Form("test -e %s", filename)) == 0) {
773  //Info("ReadCalibFile", "%s do not exist", filename);
774  //return;
775  find = kTRUE;
776  fullpath.Form("%s", filename);
777  }
778  if (!find) {
779  Info("ReadCalibFile", "%s does not exist or not found", filename);
780  return;
781  }
782 
783  Info("ReadCalibFile", "file : %s found", fullpath.Data());
784  TEnv env;
785  env.ReadFile(Form("%s", fullpath.Data()), kEnvAll);
786  TIter next(env.GetTable());
787  TEnvRec* rec = 0;
788  KVDBParameterSet* par = 0;
789  KVNumberList default_run_list = GetRunList();
790 
791  TString ssignal = "";
792  TString stype = "";
793 
794  while ((rec = (TEnvRec*)next())) {
795  TString sname(rec->GetName());
796  if (sname == "Signal") {
797  ssignal = rec->GetValue();
798  }
799  else if (sname == "CalibType") {
800  stype = rec->GetValue();
801  }
802  else if (sname == "RunList") {
803  default_run_list.Set(rec->GetValue());
804  }
805  else {
806  KVString lval(rec->GetValue());
807  Int_t np = 0;
808  lval.Begin(",");
809  while (!lval.End()) {
810  KVString sval = lval.Next();
811  np += 1;
812  }
813  par = new KVDBParameterSet(sname.Data(), stype.Data(), np);
814 
815  np = 0;
816  lval.Begin(",");
817  while (!lval.End()) {
818  par->SetParameter(np++, lval.Next().Atof());
819  }
820  fCalibrations->AddRecord(par);
821  LinkRecordToRunRange(par, default_run_list);
822  }
823  }
824 
825  if (ssignal == "") Error("ReadCalibFile", "No signal defined");
826  if (stype == "") Error("ReadCalibFile", "No calibration type defined");
827 }
828 
829 
830 
834 
836 {
837 
838  //Lit le fichier ou sont listes les dedtecteurs ne marchant plus au cours
839  //de la manip
840  TEnv* env = GetFileTEnv("ReadOoODetectors()", "OoODet");
841  if (!env)
842  return;
843 
844  fOoODets = AddTable("OoO Detectors", "Name of out of order detectors");
845 
846  KVDBRecord* dbrec = 0;
847 
848  TEnvRec* rec = 0;
849 
850  TIter it(env->GetTable());
851  while ((rec = (TEnvRec*)it.Next())) {
852  KVString srec(rec->GetName());
853  KVNumberList nl(rec->GetValue());
854 
855  if (srec.Contains(",")) {
856  srec.Begin(",");
857  while (!srec.End()) {
858  dbrec = new KVDBRecord(srec.Next(), "OoO Detector");
859  dbrec->AddKey("Runs", "List of Runs");
860  fOoODets->AddRecord(dbrec);
861  LinkRecordToRunRange(dbrec, nl);
862  }
863  }
864  else {
865  dbrec = new KVDBRecord(rec->GetName(), "OoO Detector");
866  dbrec->AddKey("Runs", "List of Runs");
867  fOoODets->AddRecord(dbrec);
868  LinkRecordToRunRange(dbrec, nl);
869  }
870  }
871  delete env;
872 }
873 
874 
875 //---------------------------------------
877 //---------------------------------------
878 
879 
894 {
895  /*
896  Use this method in order to read runs written on disk
897  during the experiment
898  File is produced with main information for each run :
899  number of files
900  size
901  starting date
902  Information on runs has to completed after reading acquisition file
903  specially information on trigger and deatdime
904 
905  usage : acqfiles_dir is the repository where acquisition files are written
906 
907  2 output files are written
908  - runlist.dat containing all runs
909  - database.log giving a summarize of stored data
910  the two file names are set by default in .kvrootrc
911 
912  */
913  if (gSystem->Exec(Form("test -d %s", acqfiles_dir.Data())) != 0) {
914  Error("BuildQuickAndDirtyDataBase", "%s is not an existing directory", acqfiles_dir.Data());
915  return;
916  }
917 
918  TString sfout = GetCalibFileName("Runlist");
919  FILE* fout = fopen(sfout.Data(), "w");
920  fprintf(fout, "# DataSet %s\n", gDataSet->GetName());
921  fprintf(fout, "# Runlist generated by KVFAZIADB::BuildQuickAndDirtyDataBase from files located at:\n");
922  fprintf(fout, "# --dir=%s\n", acqfiles_dir.Data());
923 
924  TString sflog = GetCalibFileName("DBLog");
925  FILE* flog = fopen(sflog.Data(), "w");
926  fprintf(flog, "# DataSet %s\n", gDataSet->GetName());
927  fprintf(flog, "# Log generated by KVFAZIADB::BuildQuickAndDirtyDataBase from files located at:\n");
928  fprintf(flog, "# --dir=%s\n", acqfiles_dir.Data());
929 
930  Int_t run, nfiles;
931  Long64_t size = 0;
932  Long64_t totalsize = 0;
933  Int_t date, idx;
934  KVDatime kvdate;
935 
936  KVString ldir = gSystem->GetFromPipe(Form("du %s", acqfiles_dir.Data()));
937  ldir.Begin("\n");
938  Int_t numberofruns = 0;
939  KVNumberList lruns;
940 
941  while (!ldir.End()) {
942  KVString sdir = ldir.Next();
943  sdir.Begin("\t");
944  size = sdir.Next().Atoll(); // /TMath::Power(2,10)+1; //read values are in KB
945  sdir = gSystem->BaseName(sdir.Next());
946  if (sscanf(sdir.Data(), "run%d", &run) == 1) {
947  totalsize += size;
948  Int_t dmin = 0;
949  Int_t dmax = 0;
950  KVString lfile = gSystem->GetFromPipe(Form("ls %s/%s", acqfiles_dir.Data(), sdir.Data()));
951  lfile.Begin("\n");
952  nfiles = 0;
953  while (!lfile.End()) {
954  KVString sfile = lfile.Next();
955  //FzEventSet-1434434675-41784.pb
956  if (sscanf(sfile.Data(), "FzEventSet-%d-%d.pb", &date, &idx) == 2) {
957  if (dmin == 0) {
958  dmin = dmax = date;
959  }
960  else {
961  if (date < dmin) dmin = date;
962  if (date > dmax) dmax = date;
963  }
964  nfiles += 1;
965  }
966  }
967  if (nfiles == 0 || size == 0) {
968  Warning("BuildQuickAndDirtyDataBase", "%d -> empty run", run);
969  }
970  kvdate.Set(dmin);
971  fprintf(fout, "run=%d | starting date=%s | nfiles=%d | size(GB)=%1.2lf\n", run, kvdate.AsString(), nfiles, size * TMath::Power(2., -20));
972  numberofruns += 1;
973  lruns.Add(run);
974  }
975  else {
976  Double_t conv = TMath::Power(2., -30);
977  fprintf(flog, "total size %lld - %lld\n", size, totalsize);
978  fprintf(flog, "total size (TB) %1.2lf - %1.2lf\n", size * conv, totalsize * conv);
979  fprintf(flog, "number of runs %d\n", numberofruns);
980  fprintf(flog, "last run %d done at %s\n", lruns.Last(), kvdate.AsString());
981  }
982  }
983 
984  fclose(fout);
985  fclose(flog);
986 }
987 
988 
int Int_t
size_t size(const MatrixT &matrix)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
kEnvAll
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Interface to IRODS (Integrated Rule-Oriented Data System) DMS client.
Definition: IRODS.h:15
Int_t put(const Char_t *source, const Char_t *target=".") override
put a new file into IRODS space.
Definition: IRODS.cpp:101
To store calibration parameters in a database ,.
KVNameValueList * GetParameters()
To store calibration parameters in a database ,.
void SetParameter(UShort_t i, Double_t val)
Record folder for the database.
Definition: KVDBRecord.h:43
virtual Bool_t AddKey(KVDBKey *key, Bool_t check=kTRUE)
Definition: KVDBRecord.cpp:65
virtual Int_t GetNumber() const
Definition: KVDBRecord.h:73
void SetComments(const KVString &comments)
Definition: KVDBRun.h:272
void SetTrigger(Int_t trig)
Definition: KVDBRun.h:244
Database class used to store information on different colliding systems studied during an experiment....
Definition: KVDBSystem.h:52
KVUnownedList * GetRuns() const
Returns a sorted list of all the runs associated with this system.
Definition: KVDBSystem.h:118
virtual Bool_t AddRecord(KVDBRecord *add)
Definition: KVDBTable.cpp:74
virtual Bool_t AddTable(KVDBTable *table)
Definition: KVDataBase.cpp:84
KVString GetDataTypeSubdir(const Char_t *type) const
Definition: KVDataSet.h:206
virtual const Char_t * GetDataPathSubdir() const
Definition: KVDataSet.h:201
TString GetFullPathToDataSetFile(const Char_t *filename)
Definition: KVDataSet.cpp:1875
Extension of TDatime to handle various useful date formats.
Definition: KVDatime.h:33
Base class to describe database of an experiment ,,.
Definition: KVExpDB.h:61
virtual KVDBSystem * GetSystem(const Char_t *system) const
Definition: KVExpDB.h:151
virtual void ReadSystemList()
Definition: KVExpDB.cpp:248
virtual void cd()
Definition: KVExpDB.cpp:576
void AddRun(KVDBRun *r)
Definition: KVExpDB.h:122
TString GetCalibFileName(const Char_t *type) const
Definition: KVExpDB.h:175
const KVNumberList & GetRunList() const
Definition: KVExpDB.h:143
virtual void LinkListToRunRange(TList *list, const KVNumberList &nl)
Link the records contained in the list to the set of runs (see LinkRecordToRunRanges).
Definition: KVExpDB.cpp:199
const Char_t * GetDataSetDir() const
Definition: KVExpDB.h:202
virtual void LinkRecordToRunRange(KVDBRecord *rec, UInt_t first_run, UInt_t last_run)
Definition: KVExpDB.cpp:90
Bool_t OpenCalibFile(const Char_t *type, std::ifstream &fs) const
Definition: KVExpDB.cpp:432
TString fDataSet
the name of the dataset to which this database is associated
Definition: KVExpDB.h:64
Database entry for a run in a FAZIA experiment.
Definition: KVFAZIADBRun.h:15
void SetNumberOfAcqFiles(Int_t)
void SetDuration(Double_t)
void SetGoodEvents(Int_t)
void SetError_InternalBlockError(Int_t)
void SetEvents(ULong64_t evt_number)
Definition: KVFAZIADBRun.h:63
void SetError_WrongNumberOfBlocks(Int_t)
void SetStartDate(const KVString &date)
Definition: KVFAZIADBRun.h:67
void SetRutherfordCrossSection(Double_t)
void SetRutherfordCount(Int_t)
void SetSize(Double_t s)
Definition: KVFAZIADBRun.h:75
void SetACQStatus(const KVString &status)
void SetFrequency(Double_t)
void SetTriggerRate(Double_t)
void SetDeadTime(Double_t)
void SetNumberOfTriggerBlocks(Double_t)
void SetEndDate(const KVString &d)
Definition: KVFAZIADBRun.h:71
Experiment database for FAZIA.
Definition: KVFAZIADB.h:22
const Char_t * GetFileName(const Char_t *meth, const Char_t *keyw)
Definition: KVFAZIADB.cpp:515
Bool_t TransferRunToCcali(Int_t run, TString path, TString ccali_rep="/fazia", TString option="frv")
Definition: KVFAZIADB.cpp:355
TString fFAILEDfile
Definition: KVFAZIADB.h:37
void ReadRutherfordCrossSection()
Definition: KVFAZIADB.cpp:701
Bool_t TransferAcquisitionFileToCcali(TString file, TString ccali_rep="/fazia", TString option="frv")
Definition: KVFAZIADB.cpp:324
TString fDONEfile
Definition: KVFAZIADB.h:36
void TransferRunListToCcali(KVNumberList lrun, TString path, TString ccali_rep="/fazia", TString option="frv")
Definition: KVFAZIADB.cpp:383
void init()
default initialisations
Definition: KVFAZIADB.cpp:33
void BuildQuickAndDirtyDataBase(TString)
Definition: KVFAZIADB.cpp:876
KVDBTable * fExceptions
table of exceptions
Definition: KVFAZIADB.h:27
void ReadNewRunList()
Definition: KVFAZIADB.cpp:127
void cd() override
Definition: KVFAZIADB.cpp:87
KVFileReader * GetKVFileReader(const Char_t *meth, const Char_t *keyw)
Definition: KVFAZIADB.cpp:538
KVDBTable * fCalibrations
table for calibrations
Definition: KVFAZIADB.h:28
void ReadRutherfordCounting()
Definition: KVFAZIADB.cpp:679
void Build() override
Definition: KVFAZIADB.cpp:101
void ReadExceptions()
Definition: KVFAZIADB.cpp:579
void ReadComments() override
Definition: KVFAZIADB.cpp:639
void ReadCalibrationFiles()
Definition: KVFAZIADB.cpp:739
void StartTransfer(TString filename="runlist.dat", TString ccali_rep="/fazia", TString option="frv")
Definition: KVFAZIADB.cpp:413
virtual ~KVFAZIADB()
reset global pointer gFaziaDB if it was pointing to this database
Definition: KVFAZIADB.cpp:75
KVFAZIADBRun * GetRun(Int_t run) const
Definition: KVFAZIADB.h:48
KVDBTable * fOoODets
(optional) Liste les detecteurs hors service
Definition: KVFAZIADB.h:29
TEnv * GetFileTEnv(const Char_t *meth, const Char_t *keyw)
Definition: KVFAZIADB.cpp:561
virtual void ReadOoODetectors()
Definition: KVFAZIADB.cpp:835
void ReadCalibFile(const Char_t *filename)
Definition: KVFAZIADB.cpp:761
Handle reading columns of numeric data in text files.
Definition: KVFileReader.h:121
KVString GetCurrentLine()
Definition: KVFileReader.h:320
void CloseFile()
Definition: KVFileReader.h:237
ReadStatus ReadLine(const KVString &pattern="")
Definition: KVFileReader.h:243
void Clear(Option_t *="") override
Definition: KVFileReader.h:195
Double_t GetDoubleReadPar(Int_t pos) const
Definition: KVFileReader.h:334
Int_t GetNparRead() const
Definition: KVFileReader.h:325
Bool_t IsOK()
Definition: KVFileReader.h:231
KVString GetReadPar(Int_t pos) const
Definition: KVFileReader.h:342
Bool_t OpenFileToRead(const KVString &filename)
Definition: KVFileReader.h:210
static KVMultiDetArray * MakeMultiDetector(const Char_t *dataset_name, Int_t run=-1, TString classname="KVMultiDetArray", KVExpDB *db=nullptr)
virtual void MakeCalibrationTables(KVExpDB *)
void SetValue(const Char_t *name, value_type value)
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:85
Bool_t Contains(Int_t val) const
returns kTRUE if the value 'val' is contained in the ranges defined by the number list
const Char_t * AsString(Int_t maxchars=0) const
Bool_t End(void) const
Definition: KVNumberList.h:199
Int_t GetNValues() const
void Begin(void) const
void SetList(const TString &)
void Add(Int_t)
Add value 'n' to the list.
void Set(const TString &l)
Definition: KVNumberList.h:135
Bool_t IsEmpty() const
Definition: KVNumberList.h:175
Int_t Last() const
Returns largest number included in list.
Int_t Next(void) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
void Begin(TString delim) const
Definition: KVString.cpp:565
Bool_t End() const
Definition: KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
virtual Int_t GetEntries() const
virtual void SetOwner(Bool_t enable=kTRUE)
void Set()
const char * AsString() const
THashList * GetTable() const
virtual Int_t ReadFile(const char *fname, EEnvLevel level)
TObject * Next()
void Clear(Option_t *option="") override
TObject * FindObject(const char *name) const override
void Add(TObject *obj) override
const char * GetName() const override
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
Int_t Atoi() const
Double_t Atof() const
const char * Data() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Prepend(char c, Ssiz_t rep=1)
void Form(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Long64_t Atoll() const
virtual Int_t Exec(const char *shellcmd)
virtual const char * BaseName(const char *pathname)
virtual TString GetFromPipe(const char *command)
long long Long64_t
TLine * line
void Info(const char *location, const char *fmt,...)
rec
Double_t Power(Double_t x, Double_t y)
ClassImp(TPyArg)