Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mbreisch authored Jan 11, 2021
1 parent b423203 commit 30a4ccc
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 117 deletions.
63 changes: 52 additions & 11 deletions include/ACC.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ACC
void emptyUsbLine(); //attempting to remove the crashes due to non-empty USB lines at startup.
void writeErrorLog(string errorMsg);
void writePsecData(ofstream& d, vector<int> boardsReadyForRead);
void writeRawDataToFile(vector<unsigned short> buffer, ofstream& d);
void writeRawDataToFile(vector<unsigned short> buffer, string rawfn);
//-----short usb send functions. found
//-----at the end of the cpp file.
void setHardwareTrigSrc(int src, unsigned int boardMask = 0xFF);
Expand All @@ -60,11 +60,45 @@ class ACC
stdUSB* getUsbStream(); //returns the private usb object

//Set functions for trigger
void setDetectionMode(int in){detectionMode = in;}
void setInvertMode(int in){invertMode = in;}
void setChCoin(unsigned int in){ChCoin = in;}
void setEnableCoin(int in){enableCoin = in;}
void setThreshold(int in){threshold = in;}
void setDetectionMode(int in, int source)
{
if(source==2)
{
ACC_detection_mode = in;
}else if(source==3)
{
ACDC_detection_mode = in;
}else if(source==4)
{
SELF_detection_mode = in;
}
}

void setSign(int in, int source)
{
if(source==0)
{
ACC_sign = in;
}else if(source==1)
{
ACDC_sign = in;
}else if(source==2)
{
SELF_sign = in;
}
}

void setNumChCoin(unsigned int in){SELF_number_channel_coincidence = in;}

void setEnableCoin(int in){SELF_coincidence_onoff = in;}

void setThreshold(unsigned int in){SELF_threshold = in;}

void setPsecChipMask(vector<unsigned int> in){SELF_psec_channel_mask = in;}
void setPsecChannelMask(vector<unsigned int> in){SELF_psec_chip_mask = in;}

void setValidationWindow(unsigned int in){validation_window=in;}

void setTriggermode(int in){trigMode = in;}
int getTriggermode(){return trigMode;}

Expand All @@ -78,12 +112,19 @@ class ACC
vector<unsigned short> lastAccBuffer; //most recently received ACC buffer
vector<int> alignedAcdcIndices; //number relative to ACC index (RJ45 port)
vector<ACDC*> acdcs; //a vector of active acdc boards.
int detectionMode;
int invertMode;
int enableCoin;
int ACC_detection_mode;
int ACC_sign;
int ACDC_detection_mode;
int ACDC_sign;
int SELF_detection_mode;
int SELF_sign;
int SELF_coincidence_onoff;
int trigMode;
unsigned int ChCoin;
unsigned int threshold;
vector<unsigned int> SELF_psec_channel_mask;
vector<unsigned int> SELF_psec_chip_mask;
unsigned int SELF_number_channel_coincidence;
unsigned int SELF_threshold;
unsigned int validation_window;
map<int, map<int, vector<double>>> map_data;
map<int, map<string, unsigned short>> map_meta;

Expand Down
131 changes: 68 additions & 63 deletions lib/ACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,7 @@ int ACC::readAcdcBuffers(bool raw, string timestamp)
if(raw==true)
{
string rawfn = outfilename + "Raw_" + timestamp + "_b" + to_string(bi) + ".txt";
ofstream rawofs(rawfn.c_str(), ios::app); //trunc overwrites
writeRawDataToFile(acdc_buffer, rawofs);
writeRawDataToFile(acdc_buffer, rawfn);
return 0;
}

