Commit b76bb0ad authored by dino's avatar dino
Browse files

Changed the way to write event_tstdiff.bdat in CrystalProducerPSA.

Removed tests on OS_CYGWIN.

git-svn-id: svn://gal-serv.lnl.infn.it/agata/trunk/narval_emulator@1117 170316e4-aea8-4b27-aad4-0380ec0519c9
parent b5dd9519
......@@ -21,14 +21,10 @@
#define OS_LINUX 1
#define OS_WINDOWS 2
#define OS_CYGWIN 3 // rather useless ==> to be removed ??
#define OS_CYGWIN 3 // rather useless ==> removed from the code
#define OS_APPLE 4
#if defined(__CYGWIN__)
#ifdef OS_TYPE
#undef OS_TYPE
#endif
#define OS_TYPE OS_CYGWIN
#elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) || defined(_MSC_VER)
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) || defined(_MSC_VER)
#ifdef OS_TYPE
#undef OS_TYPE
#endif
......@@ -38,12 +34,19 @@
#undef OS_TYPE
#endif
#define OS_TYPE OS_LINUX
#elif defined(OS_TYPE)
#if !(OS_TYPE == OS_LINUX) && !(OS_TYPE == OS_WINDOWS) && !(OS_TYPE == OS_CYGWIN)
#error OS_TYPE should be either OS_LINUX or OS_WINDOWS or OS_CYGWIN
//#elif defined(something for apple...)
// #ifdef OS_TYPE
// #undef OS_TYPE
// #endif
// #define OS_TYPE OS_APPLE
#endif
#if defined(OS_TYPE)
#if !(OS_TYPE == OS_LINUX) && !(OS_TYPE == OS_WINDOWS)
#error OS_TYPE should be either OS_LINUX or OS_WINDOWS
#endif
#else
#error Could not detect system to define OS_TYPE as S_LINUX or OS_WINDOWS or OS_CYGWIN
#error Could not detect system to define OS_TYPE as OS_LINUX or OS_WINDOWS
#endif
/////////////////////////////////////////////////////
......
......@@ -32,12 +32,11 @@ public:
fp = fopen(fname.c_str(), "wb");
status = (fp != NULL);
}
~sAppend()
virtual ~sAppend()
{
flush();
fclose(fp);
std::cout << fname << " --> " << totcount << " counts "
<< " ( " << (totcount + length-1)/length << "*" << length << " )" << std::endl;
std::cout << fname << " --> " << totcount << " counts " << std::endl;
}
void clear()
{
......@@ -48,8 +47,8 @@ public:
{
if(count) {
totcount += count;
size_t nn = fwrite(spec, sizeof(T), length, fp);
status = (nn == length);
size_t nn = fwrite(spec, sizeof(T), count, fp);
status = (nn == count);
clear();
}
}
......
......@@ -70,11 +70,6 @@ const float MAXNORM = 1000.f; // normalization of the signal basis
# endif
#endif
// the vectorized version does not work with the cygwin gcc compiler (to be checked!)
#if defined(USE_SSE_VERSION) && (OS_TYPE==OS_CYGWIN)
# undef USE_SSE_VERSION
#endif
#define USE_NETCHARGES // to use the net charge signals in the grid search
#define USE_CORETRACE // to use also the core signal in the grid search
......
......@@ -58,17 +58,13 @@ int SignalBasis::ReadBasis(std::string fname, bool keep)
#endif
fseek(ofp1, 0, SEEK_SET);
cout << "Size of " << theFileName << " is " << fSize << " bytes" << endl;
// tis fragment kept as a reminder
//#if OS_TYPE == OS_WINDOWS
// // positioning at the end of file and calling ftell does not work in windows for large files
// struct __stat64 filestatus;
// _stat64( theFileName.c_str(), &filestatus );
// fSize = (size_t)filestatus.st_size;
//#elif OS_TYPE == OS_CYGWIN
// // not working
// struct stat filestatus;
// stat( theFileName.c_str(), &filestatus );
// fSize = filestatus.st_size;
//#else
// // nothing to do in Linux 64 bit
//#endif
......
......@@ -51,8 +51,6 @@ using namespace ADF;
const int specLenE = 32*1024;
const int rangeADC = 1<<14;
const int tStampBuffSize = 2048;
CrystalProducerATCA::CrystalProducerATCA():
DAQ_NFILE(0), DAQ_NMEZZ(0), ANA_NSEGS(0),
FA(NULL), MZ(NULL), CC(NULL), PR(NULL), mezzFound(NULL), mezzToGet(0),
......@@ -70,9 +68,8 @@ tStampErr(0), tStampNew(0), tStampOld(0)
library_timeout = 0;
fpProdTstampDiff = NULL;
fProdTstampDiffBuff = NULL;
fProdTstampDiffCount = 0;
bWriteTstampDiff = false;
sTstampDiff = NULL;
fUseMultiHist = true;
#ifdef CRP_MULTIHIST
......@@ -87,15 +84,9 @@ CrystalProducerATCA::~CrystalProducerATCA()
{
cServer.Finish();
if(doWriteTstampDiff) {
if(fpProdTstampDiff) {
if(fProdTstampDiffCount)
fwrite(fProdTstampDiffBuff, sizeof(UInt_t), fProdTstampDiffCount, fpProdTstampDiff);
fclose(fpProdTstampDiff);
}
}
if(fProdTstampDiffBuff)
delete [] fProdTstampDiffBuff;
if(bWriteTstampDiff && sTstampDiff)
delete sTstampDiff;
sTstampDiff = NULL;
for(int nn = 0; nn < CrystalInterface::kNbSegments; nn++ )
delete [] SegmentTraces[nn];
......@@ -158,6 +149,7 @@ Int_t CrystalProducerATCA::AlgoSpecificInitialise()
if(!InitATCA(writeDataMask&1)) {
return 120;
}
writeDataMask &= ~1; // switch off the first bit to call WriteOriginalData() only if needed
if(fWriteDataMaxAmpl<=fWriteDataMinAmpl)
fWriteDataMaxAmpl = kMaxInt_t; // Int_t(UInt_t(~0)>>1) in ADFConfig.h
......@@ -247,23 +239,11 @@ Int_t CrystalProducerATCA::AlgoSpecificInitialise()
fProdBaseCount = 0;
}
fpProdTstampDiff = NULL;
fProdTstampDiffBuff = NULL;
doWriteTstampDiff = (writeDataMask & 32) != 0;
if(doWriteTstampDiff) {
writeDataMask &= 0xFFFFFFDF; // turn off the bit
std::ostringstream filename;
filename << "event_tstdiff.bdat";
fnProdTstampDiff = fOdirPrefix+filename.str();
cout << "Opening timestamp difference file " << fnProdTstampDiff << endl;
fpProdTstampDiff = fopen(fnProdTstampDiff.c_str(), "wb");
if(!fpProdTstampDiff) {
cout << "Error: could not open " << fnProdTstampDiff << endl;
return 1;
}
fProdTstampDiffBuff = new UInt_t[tStampBuffSize];
bWriteTstampDiff = (writeDataMask&32) != 0;
if(bWriteTstampDiff) {
writeDataMask &= ~32; // switch off the bit this part managed by Process(), not by WriteOriginalData()
sTstampDiff = new sAppend<UInt_t>(fOdirPrefix+"event_tstdiff.bdat", 2048);
}
fProdTstampDiffCount = 0;
File_Finished = false;
bStartCalled = false;
......@@ -388,9 +368,9 @@ UInt_t CrystalProducerATCA::ProcessBlock (ADF::FrameBlock &outBlock)
used_size_of_output_buffer = UInt_t(outBlock.GetSize());
// save original data to disk in various formats
if(writeDataMask&0xFFFFFFDE) { // b=1 and b=32 not relevant
error_code = WriteOriginalData(evnumber, timestamp);
// save original data to disk in various formats (writeDataMask tested only for 2,4,8,16)
if(writeDataMask) {
error_code = WriteOriginalData(evnumber, timestamp); // writeDataMask tested only for 2,4,8,16
if(error_code) {
LOCK_COUT;
Log.SetProcessMethod("CrystalProducerATCA::process_block");
......@@ -574,13 +554,34 @@ Int_t CrystalProducerATCA::Process()
}
}
if(ProdSpec_Tstd) {
if(tStampOld) {
if(tStampOld) { // not for the first event
UInt_t tstdiff = UInt_t((timestamp - tStampOld) & 0xFFFFFFFF);
ProdSpec_Tstd->Incr(tstdiff/100); // assuming 100 Ms/s
}
}
#endif //CRP_MULTIHIST
// this part placed here (instead being in WriteOriginalData()) so as to execute for all events
if(bWriteTstampDiff) {
if(tStampOld == 0) {
#if 1
// seconds and fraction of seconds of first timestamp, assuming 100 Ms/s
sTstampDiff->add(UInt_t(timestamp/100000000));
sTstampDiff->add(UInt_t(timestamp-100000000*(timestamp/100000000)));
#else
// time stamp of first event, written in little endian
sTstampDiff->add(UInt_t(timestamp & 0xFFFFFFFF));
sTstampDiff->add(UInt_t(timestamp >> 32));
#endif
}
else {
ULong64_t tstdiff = timestamp - tStampOld;
sTstampDiff->add(UInt_t(tstdiff & 0xFFFFFFFF));
}
}
tStampOld = timestamp;
int rval = 0;
if(fWriteNumTraces > 0) {
......@@ -593,13 +594,6 @@ Int_t CrystalProducerATCA::Process()
rval |= 2;
}
if(doWriteTstampDiff) {
if( WriteTstampDiff() )
rval |= 4;
}
tStampOld = timestamp;
return rval;
}
......@@ -698,39 +692,6 @@ int CrystalProducerATCA::WriteBaselines()
return (nwritten != vLen) ? 1 : 0;
}
int CrystalProducerATCA::WriteTstampDiff()
{
if(tStampOld == 0) {
fProdTstampDiffCount = 0;
#if 1
// seconds and fraction of seconds of first timestamp, assuming 100 Ms/s
fProdTstampDiffBuff[fProdTstampDiffCount++] = (int)(timestamp/100000000);
fProdTstampDiffBuff[fProdTstampDiffCount++] = (int)(timestamp-100000000*(timestamp/100000000));
#else
// time stamp of first event, written in little endian
fProdTstampDiffBuff[fProdTstampDiffCount++] = UInt_t(timestamp & 0xFFFFFFFF);
fProdTstampDiffBuff[fProdTstampDiffCount++] = UInt_t(timestamp >> 32);
#endif
return 0;
}
ULong64_t tstdiff = timestamp - tStampOld;
fProdTstampDiffBuff[fProdTstampDiffCount++] = UInt_t(tstdiff & 0xFFFFFFFF);
if(fProdTstampDiffCount == tStampBuffSize) {
if(fwrite(fProdTstampDiffBuff, sizeof(UInt_t), tStampBuffSize, fpProdTstampDiff) != tStampBuffSize) {
cout << "Error writing " << fnProdTstampDiff << " ==> disabled " << endl;
fclose(fpProdTstampDiff);
fpProdTstampDiff = NULL;
doWriteTstampDiff = false;
return 1;
}
fProdTstampDiffCount = 0;
}
return 0;
}
bool CrystalProducerATCA::Decodesetup(std::string setupFile, std::string odirPrefix, bool verbose)
{
int ii, nn;
......
......@@ -31,7 +31,7 @@ private:
unsigned int wWritten[5];
bool bSync; // whether to synchronize the different files
bool bStatistics; // whether to produce delta-statistics of input mezzanines
bool bStatistics; // whether to produce delta-statistics of input mezzanines (still enabled manually in the constructor)
int nfiles; // number of files to analyse in sequence
int fnstep; // step to increment or decrement filename
bool bStartCalled;
......@@ -51,7 +51,7 @@ private:
unsigned long long tStampErr; // used by the local event builder
unsigned long long tStampNew; // used by the local event builder
unsigned long long tStampOld; // to build the time-stamp difference
unsigned long long tStampOld; // to build the time-stamp difference, managed by Process()
bool bReaFromFile; // If true read raw data from file else, from what says CrystalProducerATCA.conf
......@@ -136,11 +136,8 @@ public:
FILE *fpProdBases;
UInt_t fProdBaseCount;
Bool_t doWriteTstampDiff;
std::string fnProdTstampDiff;
FILE *fpProdTstampDiff;
UInt_t *fProdTstampDiffBuff;
UInt_t fProdTstampDiffCount;
Bool_t bWriteTstampDiff;
sAppend<UInt_t> *sTstampDiff;
#ifdef CRP_MULTIHIST
MultiHist<unsigned int> *ProdSpec_Ampl;
......@@ -173,7 +170,6 @@ public:
int WriteTraces();
int WriteBaselines();
int WriteTstampDiff();
int CopyEventTags(unsigned short *vv) {
vv[0] = (unsigned short)((evnumber )&0xFFFF);
......
......@@ -12,8 +12,6 @@ using namespace std;
const int EVMOD = 10000; // writing statistics spectra after so many events
#include <fcntl.h>
//#define WRITEORIGINAL
//#define ALLPRINTS
#if OS_TYPE == OS_LINUX
# include <unistd.h>
......@@ -25,9 +23,6 @@ const int EVMOD = 10000; // writing statistics spectra after so many events
#ifdef PCI_EXPRESS
# include "xdev.h"
#endif
#elif OS_TYPE == OS_CYGWIN
# include <sys/types.h>
# include <unistd.h>
#elif OS_TYPE == OS_WINDOWS
# include <io.h>
#elif OS_TYPE == OS_APPLE
......@@ -41,7 +36,7 @@ const int EVMOD = 10000; // writing statistics spectra after so many events
# include "xdev.h"
#endif
#else
# error OS_TYPE should be either OS_LINUX or OS_WINDOWS or OS_CYGWIN
# error OS_TYPE should be either OS_LINUX or OS_WINDOWS
#endif
using namespace std;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment