9 #include "art/Framework/Core/EDProducer.h"
10 #include "art/Framework/Services/Registry/ServiceHandle.h"
11 #include "art/Persistency/Common/PtrMaker.h"
12 #include "art/Utilities/ToolMacros.h"
13 #include "art/Utilities/make_tool.h"
14 #include "cetlib/cpu_timer.h"
15 #include "fhiclcpp/ParameterSet.h"
16 #include "messagefacility/MessageLogger/MessageLogger.h"
88 int GetDataset(
const std::string&,
const std::string&,
const std::string&,
Dataset&)
const;
96 fNothing = pset.get<uint32_t>(
"Nothing");
116 const int timeout(200);
117 std::string dburl = url +
"&t=" + dataType;
119 dataSet = getDataWithTimeout(dburl.data(),name.data(),timeout,&
error);
122 std::string errorMsg =
"Database access GetDataset failed with error " +
std::to_string(error) +
"\nDB url: "
123 + dburl +
", name: " + name +
", type: " + dataType;
124 std::cout <<
"****> Database retrieval error, code: " << error << std::endl;
125 throw std::runtime_error(errorMsg);
134 const int timeout(200);
136 dataSet = getDataWithTimeout(url.c_str(),name.c_str(),timeout,&
error);
139 std::string errorMsg =
"Database access GetDataset failed with error " +
std::to_string(error) +
"\nurl: "
140 + url +
", name: " +
name;
141 std::cout <<
"****> Database retrieval error, code: " << error << std::endl;
142 throw std::runtime_error(errorMsg);
156 const unsigned int tpcIdentifier(0x00001000);
157 const std::string
name(
"icarus_hw_readoutboard");
158 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/QE/hw/app/SQ/query?dbname=icarus_hardware_prd");
159 const std::string dataType(
"readout_boards");
164 using FlangeIDToCrateMap = std::map<size_t,std::string>;
165 FlangeIDToCrateMap flangeIDToCrateMap;
166 flangeIDToCrateMap[19] =
"WW01T";
167 flangeIDToCrateMap[68] =
"WW01M";
168 flangeIDToCrateMap[41] =
"WW01B";
169 flangeIDToCrateMap[11] =
"WW02";
170 flangeIDToCrateMap[17] =
"WW03";
171 flangeIDToCrateMap[36] =
"WW04";
172 flangeIDToCrateMap[18] =
"WW05";
173 flangeIDToCrateMap[58] =
"WW06";
174 flangeIDToCrateMap[71] =
"WW07";
175 flangeIDToCrateMap[14] =
"WW08";
176 flangeIDToCrateMap[25] =
"WW09";
177 flangeIDToCrateMap[34] =
"WW10";
178 flangeIDToCrateMap[67] =
"WW11";
179 flangeIDToCrateMap[33] =
"WW12";
180 flangeIDToCrateMap[87] =
"WW13";
181 flangeIDToCrateMap[10] =
"WW14";
182 flangeIDToCrateMap[59] =
"WW15";
183 flangeIDToCrateMap[95] =
"WW16";
184 flangeIDToCrateMap[22] =
"WW17";
185 flangeIDToCrateMap[91] =
"WW18";
186 flangeIDToCrateMap[61] =
"WW19";
187 flangeIDToCrateMap[55] =
"WW20T";
188 flangeIDToCrateMap[97] =
"WW20M";
189 flangeIDToCrateMap[100] =
"WW20B";
190 flangeIDToCrateMap[83] =
"WE01T";
191 flangeIDToCrateMap[85] =
"WE01M";
192 flangeIDToCrateMap[7] =
"WE01B";
193 flangeIDToCrateMap[80] =
"WE02";
194 flangeIDToCrateMap[52] =
"WE03";
195 flangeIDToCrateMap[32] =
"WE04";
196 flangeIDToCrateMap[70] =
"WE05";
197 flangeIDToCrateMap[74] =
"WE06";
198 flangeIDToCrateMap[46] =
"WE07";
199 flangeIDToCrateMap[81] =
"WE08";
200 flangeIDToCrateMap[63] =
"WE09";
201 flangeIDToCrateMap[30] =
"WE10";
202 flangeIDToCrateMap[51] =
"WE11";
203 flangeIDToCrateMap[90] =
"WE12";
204 flangeIDToCrateMap[23] =
"WE13";
205 flangeIDToCrateMap[93] =
"WE14";
206 flangeIDToCrateMap[92] =
"WE15";
207 flangeIDToCrateMap[88] =
"WE16";
208 flangeIDToCrateMap[73] =
"WE17";
209 flangeIDToCrateMap[1] =
"WE18";
210 flangeIDToCrateMap[66] =
"WE19";
211 flangeIDToCrateMap[48] =
"WE20T";
212 flangeIDToCrateMap[13] =
"WE20M";
213 flangeIDToCrateMap[56] =
"WE20B";
214 flangeIDToCrateMap[94] =
"EW01T";
215 flangeIDToCrateMap[77] =
"EW01M";
216 flangeIDToCrateMap[72] =
"EW01B";
217 flangeIDToCrateMap[65] =
"EW02";
218 flangeIDToCrateMap[4] =
"EW03";
219 flangeIDToCrateMap[89] =
"EW04";
220 flangeIDToCrateMap[37] =
"EW05";
221 flangeIDToCrateMap[76] =
"EW06";
222 flangeIDToCrateMap[49] =
"EW07";
223 flangeIDToCrateMap[60] =
"EW08";
224 flangeIDToCrateMap[21] =
"EW09";
225 flangeIDToCrateMap[6] =
"EW10";
226 flangeIDToCrateMap[62] =
"EW11";
227 flangeIDToCrateMap[2] =
"EW12";
228 flangeIDToCrateMap[29] =
"EW13";
229 flangeIDToCrateMap[44] =
"EW14";
230 flangeIDToCrateMap[9] =
"EW15";
231 flangeIDToCrateMap[31] =
"EW16";
232 flangeIDToCrateMap[98] =
"EW17";
233 flangeIDToCrateMap[38] =
"EW18";
234 flangeIDToCrateMap[99] =
"EW19";
235 flangeIDToCrateMap[53] =
"EW20T";
236 flangeIDToCrateMap[82] =
"EW20M";
237 flangeIDToCrateMap[35] =
"EW20B";
238 flangeIDToCrateMap[96] =
"EE01T";
239 flangeIDToCrateMap[28] =
"EE01M";
240 flangeIDToCrateMap[16] =
"EE01T";
241 flangeIDToCrateMap[69] =
"EE02";
242 flangeIDToCrateMap[20] =
"EE02";
243 flangeIDToCrateMap[79] =
"EE02";
244 flangeIDToCrateMap[50] =
"EE02";
245 flangeIDToCrateMap[45] =
"EE02";
246 flangeIDToCrateMap[84] =
"EE02";
247 flangeIDToCrateMap[42] =
"EE02";
248 flangeIDToCrateMap[39] =
"EE02";
249 flangeIDToCrateMap[26] =
"EE02";
250 flangeIDToCrateMap[64] =
"EE02";
251 flangeIDToCrateMap[43] =
"EE02";
252 flangeIDToCrateMap[47] =
"EE02";
253 flangeIDToCrateMap[15] =
"EE02";
254 flangeIDToCrateMap[3] =
"EE02";
255 flangeIDToCrateMap[27] =
"EE02";
256 flangeIDToCrateMap[24] =
"EE02";
257 flangeIDToCrateMap[40] =
"EE02";
258 flangeIDToCrateMap[75] =
"EE02";
259 flangeIDToCrateMap[86] =
"EE20T";
260 flangeIDToCrateMap[54] =
"EE20M";
261 flangeIDToCrateMap[8] =
"EE20B";
263 if (error)
throw(std::exception());
266 for(
int row = 1;
row < getNtuples(dataset);
row++)
269 Tuple tuple = getTuple(dataset,
row);
274 char fragmentBuffer[16];
275 getStringValue(tuple, 8, fragmentBuffer,
sizeof(fragmentBuffer), &error);
276 if (error)
throw std::runtime_error(
"Encountered error in trying to recover FragmentID from database");
277 std::string fragmentIDString(fragmentBuffer,4);
278 unsigned int fragmentID = std::stol(fragmentIDString,
nullptr,16);
279 if (!(fragmentID & tpcIdentifier))
continue;
280 if (fragmentBoardMap.find(fragmentID) == fragmentBoardMap.end())
282 unsigned int flangeID = getLongValue(tuple, 1, &error);
283 if (error)
throw std::runtime_error(
"Encountered error in trying to recover Board Flange ID from database");
284 fragmentBoardMap[fragmentID].first = flangeIDToCrateMap[flangeID];
286 unsigned int readoutID = getLongValue(tuple, 0, &error);
287 if (error)
throw std::runtime_error(
"Encountered error in trying to recover Board ReadoutID from database");
288 fragmentBoardMap[fragmentID].second.emplace_back(readoutID);
305 const std::string
name(
"icarus_hardware_prd");
306 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/QE/hw/app/SQ/query?dbname=icarus_hardware_prd");
307 const std::string dataType(
"daq_channels");
312 if (error)
throw std::runtime_error(
"Encountered error accessing the database with GetDataset");
314 for(
int row = 1;
row < getNtuples(dataset);
row++)
317 Tuple tuple = getTuple(dataset,
row);
320 unsigned int readoutBoardID = getLongValue(tuple, 2, &error);
321 if (error)
throw std::runtime_error(
"Encountered error when trying to read Board ReadoutID");
322 if (rbChanMap.find(readoutBoardID) == rbChanMap.end())
324 unsigned int readoutBoardSlot = getLongValue(tuple, 4, &error);
325 if (error)
throw std::runtime_error(
"Encountered error when trying to read Board Readout slot");
326 rbChanMap[readoutBoardID].first = readoutBoardSlot;
329 unsigned int channelNum = getLongValue(tuple, 5, &error);
330 if (error)
throw std::runtime_error(
"Encountered error when trying to read channel number");
331 unsigned int channelID = getLongValue(tuple, 0, &error);
332 if (error)
throw std::runtime_error(
"Encountered error when recovering the channel ID list");
334 char fragmentBuffer[16];
335 getStringValue(tuple, 10, fragmentBuffer,
sizeof(fragmentBuffer), &error);
336 if (error)
throw std::runtime_error(
"Encountered error when trying to read plane type");
338 for(
size_t charIdx = 0; charIdx <
sizeof(fragmentBuffer); charIdx++) fragmentBuffer[charIdx] = tolower(fragmentBuffer[charIdx]);
339 unsigned int plane(3);
340 if (strstr(fragmentBuffer,
"collection")) plane = 2;
341 else if (strstr(fragmentBuffer,
"induction 2")) plane = 1;
342 else if (strstr(fragmentBuffer,
"induction 1")) plane = 0;
343 if (plane > 2)
std::cout <<
"YIKES!!! Plane is " << plane <<
" for channel " << channelID <<
" with type " << std::string(fragmentBuffer) << std::endl;
344 rbChanMap[readoutBoardID].second[channelNum] =
ChannelPlanePair(channelID,plane);
355 fragmentToDigitizerChannelMap.clear();
357 const std::string
name(
"Pmt_placement");
358 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/QE/hw/app/SQ/query?dbname=icarus_hardware_prd");
359 const std::string dataType(
"pmt_placements");
364 if (error)
throw(std::exception());
367 for(
int row = 1;
row < getNtuples(dataset);
row++)
370 Tuple tuple = getTuple(dataset,
row);
373 char digitizerBuffer[10];
375 getStringValue(tuple, 8, digitizerBuffer,
sizeof(digitizerBuffer), &error);
376 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the PMT digitizer label");
377 std::string digitizerLabel(digitizerBuffer, 8);
379 unsigned fragmentID = getLongValue(tuple, 18, &error);
380 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the PMT fragment id");
382 unsigned int digitizerChannelNo = getLongValue(tuple, 9, &error);
383 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the PMT digitizer channel number");
385 unsigned int channelID = getLongValue(tuple, 17, &error);
386 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the PMT channel ID");
388 fragmentToDigitizerChannelMap[fragmentID].emplace_back(digitizerChannelNo,channelID);
402 crtChannelIDToHWtoSimMacAddressPairMap.clear();
404 const std::string
name(
"Feb_channels");
405 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/QE/hw/app/SQ/query?dbname=icarus_hardware_prd");
406 const std::string dataType(
"feb_channels");
411 if (error)
throw(std::exception());
414 for(
int row = 1;
row < getNtuples(dataset);
row++)
417 Tuple tuple = getTuple(dataset,
row);
421 unsigned int simmacaddress = getLongValue(tuple, 11, &error);
422 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the CRT simmacaddress");
424 unsigned int hwmacaddress = getLongValue(tuple, 12, &error);
425 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the CRT hwmacaddress");
427 unsigned int channelID = getLongValue(tuple, 10, &error);
428 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the CRT channel ID");
430 crtChannelIDToHWtoSimMacAddressPairMap[channelID]=std::make_pair(hwmacaddress,simmacaddress);
444 topcrtHWtoSimMacAddressPairMap.clear();
446 const std::string
name(
"topcrt_febs");
447 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/QE/hw/app/SQ/query?dbname=icarus_hardware_prd");
448 const std::string dataType(
"crtfeb");
453 if (error)
throw(std::exception());
456 for(
int row = 1;
row < getNtuples(dataset);
row++)
459 Tuple tuple = getTuple(dataset,
row);
463 unsigned int simmacaddress = getLongValue(tuple, 41, &error);
464 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the CRT simmacaddress");
466 unsigned int hwmacaddress = getLongValue(tuple, 3, &error);
467 if (error)
throw std::runtime_error(
"Encountered error when trying to recover the CRT hwmacaddress");
470 topcrtHWtoSimMacAddressPairMap[hwmacaddress] = simmacaddress;
484 const std::string
name(
"SideCRT_calibration_data");
485 const std::string dburl(
"https://dbdata0vm.fnal.gov:9443/icarus_con_prod/app/data?f=crt_gain_reco_data&t=1638918270");
490 { fprintf(stderr,
"error code=%d\n", error); perror(
"error message"); }
491 if (getHTTPstatus(ds) != 200)
492 { fprintf(stderr,
"HTTP code=%ld, message: '%s'\n", getHTTPstatus(ds), getHTTPmessage(ds)); }
496 int nrows = getNtuples(ds);
500 tup = getTuple(ds,
rows);
501 ncols = getNfields(tup);
502 if(ncols <5)
continue;
505 mac5 = (int)getDoubleValue(tup,1,&err);
506 chan = (int)getDoubleValue(tup,2,&err);
507 gain = getDoubleValue(tup,3,&err);
508 ped = getDoubleValue(tup,4,&err);
510 sideCRTChannelToCalibrationMap.insert(std::make_pair(std::make_pair(mac5,chan), std::make_pair(gain,ped)));
514 else releaseTuple(tup);
virtual int BuildTPCFragmentIDToReadoutIDMap(TPCFragmentIDToReadoutIDMap &) const override
Define the returned data structures for a mapping between TPC Fragment IDs and the related crate and ...
int GetCRTCaldata(const std::string &, const std::string &, Dataset &) const
ChannelMapPostGres(fhicl::ParameterSet const &pset)
Constructor.
EResult err(const char *call)
This provides an art tool interface definition for tools handle the channel mapping The idea is to be...
std::pair< unsigned int, unsigned int > ChannelPlanePair
Define the returned data structures for a mapping between TPC readout boards and the channel informat...
std::map< unsigned int, CRTHWtoSimMacAddressPair > CRTChannelIDToHWtoSimMacAddressPairMap
virtual int BuildFragmentToDigitizerChannelMap(FragmentToDigitizerChannelMap &) const override
Define the returned data structures for a mapping between PMT Fragment IDs and the related crate and ...
std::map< unsigned int, SlotChannelVecPair > TPCReadoutBoardToChannelMap
virtual int BuildCRTChannelIDToHWtoSimMacAddressPairMap(CRTChannelIDToHWtoSimMacAddressPairMap &) const override
Define the returned data structures for a mapping between CRT hardware mac_address to the simulated m...
ChannelMapPostGres class definiton.
~ChannelMapPostGres()
Destructor.
int GetDataset(const std::string &, const std::string &, const std::string &, Dataset &) const
virtual int BuildTPCReadoutBoardToChannelMap(TPCReadoutBoardToChannelMap &) const override
Define the returned data structures for a mapping between TPC readout boards and the channel informat...
std::string to_string(WindowPattern const &pattern)
std::map< SideCRTMac5ToChannelPair, SideCRTGainToPedPair > SideCRTChannelToCalibrationMap
const unsigned int CHANNELSPERBOARD
std::map< unsigned int, CrateNameReadoutIDPair > TPCFragmentIDToReadoutIDMap
virtual int BuildSideCRTCalibrationMap(SideCRTChannelToCalibrationMap &) const override
Define the returned data structures for a mapping between Side CRT Channels and their calibration val...
std::map< size_t, DigitizerChannelChannelIDPairVec > FragmentToDigitizerChannelMap
virtual int BuildTopCRTHWtoSimMacAddressPairMap(TopCRTHWtoSimMacAddressPairMap &) const override
Top CRT harware mac5 to software mac5 relation.
IChannelMapping interface class definiton.
BEGIN_PROLOG could also be cout
std::map< unsigned int, unsigned int > TopCRTHWtoSimMacAddressPairMap