26 #include <gan_tape_erreur.h>
27 #include <gan_tape_general.h>
28 #include <gan_tape_param.h>
29 #include <gan_tape_test.h>
30 #include <gan_tape_alloc.h>
31 #include <gan_tape_mount.h>
32 #include <gan_tape_file.h>
33 #include <acq_mt_fct_ganil.h>
34 #include <acq_ebyedat_get_next_event.h>
35 #include <gan_tape_get_parametres.h>
81 SetFileName(filename);
97 strncpy(fDevice->DevName, fFileName, MAX_CARACTERES);
106 if (fScaler)
delete fScaler;
107 if (fDataParameters)
delete fDataParameters;
108 if (fDevice)
delete fDevice;
110 if (fStructEvent)
delete[] fStructEvent;
111 if (fDataArray)
delete[] fDataArray;
112 if (fEventBrut)
delete[] fEventBrut;
113 if (fEventCtrl)
delete[] fEventCtrl;
145 fIsScalerBuffer =
false;
149 fBuffer =
new in2p3_buffer_struct;
150 fStructEvent =
new char[STRUCTEVENTSIZE];
157 fStatus = acq_get_param_env(lun_id, &DeRetour, argc, argv);
158 if (DeRetour.Val_INT >= 0) fLun = DeRetour.Val_INT;
162 fStatus = acq_get_param_env(device_id, &DeRetour, argc, argv);
163 strncpy(fDevice->DevName, DeRetour.Val_CAR, MAX_CARACTERES);
164 fFileName = DeRetour.Val_CAR;
167 fStatus = acq_get_param_env(autoswbuf_id, &DeRetour, argc, argv);
170 fStatus = acq_get_param_env(swbufon_id, &DeRetour, argc, argv);
174 fStatus = acq_get_param_env(ctrlform_id, &DeRetour, argc, argv);
175 fCtrlForm = DeRetour.Val_INT;
177 fStatus = acq_get_param_env(density_id, &DeRetour, argc, argv);
178 fDensity = DeRetour.Val_INT;
180 fStatus = acq_get_param_env(bufsize_id, &DeRetour, argc, argv);
181 fBufSize = DeRetour.Val_INT;
185 fStatus = acq_get_param_env(evbsize_id, &DeRetour, argc, argv);
186 fEvbsize = DeRetour.Val_INT;
188 fStatus = acq_get_param_env(evcsize_id, &DeRetour, argc, argv);
189 fEvcsize = DeRetour.Val_INT;
191 fEventBrut =
new UShort_t[fEvbsize];
192 fEventCtrl =
new UShort_t[fEvcsize];
197 fCTRLEVNT_HD =
sizeof(CTRL_EVENT) / 2 - 1;
240 Int_t structEvent_size = STRUCTEVENTSIZE;
242 fStatus = acq_dev_is_alloc_c(*fDevice);
243 if (fStatus == ACQ_OK) fAllocated =
true;
245 gan_tape_erreur(fStatus,
"test d'allocation");
249 fStatus = acq_mt_alloc_c(*fDevice);
250 if (fStatus != ACQ_OK) {
251 if (fStatus == ACQ_NOTALLOC)
252 cout <<
"This tape drive is already in use !" << endl;
253 gan_tape_erreur(fStatus,
"allocation");
257 fStatus = acq_mt_mount_c(*fDevice, fDensity, fBufSize);
258 if (fStatus != ACQ_OK) {
259 if (fStatus == ACQ_ALREADYMOUNT)
260 cout <<
"The tape you want to use is already mounted" << endl;
261 gan_tape_erreur(fStatus,
"mount");
265 fStatus = acq_mt_open_c(fDevice, o_read, &fLun);
266 if (fStatus != ACQ_OK) {
267 gan_tape_erreur(fStatus,
"open");
272 fStatus = acq_mt_ini_run_c(fLun,
fBuffer, fBufSize, &fRunNumber,
273 fStructEvent, structEvent_size, Date);
276 if (fStatus != ACQ_OK) {
277 gan_tape_erreur(fStatus,
"Init Run");
280 cout <<
"Run " << fRunNumber <<
" opened" << endl;
301 if (strcmp(fHeader, PARAM_Id) == 0)
302 fDataArraySize = fDataParameters->Fill(
fBuffer->les_donnees.cas.Buf_param);
304 while (strcmp(fHeader, PARAM_Id) == 0);
306 fDataArray =
new UShort_t[fDataArraySize + 1];
307 for (
Int_t i = 1; i <= fDataArraySize; i++) {
321 if ((index < 1) || (index > fDataArraySize)) {
322 cout <<
"Invalid connexion:" << index <<
". Valid only in 1<=index<="
323 << fDataArraySize << endl;
326 *p = &(fDataArray[index]);
338 Int_t index = fDataParameters->GetIndex(parName);
423 if (fStatus)
return (
false);
430 if (strcmp(fHeader, SCALER_Id) == 0) {
431 switch (fWhatScaler) {
435 fScaler->Fill((
scale*) & (
fBuffer->les_donnees.cas.scale));
436 fScaler->DumpScalers();
440 fScaler->Fill((
scale*) & (
fBuffer->les_donnees.cas.scale));
441 fIsScalerBuffer =
true;
444 case kAutoWriteScaler: {
445 fScaler->Fill((
scale*) & (
fBuffer->les_donnees.cas.scale));
446 fScaler->DumpScalers();
452 cout <<
"GTGanilData::Next: unexpected value for fWhatScaler" << endl;
455 if (strcmp(fHeader, EVENTDB_Id) == 0) {
456 fIsScalerBuffer =
false;
459 return (ReadNextEvent());
461 else if (strcmp(fHeader, EVENTCT_Id) == 0) {
462 fIsScalerBuffer =
false;
465 return (ReadNextEvent());
467 else if (strcmp(fHeader, EBYEDAT_Id) == 0) {
468 fIsScalerBuffer =
false;
471 return (ReadNextEvent_EBYEDAT());
473 cout <<
"Unknown header in GTGanilData::Next:" << fHeader << endl;
492 theFilename = fFileName +
".root";
493 else theFilename = filename;
494 TFile theTreeFile(theFilename,
"recreate");
495 TTree theTree(
"AutoTree",
"Automatic filled Tree");
496 for (
Int_t i = 1; i <= fDataArraySize; i++) {
497 TString parName = fDataParameters->GetParName(i);
498 TString parType = parName +
"/s";
499 theTree.
Branch(parName, &(fDataArray[i]), parType);
505 if (nEvents <= 0)
break;
523 fStatus = get_next_event(
fBuffer, fBufSize,
524 (
short*)fEventBrut, fEvbsize, &fEventNumber);
525 if (fStatus == ACQ_OK) {
526 fStatus = s_evctrl((
short*)fEventBrut, (
short*)fEventCtrl,
527 fStructEvent, &fCtrlForm);
528 if (fStatus == GR_OK)
529 return (EventUnravelling((CTRL_EVENT*)fEventCtrl));
531 puts(
"\n>>> Erreur de reconstruction");
535 else if (fStatus == ACQ_ENDOFBUFFER) {
540 gan_tape_erreur(fStatus,
"obtention d'evenement");
545 fStatus = get_next_event(
fBuffer, fBufSize, (
short*)fEventCtrl,
546 fEvcsize, &fEventNumber);
547 if (fStatus == ACQ_OK) {
548 return (EventUnravelling((CTRL_EVENT*)fEventCtrl));
550 else if (fStatus == ACQ_ENDOFBUFFER) {
555 gan_tape_erreur(fStatus,
"obtention d'evenement");
574 UNSINT16* ebyeEventCtrl;
575 fStatus = acq_ebyedat_get_next_event((UNSINT16*)
fBuffer, &ebyeEventCtrl, &fEventNumber, EVCT_VAR);
576 if (fStatus == ACQ_OK)
return (EventUnravelling((CTRL_EVENT*)ebyeEventCtrl));
577 else if (fStatus == ACQ_ENDOFBUFFER) {
582 cout <<
" in ReadNextEvent__EBEYEDAT error status: " << fStatus <<
" n";
587 fStatus = ACQ_BADEVENTFORM;
602 fStatus = acq_mt_read_c(fLun,
fBuffer->Buffer, &fBufSize);
606 strncpy(fHeader,
fBuffer->les_donnees.Ident, 8);
629 Short_t* brutData = &(pCtrlEvent->ct_par);
631 Int_t eventLength = pCtrlEvent->ct_len - fCTRLEVNT_HD;
634 for (
Int_t i = 1; i <= fDataArraySize; i++) {
638 for (
Int_t i = 0; i < eventLength; i += 2) {
640 if (brutData[i] <= fDataArraySize && brutData[i] >= 1) {
641 fDataArray[brutData[i]] = brutData[i + 1];
665 cout <<
"--------- DUMPING EVENT ----------------------------" << endl;
666 cout <<
"------- number:" << fEventCount << endl;
667 for (
Int_t i = 1; i <= fDataArraySize; i++) {
668 if ((
Short_t)fDataArray[i] > -1) cout <<
"index :" << i <<
" " << fDataParameters->GetParName(i) <<
" : " << fDataArray[i] << endl;
670 cout <<
"--------- END ----------------------------" << endl;
682 cout <<
"--------- DUMPING PARAMETERS ----------------------------" << endl;
683 cout <<
"------- number:" << fEventCount << endl;
684 for (
Int_t i = 1; i <= fDataArraySize; i++) {
686 cout <<
"index :" << i <<
" " << fDataParameters->GetParName(i) << endl;
688 cout <<
"--------- END ----------------------------" << endl;
724 if (fWhatScaler == kAutoWriteScaler) {
726 fScalerTree =
new TTree(
"Scalers",
"Automatic filled scalers");
727 fScalerTree->Branch(
"scalers", fScaler, 8000, 99);
730 cout <<
"Error in <GTGanilData::SetScalerBuffersManagement> : ";
731 cout <<
"You must open a writable TFile before calling SetScalerBuffersManagement(kAutoWriteScaler)" << endl;
732 fWhatScaler = kSkipScaler;
756 return (fStatus == ACQ_OK && fLun);
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
virtual void ReadBuffer(char *&buffer)
R__EXTERN TSystem * gSystem
Read GANIL formatted tapes or files.
void InitDefault(const Int_t argc=0, char **argv=NULL)
void DumpEvent(void) const
Dump parameter index, name and value for the current event.
void Connect(const Int_t index, UShort_t **p) const
Connect a pointer to a data to the defined index in the Data Array.
Int_t GetRunNumber(void) const
Returns current run number.
void SetFileName(const TString filename)
bool ReadNextEvent_EBYEDAT(void)
void PrintRunParameters(void) const
Print every class parameters, for now a simple dump.
virtual void SetUserTree(TTree *)
Not used.
void DumpParameterName(void) const
Dump parameter index and name.
Bool_t IsOpen(void) const
virtual void ReadParameters(void)
GTGanilData()
Default constructor.
void SetScalerBuffersManagement(const ScalerWhat_t sc)
void MakeTree(const TString filename="", UInt_t nEvents=kMaxUInt)
virtual ~GTGanilData(void)
virtual bool EventUnravelling(CTRL_EVENT *)
void PrintDataParameters(void) const
ScalerWhat_t
What to do with scaler buffer.
Handle scaler buffers in GANIL DAQ data.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Remove(EStripType s, char c)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
union SCALE::JBUS_SCALE jbus_scale
UNSINT16 Info_jbus[NB_MAX_JBUS]
scale_struct UnScale[NB_MAX_CHANNEL]