Expand Down Expand Up @@ -662,8 +661,20 @@ int ACC::listenForAcdcData(int trigMode, bool raw, string timestamp)
//time the listen fuction
now = chrono::steady_clock::now();
if(chrono::duration_cast<chrono::seconds>(now - lastPrint) > printDuration)
{
cout << "Have been waiting for a trigger for " << chrono::duration_cast<chrono::seconds>(now - start).count() << " seconds" << endl;
{
string err_msg = "Have been waiting for a trigger for ";
err_msg += to_string(chrono::duration_cast<chrono::seconds>(now - start).count());
err_msg += " seconds";
writeErrorLog(err_msg);
for(int i=0; i<MAX_NUM_BOARDS; i++)
{
string err_msg = "Buffer for board ";
err_msg += to_string(i);
err_msg += " has ";
err_msg += to_string(lastAccBuffer.at(16+i));
err_msg += " words";
writeErrorLog(err_msg);
}
lastPrint = chrono::steady_clock::now();
}
if(chrono::duration_cast<chrono::seconds>(now - start) > timeoutDuration)
Expand All @@ -683,7 +694,7 @@ int ACC::listenForAcdcData(int trigMode, bool raw, string timestamp)
bool usbcheck = usb->sendData(command);
if(usbcheck==false)
{
cout << "Emptying the usb lines" << endl;
writeErrorLog("Emptying the usb lines");
emptyUsbLine();
}

Expand Down Expand Up @@ -763,8 +774,7 @@ int ACC::listenForAcdcData(int trigMode, bool raw, string timestamp)
if(raw==true)
{
string rawfn = outfilename + "Raw_" + timestamp + "_b" + to_string(bi) + ".txt";
ofstream rawofs(rawfn.c_str(), ios::app); //trunc overwrites
writeRawDataToFile(acdc_buffer, rawofs);
writeRawDataToFile(acdc_buffer, rawfn);
return 0;
}

Expand Down Expand Up @@ -861,76 +871,62 @@ int ACC::initializeForDataReadout(int trigMode, unsigned int boardMask, int cali
setHardwareTrigSrc(trigMode,boardMask);

command = 0xFFB30000;
command = (command & (command | (boardMask << 24))) | invertMode;
command = (command & (command | (boardMask << 24))) | ACC_sign;
usb->sendData(command);
command = 0xFFB31000;
command = (command & (command | (boardMask << 24))) | detectionMode;
command = (command & (command | (boardMask << 24))) | ACC_detection_mode;
usb->sendData(command);
break;
case 3: //SMA trigger ACDC
setHardwareTrigSrc(trigMode,boardMask);

command = 0xFFB20000;
command = (command & (command | (boardMask << 24))) | invertMode;
command = (command & (command | (boardMask << 24))) | ACDC_sign;
usb->sendData(command);

command = 0xFFB21000;
command = (command & (command | (boardMask << 24))) | detectionMode;
command = (command & (command | (boardMask << 24))) | ACDC_detection_mode;
usb->sendData(command);
break;
case 4: //Self trigger
setHardwareTrigSrc(trigMode,boardMask);

command = 0xFFB10000;
for(int masknum=0; masknum<5; masknum++)
{
command = (command & (command | (boardMask << 24))) | (masknum << 12) | 0xFF;
usb->sendData(command);
}

command = 0xFFB15000;
command = command | ChCoin;
usb->sendData(command);

command = 0xFFB16000;
command = command | invertMode;
usb->sendData(command);

command = 0xFFB17000;
command = command | detectionMode;
usb->sendData(command);

command = 0xFFB18000;
command = command | enableCoin;
usb->sendData(command);

command = 0xFFA60000;
command = command | (0x1F << 12) | threshold;
usb->sendData(command);

goto selfsetup;
break;
case 5: //Self trigger with SMA validation on ACC
setHardwareTrigSrc(trigMode,boardMask);

command = 0xFFB31001;
command = 0xFFB30000;
command = command | ACC_sign;
usb->sendData(command);

command = 0xFFB31000;
command = command | ACC_detection_mode;
usb->sendData(command);

command = 0xFFB40000;
usb->sendData(command);
command = 0xFFB41280;
command = 0xFFB41000;
command = command | validation_window;
usb->sendData(command);

goto selfsetup;
break;
case 6: //Self trigger with SMA validation on ACDC
setHardwareTrigSrc(trigMode,boardMask);

command = 0xFFB31001;
command = 0xFFB20000;
command = command | ACDC_sign;
usb->sendData(command);

command = 0xFFB21000;
command = command | ACDC_detection_mode;
usb->sendData(command);

command = 0xFFB40000;
usb->sendData(command);
command = 0xFFB41280;
command = 0xFFB41000;
command = command | validation_window;
usb->sendData(command);

goto selfsetup;
Expand All @@ -940,74 +936,82 @@ int ACC::initializeForDataReadout(int trigMode, unsigned int boardMask, int cali

command = 0xFFB40000;
usb->sendData(command);
command = 0xFFB41280;
command = 0xFFB41000;
command = command | validation_window;
usb->sendData(command);

command = 0xFFB20000;
command = (command & (command | (boardMask << 24))) | invertMode;
command = (command & (command | (boardMask << 24))) | ACDC_sign;
usb->sendData(command);
command = 0xFFB21000;
command = (command & (command | (boardMask << 24))) | detectionMode;
command = (command & (command | (boardMask << 24))) | ACDC_detection_mode;
usb->sendData(command);

command = 0xFFB30000;
command = (command & (command | (boardMask << 24))) | invertMode;
command = (command & (command | (boardMask << 24))) | ACC_sign;
usb->sendData(command);
command = 0xFFB31000;
command = (command & (command | (boardMask << 24))) | detectionMode;
command = (command & (command | (boardMask << 24))) | ACC_detection_mode;
usb->sendData(command);

break;
case 8:
setHardwareTrigSrc(trigMode,boardMask);

command = 0xFFB40000;
usb->sendData(command);
command = 0xFFB41280;
command = 0xFFB41000;
command = command | validation_window;
usb->sendData(command);

command = 0xFFB20000;
command = (command & (command | (boardMask << 24))) | invertMode;
command = (command & (command | (boardMask << 24))) | ACDC_sign;
usb->sendData(command);
command = 0xFFB21000;
command = (command & (command | (boardMask << 24))) | detectionMode;
command = (command & (command | (boardMask << 24))) | ACDC_detection_mode;
usb->sendData(command);

command = 0xFFB30000;
command = (command & (command | (boardMask << 24))) | invertMode;
command = (command & (command | (boardMask << 24))) | ACC_sign;
usb->sendData(command);
command = 0xFFB31000;
command = (command & (command | (boardMask << 24))) | detectionMode;
command = (command & (command | (boardMask << 24))) | ACC_detection_mode;
usb->sendData(command);

break;
default: // ERROR case
writeErrorLog("Specified trigger is not known!");
break;
selfsetup:
command = 0xFFB10000;
for(int masknum=0; masknum<5; masknum++)
if(SELF_psec_chip_mask.size()!=SELF_psec_channel_mask.size())
{
command = (command & (command | (boardMask << 24))) | (masknum << 12) | 0xFF;
writeErrorLog("Selftrigger mask are not set correct!");
}
for(int i=0; i<(int)SELF_psec_chip_mask.size(); i++)
{
command = (command & (command | (boardMask << 24))) | (SELF_psec_chip_mask[i] << 12) | SELF_psec_channel_mask[i];
usb->sendData(command);
}

command = 0xFFB15000;
command = command | ChCoin;
usb->sendData(command);

command = 0xFFB16000;
command = command | invertMode;
command = command | SELF_sign;
usb->sendData(command);

command = 0xFFB17000;
command = command | detectionMode;
command = command | SELF_detection_mode;
usb->sendData(command);

command = 0xFFB15000;
command = command | SELF_number_channel_coincidence;
usb->sendData(command);

command = 0xFFB18000;
command = command | enableCoin;
command = command | SELF_coincidence_onoff;
usb->sendData(command);

command = 0xFFA60000;
command = command | (0x1F << 12) | threshold;
command = command | (0x1F << 12) | SELF_threshold;
usb->sendData(command);
}

Expand Down Expand Up @@ -1149,8 +1153,9 @@ void ACC::writeErrorLog(string errorMsg)

//writes data from the presently stored event
// to file assuming file has header already
void ACC::writeRawDataToFile(vector<unsigned short> buffer, ofstream& d)
void ACC::writeRawDataToFile(vector<unsigned short> buffer, string rawfn)
{
ofstream d(rawfn.c_str(), ios::app);
for(unsigned short k: buffer)
{
d << hex << k << " ";
Expand Down
Loading

0 comments on commit 30a4ccc

Please sign in to comment.