30 inline int GetDataset(
const std::string
name,
const std::string url,
const std::string& dataType,
Dataset& dataSet)
32 const int timeout(200);
33 std::string dburl = url +
"&t=" + dataType;
37 dataSet = getDataWithTimeout(dburl.data(),name.data(),timeout,&
error);
41 std::string errorMsg =
"Database access GetDataset failed with error " +
std::to_string(error) +
"\nDB url: "
42 + dburl +
", name: " + name +
", type: " + dataType;
43 std::cout <<
"****> Database retrieval error, code: " << error << std::endl;
44 throw std::runtime_error(errorMsg);
62 const unsigned int tpcIdentifier(0x00001000);
63 const std::string
name(
"icarus_hw_readoutboard");
64 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/QE/hw/app/SQ/query?dbname=icarus_hardware_dev");
65 const std::string dataType(
"readout_boards");
72 using FlangeIDToCrateMap = std::map<size_t,std::string>;
74 FlangeIDToCrateMap flangeIDToCrateMap;
76 flangeIDToCrateMap[19] =
"WW01T";
77 flangeIDToCrateMap[68] =
"WW01M";
78 flangeIDToCrateMap[41] =
"WW01B";
79 flangeIDToCrateMap[11] =
"WW02";
80 flangeIDToCrateMap[17] =
"WW03";
81 flangeIDToCrateMap[36] =
"WW04";
82 flangeIDToCrateMap[18] =
"WW05";
83 flangeIDToCrateMap[58] =
"WW06";
84 flangeIDToCrateMap[71] =
"WW07";
85 flangeIDToCrateMap[14] =
"WW08";
86 flangeIDToCrateMap[25] =
"WW09";
87 flangeIDToCrateMap[34] =
"WW10";
88 flangeIDToCrateMap[67] =
"WW11";
89 flangeIDToCrateMap[33] =
"WW12";
90 flangeIDToCrateMap[87] =
"WW13";
91 flangeIDToCrateMap[10] =
"WW14";
92 flangeIDToCrateMap[59] =
"WW15";
93 flangeIDToCrateMap[95] =
"WW16";
94 flangeIDToCrateMap[22] =
"WW17";
95 flangeIDToCrateMap[91] =
"WW18";
96 flangeIDToCrateMap[61] =
"WW19";
97 flangeIDToCrateMap[55] =
"WW20T";
98 flangeIDToCrateMap[97] =
"WW20M";
99 flangeIDToCrateMap[100] =
"WW20B";
100 flangeIDToCrateMap[83] =
"WE01T";
101 flangeIDToCrateMap[85] =
"WE01M";
102 flangeIDToCrateMap[7] =
"WE01B";
103 flangeIDToCrateMap[80] =
"WE02";
104 flangeIDToCrateMap[52] =
"WE03";
105 flangeIDToCrateMap[32] =
"WE04";
106 flangeIDToCrateMap[70] =
"WE05";
107 flangeIDToCrateMap[74] =
"WE06";
108 flangeIDToCrateMap[46] =
"WE07";
109 flangeIDToCrateMap[81] =
"WE08";
110 flangeIDToCrateMap[63] =
"WE09";
111 flangeIDToCrateMap[30] =
"WE10";
112 flangeIDToCrateMap[51] =
"WE11";
113 flangeIDToCrateMap[90] =
"WE12";
114 flangeIDToCrateMap[23] =
"WE13";
115 flangeIDToCrateMap[93] =
"WE14";
116 flangeIDToCrateMap[92] =
"WE15";
117 flangeIDToCrateMap[88] =
"WE16";
118 flangeIDToCrateMap[73] =
"WE17";
119 flangeIDToCrateMap[1] =
"WE18";
120 flangeIDToCrateMap[66] =
"WE19";
121 flangeIDToCrateMap[48] =
"WE20T";
122 flangeIDToCrateMap[13] =
"WE20M";
123 flangeIDToCrateMap[56] =
"WE20B";
124 flangeIDToCrateMap[94] =
"EW01T";
125 flangeIDToCrateMap[77] =
"EW01M";
126 flangeIDToCrateMap[72] =
"EW01B";
127 flangeIDToCrateMap[65] =
"EW02";
128 flangeIDToCrateMap[4] =
"EW03";
129 flangeIDToCrateMap[89] =
"EW04";
130 flangeIDToCrateMap[37] =
"EW05";
131 flangeIDToCrateMap[76] =
"EW06";
132 flangeIDToCrateMap[49] =
"EW07";
133 flangeIDToCrateMap[60] =
"EW08";
134 flangeIDToCrateMap[21] =
"EW09";
135 flangeIDToCrateMap[6] =
"EW10";
136 flangeIDToCrateMap[62] =
"EW11";
137 flangeIDToCrateMap[2] =
"EW12";
138 flangeIDToCrateMap[29] =
"EW13";
139 flangeIDToCrateMap[44] =
"EW14";
140 flangeIDToCrateMap[9] =
"EW15";
141 flangeIDToCrateMap[31] =
"EW16";
142 flangeIDToCrateMap[98] =
"EW17";
143 flangeIDToCrateMap[38] =
"EW18";
144 flangeIDToCrateMap[99] =
"EW19";
145 flangeIDToCrateMap[53] =
"EW20T";
146 flangeIDToCrateMap[82] =
"EW20M";
147 flangeIDToCrateMap[35] =
"EW20B";
148 flangeIDToCrateMap[96] =
"EE01T";
149 flangeIDToCrateMap[28] =
"EE01M";
150 flangeIDToCrateMap[16] =
"EE01T";
151 flangeIDToCrateMap[69] =
"EE02";
152 flangeIDToCrateMap[20] =
"EE02";
153 flangeIDToCrateMap[79] =
"EE02";
154 flangeIDToCrateMap[50] =
"EE02";
155 flangeIDToCrateMap[45] =
"EE02";
156 flangeIDToCrateMap[84] =
"EE02";
157 flangeIDToCrateMap[42] =
"EE02";
158 flangeIDToCrateMap[39] =
"EE02";
159 flangeIDToCrateMap[26] =
"EE02";
160 flangeIDToCrateMap[64] =
"EE02";
161 flangeIDToCrateMap[43] =
"EE02";
162 flangeIDToCrateMap[47] =
"EE02";
163 flangeIDToCrateMap[15] =
"EE02";
164 flangeIDToCrateMap[3] =
"EE02";
165 flangeIDToCrateMap[27] =
"EE02";
166 flangeIDToCrateMap[24] =
"EE02";
167 flangeIDToCrateMap[40] =
"EE02";
168 flangeIDToCrateMap[75] =
"EE02";
169 flangeIDToCrateMap[86] =
"EE20T";
170 flangeIDToCrateMap[54] =
"EE20M";
171 flangeIDToCrateMap[8] =
"EE20B";
174 if (error)
throw(std::exception());
178 for(
int row = 1;
row < getNtuples(dataset);
row++)
181 Tuple tuple = getTuple(dataset,
row);
187 char fragmentBuffer[16];
189 getStringValue(tuple, 8, fragmentBuffer,
sizeof(fragmentBuffer), &error);
191 if (error)
throw std::runtime_error(
"Encountered error in trying to recover FragmentID from database");
193 std::string fragmentIDString(fragmentBuffer,4);
195 unsigned int fragmentID = std::stol(fragmentIDString,
nullptr,16);
197 if (!(fragmentID & tpcIdentifier))
continue;
199 if (fragmentBoardMap.find(fragmentID) == fragmentBoardMap.end())
201 unsigned int flangeID = getLongValue(tuple, 1, &error);
203 if (error)
throw std::runtime_error(
"Encountered error in trying to recover Board Flange ID from database");
205 fragmentBoardMap[fragmentID].first = flangeIDToCrateMap[flangeID];
208 unsigned int readoutID = getLongValue(tuple, 0, &error);
210 if (error)
throw std::runtime_error(
"Encountered error in trying to recover Board ReadoutID from database");
212 fragmentBoardMap[fragmentID].second.emplace_back(readoutID);
238 const std::string
name(
"icarus_hardware_dev");
239 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/QE/hw/app/SQ/query?dbname=icarus_hardware_dev");
240 const std::string dataType(
"daq_channels");
247 if (error)
throw std::runtime_error(
"Encountered error accessing the database with GetDataset");
250 for(
int row = 1;
row < getNtuples(dataset);
row++)
253 Tuple tuple = getTuple(dataset,
row);
257 unsigned int readoutBoardID = getLongValue(tuple, 2, &error);
259 if (error)
throw std::runtime_error(
"Encountered error when trying to read Board ReadoutID");
261 if (rbChanMap.find(readoutBoardID) == rbChanMap.end())
263 unsigned int readoutBoardSlot = getLongValue(tuple, 4, &error);
265 if (error)
throw std::runtime_error(
"Encountered error when trying to read Board Readout slot");
267 rbChanMap[readoutBoardID].first = readoutBoardSlot;
271 unsigned int channelNum = getLongValue(tuple, 5, &error);
273 if (error)
throw std::runtime_error(
"Encountered error when trying to read channel number");
275 unsigned int channelID = getLongValue(tuple, 0, &error);
277 if (error)
throw std::runtime_error(
"Encountered error when recovering the channel ID list");
280 char fragmentBuffer[16];
282 getStringValue(tuple, 10, fragmentBuffer,
sizeof(fragmentBuffer), &error);
284 if (error)
throw std::runtime_error(
"Encountered error when trying to read plane type");
287 for(
size_t charIdx = 0; charIdx <
sizeof(fragmentBuffer); charIdx++) fragmentBuffer[charIdx] = tolower(fragmentBuffer[charIdx]);
289 unsigned int plane(3);
291 if (strstr(fragmentBuffer,
"collection")) plane = 2;
292 else if (strstr(fragmentBuffer,
"induction 2")) plane = 1;
293 else if (strstr(fragmentBuffer,
"induction 1")) plane = 0;
295 if (plane > 2)
std::cout <<
"YIKES!!! Plane is " << plane <<
" for channel " << channelID <<
" with type " << std::string(fragmentBuffer) << std::endl;
297 rbChanMap[readoutBoardID].second[channelNum] =
ChannelPlanePair(channelID,plane);
312 const std::string
name(
"icarus_hw_readoutboard");
313 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/QE/hw/app/SQ/query?dbname=icarus_hardware_dev");
314 const std::string dataType =
"readout_boards";
320 fprintf(stderr,
"error code=%d\n", error); perror(
"error message");
322 if (getHTTPstatus(ds) != 200)
324 fprintf(stderr,
"HTTP code=%ld, message: '%s'\n", getHTTPstatus(ds), getHTTPmessage(ds));
330 int nrows = getNtuples(ds);
333 tup = getTuple(ds,
rows);
342 readoutboard_id = (int)getDoubleValue(tup, 0, &err);
343 if (readoutboard_id == readout_board_ID){
344 getStringValue(tup, 8 ,ss,
sizeof (ss), &err);
349 char* fragment_id =
new char[4];
350 std::strcpy(fragment_id, ss);
363 const std::string
name(
"icarus_hardware_dev");
364 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/QE/hw/app/SQ/query?dbname=icarus_hardware_dev");
365 const std::string dataType =
"daq_channels";
370 fprintf(stderr,
"error code=%d\n", error); perror(
"error message");
372 if (getHTTPstatus(ds) != 200) {
373 fprintf(stderr,
"HTTP code=%ld, message: '%s'\n", getHTTPstatus(ds), getHTTPmessage(ds));
377 std::vector<int> channelidvec;
378 int nrows = getNtuples(ds);
386 int readoutboardid = (int)getDoubleValue(tu, 2, &err);
388 if (readoutboardid == readout_board_ID){
389 channel_id = (int)getDoubleValue(tu, 0, &err);
390 channelidvec.push_back(channel_id);
409 fragmentToDigitizerChannelMap.clear();
412 const std::string
name(
"Pmt_placement");
413 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/QE/hw/app/SQ/query?dbname=icarus_hardware_dev");
414 const std::string dataType(
"pmt_placements");
421 if (error)
throw(std::exception());
425 for(
int row = 1;
row < getNtuples(dataset);
row++)
428 Tuple tuple = getTuple(dataset,
row);
432 char digitizerBuffer[10];
435 getStringValue(tuple, 8, digitizerBuffer,
sizeof(digitizerBuffer), &error);
437 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the PMT digitizer label");
439 std::string digitizerLabel(digitizerBuffer, 8);
442 unsigned fragmentID = getLongValue(tuple, 18, &error);
444 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the PMT fragment id");
447 unsigned int digitizerChannelNo = getLongValue(tuple, 9, &error);
449 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the PMT digitizer channel number");
452 unsigned int channelID = getLongValue(tuple, 17, &error);
454 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the PMT channel ID");
457 fragmentToDigitizerChannelMap[fragmentID].emplace_back(digitizerChannelNo,channelID);
473 const std::string
name(
"icarus_hw_readoutboard");
474 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/QE/hw/app/SQ/query?dbname=icarus_hardware_dev");
475 const std::string dataType(
"pmt_placements");
482 if (error)
throw(std::exception());
484 unsigned int PhysicalPMTPositionID;
485 unsigned int PMTChannelID;
489 for(
int row = 1;
row < getNtuples(dataset);
row++)
492 Tuple tuple = getTuple(dataset,
row);
497 PhysicalPMTPositionID = getLongValue(tuple, 0, &error);
499 if (error)
throw std::runtime_error(
"Encountered error when trying to read Physical PMT Position ID from database");
501 if (PhysicalPMTPositionID == pmtid) {
503 PMTChannelID = getLongValue(tuple, 17, &error);
505 if (error)
throw std::runtime_error(
"Encountered error in trying to recover Larsoft PMT Channel ID from database");
523 const std::string
name(
"icarus_hw_readoutboard");
524 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/QE/hw/app/SQ/query?dbname=icarus_hardware_dev");
525 const std::string dataType(
"pmt_placements");
532 if (error)
throw(std::exception());
534 unsigned int PMTChannelID;
538 for(
int row = 1;
row < getNtuples(dataset);
row++)
541 Tuple tuple = getTuple(dataset,
row);
545 char digitizerBuffer[10];
547 getStringValue(tuple, 8, digitizerBuffer,
sizeof(digitizerBuffer), &error);
548 std::string digitizerLabel(digitizerBuffer,
sizeof(digitizerBuffer));
550 int digitizerChannelNumber = getDoubleValue(tuple, 9, &error);
553 int matchedcharacter = digitizerLabel.compare(digitizerlabel);
562 if(matchedcharacter == 2 && digitizerChannelNumber == digitizerchannelnumber){
564 PMTChannelID = getLongValue(tuple, 17, &error);
566 if (error)
throw std::runtime_error(
"Encountered error in trying to recover Larsoft PMT Channel ID from database");
int GetDataset(const std::string name, const std::string url, const std::string &dataType, Dataset &dataSet)
int PMTChannelIDFromDigitizer(std::string digitizerlabel, int digitizerchannelnumber)
std::map< unsigned int, CrateNameReadoutIDPair > TPCFragmentIDToReadoutIDMap
int BuildTPCFragmentIDToReadoutIDMap(TPCFragmentIDToReadoutIDMap &fragmentBoardMap)
std::vector< int > Channel_ID(int readout_board_ID)
EResult err(const char *call)
std::vector< DigitizerChannelChannelIDPair > DigitizerChannelChannelIDPairVec
char * Fragment_ID(int readout_board_ID)
std::pair< size_t, size_t > DigitizerChannelChannelIDPair
std::pair< unsigned int, unsigned int > ChannelPlanePair
std::vector< unsigned int > ReadoutIDVec
std::map< size_t, DigitizerChannelChannelIDPairVec > FragmentToDigitizerChannelMap
int PMTChannelIDFromPhysicalPMTPositionID(unsigned int pmtid)
int BuildFragmentToDigitizerChannelMap(FragmentToDigitizerChannelMap &fragmentToDigitizerChannelMap)
std::string to_string(WindowPattern const &pattern)
std::pair< std::string, ReadoutIDVec > CrateNameReadoutIDPair
const unsigned int CHANNELSPERBOARD
std::pair< unsigned int, ChannelPlanePairVec > SlotChannelVecPair
std::map< unsigned int, SlotChannelVecPair > TPCReadoutBoardToChannelMap
std::vector< ChannelPlanePair > ChannelPlanePairVec
BEGIN_PROLOG could also be cout
int BuildTPCReadoutBoardToChannelMap(TPCReadoutBoardToChannelMap &rbChanMap)