ReadMezzAFP.h 4.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/***************************************************************************
 *   Copyright (C) 2004 by Olivier Stezowski                               *
 *   stezow(AT)ipnl.in2p3.fr                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
 
/** @file ReadMezzAFP.h header file for ReadMezzAFP.cpp */

#ifndef _ReadMezzAFP
#define _ReadMezzAFP

#include "NarvalInterface.h"
#include "CrystalFrame.h"
#include "FrameBlock.h"
#include "Trigger.h"

31
#include "BashColor.h"
32
#include "XtermProgressBar.h"
33

34 35
#include "AgataFrameFactory.h"
#include "AgataKeyFactory.h"
36 37
#include "BufferIO.h"

38 39 40 41 42 43 44 45
#include <list>
#include <utility>
#include <vector>

//! ReadMezzAFP
/*!

*/
46 47 48

using namespace ADF;

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
class ReadMezzAFP : public ADF::NarvalProducer
{   
public:
  static const int kNCC = ADF::CrystalInterface::kNbCores;
  static const int kNSG = ADF::CrystalInterface::kNbSegments;

private:
	//! source of the frames
	ADF::FileBlock fSourceOfFrames;
private:	
	//! directory where to write files
	std::string fPath;
	//! base for all the files produced
	std::string fBaseForName;
	//! current file 
	FILE *fCurrentFile;
	//! current file number
    unsigned int fCurrentFileNumber;
	//! max size for a file (in bytes)
    unsigned int fMaxSize;
	
	//! fConfMode = 0 to emulate BasicAFP, otherwise based on a catalogue
    short fConfMode;
	//! list of files to ne read in case 
	std::vector< std::string > fListOfFile;
	
private:
	ADF::AgataFrameTrigger fEndOfFrame; 

    std::vector<std::string> split(std::string s, char c);
    bool replace(std::string& str, const std::string& from, const std::string& to);
    bool contains(std::string s1, std::string s2);
    unsigned int uncompress_single_trace_AB(unsigned char* compr, unsigned int csize, unsigned short* trace);

83 84 85
public:
    void PrintStats();
    void ResetStats(){fNEvts=0; fNIgnoredEvts=0;}
86
    bool IsUsingFiler() {return fUseKeyFilter;}
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

protected:
    unsigned short  crystal_id;
    unsigned short  crystal_status;
    unsigned int    evnumber;
    unsigned long long timestamp;

    unsigned int fTraceLengthRaw;

    unsigned short *SegmentTraces[kNSG];
    unsigned short *CoreTraces[kNCC];

    float SegE[kNSG];
    unsigned short SegStatus[kNSG];
    unsigned short SegID[kNSG];

    float CoreE[kNCC];
    unsigned short CoreStatus[kNSG];
    unsigned short CoreID[kNSG];

    ADF::GeSegment *segMezz;    //
    ADF::GeCore    *coreMezz;   //

protected:
    ADF::SharedFP         *fFrameCrystal_Out;
    ADF::AgataFrameTrigger fTrigger;        //! Trigger for the input frame

protected:
    static const int mezzanineMezzHeader =  16;   // fixed header length (short)
    static const int mezzanineChanHeader =   8;   // fixed header length of the mezzanine channels

    static const int MIN_1x6     = -32;
    static const int TOK_BINSIZE =  32;    // normalmente 32
120

121 122 123
private:
    bool fdebug;
    BashColor *fBashColor;
124
    Gw::XtermProgressBar *fProgressBar;
125 126 127 128

protected:
    FILE * fKeyFilterFile;
    bool fUseKeyFilter;
129
    bool fLastKeyIsRead;
130 131 132 133 134 135 136 137 138 139 140 141 142 143

    AgataKey *fKeyToLink;

    BufferIO *fKeyFilterBuffer;

    unsigned int  fNextEvtNbr;
    unsigned long long fNextTS;
    void NextKeyToFind();

private:
    unsigned int fNEvts;
    unsigned int fNIgnoredEvts;


144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
protected:	
    bool NewFile();

    bool ReadEvent();


public:
    ReadMezzAFP();
    virtual ~ReadMezzAFP();

	//! to init globals (static) from a directory
    static void process_config (const char *, unsigned int *) ;
	
	//! Constructor implementation 	
    virtual	void process_initialise (unsigned int *error_code);
	
	//! Destructor implementation  
    virtual	void process_reset (unsigned int *error_code);
		
	//! Produce one block of data  
    virtual unsigned int ProcessBlock (ADF::FrameBlock &) ;
};

#endif