1616const Utils = require ( '../../utils' ) ;
1717const { rctData } = require ( '../../config/configProvider.js' ) ;
1818
19+ /**
20+ * PERIOD_NAME_REGEX is a regular expression for examining
21+ * whether given string can be considered period name, e.g. LHC22o is a period name.
22+ * It is defined as ^LHC\d\d[a-zA-Z]+
23+ * The regex can be (right) extended in order to match e.g.:
24+ * 1. data passes, e.g. LHC22o_apass1 can be matched with PERIOD_NAME_REGEX.rightExtend('_apass\\d');
25+ * 2. simulation passes, e.g. LHC21i12 can be matched with PERIOD_NAME_REGEX.rightExtend('.*');
26+ */
27+ const PERIOD_NAME_REGEX = / ^ L H C \d \d [ a - z A - Z ] + / ;
28+ const rightExtendRegEx = ( srcRegEx , suffix ) => {
29+ const extenedRegex = RegExp ( srcRegEx . source + suffix ) ;
30+ extenedRegex . rightExtend = ( _suffix ) => rightExtendRegEx ( extenedRegex , _suffix ) ;
31+ return extenedRegex ;
32+ } ;
33+ PERIOD_NAME_REGEX . rightExtend = ( suffix ) => rightExtendRegEx ( PERIOD_NAME_REGEX , suffix ) ;
34+
1935/**
2036 * Update objectData.beam_type to valid format if mapping is provided with app config
2137 * if not there is assumption that in other scenerio name is consistant with foramt '<typeA>-<typeB>'
@@ -56,7 +72,7 @@ function extractPeriodYear(name) {
5672 */
5773function extractPeriod ( name , beamType = undefined ) {
5874 const [ extractedName ] = name . split ( '_' ) ;
59- if ( ! / L H C [ 0 - 9 ] { 2 } [ a - z ] + / . test ( extractedName ) ) {
75+ if ( ! PERIOD_NAME_REGEX . test ( extractedName ) ) {
6076 throw new Error ( `Incorrect period name ${ extractedName } extracted from ${ name } ` ) ;
6177 }
6278 return {
@@ -70,4 +86,5 @@ module.exports = {
7086 mapBeamTypeToCommonFormat,
7187 extractPeriodYear,
7288 extractPeriod,
89+ PERIOD_NAME_REGEX ,
7390} ;
0 commit comments